- extension of normalization of equations to nonlinear equations

- mfs: new option for 'steady' and 'model' commands. Determines the equation belonging to the set of feedback variables.
  mfs = 0 => all variables are considered as feedback variables (default value)
  mfs = 1 => using only naturally normalized equation as potential recursive equations (all variables assigned to unnormalized equations are considered as feedback variable)
  mfs = 2 => adding to the set of potential recursive equation with mfs = 1 the linear equation in endogenous variable normalized (all variables assigned to nonlinear unnormalized equations are considered as feedback variable)
  mfs = 3 => adding to the set of potential recursive equation with mfs = 2 the non linear equation in endogenous variable normalized
- correction of few buggs in simulate.dll
- block_mfs_dll: new option for 'steady' command. Use simulate.dll to solve the steady state model (speedup the computation of the steady-state and the homotopy)

git-svn-id: https://www.dynare.org/svn/dynare/trunk@2866 ac1d8469-bf42-47a9-8791-bf33cf982152
time-shift
ferhat 2009-08-25 09:43:01 +00:00
parent 5d1fdab1f0
commit d32dd99210
35 changed files with 3156 additions and 4249 deletions

View File

@ -224,4 +224,7 @@ function global_initialization()
% block decomposition + minimum feedback set for steady state computation
options_.block_mfs = 0;
% block decomposition + minimum feedback set for steady state computation
% using simulate.dll
options_.block_mfs_dll = 0;

View File

@ -24,23 +24,23 @@ function model_info;
if(isfield(M_,'block_structure'))
nb_blocks=length(M_.block_structure.block);
fprintf('The model has %d equations and is decomposed in %d blocks as follow:\n',M_.endo_nbr,nb_blocks);
fprintf('==============================================================================================================\n');
fprintf('| %10s | %10s | %30s | %14s | %30s |\n','Block n°','Size','Block Type','Equation','Dependent variable');
fprintf('|============|============|================================|================|================================|\n');
fprintf('===============================================================================================================\n');
fprintf('| %10s | %10s | %30s | %14s | %31s |\n','Block n°','Size','Block Type','E quation','Dependent variable');
fprintf('|============|============|================================|================|=================================|\n');
for i=1:nb_blocks
size_block=length(M_.block_structure.block(i).equation);
if(i>1)
fprintf('|------------|------------|--------------------------------|----------------|--------------------------------|\n');
fprintf('|------------|------------|--------------------------------|----------------|---------------------------------|\n');
end;
for j=1:size_block
if(j==1)
fprintf('| %3d (%4d) | %10d | %30s | %14d | %30s |\n',i,M_.block_structure.block(i).num,size_block,Sym_type(M_.block_structure.block(i).Simulation_Type),M_.block_structure.block(i).equation(j),M_.endo_names(M_.block_structure.block(i).variable(j),:));
fprintf('| %3d (%4d) | %10d | %30s | %14d | %-6d %24s |\n',i,M_.block_structure.block(i).num,size_block,Sym_type(M_.block_structure.block(i).Simulation_Type),M_.block_structure.block(i).equation(j),M_.block_structure.block(i).variable(j),M_.endo_names(M_.block_structure.block(i).variable(j),:));
else
fprintf('| %10s | %10s | %30s | %14d | %30s |\n','','','',M_.block_structure.block(i).equation(j),M_.endo_names(M_.block_structure.block(i).variable(j),:));
fprintf('| %10s | %10s | %30s | %14d | %-6d %24s |\n','','','',M_.block_structure.block(i).equation(j),M_.block_structure.block(i).variable(j),M_.endo_names(M_.block_structure.block(i).variable(j),:));
end;
end;
end;
fprintf('==============================================================================================================\n');
fprintf('===============================================================================================================\n');
fprintf('\n');
for k=1:M_.maximum_endo_lag+M_.maximum_endo_lead+1
if(k==M_.maximum_endo_lag+1)

View File

@ -53,12 +53,12 @@ function resid(period)
addpath(M_.fname);
end;
for it_=M_.maximum_lag+1:period+M_.maximum_lag
if(options_.model_mode == 1 || options_.model_mode == 3)
z(:,it_-M_.maximum_lag) = feval(fh,oo_.endo_simul',oo_.exo_simul, M_.params, it_);
else
%if(options_.model_mode == 1 || options_.model_mode == 3)
% z(:,it_-M_.maximum_lag) = feval(fh,oo_.endo_simul',oo_.exo_simul, M_.params, it_);
%else
z(:,it_-M_.maximum_lag) = feval(fh,y(iyr0),oo_.exo_simul, M_.params, it_);
iyr0 = iyr0 + n;
end;
%end;
end
if(options_.model_mode == 1 || options_.model_mode == 3)
rmpath(M_.fname);

View File

@ -100,8 +100,42 @@ function [y, info] = solve_one_boundary(fname, y, x, params, y_index_eq, nze, pe
max_res=max(max(abs(r)));
end;
%['max_res=' num2str(max_res) ' Block_Num=' int2str(Block_Num) ' it_=' int2str(it_)]
disp(['iteration : ' int2str(iter+1) ' => ' num2str(max_res) ' time = ' int2str(it_)]);
% fjac = zeros(Blck_size, Blck_size);
% disp(['Blck_size=' int2str(Blck_size) ' it_=' int2str(it_)]);
% dh = max(abs(y(it_, y_index_eq)),options_.gstep*ones(1, Blck_size))*eps^(1/3);
% fvec = r;
% for j = 1:Blck_size
% ydh = y ;
% ydh(it_, y_index_eq(j)) = ydh(it_, y_index_eq(j)) + dh(j) ;
% [t, y1, g11, g21, g31]=feval(fname, ydh, x, params, it_, 0);
% fjac(:,j) = (t - fvec)./dh(j) ;
% end;
% diff = g1 -fjac;
% diff
% disp('g1');
% disp([num2str(g1,'%4.5f')]);
% disp('fjac');
% disp([num2str(fjac,'%4.5f')]);
% [c_max, i_c_max] = max(abs(diff));
% [l_c_max, i_r_max] = max(c_max);
% disp(['maximum element row=' int2str(i_c_max(i_r_max)) ' and column=' int2str(i_r_max) ' value = ' num2str(l_c_max)]);
% equation = i_c_max(i_r_max);
% variable = i_r_max;
% variable
% mod(variable, Blck_size)
% disp(['equation ' int2str(equation) ' and variable ' int2str(y_index_eq(variable)) ' ' M_.endo_names(y_index_eq(variable), :)]);
% disp(['g1(' int2str(equation) ', ' int2str(variable) ')=' num2str(g1(equation, variable),'%3.10f') ' fjac(' int2str(equation) ', ' int2str(variable) ')=' num2str(fjac(equation, variable), '%3.10f') ' y(' int2str(it_) ', ' int2str(variable) ')=' num2str(y(it_, variable))]);
% %return;
% %g1 = fjac;
if(verbose==1)
disp(['iteration : ' int2str(iter) ' => ' num2str(max_res) ' time = ' int2str(it_)]);
disp(['iteration : ' int2str(iter+1) ' => ' num2str(max_res) ' time = ' int2str(it_)]);
if(is_dynamic)
disp([M_.endo_names(y_index_eq,:) num2str([y(it_,y_index_eq)' r g1])]);
else
@ -118,7 +152,7 @@ function [y, info] = solve_one_boundary(fname, y, x, params, y_index_eq, nze, pe
if(~cvg)
if(iter>0)
if(~isreal(max_res) | isnan(max_res) | (max_resa<max_res && iter>1))
if(isnan(max_res))
if(isnan(max_res)| (max_resa<max_res && iter>0))
detJ=det(g1a);
if(abs(detJ)<1e-7)
max_factor=max(max(abs(g1a)));
@ -198,15 +232,23 @@ function [y, info] = solve_one_boundary(fname, y, x, params, y_index_eq, nze, pe
else
info = -Block_Num*10;
end
elseif(~is_dynamic & options_.solve_algo==2)
elseif((~is_dynamic & options_.solve_algo==2) || (is_dynamic & options_.solve_algo==4))
lambda=1;
stpmx = 100 ;
stpmax = stpmx*max([sqrt(y'*y);size(y_index_eq,2)]);
if (is_dynamic)
stpmax = stpmx*max([sqrt(y*y');size(y_index_eq,2)]);
else
stpmax = stpmx*max([sqrt(y'*y);size(y_index_eq,2)]);
end;
nn=1:size(y_index_eq,2);
g = (r'*g1)';
f = 0.5*r'*r;
p = -g1\r ;
[y,f,r,check]=lnsrch1(y,f,g,p,stpmax,fname,nn,y_index_eq,x, params, 0);
if (is_dynamic)
[y,f,r,check]=lnsrch1(y,f,g,p,stpmax,fname,nn,y_index_eq,x, params, it_, 0);
else
[y,f,r,check]=lnsrch1(y,f,g,p,stpmax,fname,nn,y_index_eq,x, params, 0);
end;
dx = ya - y(y_index_eq);
elseif(~is_dynamic & options_.solve_algo==3)
[yn,info] = csolve(@local_fname, y(y_index_eq),@local_fname,1e-6,500, x, params, y, y_index_eq, fname, 1);
@ -283,6 +325,7 @@ function [y, info] = solve_one_boundary(fname, y, x, params, y_index_eq, nze, pe
return;
end;
iter=iter+1;
max_resa = max_res;
end
end
if cvg==0

View File

@ -58,7 +58,7 @@ function y = solve_two_boundaries(fname, y, x, params, y_index, nze, periods, y_
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
global oo_ M_ T9025 T1149 T11905;
global options_ oo_ M_ T9025 T1149 T11905;
cvg=0;
iter=0;
Per_u_=0;
@ -73,11 +73,48 @@ function y = solve_two_boundaries(fname, y, x, params, y_index, nze, periods, y_
reduced = 0;
while ~(cvg==1 | iter>maxit_),
[r, y, g1, g2, g3, b]=feval(fname, y, x, params, periods, 0, y_kmin, Blck_size);
% fjac = zeros(Blck_size, Blck_size*(y_kmin_l+1+y_kmax_l));
% disp(['Blck_size=' int2str(Blck_size) ' size(y_index)=' int2str(size(y_index,2))]);
% dh = max(abs(y(y_kmin+1-y_kmin_l:y_kmin+1+y_kmax_l, y_index)),options_.gstep*ones(y_kmin_l+1+y_kmax_l, Blck_size))*eps^(1/3);
% fvec = r;
% %for i = y_kmin+1-y_kmin_l:y_kmin+1+y_kmax_l
% i = y_kmin+1;
% i
% for j = 1:Blck_size
% ydh = y ;
% ydh(i, y_index(j)) = ydh(i, y_index(j)) + dh(i, j) ;
% if(j==11 && i==2)
% disp(['y(i,y_index(11)=' int2str(y_index(11)) ')= ' num2str(y(i,y_index(11))) ' ydh(i, y_index(j))=' num2str(ydh(i, y_index(j))) ' dh(i,j)= ' num2str(dh(i,j))]);
% end;
% [t, y1, g11, g21, g31, b1]=feval(fname, ydh, x, params, periods, 0, y_kmin, Blck_size);
% fjac(:,j+(i-(y_kmin+1-y_kmin_l))*Blck_size) = (t(:, 1+y_kmin) - fvec(:, 1+y_kmin))./dh(i, j) ;
% if(j==11 && i==2)
% disp(['fjac(:,' int2str(j+(i-(y_kmin+1-y_kmin_l))*Blck_size) ')=']);
% disp([num2str(fjac(:,j+(i-(y_kmin+1-y_kmin_l))*Blck_size))]);
% end;
% end;
% % end
% %diff = g1(1:Blck_size, 1:Blck_size*(y_kmin_l+1+y_kmax_l)) -fjac;
% diff = g1(1:Blck_size, y_kmin_l*Blck_size+1:(y_kmin_l+1)*Blck_size) -fjac(1:Blck_size, y_kmin_l*Blck_size+1:(y_kmin_l+1)*Blck_size);
% disp(diff);
% [c_max, i_c_max] = max(abs(diff));
% [l_c_max, i_r_max] = max(c_max);
% disp(['maximum element row=' int2str(i_c_max(i_r_max)) ' and column=' int2str(i_r_max) ' value = ' num2str(l_c_max)]);
% equation = i_c_max(i_r_max);
% variable = i_r_max;
% variable
% disp(['equation ' int2str(equation) ' and variable ' int2str(y_index(mod(variable, Blck_size))) ' ' M_.endo_names(y_index(mod(variable, Blck_size)), :)]);
% disp(['g1(' int2str(equation) ', ' int2str(variable) ')=' num2str(g1(equation, y_kmin_l*Blck_size+variable),'%3.10f') ' fjac(' int2str(equation) ', ' int2str(variable) ')=' num2str(fjac(equation, y_kmin_l*Blck_size+variable), '%3.10f')]);
% return;
% for i=1:periods;
% disp([sprintf('%5.14f ',[T9025(i) T1149(i) T11905(i)])]);
% end;
% return;
residual = r(:,y_kmin+1:y_kmin+1+y_kmax_l);
%residual = r(:,y_kmin+1:y_kmin+1+y_kmax_l);
%num2str(residual,' %1.6f')
%jac_ = g1(1:(y_kmin)*Blck_size, 1:(y_kmin+1+y_kmax_l)*Blck_size);
%jac_
@ -87,15 +124,15 @@ function y = solve_two_boundaries(fname, y, x, params, y_index, nze, periods, y_
term2 = g1(:, (periods+y_kmin_l)*Blck_size+1:(periods+y_kmin_l+y_kmax_l)*Blck_size)*reshape(y(periods+y_kmin+1:periods+y_kmin+y_kmax_l,y_index)',1,y_kmax_l*Blck_size)';
b = b - term1 - term2;
% fid = fopen(['result' num2str(iter)],'w');
% fg1a = full(g1a);
% fprintf(fid,'%d\n',size(fg1a,1));
% fprintf(fid,'%d\n',size(fg1a,2));
% fprintf(fid,'%5.14f\n',fg1a);
% fprintf(fid,'%d\n',size(b,1));
% fprintf(fid,'%5.14f\n',b);
% fclose(fid);
% return;
% fid = fopen(['result' num2str(iter)],'w');
% fg1a = full(g1a);
% fprintf(fid,'%d\n',size(fg1a,1));
% fprintf(fid,'%d\n',size(fg1a,2));
% fprintf(fid,'%5.14f\n',fg1a);
% fprintf(fid,'%d\n',size(b,1));
% fprintf(fid,'%5.14f\n',b);
% fclose(fid);
% return;
%ipconfigb_ = b(1:(1+y_kmin)*Blck_size);
%b_

View File

@ -79,6 +79,8 @@ function steady_()
[oo_.exo_steady_state; ...
oo_.exo_det_steady_state], M_.params);
end
elseif options_.block_mfs_dll
[oo_.steady_state,check] = simulate('steady_state');
else
[oo_.steady_state,check] = dynare_solve([M_.fname '_static'],...
oo_.steady_state,...

File diff suppressed because it is too large Load Diff

View File

@ -67,8 +67,9 @@ class Interpreter : SparseMatrix
{
protected :
double pow1(double a, double b);
double log1(double a);
void compute_block_time(int Per_u_);
void simulate_a_block(int size,int type, string file_name, string bin_basename, bool Gaussian_Elimination);
bool simulate_a_block(int size,int type, string file_name, string bin_basename, bool Gaussian_Elimination, bool steady_state, int block_num);
double *T;
vector<Block_contain_type> Block_Contain;
vector<Block_type> Block;
@ -83,6 +84,7 @@ class Interpreter : SparseMatrix
double *x, *params;
//double *y, *ya, *x, *direction;
map<pair<pair<int, int> ,int>, int> IM_i;
int equation, derivative_equation, derivative_variable;
string filename;
public :
//ReadBinFile read_bin_file;
@ -90,7 +92,7 @@ class Interpreter : SparseMatrix
Interpreter(double *params_arg, double *y_arg, double *ya_arg, double *x_arg, double *direction_arg, int y_size_arg, int nb_row_x_arg,
int nb_row_xd_arg, int periods_arg, int y_kmin_arg, int y_kmax_arg, int maxit_arg_, double solve_tolf_arg, int size_o_direction_arg,
double slowc_arg, int y_decal_arg, double markowitz_c_arg, string &filename_arg);
void compute_blocks(string file_name, string bin_basename);
bool compute_blocks(string file_name, string bin_basename, bool steady_state);
};

View File

@ -34,7 +34,7 @@ struct NonZeroElem
{
int u_index;
int r_index, c_index, lag_index;
NonZeroElem *NZE_R_N, *NZE_C_N;
NonZeroElem *NZE_R_N, *NZE_C_N/*, *NZE_C_P*/;
};
typedef vector<NonZeroElem*> v_NonZeroElem;

File diff suppressed because it is too large Load Diff

View File

@ -33,15 +33,13 @@
#endif
#define NEW_ALLOC
#define MARKOVITZ
//#define PROFILER
//#define MEMORY_LEAKS
using namespace std;
struct t_save_op_s
{
short int lag, operat;
long int first, second;
int first, second;
};
const int IFLD =0;
@ -62,11 +60,10 @@ class SparseMatrix
public:
SparseMatrix();
int simulate_NG1(int blck, int y_size, int it_, int y_kmin, int y_kmax, int Size, int periods, bool print_it, bool cvg, int &iter);
int simulate_NG(int blck, int y_size, int it_, int y_kmin, int y_kmax, int Size, bool print_it, bool cvg, int &iter);
bool simulate_NG(int blck, int y_size, int it_, int y_kmin, int y_kmax, int Size, bool print_it, bool cvg, int &iter, bool steady_state);
void Direct_Simulate(int blck, int y_size, int it_, int y_kmin, int y_kmax, int Size, int periods, bool print_it, int iter);
void fixe_u(double **u, int u_count_int, int max_lag_plus_max_lead_plus_1);
//void initialize(int periods_arg, int nb_endo_arg, int y_kmin_arg, int y_kmax_arg, int y_size_arg, int u_count_arg, int u_count_init_arg, double *u_arg, double *y_arg, double *ya_arg, double slowc_arg, int y_decal_arg, double markowitz_c_arg, double res1_arg, double res2_arg, double max_res_arg);
void Read_SparseMatrix(string file_name, int Size, int periods, int y_kmin, int y_kmax);
void Read_SparseMatrix(string file_name, int Size, int periods, int y_kmin, int y_kmax, bool steady_state);
void Read_file(string file_name, int periods, int u_size1, int y_size, int y_kmin, int y_kmax, int &nb_endo, int &u_count, int &u_count_init, double* u);
private:
@ -80,7 +77,7 @@ class SparseMatrix
#endif
);
void Insert(const int r, const int c, const int u_index, const int lag_index);
void Delete(const int r,const int c, const int Size);
void Delete(const int r,const int c);
int At_Row(int r, NonZeroElem **first);
int At_Pos(int r, int c, NonZeroElem **first);
int At_Col(int c, NonZeroElem **first);
@ -102,9 +99,6 @@ class SparseMatrix
#endif
);
double simple_bksub(int it_, int Size, double slowc_l);
void run_triangular(int nop_all,int *op_all);
void run_it(int nop_all,int *op_all);
void run_u_period1(int periods);
void close_swp_file();
stack<double> Stack;
int nb_prologue_table_u, nb_first_table_u, nb_middle_table_u, nb_last_table_u;
@ -118,6 +112,7 @@ class SparseMatrix
Mem_Mngr mem_mngr;
vector<int> u_liste;
map<pair<int, int>,NonZeroElem*> Mapped_Array;
int *NbNZRow, *NbNZCol;
NonZeroElem **FNZE_R, **FNZE_C;
int nb_endo, u_count_init;
@ -148,6 +143,7 @@ protected:
double *direction;
int start_compare;
int restart;
bool error_not_printed;
};

View File

@ -43,7 +43,6 @@ max(int a, int b)
#ifdef DEBUG_EX
/*The Matlab c++ interface*/
using namespace std;
#include <sstream>
@ -53,7 +52,14 @@ int
main( int argc, const char* argv[] )
{
FILE *fid;
bool steady_state = false;
printf("argc=%d\n",argc);
if(argc<2)
{
mexPrintf("model filename expected\n");
mexEvalString("st=fclose('all');clear all;");
mexErrMsgTxt("Exit from Dynare");
}
float f_tmp;
ostringstream tmp_out("");
tmp_out << argv[1] << "_options.txt";
@ -64,51 +70,48 @@ main( int argc, const char* argv[] )
double *direction;
string file_name(argv[1]);
//mexPrintf("file_name=%s\n",file_name.c_str());
if(argc>2)
{
string f(argv[1]);
if(f == "steady_state")
steady_state = true;
}
fid = fopen(tmp_out.str().c_str(),"r");
int periods;
fscanf(fid,"%d",&periods);
int maxit_;
fscanf(fid,"%d",&maxit_);
fscanf(fid,"%f",&f_tmp);
slowc = f_tmp;
//mexPrintf("slowc_save=%f\n",slowc_save);
double slowc = f_tmp;
fscanf(fid,"%f",&f_tmp);
markowitz_c = f_tmp;
double markowitz_c = f_tmp;
fscanf(fid,"%f",&f_tmp);
solve_tolf = f_tmp;
double solve_tolf = f_tmp;
fclose(fid);
tmp_out.str("");
tmp_out << argv[1] << "_M.txt";
//printf("%s\n",tmp_out.str().c_str());
fid = fopen(tmp_out.str().c_str(),"r");
int y_kmin;
fscanf(fid,"%d",&y_kmin);
//printf("y_kmin=%d\n",y_kmin);
int y_kmax;
fscanf(fid,"%d",&y_kmax);
//printf("y_kmax=%d\n",y_kmax);
int y_decal;
fscanf(fid,"%d",&y_decal);
//printf("y_decal=%d\n",y_decal);
fscanf(fid,"%d",&nb_params);
//printf("nb_params=%d\n",nb_params);
fscanf(fid,"%d",&row_x);
//printf("row_x=%d\n",row_x);
fscanf(fid,"%d",&col_x);
//printf("col_x=%d\n",col_x);
fscanf(fid,"%d",&row_y);
//printf("row_y=%d\n",row_y);
fscanf(fid,"%d",&col_y);
//printf("col_y=%d\n",col_y);
int nb_row_xd;
fscanf(fid,"%d",&nb_row_xd);
//printf("nb_row_xd=%d\n",nb_row_xd);
params = (double*)malloc(nb_params*sizeof(params[0]));
//printf("OK1\n");
double * params = (double*)malloc(nb_params*sizeof(params[0]));
for(i=0; i < nb_params; i++)
{
fscanf(fid,"%f",&f_tmp);
params[i] = f_tmp;
//printf("param[%d]=%f\n",i,params[i]);
}
//printf("OK2\n");
fclose(fid);
yd = (double*)malloc(row_y*col_y*sizeof(yd[0]));
xd = (double*)malloc(row_x*col_x*sizeof(xd[0]));
@ -127,12 +130,12 @@ main( int argc, const char* argv[] )
}
fclose(fid);
size_of_direction=col_y*row_y*sizeof(double);
y=(double*)mxMalloc(size_of_direction);
ya=(double*)mxMalloc(size_of_direction);
int size_of_direction=col_y*row_y*sizeof(double);
double * y=(double*)mxMalloc(size_of_direction);
double * ya=(double*)mxMalloc(size_of_direction);
direction=(double*)mxMalloc(size_of_direction);
memset(direction,0,size_of_direction);
x=(double*)mxMalloc(col_x*row_x*sizeof(double));
double * x=(double*)mxMalloc(col_x*row_x*sizeof(double));
for (i=0;i<row_x*col_x;i++)
x[i]=double(xd[i]);
for (i=0;i<row_y*col_y;i++)
@ -140,36 +143,14 @@ main( int argc, const char* argv[] )
free(yd);
free(xd);
y_size=row_y;
x_size=col_x/*row_x*/;
nb_row_x=row_x;
/*for(int i=0; i<y_size; i++)
{
for(int it_=0; it_<8;it_++)
mexPrintf("y[t=%d, var=%d]=%f ",it_+1, i+1, y[(it_)*y_size+i]);
mexPrintf("\n");
}
for(int i=0; i<col_x; i++)
{
for(int it_=0; it_<8;it_++)
mexPrintf("x[t=%d, var=%d]=%f ",it_, i+1, x[it_+i*nb_row_x]);
mexPrintf("\n");
}*/
t0= clock();
int y_size=row_y;
int nb_row_x=row_x;
clock_t t0= clock();
Interpreter interprete(params, y, ya, x, direction, y_size, nb_row_x, nb_row_xd, periods, y_kmin, y_kmax, maxit_, solve_tolf, size_of_direction, slowc, y_decal, markowitz_c, file_name);
string f(file_name);
interprete.compute_blocks(f+"_dynamic", f);
t1= clock();
interprete.compute_blocks(f, f, steady_state);
clock_t t1= clock();
mexPrintf("Simulation Time=%f milliseconds\n",1000.0*(double(t1)-double(t0))/double(CLOCKS_PER_SEC));
/*if (nlhs>0)
{
plhs[0] = mxCreateDoubleMatrix(row_y, col_y, mxREAL);
pind = mxGetPr(plhs[0]);
for (i=0;i<row_y*col_y;i++)
pind[i]=y[i];
}*/
if(x)
mxFree(x);
if(y)
@ -187,9 +168,24 @@ void
mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
mxArray *M_, *oo_, *options_;
int i, row_y, col_y, row_x, col_x;
int i, row_y, col_y, row_x, col_x, nb_row_xd;
int y_kmin=0, y_kmax=0, y_decal=0, periods=1;
double * pind ;
double *direction;
bool steady_state = false;
if(nrhs>0)
{
const mxArray *mxa = prhs[0];
int buflen=mxGetM(mxa) * mxGetN(mxa) + 1;
char *first_argument;
first_argument=(char*)mxCalloc(buflen, sizeof(char));
int status = mxGetString(mxa, first_argument, buflen);
if (status != 0)
mexWarnMsgTxt("Not enough space. The first argument is truncated.");
string f(first_argument);
if(f == "steady_state")
steady_state = true;
}
M_ = mexGetVariable("global","M_");
if (M_ == NULL )
{
@ -213,22 +209,41 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
mexErrMsgTxt("options_ \n");
}
//mexPrintf("ok0\n");
params = mxGetPr(mxGetFieldByNumber(M_, 0, mxGetFieldNumber(M_,"params")));
double * params = mxGetPr(mxGetFieldByNumber(M_, 0, mxGetFieldNumber(M_,"params")));
double *yd, *xd;
yd= mxGetPr(mxGetFieldByNumber(oo_, 0, mxGetFieldNumber(oo_,"endo_simul")));
row_y=mxGetM(mxGetFieldByNumber(oo_, 0, mxGetFieldNumber(oo_,"endo_simul")));
xd= mxGetPr(mxGetFieldByNumber(oo_, 0, mxGetFieldNumber(oo_,"exo_simul")));
row_x=mxGetM(mxGetFieldByNumber(oo_, 0, mxGetFieldNumber(oo_,"exo_simul")));
col_x=mxGetN(mxGetFieldByNumber(oo_, 0, mxGetFieldNumber(oo_,"exo_simul")));
y_kmin=int(floor(*(mxGetPr(mxGetFieldByNumber(M_, 0, mxGetFieldNumber(M_,"maximum_lag"))))));
y_kmax=int(floor(*(mxGetPr(mxGetFieldByNumber(M_, 0, mxGetFieldNumber(M_,"maximum_lead"))))));
y_decal=max(0,y_kmin-int(floor(*(mxGetPr(mxGetFieldByNumber(M_, 0, mxGetFieldNumber(M_,"maximum_endo_lag")))))));
periods=int(floor(*(mxGetPr(mxGetFieldByNumber(options_, 0, mxGetFieldNumber(options_,"periods"))))));
maxit_=int(floor(*(mxGetPr(mxGetFieldByNumber(options_, 0, mxGetFieldNumber(options_,"maxit_"))))));
slowc=double(*(mxGetPr(mxGetFieldByNumber(options_, 0, mxGetFieldNumber(options_,"slowc")))));
//slowc_save=slowc;
markowitz_c=double(*(mxGetPr(mxGetFieldByNumber(options_, 0, mxGetFieldNumber(options_,"markowitz")))));
nb_row_xd=int(floor(*(mxGetPr(mxGetFieldByNumber(M_, 0, mxGetFieldNumber(M_,"exo_det_nbr"))))));
if(!steady_state)
{
yd= mxGetPr(mxGetFieldByNumber(oo_, 0, mxGetFieldNumber(oo_,"endo_simul")));
row_y=mxGetM(mxGetFieldByNumber(oo_, 0, mxGetFieldNumber(oo_,"endo_simul")));
col_y=mxGetN(mxGetFieldByNumber(oo_, 0, mxGetFieldNumber(oo_,"endo_simul")));;
xd= mxGetPr(mxGetFieldByNumber(oo_, 0, mxGetFieldNumber(oo_,"exo_simul")));
row_x=mxGetM(mxGetFieldByNumber(oo_, 0, mxGetFieldNumber(oo_,"exo_simul")));
col_x=mxGetN(mxGetFieldByNumber(oo_, 0, mxGetFieldNumber(oo_,"exo_simul")));
nb_row_xd=int(floor(*(mxGetPr(mxGetFieldByNumber(M_, 0, mxGetFieldNumber(M_,"exo_det_nbr"))))));
y_kmin=int(floor(*(mxGetPr(mxGetFieldByNumber(M_, 0, mxGetFieldNumber(M_,"maximum_lag"))))));
y_kmax=int(floor(*(mxGetPr(mxGetFieldByNumber(M_, 0, mxGetFieldNumber(M_,"maximum_lead"))))));
y_decal=max(0,y_kmin-int(floor(*(mxGetPr(mxGetFieldByNumber(M_, 0, mxGetFieldNumber(M_,"maximum_endo_lag")))))));
periods=int(floor(*(mxGetPr(mxGetFieldByNumber(options_, 0, mxGetFieldNumber(options_,"periods"))))));
}
else
{
yd= mxGetPr(mxGetFieldByNumber(oo_, 0, mxGetFieldNumber(oo_,"steady_state")));
row_y=mxGetM(mxGetFieldByNumber(oo_, 0, mxGetFieldNumber(oo_,"steady_state")));
col_y=mxGetN(mxGetFieldByNumber(oo_, 0, mxGetFieldNumber(oo_,"steady_state")));;
xd= mxGetPr(mxGetFieldByNumber(oo_, 0, mxGetFieldNumber(oo_,"exo_steady_state")));
row_x=mxGetM(mxGetFieldByNumber(oo_, 0, mxGetFieldNumber(oo_,"exo_steady_state")));
col_x=mxGetN(mxGetFieldByNumber(oo_, 0, mxGetFieldNumber(oo_,"exo_steady_state")));
nb_row_xd=int(floor(*(mxGetPr(mxGetFieldByNumber(M_, 0, mxGetFieldNumber(M_,"exo_det_nbr"))))));
}
int maxit_=int(floor(*(mxGetPr(mxGetFieldByNumber(options_, 0, mxGetFieldNumber(options_,"maxit_"))))));
double slowc=double(*(mxGetPr(mxGetFieldByNumber(options_, 0, mxGetFieldNumber(options_,"slowc")))));
double markowitz_c=double(*(mxGetPr(mxGetFieldByNumber(options_, 0, mxGetFieldNumber(options_,"markowitz")))));
double solve_tolf;
if(steady_state)
solve_tolf=*(mxGetPr(mxGetFieldByNumber(options_, 0, mxGetFieldNumber(options_,"solve_tolf"))));
else
solve_tolf=*(mxGetPr(mxGetFieldByNumber(options_, 0, mxGetFieldNumber(options_,"dynatol"))));
mxArray *mxa=mxGetFieldByNumber(M_, 0, mxGetFieldNumber(M_,"fname"));
int buflen=mxGetM(mxa) * mxGetN(mxa) + 1;
char *fname;
@ -237,48 +252,47 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
int status = mxGetString(mxa, fname, buflen);
if (status != 0)
mexWarnMsgTxt("Not enough space. Filename is truncated.");
col_y=mxGetN(mxGetFieldByNumber(oo_, 0, mxGetFieldNumber(oo_,"endo_simul")));;
solve_tolf=*(mxGetPr(mxGetFieldByNumber(options_, 0, mxGetFieldNumber(options_,"dynatol"))));
size_of_direction=col_y*row_y*sizeof(double);
y=(double*)mxMalloc(size_of_direction);
ya=(double*)mxMalloc(size_of_direction);
int size_of_direction=col_y*row_y*sizeof(double);
double * y=(double*)mxMalloc(size_of_direction);
double * ya=(double*)mxMalloc(size_of_direction);
direction=(double*)mxMalloc(size_of_direction);
memset(direction,0,size_of_direction);
x=(double*)mxMalloc(col_x*row_x*sizeof(double));
double * x=(double*)mxMalloc(col_x*row_x*sizeof(double));
for (i=0;i<row_x*col_x;i++)
x[i]=double(xd[i]);
for (i=0;i<row_y*col_y;i++)
y[i]=double(yd[i]);
y_size=row_y;
x_size=col_x/*row_x*/;
nb_row_x=row_x;
int y_size=row_y;
int nb_row_x=row_x;
/*for(int i=0; i<y_size; i++)
{
for(int it_=0; it_<8;it_++)
mexPrintf("y[t=%d, var=%d]=%f ",it_+1, i+1, y[(it_)*y_size+i]);
mexPrintf("\n");
}
/*int it_ = y_kmin;
for (int j = 0; j < y_size; j++)
mexPrintf(" variable %d at time %d and %d = %f\n", j+1, it_, it_+1, y[j+it_*y_size]);*/
for(int i=0; i<col_x; i++)
{
for(int it_=0; it_<8;it_++)
mexPrintf("x[t=%d, var=%d]=%f ",it_, i+1, x[it_+i*nb_row_x]);
mexPrintf("\n");
}*/
t0= clock();
clock_t t0= clock();
Interpreter interprete(params, y, ya, x, direction, y_size, nb_row_x, nb_row_xd, periods, y_kmin, y_kmax, maxit_, solve_tolf, size_of_direction, slowc, y_decal, markowitz_c, file_name);
string f(fname);
interprete.compute_blocks(f+"_dynamic", f);
t1= clock();
mexPrintf("Simulation Time=%f milliseconds\n",1000.0*(double(t1)-double(t0))/double(CLOCKS_PER_SEC));
bool result = interprete.compute_blocks(f, f, steady_state);
clock_t t1= clock();
if(!steady_state)
mexPrintf("Simulation Time=%f milliseconds\n",1000.0*(double(t1)-double(t0))/double(CLOCKS_PER_SEC));
if (nlhs>0)
{
plhs[0] = mxCreateDoubleMatrix(row_y, col_y, mxREAL);
pind = mxGetPr(plhs[0]);
for (i=0;i<row_y*col_y;i++)
pind[i]=y[i];
if(nlhs>1)
{
plhs[1] = mxCreateDoubleMatrix(1, 1, mxREAL);
pind = mxGetPr(plhs[1]);
if(result)
pind[0] = 0;
else
pind[0] = 1;
}
}
if(x)
mxFree(x);

View File

@ -31,32 +31,6 @@
using namespace std;
int nb_row_x, nb_row_xd, u_size, y_size, x_size, y_kmin, y_kmax, y_decal;
int periods, maxit_;
double *params, markowitz_c, slowc, slowc_save;
double *u, *y, *x, *r, *g1, *g2, *ya;
double solve_tolf;
//pctimer_t t0, t1;
clock_t t0, t1;
int size_of_direction;
int i, j, k;
/*double err;
double res1, res2;
double max_res;
bool cvg;
*/
//double *u, *y, *x, *r, *g1, *g2, *ya;
#endif // SIMULATE_HH_INCLUDED

View File

@ -5,66 +5,23 @@
using namespace std;
int
mexPrintf(/*string */const char *str, ...)
mexPrintf(const char *str, ...)
{
/*va_list vl;
size_t found, found_p=0;
found=str.find_first_of("%");
va_start(vl,str);
while (found!=string::npos)
{
ostringstream tmp_out("");
//tmp_out.clear();
tmp_out << "%";
char c = str[found+1];
while((c>='0' and c<='9') or c=='.')
{
tmp_out << c;
found++;
c = str[found+1];
}
tmp_out << c;
switch(c)
{
case 'd':
printf(str.substr(found_p, found-found_p).c_str());
printf(tmp_out.str().c_str(),va_arg(vl,int));
break;
case 'e':
case 'f':
case 'g':
printf(str.substr(found_p, found-found_p).c_str());
printf(tmp_out.str().c_str(),va_arg(vl,double));
break;
case 's':
printf(str.substr(found_p, found-found_p).c_str());
printf(tmp_out.str().c_str(),va_arg(vl,char*));
break;
case 'x':
printf(str.substr(found_p, found-found_p).c_str());
printf(tmp_out.str().c_str(),va_arg(vl,int));
break;
}
found_p = found+2;
found=str.find_first_of("%",found_p);
}
printf(str.substr(found_p, str.size()-found_p+1).c_str());
return 0;*/
va_list args;
int retval;
int retval;
va_start (args, str);
retval = vprintf (str, args);
va_end (args);
return retval;
va_start (args, str);
retval = vprintf (str, args);
va_end (args);
return retval;
}
void
mexErrMsgTxt(const string str)
{
perror(str.c_str());
exit(EXIT_FAILURE);
}
void

View File

@ -3,9 +3,9 @@ global M_ oo_ options_;
fid = fopen([M_.fname '_options.txt'],'wt');
fprintf(fid,'%d\n',options_.periods);
fprintf(fid,'%d\n',options_.maxit_);
fprintf(fid,'%f\n',options_.slowc);
fprintf(fid,'%f\n',options_.markowitz);
fprintf(fid,'%f\n',options_.dynatol);
fprintf(fid,'%6.20f\n',options_.slowc);
fprintf(fid,'%6.20f\n',options_.markowitz);
fprintf(fid,'%6.20f\n',options_.dynatol);
fclose(fid);
fid = fopen([M_.fname '_M.txt'],'wt');
@ -18,11 +18,11 @@ global M_ oo_ options_;
fprintf(fid,'%d\n',M_.endo_nbr);
fprintf(fid,'%d\n',size(oo_.endo_simul, 2));
fprintf(fid,'%d\n',M_.exo_det_nbr);
fprintf(fid,'%f\n',M_.params);
fprintf(fid,'%6.20f\n',M_.params);
fclose(fid);
fid = fopen([M_.fname '_oo.txt'],'wt');
fprintf(fid,'%f\n',oo_.endo_simul);
fprintf(fid,'%f\n',oo_.exo_simul);
fprintf(fid,'%6.20f\n',oo_.endo_simul);
fprintf(fid,'%6.20f\n',oo_.exo_simul);
fclose(fid);

View File

@ -20,7 +20,6 @@
#include <iostream>
#include <sstream>
#include <fstream>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <cmath>
@ -46,6 +45,7 @@ BlockTriangular::BlockTriangular(SymbolTable &symbol_table_arg, NumericalConstan
bt_verbose = 0;
ModelBlock = NULL;
periods = 0;
prologue = epilogue = 0;
Normalized_Equation = new DataTree(symbol_table, num_const);
}
@ -114,7 +114,7 @@ BlockTriangular::Prologue_Epilogue(bool *IM, int &prologue, int &epilogue, int n
//------------------------------------------------------------------------------
// Find a matching between equations and endogenous variables
bool
BlockTriangular::Compute_Normalization(bool *IM, int equation_number, int prologue, int epilogue, bool verbose, bool *IM0, vector<int> &Index_Equ_IM) const
BlockTriangular::Compute_Normalization(bool *IM, int equation_number, int prologue, int epilogue, int verbose, bool *IM0, vector<int> &Index_Equ_IM) const
{
int n = equation_number - prologue - epilogue;
@ -143,9 +143,17 @@ BlockTriangular::Compute_Normalization(bool *IM, int equation_number, int prolog
mate_map_t::const_iterator it = find(mate_map.begin(), mate_map.begin() + n, graph_traits<BipartiteGraph>::null_vertex());
if (it != mate_map.begin() + n)
{
if (verbose)
if (verbose == 1)
{
cerr << "ERROR: Could not normalize dynamic model. Variable "
cerr << "WARNING: Could not normalize dynamic model. Variable "
<< symbol_table.getName(symbol_table.getID(eEndogenous, it - mate_map.begin()))
<< " is not in the maximum cardinality matching. Trying to find a singular normalization." << endl;
//exit(EXIT_FAILURE);
return false;
}
else if (verbose == 2)
{
cerr << "ERROR: Could not normalize dynamic model (even with a singularity). Variable "
<< symbol_table.getName(symbol_table.getID(eEndogenous, it - mate_map.begin()))
<< " is not in the maximum cardinality matching." << endl;
exit(EXIT_FAILURE);
@ -183,7 +191,7 @@ BlockTriangular::Get_Variable_LeadLag_By_Block(vector<int > &components_set, int
variable_blck[Index_Var_IM[i]] = i;
equation_blck[Index_Equ_IM[i]] = i;
}
else if (i < components_set.size() + prologue)
else if (i < (int)components_set.size() + prologue)
{
variable_blck[Index_Var_IM[i]] = components_set[i-prologue] + prologue;
equation_blck[Index_Equ_IM[i]] = components_set[i-prologue] + prologue;
@ -226,7 +234,7 @@ BlockTriangular::Get_Variable_LeadLag_By_Block(vector<int > &components_set, int
}
void
BlockTriangular::Compute_Block_Decomposition_and_Feedback_Variables_For_Each_Block(bool *IM, int nb_var, int prologue, int epilogue, vector<int> &Index_Equ_IM, vector<int> &Index_Var_IM, vector<pair<int, int> > &blocks, t_etype &Equation_Type, bool verbose_) const
BlockTriangular::Compute_Block_Decomposition_and_Feedback_Variables_For_Each_Block(bool *IM, int nb_var, int prologue, int epilogue, vector<int> &Index_Equ_IM, vector<int> &Index_Var_IM, vector<pair<int, int> > &blocks, t_etype &Equation_Type, bool verbose_, bool select_feedback_variable, int mfs) const
{
t_vtype V_Variable_Type;
int n = nb_var - prologue - epilogue;
@ -272,11 +280,16 @@ BlockTriangular::Compute_Block_Decomposition_and_Feedback_Variables_For_Each_Blo
memcpy(SIM, IM, nb_var*nb_var*sizeof(bool));
//Add a loop on vertices which could not be normalized or vertices related to lead variables => force those vertices to belong to the feedback set
for (int i = 0; i < n; i++)
if (Equation_Type[Index_Equ_IM[i+prologue]].first == E_SOLVE or V_Variable_Type[Index_Var_IM[i+prologue]].second > 0 or V_Variable_Type[Index_Var_IM[i+prologue]].first > 0
or equation_lead_lag[Index_Equ_IM[i+prologue]].second > 0 or equation_lead_lag[Index_Equ_IM[i+prologue]].first > 0)
add_edge(i, i, G2);
if(select_feedback_variable)
for (int i = 0; i < n; i++)
if (Equation_Type[Index_Equ_IM[i+prologue]].first == E_SOLVE or V_Variable_Type[Index_Var_IM[i+prologue]].second > 0 or V_Variable_Type[Index_Var_IM[i+prologue]].first > 0
or equation_lead_lag[Index_Equ_IM[i+prologue]].second > 0 or equation_lead_lag[Index_Equ_IM[i+prologue]].first > 0
or mfs == 0)
add_edge(i, i, G2);
else
for (int i = 0; i < n; i++)
if (Equation_Type[Index_Equ_IM[i+prologue]].first == E_SOLVE or mfs == 0)
add_edge(i, i, G2);
//For each block, the minimum set of feedback variable is computed
// and the non-feedback variables are reordered to get
// a sub-recursive block without feedback variables
@ -686,7 +699,7 @@ BlockTriangular::Free_Block(Model_Block *ModelBlock) const
}
t_etype
BlockTriangular::Equation_Type_determination(vector<BinaryOpNode *> &equations, map<pair<int, pair<int, int> >, NodeID> &first_order_endo_derivatives, vector<int> &Index_Var_IM, vector<int> &Index_Equ_IM)
BlockTriangular::Equation_Type_determination(vector<BinaryOpNode *> &equations, map<pair<int, pair<int, int> >, NodeID> &first_order_endo_derivatives, vector<int> &Index_Var_IM, vector<int> &Index_Equ_IM, int mfs)
{
NodeID lhs, rhs;
ostringstream tmp_output;
@ -709,44 +722,40 @@ BlockTriangular::Equation_Type_determination(vector<BinaryOpNode *> &equations,
lhs->writeOutput(tmp_output, oMatlabDynamicModelSparse, temporary_terms);
tmp_s << "y(it_, " << Index_Var_IM[i]+1 << ")";
map<pair<int, pair<int, int> >, NodeID>::iterator derivative = first_order_endo_derivatives.find(make_pair(eq, make_pair(var, 0)));
/*cout << "eq=" << eq << " var=" << var << "=";
first_cur_endo_derivatives[make_pair(eq, var)]->writeOutput(cout, oMatlabDynamicModelSparse, temporary_terms);
cout << "\n";
cout << "equation : ";
eq_node->writeOutput(cout, oMatlabDynamicModelSparse, temporary_terms);
cout << "\n";*/
set<pair<int, int> > result;
pair<bool, NodeID> res;
derivative->second->collectEndogenous(result);
/*for(set<pair<int, int> >::const_iterator iitt = result.begin(); iitt!=result.end(); iitt++)
cout << "result = " << iitt->first << ", " << iitt->second << "\n";*/
set<pair<int, int> >::const_iterator d_endo_variable = result.find(make_pair(var, 0));
//Determine whether the equation could be evaluated rather than to be solved
if (tmp_output.str() == tmp_s.str() and d_endo_variable == result.end())
ostringstream tt("");
derivative->second->writeOutput(tt, oMatlabDynamicModelSparse, temporary_terms);
//cout << tt.str().c_str() << " tmp_output.str()=" << tmp_output.str() << " tmp_s.str()=" << tmp_s.str();
if (tmp_output.str() == tmp_s.str() and tt.str()=="1")
{
Equation_Simulation_Type = E_EVALUATE;
//cout << " E_EVALUATE ";
}
else
{
//vector<pair<int, NodeID> > List_of_Op_RHS;
//the equation could be normalized by a permutation of the rhs and the lhs
if (d_endo_variable == result.end()) //the equation is linear in the endogenous and could be normalized using the derivative
vector<pair<int, pair<NodeID, NodeID> > > List_of_Op_RHS;
res = equations[eq]->normalizeEquation(var, List_of_Op_RHS);
if(mfs==2)
{
Equation_Simulation_Type = E_EVALUATE_S;
//cout << " gone normalized : ";
res = equations[eq]->normalizeLinearInEndoEquation(var, derivative->second/*, List_of_Op_RHS*/);
/*res.second->writeOutput(cout, oMatlabDynamicModelSparse, temporary_terms);
cout << " done\n";*/
if(d_endo_variable == result.end() && res.second)
Equation_Simulation_Type = E_EVALUATE_S;
}
else if(mfs==3)
{
if(res.second) // The equation could be solved analytically
Equation_Simulation_Type = E_EVALUATE_S;
}
}
//cout << " " << c_Equation_Type(Equation_Simulation_Type) << endl;
V_Equation_Simulation_Type[eq] = make_pair(Equation_Simulation_Type, dynamic_cast<BinaryOpNode *>(res.second));
}
return (V_Equation_Simulation_Type);
}
/*void
BlockTriangular::Recompute_Deriavtives_Respect_to_Feedback_Variables(
*/
t_type
BlockTriangular::Reduce_Blocks_and_type_determination(int prologue, int epilogue, vector<pair<int, int> > &blocks, vector<BinaryOpNode *> &equations, t_etype &Equation_Type, vector<int> &Index_Var_IM, vector<int> &Index_Equ_IM)
{
@ -859,15 +868,15 @@ BlockTriangular::Reduce_Blocks_and_type_determination(int prologue, int epilogue
map<pair<pair<int, pair<int, int> >, pair<int, int> >, int>
BlockTriangular::get_Derivatives(Model_Block *ModelBlock, int blck)
{
map<pair<pair<int, pair<int, int> >, pair<int, int> >, int> Derivatives;
Derivatives.clear();
int nb_endo = symbol_table.endo_nbr();
/*ModelBlock.Block_List[Blck].first_order_determinstic_simulation_derivatives = new*/
map<pair<pair<int, pair<int, int> >, pair<int, int> >, int> Derivatives;
Derivatives.clear();
int nb_endo = symbol_table.endo_nbr();
/*ModelBlock.Block_List[Blck].first_order_determinstic_simulation_derivatives = new*/
for(int lag = -ModelBlock->Block_List[blck].Max_Lag; lag <= ModelBlock->Block_List[blck].Max_Lead; lag++)
{
bool *IM=incidencematrix.Get_IM(lag, eEndogenous);
if(IM)
{
bool *IM=incidencematrix.Get_IM(lag, eEndogenous);
if(IM)
{
for(int eq = 0; eq < ModelBlock->Block_List[blck].Size; eq++)
{
int eqr = ModelBlock->Block_List[blck].Equation[eq];
@ -886,26 +895,26 @@ BlockTriangular::get_Derivatives(Model_Block *ModelBlock, int blck)
OK=false;
}
if(OK)
{
if (ModelBlock->Block_List[blck].Equation_Type[eq] == E_EVALUATE_S and eq<ModelBlock->Block_List[blck].Nb_Recursives)
//It's a normalized equation, we have to recompute the derivative using chain rule derivative function*/
if(OK)
{
if (ModelBlock->Block_List[blck].Equation_Type[eq] == E_EVALUATE_S and eq<ModelBlock->Block_List[blck].Nb_Recursives)
//It's a normalized equation, we have to recompute the derivative using chain rule derivative function*/
Derivatives[make_pair(make_pair(lag, make_pair(eq, var)), make_pair(eqr, varr))] = 1;
else
//It's a feedback equation we can use the derivatives
Derivatives[make_pair(make_pair(lag, make_pair(eq, var)), make_pair(eqr, varr))] = 0;
}
if(var<ModelBlock->Block_List[blck].Nb_Recursives)
{
int eqs = ModelBlock->Block_List[blck].Equation[var];
for(int vars=ModelBlock->Block_List[blck].Nb_Recursives; vars<ModelBlock->Block_List[blck].Size; vars++)
{
int varrs = ModelBlock->Block_List[blck].Variable[vars];
//A new derivative need to be computed using the chain rule derivative function (a feedback variable appear in a recursive equation)
if(Derivatives.find(make_pair(make_pair(lag, make_pair(var, vars)), make_pair(eqs, varrs)))!=Derivatives.end())
Derivatives[make_pair(make_pair(lag, make_pair(eq, vars)), make_pair(eqr, varrs))] = 2;
}
}
else
//It's a feedback equation we can use the derivatives
Derivatives[make_pair(make_pair(lag, make_pair(eq, var)), make_pair(eqr, varr))] = 0;
}
if(var<ModelBlock->Block_List[blck].Nb_Recursives)
{
int eqs = ModelBlock->Block_List[blck].Equation[var];
for(int vars=ModelBlock->Block_List[blck].Nb_Recursives; vars<ModelBlock->Block_List[blck].Size; vars++)
{
int varrs = ModelBlock->Block_List[blck].Variable[vars];
//A new derivative need to be computed using the chain rule derivative function (a feedback variable appear in a recursive equation)
if(Derivatives.find(make_pair(make_pair(lag, make_pair(var, vars)), make_pair(eqs, varrs)))!=Derivatives.end())
Derivatives[make_pair(make_pair(lag, make_pair(eq, vars)), make_pair(eqr, varrs))] = 2;
}
}
}
}
}
@ -915,18 +924,18 @@ BlockTriangular::get_Derivatives(Model_Block *ModelBlock, int blck)
}
void
BlockTriangular::Normalize_and_BlockDecompose(bool *IM, Model_Block *ModelBlock, int n, int &prologue, int &epilogue, vector<int> &Index_Var_IM, vector<int> &Index_Equ_IM, bool *IM_0, jacob_map &j_m, vector<BinaryOpNode *> &equations, t_etype &V_Equation_Type, map<pair<int, pair<int, int> >, NodeID> &first_order_endo_derivatives)
BlockTriangular::Normalize_and_BlockDecompose(bool *IM, Model_Block *ModelBlock, int n, int &prologue, int &epilogue, vector<int> &Index_Var_IM, vector<int> &Index_Equ_IM, bool *IM_0, jacob_map &j_m, vector<BinaryOpNode *> &equations, t_etype &V_Equation_Type, map<pair<int, pair<int, int> >, NodeID> &first_order_endo_derivatives, bool dynamic, int mfs, double cutoff)
{
int i, j, Nb_TotalBlocks, Nb_RecursBlocks, Nb_SimulBlocks;
BlockType Btype;
int count_Block, count_Equ;
bool *SIM0, *SIM00;
SIM0 = (bool *) malloc(n * n * sizeof(bool));
SIM0 = (bool *) malloc(n * n * sizeof(bool));
memcpy(SIM0, IM_0, n*n*sizeof(bool));
Prologue_Epilogue(IM, prologue, epilogue, n, Index_Var_IM, Index_Equ_IM, SIM0);
free(SIM0);
int counted = 0;
if (prologue+epilogue < n)
{
@ -956,7 +965,7 @@ BlockTriangular::Normalize_and_BlockDecompose(bool *IM, Model_Block *ModelBlock,
memset(SIM00, 0, n*n*sizeof(bool));
for (map< pair< int, int >, double >::iterator iter = j_m.begin(); iter != j_m.end(); iter++)
{
if (fabs(iter->second) > bi)
if (fabs(iter->second) > max(bi, cutoff))
{
SIM0[iter->first.first*n+iter->first.second] = 1;
if (!IM_0[iter->first.first*n+iter->first.second])
@ -974,7 +983,7 @@ BlockTriangular::Normalize_and_BlockDecompose(bool *IM, Model_Block *ModelBlock,
}
free(SIM0);
if (suppress != suppressed)
OK = Compute_Normalization(IM, n, prologue, epilogue, false, SIM00, Index_Equ_IM);
OK = Compute_Normalization(IM, n, prologue, epilogue, 0, SIM00, Index_Equ_IM);
suppressed = suppress;
if (!OK)
//bi/=1.07;
@ -984,15 +993,23 @@ BlockTriangular::Normalize_and_BlockDecompose(bool *IM, Model_Block *ModelBlock,
free(SIM00);
}
if (!OK)
Compute_Normalization(IM, n, prologue, epilogue, true, SIM00, Index_Equ_IM);
{
Compute_Normalization(IM, n, prologue, epilogue, 1, SIM00, Index_Equ_IM);
Compute_Normalization(IM, n, prologue, epilogue, 2, IM_0, Index_Equ_IM);
}
}
V_Equation_Type = Equation_Type_determination(equations, first_order_endo_derivatives, Index_Var_IM, Index_Equ_IM);
V_Equation_Type = Equation_Type_determination(equations, first_order_endo_derivatives, Index_Var_IM, Index_Equ_IM, mfs);
cout << "Finding the optimal block decomposition of the model ...\n";
vector<pair<int, int> > blocks;
if (prologue+epilogue < n)
Compute_Block_Decomposition_and_Feedback_Variables_For_Each_Block(IM, n, prologue, epilogue, Index_Equ_IM, Index_Var_IM, blocks, V_Equation_Type, false);
{
if(dynamic)
Compute_Block_Decomposition_and_Feedback_Variables_For_Each_Block(IM, n, prologue, epilogue, Index_Equ_IM, Index_Var_IM, blocks, V_Equation_Type, false, true, mfs);
else
Compute_Block_Decomposition_and_Feedback_Variables_For_Each_Block(IM, n, prologue, epilogue, Index_Equ_IM, Index_Var_IM, blocks, V_Equation_Type, false, false, mfs);
}
t_type Type = Reduce_Blocks_and_type_determination(prologue, epilogue, blocks, equations, V_Equation_Type, Index_Var_IM, Index_Equ_IM);
@ -1049,7 +1066,7 @@ BlockTriangular::Normalize_and_BlockDecompose(bool *IM, Model_Block *ModelBlock,
// normalize each equation of the dynamic model
// and find the optimal block triangular decomposition of the static model
void
BlockTriangular::Normalize_and_BlockDecompose_Static_0_Model(jacob_map &j_m, vector<BinaryOpNode *> &equations, t_etype &equation_simulation_type, map<pair<int, pair<int, int> >, NodeID> &first_order_endo_derivatives)
BlockTriangular::Normalize_and_BlockDecompose_Static_0_Model(jacob_map &j_m, vector<BinaryOpNode *> &equations, t_etype &equation_simulation_type, map<pair<int, pair<int, int> >, NodeID> &first_order_endo_derivatives, int mfs, double cutoff)
{
bool *SIM, *SIM_0;
bool *Cur_IM;
@ -1091,7 +1108,7 @@ BlockTriangular::Normalize_and_BlockDecompose_Static_0_Model(jacob_map &j_m, vec
SIM_0 = (bool *) malloc(symbol_table.endo_nbr() * symbol_table.endo_nbr() * sizeof(*SIM_0));
for (i = 0; i < symbol_table.endo_nbr()*symbol_table.endo_nbr(); i++)
SIM_0[i] = Cur_IM[i];
Normalize_and_BlockDecompose(SIM, ModelBlock, symbol_table.endo_nbr(), prologue, epilogue, Index_Var_IM, Index_Equ_IM, SIM_0, j_m, equations, equation_simulation_type, first_order_endo_derivatives);
Normalize_and_BlockDecompose(SIM, ModelBlock, symbol_table.endo_nbr(), prologue, epilogue, Index_Var_IM, Index_Equ_IM, SIM_0, j_m, equations, equation_simulation_type, first_order_endo_derivatives, true, mfs, cutoff);
free(SIM_0);
free(SIM);
}

View File

@ -97,11 +97,11 @@ private:
//! Allocates and fills the Model structure describing the content of each block
void Allocate_Block(int size, int *count_Equ, int count_Block, BlockType type, BlockSimulationType SimType, Model_Block *ModelBlock, t_etype &Equation_Type, int recurs_Size, vector<int> &Index_Var_IM, vector<int> &Index_Equ_IM);
//! Finds a matching between equations and endogenous variables
bool Compute_Normalization(bool *IM, int equation_number, int prologue, int epilogue, bool verbose, bool *IM0, vector<int> &Index_Var_IM) const;
bool Compute_Normalization(bool *IM, int equation_number, int prologue, int epilogue, int verbose, bool *IM0, vector<int> &Index_Var_IM) const;
//! Decomposes into recurive blocks the non purely recursive equations and determines for each block the minimum feedback variables
void Compute_Block_Decomposition_and_Feedback_Variables_For_Each_Block(bool *IM, int nb_var, int prologue, int epilogue, vector<int> &Index_Equ_IM, vector<int> &Index_Var_IM, vector<pair<int, int> > &blocks, t_etype &Equation_Type, bool verbose_) const;
void Compute_Block_Decomposition_and_Feedback_Variables_For_Each_Block(bool *IM, int nb_var, int prologue, int epilogue, vector<int> &Index_Equ_IM, vector<int> &Index_Var_IM, vector<pair<int, int> > &blocks, t_etype &Equation_Type, bool verbose_, bool select_feedback_variable, int mfs) const;
//! determines the type of each equation of the model (could be evaluated or need to be solved)
t_etype Equation_Type_determination(vector<BinaryOpNode *> &equations, map<pair<int, pair<int, int> >, NodeID> &first_order_endo_derivatives, vector<int> &Index_Var_IM, vector<int> &Index_Equ_IM);
t_etype Equation_Type_determination(vector<BinaryOpNode *> &equations, map<pair<int, pair<int, int> >, NodeID> &first_order_endo_derivatives, vector<int> &Index_Var_IM, vector<int> &Index_Equ_IM, int mfs);
//! Tries to merge the consecutive blocks in a single block and determine the type of each block: recursive, simultaneous, ...
t_type Reduce_Blocks_and_type_determination(int prologue, int epilogue, vector<pair<int, int> > &blocks, vector<BinaryOpNode *> &equations, t_etype &Equation_Type, vector<int> &Index_Var_IM, vector<int> &Index_Equ_IM);
//! Compute for each variable its maximum lead and lag in its block
@ -121,8 +121,8 @@ public:
map<pair<pair<int, pair<int, int> >, pair<int, int> >, int> get_Derivatives(Model_Block *ModelBlock, int Blck);
void Normalize_and_BlockDecompose_Static_0_Model(jacob_map &j_m, vector<BinaryOpNode *> &equations, t_etype &V_Equation_Type, map<pair<int, pair<int, int> >, NodeID> &first_order_endo_derivatives);
void Normalize_and_BlockDecompose(bool* IM, Model_Block* ModelBlock, int n, int &prologue, int &epilogue, vector<int> &Index_Var_IM, vector<int> &Index_Equ_IM, bool* IM_0 , jacob_map &j_m, vector<BinaryOpNode *> &equations, t_etype &equation_simulation_type, map<pair<int, pair<int, int> >, NodeID> &first_order_endo_derivatives);
void Normalize_and_BlockDecompose_Static_0_Model(jacob_map &j_m, vector<BinaryOpNode *> &equations, t_etype &V_Equation_Type, map<pair<int, pair<int, int> >, NodeID> &first_order_endo_derivatives, int mfs, double cutoff);
void Normalize_and_BlockDecompose(bool* IM, Model_Block* ModelBlock, int n, int &prologue, int &epilogue, vector<int> &Index_Var_IM, vector<int> &Index_Equ_IM, bool* IM_0 , jacob_map &j_m, vector<BinaryOpNode *> &equations, t_etype &equation_simulation_type, map<pair<int, pair<int, int> >, NodeID> &first_order_endo_derivatives, bool dynamic, int mfs, double cutoff);
vector<int> Index_Equ_IM;
vector<int> Index_Var_IM;
int prologue, epilogue;
@ -187,11 +187,10 @@ public:
};
inline static std::string c_Equation_Type(int type)
{
char c_Equation_Type[5][13]=
char c_Equation_Type[4][13]=
{
"E_UNKNOWN ",
"E_EVALUATE ",
//"E_EVALUATE_R",
"E_EVALUATE_S",
"E_SOLVE "
};

View File

@ -40,6 +40,15 @@ const char FDIMT=16;
const char FEND=17;
const char FOK=18;
const char FENDEQU=19;
const char FLDSV=20;
const char FSTPSV=21;
const char FLDSU=22;
const char FSTPSU=23;
const char FLDST=24;
const char FSTPST=25;
const char FDIMST=26;
enum BlockType
{
@ -53,7 +62,6 @@ enum EquationType
{
E_UNKNOWN, //!< Unknown equation type
E_EVALUATE, //!< Simple evaluation, normalized variable on left-hand side
//E_EVALUATE_R, //!< Simple evaluation, normalized variable on right-hand side
E_EVALUATE_S, //!< Simple evaluation, normalize using the first order derivative
E_SOLVE //!< No simple evaluation of the equation, it has to be solved
};

View File

@ -27,8 +27,8 @@ using namespace std;
#include "ComputingTasks.hh"
#include "Statement.hh"
SteadyStatement::SteadyStatement(const OptionsList &options_list_arg) :
options_list(options_list_arg)
SteadyStatement::SteadyStatement(const OptionsList &options_list_arg, StaticDllModel::mode_t mode_arg) :
options_list(options_list_arg), mode(mode_arg)
{
}
@ -37,12 +37,17 @@ SteadyStatement::checkPass(ModFileStructure &mod_file_struct)
{
if (options_list.num_options.find("block_mfs") != options_list.num_options.end())
mod_file_struct.steady_block_mfs_option = true;
else if (options_list.num_options.find("block_mfs_dll") != options_list.num_options.end())
mod_file_struct.steady_block_mfs_dll_option = true;
}
void
SteadyStatement::writeOutput(ostream &output, const string &basename) const
{
options_list.writeOutput(output);
/*if (mode == StaticDllModel::eSparseDLLMode)
output << "oo_.steady_state=simulate('steady');" << endl;
else*/
output << "steady;\n";
}

View File

@ -32,8 +32,9 @@ class SteadyStatement : public Statement
{
private:
const OptionsList options_list;
const StaticDllModel::mode_t mode;
public:
SteadyStatement(const OptionsList &options_list_arg);
SteadyStatement(const OptionsList &options_list_arg, StaticDllModel::mode_t mode_arg);
virtual void checkPass(ModFileStructure &mod_file_struct);
virtual void writeOutput(ostream &output, const string &basename) const;
};

File diff suppressed because it is too large Load Diff

View File

@ -25,6 +25,7 @@ using namespace std;
#include <fstream>
#include "StaticModel.hh"
#include "StaticDllModel.hh"
#include "BlockTriangular.hh"
//! Stores a dynamic model
@ -100,7 +101,7 @@ private:
- computes the jacobian for the model w.r. to contemporaneous variables
- removes edges of the incidence matrix when derivative w.r. to the corresponding variable is too close to zero (below the cutoff)
*/
void evaluateJacobian(const eval_context_type &eval_context, jacob_map *j_m);
void evaluateJacobian(const eval_context_type &eval_context, jacob_map *j_m, bool dynamic);
void BlockLinear(Model_Block *ModelBlock);
string reform(string name) const;
map_idx_type map_idx;
@ -152,8 +153,15 @@ public:
virtual NodeID AddVariable(const string &name, int lag = 0);
//! Absolute value under which a number is considered to be zero
double cutoff;
//! The weight of the Markowitz criteria to determine the pivot in the linear solver (simul_NG1 from simulate.cc)
//! The weight of the Markowitz criteria to determine the pivot in the linear solver (simul_NG1 and simul_NG from simulate.cc)
double markowitz;
//! Compute the minimum feedback set in the dynamic model:
/*! 0 : all endogenous variables are considered as feedback variables
1 : the variables belonging to non normalized equation are considered as feedback variables
2 : the variables belonging to a non linear equation are considered as feedback variables
3 : the variables belonging to a non normalizable non linear equation are considered as feedback variables
default value = 0 */
int mfs;
//! the file containing the model and the derivatives code
ofstream code_file;
//! Execute computations (variable sorting + derivation)
@ -184,6 +192,8 @@ public:
/*! It assumes that the static model given in argument has just been allocated */
void toStatic(StaticModel &static_model) const;
void toStaticDll(StaticDllModel &static_model) const;
//! Writes LaTeX file with the equations of the dynamic model
void writeLatexFile(const string &basename) const;

View File

@ -87,7 +87,7 @@ class ParsingDriver;
%}
%token AR AUTOCORR
%token BAYESIAN_IRF BETA_PDF BICGSTAB BLOCK_MFS
%token BAYESIAN_IRF BETA_PDF BICGSTAB BLOCK_MFS BLOCK_MFS_DLL
%token BVAR_DENSITY BVAR_FORECAST
%token BVAR_PRIOR_DECAY BVAR_PRIOR_FLAT BVAR_PRIOR_LAMBDA
%token BVAR_PRIOR_MU BVAR_PRIOR_OMEGA BVAR_PRIOR_TAU BVAR_PRIOR_TRAIN
@ -106,7 +106,7 @@ class ParsingDriver;
%token KALMAN_ALGO KALMAN_TOL
%token LAPLACE LIK_ALGO LIK_INIT LINEAR LOAD_MH_FILE LOAD_PARAMS_AND_STEADY_STATE LOGLINEAR LU
%token MARKOWITZ MARGINAL_DENSITY MAX
%token METHOD MH_DROP MH_INIT_SCALE MH_JSCALE MH_MODE MH_NBLOCKS MH_REPLIC MH_RECOVER MIN
%token METHOD MFS MH_DROP MH_INIT_SCALE MH_JSCALE MH_MODE MH_NBLOCKS MH_REPLIC MH_RECOVER MIN
%token MODE_CHECK MODE_COMPUTE MODE_FILE MODEL MODEL_COMPARISON MODEL_INFO MSHOCKS
%token MODIFIEDHARMONICMEAN MOMENTS_VARENDO DIFFUSE_FILTER
%token <string_val> NAME
@ -449,6 +449,7 @@ model_sparse_options_list : model_sparse_options_list COMMA model_sparse_options
model_sparse_options : o_cutoff
| o_markowitz
| o_mfs
;
model : MODEL ';' { driver.begin_model(); }
@ -641,6 +642,10 @@ steady_options : o_solve_algo
| o_homotopy_mode
| o_homotopy_steps
| o_block_mfs
| o_block_mfs_dll
| o_cutoff
| o_markowitz
| o_mfs
;
check : CHECK ';'
@ -1496,6 +1501,7 @@ o_method : METHOD EQUAL INT_NUMBER { driver.option_num("simulation_method",$3);}
| METHOD EQUAL GMRES { driver.option_num("simulation_method", "2"); }
| METHOD EQUAL BICGSTAB { driver.option_num("simulation_method", "3"); };
o_markowitz : MARKOWITZ EQUAL number { driver.option_num("markowitz", $3); };
o_mfs : MFS EQUAL number { driver.option_num("mfs", $3); };
o_simul : SIMUL { driver.option_num("simul", "1"); };
o_simul_seed : SIMUL_SEED EQUAL INT_NUMBER { driver.option_num("simul_seed", $3); } ;
o_qz_criterium : QZ_CRITERIUM EQUAL number { driver.option_num("qz_criterium", $3); };
@ -1602,6 +1608,8 @@ o_gsa_trans_ident : TRANS_IDENT EQUAL INT_NUMBER { driver.option_num("trans_iden
o_homotopy_mode : HOMOTOPY_MODE EQUAL INT_NUMBER {driver.option_num("homotopy_mode",$3); };
o_homotopy_steps : HOMOTOPY_STEPS EQUAL INT_NUMBER {driver.option_num("homotopy_steps",$3); };
o_block_mfs : BLOCK_MFS { driver.option_num("block_mfs", "1"); }
o_block_mfs_dll : BLOCK_MFS_DLL { driver.option_num("block_mfs_dll", "1"); }
o_parameters : PARAMETERS EQUAL symbol {driver.option_str("parameters",$3);};
o_shocks : SHOCKS EQUAL '(' list_of_symbol_lists ')' { driver.option_symbol_list("shocks"); };
o_labels : LABELS EQUAL '(' symbol_list ')' { driver.option_symbol_list("labels"); };

View File

@ -210,6 +210,7 @@ int sigma_e = 0;
<DYNARE_STATEMENT>periods {return token::PERIODS;}
<DYNARE_STATEMENT>cutoff {return token::CUTOFF;}
<DYNARE_STATEMENT>markowitz {return token::MARKOWITZ;}
<DYNARE_STATEMENT>mfs {return token::MFS;}
<DYNARE_STATEMENT>marginal_density {return token::MARGINAL_DENSITY;}
<DYNARE_STATEMENT>laplace {return token::LAPLACE;}
<DYNARE_STATEMENT>modifiedharmonicmean {return token::MODIFIEDHARMONICMEAN;}
@ -220,6 +221,8 @@ int sigma_e = 0;
<DYNARE_STATEMENT>diffuse_filter {return token::DIFFUSE_FILTER;}
<DYNARE_STATEMENT>plot_priors {return token::PLOT_PRIORS;}
<DYNARE_STATEMENT>block_mfs {return token::BLOCK_MFS;}
<DYNARE_STATEMENT>block_mfs_dll {return token::BLOCK_MFS_DLL;}
<DYNARE_STATEMENT>freq {return token::FREQ;}
<DYNARE_STATEMENT>initial_year {return token::INITIAL_YEAR;}
<DYNARE_STATEMENT>initial_subperiod {return token::INITIAL_SUBPERIOD;}
@ -302,6 +305,7 @@ int sigma_e = 0;
<DYNARE_BLOCK>periods {return token::PERIODS;}
<DYNARE_BLOCK>cutoff {return token::CUTOFF;}
<DYNARE_BLOCK>markowitz {return token::MARKOWITZ;}
<DYNARE_BLOCK>mfs {return token::MFS;}
<DYNARE_BLOCK>gamma_pdf {return token::GAMMA_PDF;}
<DYNARE_BLOCK>beta_pdf {return token::BETA_PDF;}
<DYNARE_BLOCK>normal_pdf {return token::NORMAL_PDF;}

View File

@ -131,6 +131,13 @@ ExprNode::computeTemporaryTerms(map<NodeID, int> &reference_count,
}
pair<int, NodeID >
ExprNode::normalizeEquation(int var_endo, vector<pair<int, pair<NodeID, NodeID> > > &List_of_Op_RHS) const
{
return(make_pair(0, (NodeID)NULL));
}
void
ExprNode::writeOutput(ostream &output)
{
@ -184,13 +191,10 @@ NumConstNode::eval(const eval_context_type &eval_context) const throw (EvalExcep
}
void
NumConstNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const
NumConstNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic) const
{
CompileCode.write(&FLDC, sizeof(FLDC));
double vard = datatree.num_constants.getDouble(id);
#ifdef DEBUGC
cout << "FLDC " << vard << "\n";
#endif
CompileCode.write(reinterpret_cast<char *>(&vard),sizeof(vard));
}
@ -199,10 +203,10 @@ NumConstNode::collectVariables(SymbolType type_arg, set<pair<int, int> > &result
{
}
pair<bool, NodeID>
NumConstNode::normalizeLinearInEndoEquation(int var_endo, NodeID Derivative) const
pair<int, NodeID >
NumConstNode::normalizeEquation(int var_endo, vector<pair<int, pair<NodeID, NodeID> > > &List_of_Op_RHS) const
{
return(make_pair(false, datatree.AddNumConstant(datatree.num_constants.get(id))));
return(make_pair(0, datatree.AddNumConstant(datatree.num_constants.get(id))));
}
NodeID
@ -295,9 +299,6 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
const temporary_terms_type &temporary_terms) const
{
// If node is a temporary term
#ifdef DEBUGC
cout << "write_ouput Variable output_type=" << output_type << "\n";
#endif
temporary_terms_type::const_iterator it = temporary_terms.find(const_cast<VariableNode *>(this));
if (it != temporary_terms.end())
{
@ -464,19 +465,22 @@ VariableNode::eval(const eval_context_type &eval_context) const throw (EvalExcep
}
void
VariableNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const
VariableNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic) const
{
int i, lagl;
#ifdef DEBUGC
cout << "output_type=" << output_type << "\n";
#endif
if (!lhs_rhs)
{
CompileCode.write(&FLDV, sizeof(FLDV));
if(dynamic)
CompileCode.write(&FLDV, sizeof(FLDV));
else
CompileCode.write(&FLDSV, sizeof(FLDSV));
}
else
{
CompileCode.write(&FSTPV, sizeof(FSTPV));
if(dynamic)
CompileCode.write(&FSTPV, sizeof(FSTPV));
else
CompileCode.write(&FSTPSV, sizeof(FSTPSV));
}
char typel=(char)type;
CompileCode.write(&typel, sizeof(typel));
@ -487,35 +491,41 @@ VariableNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_
//cout << "Parameter=" << tsid << "\n";
i = tsid;
CompileCode.write(reinterpret_cast<char *>(&i), sizeof(i));
#ifdef DEBUGC
cout << "FLD Param[ " << i << ", symb_id=" << symb_id << "]\n";
#endif
break;
case eEndogenous :
//cout << "Endogenous=" << symb_id << "\n";
i = tsid;//symb_id;
CompileCode.write(reinterpret_cast<char *>(&i), sizeof(i));
lagl=lag;
CompileCode.write(reinterpret_cast<char *>(&lagl), sizeof(lagl));
if(dynamic)
{
lagl=lag;
CompileCode.write(reinterpret_cast<char *>(&lagl), sizeof(lagl));
}
break;
case eExogenous :
//cout << "Exogenous=" << tsid << "\n";
i = tsid;
CompileCode.write(reinterpret_cast<char *>(&i), sizeof(i));
lagl=lag;
CompileCode.write(reinterpret_cast<char *>(&lagl), sizeof(lagl));
if(dynamic)
{
lagl=lag;
CompileCode.write(reinterpret_cast<char *>(&lagl), sizeof(lagl));
}
break;
case eExogenousDet:
i = tsid + datatree.symbol_table.exo_nbr();
//cout << "ExogenousDet=" << i << "\n";
CompileCode.write(reinterpret_cast<char *>(&i), sizeof(i));
lagl=lag;
CompileCode.write(reinterpret_cast<char *>(&lagl), sizeof(lagl));
if(dynamic)
{
lagl=lag;
CompileCode.write(reinterpret_cast<char *>(&lagl), sizeof(lagl));
}
break;
case eModelLocalVariable:
case eModFileLocalVariable:
//cout << "eModelLocalVariable=" << symb_id << "\n";
datatree.local_variables_table[symb_id]->compile(CompileCode, lhs_rhs, temporary_terms, map_idx);
datatree.local_variables_table[symb_id]->compile(CompileCode, lhs_rhs, temporary_terms, map_idx, dynamic);
break;
case eUnknownFunction:
cerr << "Impossible case: eUnknownFuncion" << endl;
@ -545,22 +555,22 @@ VariableNode::collectVariables(SymbolType type_arg, set<pair<int, int> > &result
datatree.local_variables_table[symb_id]->collectVariables(type_arg, result);
}
pair<bool, NodeID>
VariableNode::normalizeLinearInEndoEquation(int var_endo, NodeID Derivative) const
pair<int, NodeID>
VariableNode::normalizeEquation(int var_endo, vector<pair<int, pair<NodeID, NodeID> > > &List_of_Op_RHS) const
{
if (type ==eEndogenous)
{
if (datatree.symbol_table.getTypeSpecificID(symb_id)==var_endo && lag==0)
return(make_pair(true, (NodeID)NULL));
return(make_pair(1, (NodeID)NULL ));
else
return(make_pair(false, datatree.AddVariableInternal(datatree.symbol_table.getName(symb_id), lag)));
return(make_pair(0, datatree.AddVariableInternal(datatree.symbol_table.getName(symb_id), lag) ));
}
else
{
if (type == eParameter)
return(make_pair(false, datatree.AddVariableInternal(datatree.symbol_table.getName(symb_id), 0)));
return(make_pair(0, datatree.AddVariableInternal(datatree.symbol_table.getName(symb_id), 0) ));
else
return(make_pair(false, datatree.AddVariableInternal(datatree.symbol_table.getName(symb_id), lag)));
return(make_pair(0, datatree.AddVariableInternal(datatree.symbol_table.getName(symb_id), lag) ));
}
}
@ -581,9 +591,19 @@ VariableNode::getChainRuleDerivative(int deriv_id_arg, const map<int, NodeID> &r
map<int, NodeID>::const_iterator it = recursive_variables.find(deriv_id);
if (it != recursive_variables.end())
{
map<int, NodeID> recursive_vars2(recursive_variables);
recursive_vars2.erase(it->first);
return datatree.AddUMinus(it->second->getChainRuleDerivative(deriv_id_arg, recursive_vars2));
map<int, NodeID>::const_iterator it2 = derivatives.find(deriv_id_arg);
if (it2 != derivatives.end())
return it2->second;
else
{
map<int, NodeID> recursive_vars2(recursive_variables);
recursive_vars2.erase(it->first);
//NodeID c = datatree.AddNumConstant("1");
NodeID d = datatree.AddUMinus(it->second->getChainRuleDerivative(deriv_id_arg, recursive_vars2));
//d = datatree.AddTimes(c, d);
derivatives[deriv_id_arg] = d;
return d;
}
}
else
return datatree.Zero;
@ -997,17 +1017,20 @@ UnaryOpNode::eval(const eval_context_type &eval_context) const throw (EvalExcept
}
void
UnaryOpNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const
UnaryOpNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic) const
{
temporary_terms_type::const_iterator it = temporary_terms.find(const_cast<UnaryOpNode *>(this));
if (it != temporary_terms.end())
{
CompileCode.write(&FLDT, sizeof(FLDT));
if(dynamic)
CompileCode.write(&FLDT, sizeof(FLDT));
else
CompileCode.write(&FLDST, sizeof(FLDST));
int var=map_idx[idx];
CompileCode.write(reinterpret_cast<char *>(&var), sizeof(var));
return;
}
arg->compile(CompileCode, lhs_rhs, temporary_terms, map_idx);
arg->compile(CompileCode, lhs_rhs, temporary_terms, map_idx, dynamic);
CompileCode.write(&FUNARY, sizeof(FUNARY));
UnaryOpcode op_codel=op_code;
CompileCode.write(reinterpret_cast<char *>(&op_codel), sizeof(op_codel));
@ -1019,53 +1042,101 @@ UnaryOpNode::collectVariables(SymbolType type_arg, set<pair<int, int> > &result)
arg->collectVariables(type_arg, result);
}
pair<bool, NodeID>
UnaryOpNode::normalizeLinearInEndoEquation(int var_endo, NodeID Derivative) const
pair<int, NodeID>
UnaryOpNode::normalizeEquation(int var_endo, vector<pair<int, pair<NodeID, NodeID> > > &List_of_Op_RHS) const
{
pair<bool, NodeID> res = arg->normalizeLinearInEndoEquation(var_endo, Derivative);
bool is_endogenous_present = res.first;
pair<bool, NodeID > res = arg->normalizeEquation(var_endo, List_of_Op_RHS);
int is_endogenous_present = res.first;
NodeID New_NodeID = res.second;
if (!is_endogenous_present)
/*if(res.second.second)*/
if(is_endogenous_present==2)
return(make_pair(2, (NodeID)NULL));
else if (is_endogenous_present)
{
switch (op_code)
{
case oUminus:
return(make_pair(false, /*tmp_*/datatree.AddUMinus(New_NodeID)));
List_of_Op_RHS.push_back(make_pair(oUminus, make_pair((NodeID)NULL, (NodeID)NULL)));
return(make_pair(1, (NodeID)NULL));
case oExp:
return(make_pair(false, /*tmp_*/datatree.AddExp(New_NodeID)));
List_of_Op_RHS.push_back(make_pair(oLog, make_pair((NodeID)NULL, (NodeID)NULL)));
return(make_pair(1, (NodeID)NULL));
case oLog:
return(make_pair(false, /*tmp_*/datatree.AddLog(New_NodeID)));
List_of_Op_RHS.push_back(make_pair(oExp, make_pair((NodeID)NULL, (NodeID)NULL)));
return(make_pair(1, (NodeID)NULL));
case oLog10:
return(make_pair(false, /*tmp_*/datatree.AddLog10(New_NodeID)));
List_of_Op_RHS.push_back(make_pair(oPower, make_pair((NodeID)NULL, datatree.AddNumConstant("10"))));
return(make_pair(1, (NodeID)NULL));
case oCos:
return(make_pair(false, /*tmp_*/datatree.AddCos(New_NodeID)));
return(make_pair(1, (NodeID)NULL));
case oSin:
return(make_pair(false, /*tmp_*/datatree.AddSin(New_NodeID)));
return(make_pair(1, (NodeID)NULL));
case oTan:
return(make_pair(false, /*tmp_*/datatree.AddTan(New_NodeID)));
return(make_pair(1, (NodeID)NULL));
case oAcos:
return(make_pair(false, /*tmp_*/datatree.AddAcos(New_NodeID)));
return(make_pair(1, (NodeID)NULL));
case oAsin:
return(make_pair(false, /*tmp_*/datatree.AddAsin(New_NodeID)));
return(make_pair(1, (NodeID)NULL));
case oAtan:
return(make_pair(false, /*tmp_*/datatree.AddAtan(New_NodeID)));
return(make_pair(1, (NodeID)NULL));
case oCosh:
return(make_pair(false, /*tmp_*/datatree.AddCosh(New_NodeID)));
return(make_pair(1, (NodeID)NULL));
case oSinh:
return(make_pair(false, /*tmp_*/datatree.AddSinh(New_NodeID)));
return(make_pair(1, (NodeID)NULL));
case oTanh:
return(make_pair(false, /*tmp_*/datatree.AddTanh(New_NodeID)));
return(make_pair(1, (NodeID)NULL));
case oAcosh:
return(make_pair(false, /*tmp_*/datatree.AddAcosh(New_NodeID)));
return(make_pair(1, (NodeID)NULL));
case oAsinh:
return(make_pair(false, /*tmp_*/datatree.AddAsinh(New_NodeID)));
return(make_pair(1, (NodeID)NULL));
case oAtanh:
return(make_pair(false, /*tmp_*/datatree.AddAtanh(New_NodeID)));
return(make_pair(1, (NodeID)NULL));
case oSqrt:
return(make_pair(false, /*tmp_*/datatree.AddSqrt(New_NodeID)));
List_of_Op_RHS.push_back(make_pair(oPower, make_pair((NodeID)NULL, datatree.AddNumConstant("2"))));
return(make_pair(1, (NodeID)NULL));
}
}
return(make_pair(true, (NodeID)NULL));
else
{
switch (op_code)
{
case oUminus:
return(make_pair(0, datatree.AddUMinus(New_NodeID)));
case oExp:
return(make_pair(0, datatree.AddExp(New_NodeID)));
case oLog:
return(make_pair(0, datatree.AddLog(New_NodeID)));
case oLog10:
return(make_pair(0, datatree.AddLog10(New_NodeID)));
case oCos:
return(make_pair(0, datatree.AddCos(New_NodeID)));
case oSin:
return(make_pair(0, datatree.AddSin(New_NodeID)));
case oTan:
return(make_pair(0, datatree.AddTan(New_NodeID)));
case oAcos:
return(make_pair(0, datatree.AddAcos(New_NodeID)));
case oAsin:
return(make_pair(0, datatree.AddAsin(New_NodeID)));
case oAtan:
return(make_pair(0, datatree.AddAtan(New_NodeID)));
case oCosh:
return(make_pair(0, datatree.AddCosh(New_NodeID)));
case oSinh:
return(make_pair(0, datatree.AddSinh(New_NodeID)));
case oTanh:
return(make_pair(0, datatree.AddTanh(New_NodeID)));
case oAcosh:
return(make_pair(0, datatree.AddAcosh(New_NodeID)));
case oAsinh:
return(make_pair(0, datatree.AddAsinh(New_NodeID)));
case oAtanh:
return(make_pair(0, datatree.AddAtanh(New_NodeID)));
case oSqrt:
return(make_pair(0, datatree.AddSqrt(New_NodeID)));
}
}
return(make_pair(1, (NodeID)NULL));
}
@ -1435,19 +1506,22 @@ BinaryOpNode::eval(const eval_context_type &eval_context) const throw (EvalExcep
}
void
BinaryOpNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const
BinaryOpNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic) const
{
// If current node is a temporary term
temporary_terms_type::const_iterator it = temporary_terms.find(const_cast<BinaryOpNode *>(this));
if (it != temporary_terms.end())
{
CompileCode.write(&FLDT, sizeof(FLDT));
if(dynamic)
CompileCode.write(&FLDT, sizeof(FLDT));
else
CompileCode.write(&FLDST, sizeof(FLDST));
int var=map_idx[idx];
CompileCode.write(reinterpret_cast<char *>(&var), sizeof(var));
return;
}
arg1->compile(CompileCode, lhs_rhs, temporary_terms, map_idx);
arg2->compile(CompileCode, lhs_rhs, temporary_terms, map_idx);
arg1->compile(CompileCode, lhs_rhs, temporary_terms, map_idx, dynamic);
arg2->compile(CompileCode, lhs_rhs, temporary_terms, map_idx, dynamic);
CompileCode.write(&FBINARY, sizeof(FBINARY));
BinaryOpcode op_codel=op_code;
CompileCode.write(reinterpret_cast<char *>(&op_codel),sizeof(op_codel));
@ -1636,129 +1710,272 @@ BinaryOpNode::collectVariables(SymbolType type_arg, set<pair<int, int> > &result
arg2->collectVariables(type_arg, result);
}
pair<bool, NodeID>
BinaryOpNode::normalizeLinearInEndoEquation(int var_endo, NodeID Derivative) const
NodeID
BinaryOpNode::Compute_RHS(NodeID arg1, NodeID arg2, int op, int op_type) const
{
temporary_terms_type temp;
switch(op_type)
{
case 0: /*Unary Operator*/
switch(op)
{
case oUminus:
return(datatree.AddUMinus(arg1));
break;
case oExp:
return(datatree.AddExp(arg1));
break;
case oLog:
return(datatree.AddLog(arg1));
break;
case oLog10:
return(datatree.AddLog10(arg1));
break;
}
break;
case 1: /*Binary Operator*/
switch(op)
{
case oPlus:
return(datatree.AddPlus(arg1, arg2));
break;
case oMinus:
return(datatree.AddMinus(arg1, arg2));
break;
case oTimes:
return(datatree.AddTimes(arg1, arg2));
break;
case oDivide:
return(datatree.AddDivide(arg1, arg2));
break;
case oPower:
return(datatree.AddPower(arg1, arg2));
break;
}
break;
}
return((NodeID)NULL);
}
pair<int, NodeID>
BinaryOpNode::normalizeEquation(int var_endo, vector<pair<int, pair<NodeID, NodeID> > > &List_of_Op_RHS) const
{
pair<bool, NodeID> res = arg1->normalizeLinearInEndoEquation(var_endo, Derivative);
bool is_endogenous_present_1 = res.first;
NodeID NodeID_1 = res.second;
res = arg2->normalizeLinearInEndoEquation(var_endo, Derivative);
bool is_endogenous_present_2 = res.first;
NodeID NodeID_2 = res.second;
vector<pair<int, pair<NodeID, NodeID> > > List_of_Op_RHS1, List_of_Op_RHS2;
int is_endogenous_present_1, is_endogenous_present_2;
pair<int, NodeID> res;
NodeID NodeID_1, NodeID_2;
res = arg1->normalizeEquation(var_endo, List_of_Op_RHS1);
is_endogenous_present_1 = res.first;
NodeID_1 = res.second;
res = arg2->normalizeEquation(var_endo, List_of_Op_RHS2);
is_endogenous_present_2 = res.first;
NodeID_2 = res.second;
if(is_endogenous_present_1==2 || is_endogenous_present_2==2)
return(make_pair(2,(NodeID)NULL));
else if(is_endogenous_present_1 && is_endogenous_present_2)
return(make_pair(2,(NodeID)NULL));
else if(is_endogenous_present_1)
{
if(op_code==oEqual)
{
pair<int, pair<NodeID, NodeID> > it;
int oo=List_of_Op_RHS1.size();
for(int i=0;i<oo;i++)
{
it = List_of_Op_RHS1.back();
List_of_Op_RHS1.pop_back();
if(it.second.first && !it.second.second) /*Binary operator*/
NodeID_2 = Compute_RHS(NodeID_2, (BinaryOpNode*)it.second.first, it.first, 1);
else if(it.second.second && !it.second.first) /*Binary operator*/
NodeID_2 = Compute_RHS(it.second.second, NodeID_2, it.first, 1);
else if(it.second.second && it.second.first) /*Binary operator*/
NodeID_2 = Compute_RHS(it.second.first, it.second.second, it.first, 1);
else /*Unary operator*/
NodeID_2 = Compute_RHS((UnaryOpNode*)NodeID_2, (UnaryOpNode*)it.second.first, it.first, 0);
}
}
else
List_of_Op_RHS = List_of_Op_RHS1;
}
else if(is_endogenous_present_2)
{
if(op_code==oEqual)
{
int oo=List_of_Op_RHS2.size();
for(int i=0;i<oo;i++)
{
pair<int, pair<NodeID, NodeID> > it;
it = List_of_Op_RHS2.back();
List_of_Op_RHS2.pop_back();
if(it.second.first && !it.second.second) /*Binary operator*/
NodeID_1 = Compute_RHS((BinaryOpNode*)NodeID_1, (BinaryOpNode*)it.second.first, it.first, 1);
else if(it.second.second && !it.second.first) /*Binary operator*/
NodeID_1 = Compute_RHS((BinaryOpNode*)it.second.second, (BinaryOpNode*)NodeID_1, it.first, 1);
else if(it.second.second && it.second.first) /*Binary operator*/
NodeID_1 = Compute_RHS(it.second.first, it.second.second, it.first, 1);
else
NodeID_1 = Compute_RHS((UnaryOpNode*)NodeID_1, (UnaryOpNode*)it.second.first, it.first, 0);
}
}
else
List_of_Op_RHS =List_of_Op_RHS2;
}
switch (op_code)
{
case oPlus:
if (!is_endogenous_present_1 && !is_endogenous_present_2)
return(make_pair(false, /*tmp_*/datatree.AddPlus(NodeID_1, NodeID_2)));
{
List_of_Op_RHS.push_back(make_pair(oMinus, make_pair(datatree.AddPlus(NodeID_1, NodeID_2), (NodeID)NULL)));
return(make_pair(0, datatree.AddPlus(NodeID_1, NodeID_2)));
}
else if (is_endogenous_present_1 && is_endogenous_present_2)
return(make_pair(true, (NodeID)NULL));
return(make_pair(1, (NodeID)NULL));
else if (!is_endogenous_present_1 && is_endogenous_present_2)
return(make_pair(false, NodeID_1));
{
List_of_Op_RHS.push_back(make_pair(oMinus, make_pair(NodeID_1, (NodeID)NULL)));
return(make_pair(1, NodeID_1));
}
else if (is_endogenous_present_1 && !is_endogenous_present_2)
return(make_pair(false, NodeID_2));
{
List_of_Op_RHS.push_back(make_pair(oMinus, make_pair(NodeID_2, (NodeID)NULL) ));
return(make_pair(1, NodeID_2));
}
break;
case oMinus:
if (!is_endogenous_present_1 && !is_endogenous_present_2)
return(make_pair(false, /*tmp_*/datatree.AddMinus(NodeID_1, NodeID_2)));
{
List_of_Op_RHS.push_back(make_pair(oMinus, make_pair(datatree.AddMinus(NodeID_1, NodeID_2), (NodeID)NULL) ));
return(make_pair(0, datatree.AddMinus(NodeID_1, NodeID_2)));
}
else if (is_endogenous_present_1 && is_endogenous_present_2)
return(make_pair(true, (NodeID)NULL));
return(make_pair(1, (NodeID)NULL));
else if (!is_endogenous_present_1 && is_endogenous_present_2)
return(make_pair(false, NodeID_1));
{
List_of_Op_RHS.push_back(make_pair(oUminus, make_pair((NodeID)NULL, (NodeID)NULL)));
List_of_Op_RHS.push_back(make_pair(oMinus, make_pair(NodeID_1, (NodeID)NULL) ));
return(make_pair(1, NodeID_1));
}
else if (is_endogenous_present_1 && !is_endogenous_present_2)
return(make_pair(false, /*tmp_*/datatree.AddUMinus(NodeID_2)));
{
List_of_Op_RHS.push_back(make_pair(oPlus, make_pair(NodeID_2, (NodeID) NULL) ));
return(make_pair(1, datatree.AddUMinus(NodeID_2)));
}
break;
case oTimes:
if (!is_endogenous_present_1 && !is_endogenous_present_2)
return(make_pair(false, /*tmp_*/datatree.AddTimes(NodeID_1, NodeID_2)));
return(make_pair(0, datatree.AddTimes(NodeID_1, NodeID_2)));
else if(!is_endogenous_present_1 && is_endogenous_present_2)
{
List_of_Op_RHS.push_back(make_pair(oDivide, make_pair(NodeID_1, (NodeID)NULL) ));
return(make_pair(1, NodeID_1));
}
else if(is_endogenous_present_1 && !is_endogenous_present_2)
{
List_of_Op_RHS.push_back(make_pair(oDivide, make_pair(NodeID_2, (NodeID)NULL) ));
return(make_pair(1, NodeID_2));
}
else
return(make_pair(true, (NodeID)NULL));
return(make_pair(1, (NodeID)NULL));
break;
case oDivide:
if (!is_endogenous_present_1 && !is_endogenous_present_2)
return(make_pair(false, datatree.AddDivide(NodeID_1, NodeID_2)));
return(make_pair(0, datatree.AddDivide(NodeID_1, NodeID_2)));
else if(!is_endogenous_present_1 && is_endogenous_present_2)
{
List_of_Op_RHS.push_back(make_pair(oDivide, make_pair((NodeID)NULL, NodeID_1) ));
return(make_pair(1, NodeID_1));
}
else if(is_endogenous_present_1 && !is_endogenous_present_2)
{
List_of_Op_RHS.push_back(make_pair(oTimes, make_pair(NodeID_2, (NodeID)NULL) ));
return(make_pair(1, NodeID_2));
}
else
return(make_pair(true, (NodeID)NULL));
return(make_pair(1, (NodeID)NULL));
break;
case oPower:
if (!is_endogenous_present_1 && !is_endogenous_present_2)
return(make_pair(false, datatree.AddPower(NodeID_1, NodeID_2)));
else
return(make_pair(true, (NodeID)NULL));
return(make_pair(0, datatree.AddPower(NodeID_1, NodeID_2)));
else if(is_endogenous_present_1 && !is_endogenous_present_2)
{
List_of_Op_RHS.push_back(make_pair(oPower, make_pair(datatree.AddDivide( datatree.AddNumConstant("1"), NodeID_2), (NodeID)NULL) ));
return(make_pair(1, (NodeID)NULL));
}
break;
case oEqual:
if (!is_endogenous_present_1 && !is_endogenous_present_2)
{
if (Derivative!=datatree.One)
return( make_pair(false, datatree.AddEqual(datatree.AddVariable(datatree.symbol_table.getName(datatree.symbol_table.getID(eEndogenous, var_endo)), 0), datatree.AddDivide(datatree.AddMinus(NodeID_2, NodeID_1), Derivative))) );
else
return( make_pair(false, datatree.AddEqual(datatree.AddVariable(datatree.symbol_table.getName(datatree.symbol_table.getID(eEndogenous, var_endo)), 0), datatree.AddMinus(NodeID_2, NodeID_1))) );
return( make_pair(0,
datatree.AddEqual(datatree.AddVariable(datatree.symbol_table.getName(datatree.symbol_table.getID(eEndogenous, var_endo)), 0), datatree.AddMinus(NodeID_2, NodeID_1))
));
}
else if (is_endogenous_present_1 && is_endogenous_present_2)
{
return(make_pair(false, datatree.AddEqual(datatree.AddVariable(datatree.symbol_table.getName(datatree.symbol_table.getID(eEndogenous, var_endo)), 0), datatree.Zero)));
return(make_pair(0,
datatree.AddEqual(datatree.AddVariable(datatree.symbol_table.getName(datatree.symbol_table.getID(eEndogenous, var_endo)), 0), datatree.Zero)
));
}
else if (!is_endogenous_present_1 && is_endogenous_present_2)
{
if (Derivative!=datatree.One)
return(make_pair(false, datatree.AddEqual(datatree.AddVariable(datatree.symbol_table.getName(datatree.symbol_table.getID(eEndogenous, var_endo)), 0), datatree.AddDivide(datatree.AddUMinus(NodeID_1), Derivative))));
else
return(make_pair(false, datatree.AddEqual(datatree.AddVariable(datatree.symbol_table.getName(datatree.symbol_table.getID(eEndogenous, var_endo)), 0), datatree.AddUMinus(NodeID_1))));
return(make_pair(0,
datatree.AddEqual(datatree.AddVariable(datatree.symbol_table.getName(datatree.symbol_table.getID(eEndogenous, var_endo)), 0), /*datatree.AddUMinus(NodeID_1)*/NodeID_1)
));
}
else if (is_endogenous_present_1 && !is_endogenous_present_2)
{
if (Derivative!=datatree.One)
return(make_pair(false, datatree.AddEqual(datatree.AddVariable(datatree.symbol_table.getName(datatree.symbol_table.getID(eEndogenous, var_endo)), 0), datatree.AddDivide(NodeID_2, Derivative))));
else
return(make_pair(false, datatree.AddEqual(datatree.AddVariable(datatree.symbol_table.getName(datatree.symbol_table.getID(eEndogenous, var_endo)), 0), NodeID_2)));
return(make_pair(0,
datatree.AddEqual(datatree.AddVariable(datatree.symbol_table.getName(datatree.symbol_table.getID(eEndogenous, var_endo)), 0), NodeID_2)
));
}
break;
case oMax:
if (!is_endogenous_present_1 && !is_endogenous_present_2)
return(make_pair(false, datatree.AddMax(NodeID_1, NodeID_2)));
return(make_pair(0, datatree.AddMax(NodeID_1, NodeID_2) ));
else
return(make_pair(true, (NodeID)NULL));
return(make_pair(1, (NodeID)NULL ));
break;
case oMin:
if (!is_endogenous_present_1 && !is_endogenous_present_2)
return(make_pair(false, datatree.AddMin(NodeID_1, NodeID_2)));
return(make_pair(0, datatree.AddMin(NodeID_1, NodeID_2) ));
else
return(make_pair(true, (NodeID)NULL));
return(make_pair(1, (NodeID)NULL ));
break;
case oLess:
if (!is_endogenous_present_1 && !is_endogenous_present_2)
return(make_pair(false, /*tmp_*/datatree.AddLess(NodeID_1, NodeID_2)));
return(make_pair(0, datatree.AddLess(NodeID_1, NodeID_2) ));
else
return(make_pair(true, (NodeID)NULL));
return(make_pair(1, (NodeID)NULL ));
break;
case oGreater:
if (!is_endogenous_present_1 && !is_endogenous_present_2)
return(make_pair(false, /*tmp_*/datatree.AddGreater(NodeID_1, NodeID_2)));
return(make_pair(0, datatree.AddGreater(NodeID_1, NodeID_2) ));
else
return(make_pair(true, (NodeID)NULL));
return(make_pair(1, (NodeID)NULL ));
break;
case oLessEqual:
if (!is_endogenous_present_1 && !is_endogenous_present_2)
return(make_pair(false, /*tmp_*/datatree.AddLessEqual(NodeID_1, NodeID_2)));
return(make_pair(0, datatree.AddLessEqual(NodeID_1, NodeID_2) ));
else
return(make_pair(true, (NodeID)NULL));
return(make_pair(1, (NodeID)NULL ));
break;
case oGreaterEqual:
if (!is_endogenous_present_1 && !is_endogenous_present_2)
return(make_pair(false, /*tmp_*/datatree.AddGreaterEqual(NodeID_1, NodeID_2)));
return(make_pair(0, datatree.AddGreaterEqual(NodeID_1, NodeID_2) ));
else
return(make_pair(true, (NodeID)NULL));
return(make_pair(1, (NodeID)NULL ));
break;
case oEqualEqual:
if (!is_endogenous_present_1 && !is_endogenous_present_2)
return(make_pair(false, /*tmp_*/datatree.AddEqualEqual(NodeID_1, NodeID_2)));
return(make_pair(0, datatree.AddEqualEqual(NodeID_1, NodeID_2) ));
else
return(make_pair(true, (NodeID)NULL));
return(make_pair(1, (NodeID)NULL ));
break;
case oDifferent:
if (!is_endogenous_present_1 && !is_endogenous_present_2)
return(make_pair(false, /*tmp_*/datatree.AddDifferent(NodeID_1, NodeID_2)));
return(make_pair(0, datatree.AddDifferent(NodeID_1, NodeID_2) ));
else
return(make_pair(true, (NodeID)NULL));
return(make_pair(1, (NodeID)NULL ));
break;
}
// Suppress GCC warning
@ -2023,20 +2240,23 @@ TrinaryOpNode::eval(const eval_context_type &eval_context) const throw (EvalExce
}
void
TrinaryOpNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const
TrinaryOpNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic) const
{
// If current node is a temporary term
temporary_terms_type::const_iterator it = temporary_terms.find(const_cast<TrinaryOpNode *>(this));
if (it != temporary_terms.end())
{
CompileCode.write(&FLDT, sizeof(FLDT));
if(dynamic)
CompileCode.write(&FLDT, sizeof(FLDT));
else
CompileCode.write(&FLDST, sizeof(FLDST));
int var=map_idx[idx];
CompileCode.write(reinterpret_cast<char *>(&var), sizeof(var));
return;
}
arg1->compile(CompileCode, lhs_rhs, temporary_terms, map_idx);
arg2->compile(CompileCode, lhs_rhs, temporary_terms, map_idx);
arg3->compile(CompileCode, lhs_rhs, temporary_terms, map_idx);
arg1->compile(CompileCode, lhs_rhs, temporary_terms, map_idx, dynamic);
arg2->compile(CompileCode, lhs_rhs, temporary_terms, map_idx, dynamic);
arg3->compile(CompileCode, lhs_rhs, temporary_terms, map_idx, dynamic);
CompileCode.write(&FBINARY, sizeof(FBINARY));
TrinaryOpcode op_codel=op_code;
CompileCode.write(reinterpret_cast<char *>(&op_codel),sizeof(op_codel));
@ -2094,22 +2314,22 @@ TrinaryOpNode::collectVariables(SymbolType type_arg, set<pair<int, int> > &resul
arg3->collectVariables(type_arg, result);
}
pair<bool, NodeID>
TrinaryOpNode::normalizeLinearInEndoEquation(int var_endo, NodeID Derivative) const
pair<int, NodeID>
TrinaryOpNode::normalizeEquation(int var_endo, vector<pair<int, pair<NodeID, NodeID> > > &List_of_Op_RHS) const
{
pair<bool, NodeID> res = arg1->normalizeLinearInEndoEquation(var_endo, Derivative);
pair<int, NodeID> res = arg1->normalizeEquation(var_endo, List_of_Op_RHS);
bool is_endogenous_present_1 = res.first;
NodeID NodeID_1 = res.second;
res = arg2->normalizeLinearInEndoEquation(var_endo, Derivative);
res = arg2->normalizeEquation(var_endo, List_of_Op_RHS);
bool is_endogenous_present_2 = res.first;
NodeID NodeID_2 = res.second;
res = arg3->normalizeLinearInEndoEquation(var_endo, Derivative);
res = arg3->normalizeEquation(var_endo, List_of_Op_RHS);
bool is_endogenous_present_3 = res.first;
NodeID NodeID_3 = res.second;
if (!is_endogenous_present_1 && !is_endogenous_present_2 && !is_endogenous_present_3)
return(make_pair(false, /*tmp_*/datatree.AddNormcdf(NodeID_1, NodeID_2, NodeID_3)));
return(make_pair(0, datatree.AddNormcdf(NodeID_1, NodeID_2, NodeID_3) ));
else
return(make_pair(true, (NodeID)NULL));
return(make_pair(1, (NodeID)NULL ));
}
NodeID
@ -2226,14 +2446,14 @@ UnknownFunctionNode::eval(const eval_context_type &eval_context) const throw (Ev
}
void
UnknownFunctionNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const
UnknownFunctionNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic) const
{
cerr << "UnknownFunctionNode::compile: operation impossible!" << endl;
exit(EXIT_FAILURE);
}
pair<bool, NodeID>
UnknownFunctionNode::normalizeLinearInEndoEquation(int var_endo, NodeID Derivative) const
pair<int, NodeID>
UnknownFunctionNode::normalizeEquation(int var_endo, vector<pair<int, pair<NodeID, NodeID> > > &List_of_Op_RHS) const
{
vector<pair<bool, NodeID> > V_arguments;
vector<NodeID> V_NodeID;
@ -2241,14 +2461,14 @@ UnknownFunctionNode::normalizeLinearInEndoEquation(int var_endo, NodeID Derivati
for (vector<NodeID>::const_iterator it = arguments.begin();
it != arguments.end(); it++)
{
V_arguments.push_back((*it)->normalizeLinearInEndoEquation(var_endo, Derivative));
V_arguments.push_back((*it)->normalizeEquation(var_endo, List_of_Op_RHS));
present = present || V_arguments[V_arguments.size()-1].first;
V_NodeID.push_back(V_arguments[V_arguments.size()-1].second);
}
if (!present)
return(make_pair(false, datatree.AddUnknownFunction(datatree.symbol_table.getName(symb_id), V_NodeID)));
return(make_pair(0, datatree.AddUnknownFunction(datatree.symbol_table.getName(symb_id), V_NodeID)));
else
return(make_pair(true, (NodeID)NULL));
return(make_pair(1, (NodeID)NULL ));
}
NodeID

View File

@ -94,6 +94,7 @@ class ExprNode
{
friend class DataTree;
friend class DynamicModel;
friend class StaticDllModel;
friend class ExprNodeLess;
friend class NumConstNode;
friend class VariableNode;
@ -200,7 +201,7 @@ public:
};
virtual double eval(const eval_context_type &eval_context) const throw (EvalException) = 0;
virtual void compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const = 0;
virtual void compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic) const = 0;
//! Creates a static version of this node
/*!
This method duplicates the current node by creating a similar node from which all leads/lags have been stripped,
@ -208,7 +209,7 @@ public:
*/
virtual NodeID toStatic(DataTree &static_datatree) const = 0;
//! Try to normalize an equation linear in its endogenous variable
virtual pair<bool, NodeID> normalizeLinearInEndoEquation(int symb_id_endo, NodeID Derivative) const = 0;
virtual pair<int, NodeID> normalizeEquation(int symb_id_endo, vector<pair<int, pair<NodeID, NodeID> > > &List_of_Op_RHS) const = 0;
};
//! Object used to compare two nodes (using their indexes)
@ -234,9 +235,9 @@ public:
virtual void collectVariables(SymbolType type_arg, set<pair<int, int> > &result) const;
virtual void collectTemporary_terms(const temporary_terms_type &temporary_terms, Model_Block *ModelBlock, int Curr_Block) const;
virtual double eval(const eval_context_type &eval_context) const throw (EvalException);
virtual void compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const;
virtual void compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic) const;
virtual NodeID toStatic(DataTree &static_datatree) const;
virtual pair<bool, NodeID> normalizeLinearInEndoEquation(int symb_id_endo, NodeID Derivative) const;
virtual pair<int, NodeID> normalizeEquation(int symb_id_endo, vector<pair<int, pair<NodeID, NodeID> > > &List_of_Op_RHS) const;
virtual NodeID getChainRuleDerivative(int deriv_id, const map<int, NodeID> &recursive_variables);
};
@ -264,10 +265,10 @@ public:
map_idx_type &map_idx) const;
virtual void collectTemporary_terms(const temporary_terms_type &temporary_terms, Model_Block *ModelBlock, int Curr_Block) const;
virtual double eval(const eval_context_type &eval_context) const throw (EvalException);
virtual void compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const;
virtual void compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic) const;
virtual NodeID toStatic(DataTree &static_datatree) const;
int get_symb_id() const { return symb_id; };
virtual pair<bool, NodeID> normalizeLinearInEndoEquation(int symb_id_endo, NodeID Derivative) const;
virtual pair<int, NodeID> normalizeEquation(int symb_id_endo, vector<pair<int, pair<NodeID, NodeID> > > &List_of_Op_RHS) const;
virtual NodeID getChainRuleDerivative(int deriv_id, const map<int, NodeID> &recursive_variables);
};
@ -296,13 +297,13 @@ public:
virtual void collectTemporary_terms(const temporary_terms_type &temporary_terms, Model_Block *ModelBlock, int Curr_Block) const;
static double eval_opcode(UnaryOpcode op_code, double v) throw (EvalException);
virtual double eval(const eval_context_type &eval_context) const throw (EvalException);
virtual void compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const;
virtual void compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic) const;
//! Returns operand
NodeID get_arg() const { return(arg); };
//! Returns op code
UnaryOpcode get_op_code() const { return(op_code); };
virtual NodeID toStatic(DataTree &static_datatree) const;
virtual pair<bool, NodeID> normalizeLinearInEndoEquation(int symb_id_endo, NodeID Derivative) const;
virtual pair<int, NodeID> normalizeEquation(int symb_id_endo, vector<pair<int, pair<NodeID, NodeID> > > &List_of_Op_RHS) const;
virtual NodeID getChainRuleDerivative(int deriv_id, const map<int, NodeID> &recursive_variables);
};
@ -333,7 +334,8 @@ public:
virtual void collectTemporary_terms(const temporary_terms_type &temporary_terms, Model_Block *ModelBlock, int Curr_Block) const;
static double eval_opcode(double v1, BinaryOpcode op_code, double v2) throw (EvalException);
virtual double eval(const eval_context_type &eval_context) const throw (EvalException);
virtual void compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const;
virtual void compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic) const;
virtual NodeID Compute_RHS(NodeID arg1, NodeID arg2, int op, int op_type) const;
//! Returns first operand
NodeID get_arg1() const { return(arg1); };
//! Returns second operand
@ -341,7 +343,7 @@ public:
//! Returns op code
BinaryOpcode get_op_code() const { return(op_code); };
virtual NodeID toStatic(DataTree &static_datatree) const;
pair<bool, NodeID> normalizeLinearInEndoEquation(int symb_id_endo, NodeID Derivative) const;
virtual pair<int, NodeID> normalizeEquation(int symb_id_endo, vector<pair<int, pair<NodeID, NodeID> > > &List_of_Op_RHS) const;
virtual NodeID getChainRuleDerivative(int deriv_id, const map<int, NodeID> &recursive_variables);
};
@ -373,9 +375,9 @@ public:
virtual void collectTemporary_terms(const temporary_terms_type &temporary_terms, Model_Block *ModelBlock, int Curr_Block) const;
static double eval_opcode(double v1, TrinaryOpcode op_code, double v2, double v3) throw (EvalException);
virtual double eval(const eval_context_type &eval_context) const throw (EvalException);
virtual void compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const;
virtual void compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic) const;
virtual NodeID toStatic(DataTree &static_datatree) const;
virtual pair<bool, NodeID> normalizeLinearInEndoEquation(int symb_id_endo, NodeID Derivative) const;
virtual pair<int, NodeID> normalizeEquation(int symb_id_endo, vector<pair<int, pair<NodeID, NodeID> > > &List_of_Op_RHS) const;
virtual NodeID getChainRuleDerivative(int deriv_id, const map<int, NodeID> &recursive_variables);
};
@ -401,9 +403,9 @@ public:
virtual void collectVariables(SymbolType type_arg, set<pair<int, int> > &result) const;
virtual void collectTemporary_terms(const temporary_terms_type &temporary_terms, Model_Block *ModelBlock, int Curr_Block) const;
virtual double eval(const eval_context_type &eval_context) const throw (EvalException);
virtual void compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const;
virtual void compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx, bool dynamic) const;
virtual NodeID toStatic(DataTree &static_datatree) const;
virtual pair<bool, NodeID> normalizeLinearInEndoEquation(int symb_id_endo, NodeID Derivative) const;
virtual pair<int, NodeID> normalizeEquation(int symb_id_endo, vector<pair<int, pair<NodeID, NodeID> > > &List_of_Op_RHS) const;
virtual NodeID getChainRuleDerivative(int deriv_id, const map<int, NodeID> &recursive_variables);
};

View File

@ -14,6 +14,7 @@ MAIN_OBJS = \
ComputingTasks.o \
ModelTree.o \
StaticModel.o \
StaticDllModel.o \
DynamicModel.o \
NumericalConstants.o \
NumericalInitialization.o \

View File

@ -382,6 +382,7 @@ namespace MFS
{
bool something_has_been_done = true;
int cut_ = 0;
feed_back_vertices.clear();
AdjacencyList_type G(G1);
while (num_vertices(G) > 0)
{

View File

@ -25,6 +25,7 @@
ModFile::ModFile() : expressions_tree(symbol_table, num_constants),
static_model(symbol_table, num_constants),
static_dll_model(symbol_table, num_constants),
dynamic_model(symbol_table, num_constants),
linear(false)
{
@ -143,9 +144,16 @@ ModFile::computingPass(bool no_tmp_terms)
if (dynamic_model.equation_number() > 0)
{
// Compute static model and its derivatives
dynamic_model.toStatic(static_model);
static_model.computingPass(mod_file_struct.steady_block_mfs_option, false, no_tmp_terms);
if(mod_file_struct.steady_block_mfs_dll_option)
{
dynamic_model.toStaticDll(static_dll_model);
static_dll_model.computingPass(global_eval_context, no_tmp_terms);
}
else
{
dynamic_model.toStatic(static_model);
static_model.computingPass(mod_file_struct.steady_block_mfs_option, false, no_tmp_terms);
}
// Set things to compute for dynamic model
if (mod_file_struct.simul_present)
@ -228,7 +236,10 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all) const
if (dynamic_model.equation_number() > 0)
{
dynamic_model.writeOutput(mOutputFile, basename);
static_model.writeOutput(mOutputFile);
if(mod_file_struct.steady_block_mfs_dll_option)
static_dll_model.writeOutput(mOutputFile, basename);
else
static_model.writeOutput(mOutputFile);
}
// Print statements
@ -248,7 +259,10 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all) const
// Create static and dynamic files
if (dynamic_model.equation_number() > 0)
{
static_model.writeStaticFile(basename);
if(mod_file_struct.steady_block_mfs_dll_option)
static_dll_model.writeStaticFile(basename);
else
static_model.writeStaticFile(basename);
dynamic_model.writeDynamicFile(basename);
dynamic_model.writeParamsDerivativesFile(basename);
}

View File

@ -29,6 +29,7 @@ using namespace std;
#include "NumericalConstants.hh"
#include "NumericalInitialization.hh"
#include "StaticModel.hh"
#include "StaticDllModel.hh"
#include "DynamicModel.hh"
#include "Statement.hh"
@ -46,6 +47,8 @@ public:
DataTree expressions_tree;
//! Static model
StaticModel static_model;
//! Static Dll model
StaticDllModel static_dll_model;
//! Dynamic model
DynamicModel dynamic_model;
//! Option linear

View File

@ -586,7 +586,7 @@ ParsingDriver::add_to_row(NodeID v)
void
ParsingDriver::steady()
{
mod_file->addStatement(new SteadyStatement(options_list));
mod_file->addStatement(new SteadyStatement(options_list, mod_file->static_dll_model.mode));
options_list.clear();
}
@ -620,7 +620,17 @@ ParsingDriver::option_num(const string &name_option, const string &opt)
if ((name_option == "periods") && (mod_file->dynamic_model.mode == DynamicModel::eSparseDLLMode || mod_file->dynamic_model.mode == DynamicModel::eSparseMode))
mod_file->dynamic_model.block_triangular.periods = atoi(opt.c_str());
else if (name_option == "cutoff")
mod_file->dynamic_model.cutoff = atof(opt.c_str());
{
mod_file->dynamic_model.cutoff = atof(opt.c_str());
mod_file->static_dll_model.cutoff = atof(opt.c_str());
}
else if (name_option == "mfs")
{
mod_file->dynamic_model.mfs = atoi(opt.c_str());
mod_file->static_dll_model.mfs = atoi(opt.c_str());
}
else if (name_option == "block_mfs_dll")
mod_file->static_dll_model.mode = (StaticDllModel::mode_t)DynamicModel::eSparseDLLMode;
options_list.num_options[name_option] = opt;
}

View File

@ -31,7 +31,8 @@ ModFileStructure::ModFileStructure() :
bvar_density_present(false),
bvar_forecast_present(false),
identification_present(false),
steady_block_mfs_option(false)
steady_block_mfs_option(false),
steady_block_mfs_dll_option(false)
{
}

View File

@ -62,6 +62,8 @@ public:
bool identification_present;
//! Whether the option "block_mfs" is used on steady statement
bool steady_block_mfs_option;
//! Whether the option "block_mfs_dll" is used on steady statement
bool steady_block_mfs_dll_option;
};
class Statement

View File

@ -93,7 +93,7 @@ end;
//options_.solve_tolf=1e-10;
options_.maxit_=10;
steady(block_mfs);
steady;//(block_mfs);
model_info;
//check;
shocks;

View File

@ -852,7 +852,7 @@ W0906=0.0800069594276;
W0907=0.147854375051;
W0908=0.206834342322;
W0909=-1;
model(SPARSE_DLL,markowitz=2/*0.5*//*2.0*/);
model(SPARSE_DLL,markowitz=3, mfs = 3);
//model(SPARSE,markowitz=2.0);
//model;
( log(US_CPI)-(log(US_CPI(-1)))) = US_CPI1*( log(US_PIM)-(log(US_PIM(-1))))+US_CPI2*( log(US_PGNP)-(log(US_PGNP(-1))))+(1-US_CPI1-US_CPI2)*log(US_CPI(-1)/US_CPI(-2))+RES_US_CPI ;