### Added routine to compute one step ahead state space iteration (mex and m). The state space

`equations are approximated at order two around the deterministic steady state.`
parent 8f957114
 ... ... @@ -193,6 +193,9 @@ mex_status(3,3) = {'Kronecker products'}; mex_status(4,1) = {'sparse_hessian_times_B_kronecker_C'}; mex_status(4,2) = {'kronecker'}; mex_status(4,3) = {'Sparse kronecker products'}; mex_status(5,1) = {'local_state_space_iteration_2'}; mex_status(5,2) = {'particle/local_state_space_iteration'}; mex_status(5,3) = {'Local state space iteraton (second order)'}; number_of_mex_files = size(mex_status,1); %% Remove some directories from matlab's path. This is necessary if the user has %% added dynare_v4/matlab with the subfolders. Matlab has to ignore these ... ...
 function [y,y_] = local_state_equation_2(yhat,epsilon,ghx,ghu,constant,ghxx,ghuu,ghxu,yhat_,ss) function [y,y_] = local_state_space_iteration_2(yhat,epsilon,ghx,ghu,constant,ghxx,ghuu,ghxu,yhat_,ss) %@info: %! @deftypefn {Function File} {@var{y}, @var{y_} =} local_state_equation_2 (@var{yhat},@var{epsilon}, @var{ghx}, @var{ghu}, @var{constant}, @var{ghxx}, @var{ghuu}, @var{ghxu}, @var{yhat_}, @var{ss}) %! @anchor{particle/local_state_equation_2} %! @anchor{particle/local_state_space_iteration_2} %! @sp 1 %! Given the states (y) and structural innovations (epsilon), this routine computes the level of selected endogenous variables when the %! model is approximated by an order two taylor expansion around the deterministic steady state. Depending on the number of input/output ... ... @@ -76,22 +76,22 @@ function [y,y_] = local_state_equation_2(yhat,epsilon,ghx,ghu,constant,ghxx,ghuu % along with Dynare. If not, see . % AUTHOR(S) stephane DOT adjemian AT univ DASH lemans DOT fr % frederic DOT karame AT univ DASH evry DOT fr % frederic DOT karame AT univ DASH evry DOT fr number_of_threads = 1; if nargin==8 pruning = 0; if nargout>1 error('local_state_equation_2:: Numbers of input and output argument are inconsistent!') error('local_state_space_iteration_2:: Numbers of input and output argument are inconsistent!') end elseif nargin==10 pruning = 1; if nargout~=2 error('local_state_equation_2:: Numbers of input and output argument are inconsistent!') error('local_state_space_iteration_2:: Numbers of input and output argument are inconsistent!') end else error('local_state_equation_2:: Wrong number of input arguments!') error('local_state_space_iteration_2:: Wrong number of input arguments!') end switch pruning ... ... @@ -152,7 +152,7 @@ end %\$ n = dr.npred; %\$ q = size(dr.ghu,2); %\$ yhat = zeros(n,1); %\$ epsilon = zeros(q,1); %\$ epsilon = zeros(q,1); %\$ ghx = dr.ghx(istates,:); %\$ ghu = dr.ghu(istates,:); %\$ constant = dr.ys(istates,:)+dr.ghs2(istates,:); ... ...
 vpath %.cc \$(top_srcdir)/../../sources/local_state_space_iterations noinst_PROGRAMS = local_state_space_iteration_2 nodist_local_state_space_iteration_2_SOURCES = local_state_space_iteration_2.cc \ No newline at end of file
 ... ... @@ -2,7 +2,7 @@ ACLOCAL_AMFLAGS = -I ../../../m4 # libdynare++ must come before gensylv, k_order_perturbation, dynare_simul_ if DO_SOMETHING SUBDIRS = mjdgges kronecker bytecode libdynare++ gensylv k_order_perturbation dynare_simul_ estimation block_kalman_filter sobol SUBDIRS = mjdgges kronecker bytecode libdynare++ gensylv k_order_perturbation dynare_simul_ estimation block_kalman_filter sobol local_state_space_iterations if HAVE_GSL SUBDIRS += ms_sbvar ... ...
 ... ... @@ -144,6 +144,7 @@ AC_CONFIG_FILES([Makefile kalman_steady_state/Makefile ms_sbvar/Makefile block_kalman_filter/Makefile sobol/Makefile]) sobol/Makefile local_state_space_iterations/Makefile]) AC_OUTPUT
 include ../mex.am include ../../local_state_space_iterations.am \ No newline at end of file
 ... ... @@ -2,7 +2,7 @@ ACLOCAL_AMFLAGS = -I ../../../m4 # libdynare++ must come before gensylv, k_order_perturbation, dynare_simul_ if DO_SOMETHING SUBDIRS = mjdgges kronecker bytecode libdynare++ gensylv k_order_perturbation dynare_simul_ qzcomplex ordschur block_kalman_filter sobol SUBDIRS = mjdgges kronecker bytecode libdynare++ gensylv k_order_perturbation dynare_simul_ qzcomplex ordschur block_kalman_filter sobol local_state_space_iterations if HAVE_GSL SUBDIRS += ms_sbvar ... ...
 ... ... @@ -131,6 +131,7 @@ AC_CONFIG_FILES([Makefile kalman_steady_state/Makefile ms_sbvar/Makefile block_kalman_filter/Makefile sobol/Makefile]) sobol/Makefile local_state_space_iterations/Makefile]) AC_OUTPUT
 EXEEXT = .mex include ../mex.am include ../../local_state_space_iterations.am
 /* * Copyright (C) 2010 Dynare Team * * This file is part of Dynare. * * Dynare is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Dynare is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Dynare. If not, see . */ /* * This mex file computes particles at time t+1 given particles and innovations at time t, * using a second order approximation of the nonlinear state space model. */ #include #include #include #include #include #ifdef USE_OMP #include #endif using namespace std; //#define FIRST_ORDER_LOOP 1// Comment out this line to use mkl-blas instead of loops when computing ghx*yhat and ghu*epsilon void set_vector_of_indices(const int n, const int r, vector &v1, vector &v2, vector &v3) { const int m = n*(n+1)/2; v1.resize(m,0); v2.resize(m,0); v3.resize(m,0); for(int i=0, index=0, jndex=0;i ii1, ii2, ii3;// vector indices for ghxx vector jj1, jj2, jj3;// vector indices for ghuu set_vector_of_indices(n, m, ii1, ii2, ii3); set_vector_of_indices(q, m, jj1, jj2, jj3); for (int particle = 0; particle ii1, ii2, ii3;// vector indices for ghxx vector jj1, jj2, jj3;// vector indices for ghuu set_vector_of_indices(n, m, ii1, ii2, ii3); set_vector_of_indices(q, m, jj1, jj2, jj3); for (int particle = 0; particle 2) { mexErrMsgTxt("Too many output arguments."); } // Get dimensions. mwSize n = mxGetM(prhs);// Number of states. mwSize s = mxGetN(prhs);// Number of particles. mwSize q = mxGetM(prhs);// Number of innovations. mwSize m = mxGetM(prhs);// Number of elements in the union of states and observed variables. // Check the dimensions. if ( (s != mxGetN(prhs)) || // Number of columns for epsilon (n != mxGetN(prhs)) || // Number of columns for ghx (m != mxGetM(prhs)) || // Number of rows for ghu (q != mxGetN(prhs)) || // Number of columns for ghu (m != mxGetM(prhs)) || // Number of rows for 2nd order constant correction + deterministic steady state (m != mxGetM(prhs)) || // Number of rows for ghxx (n*n != mxGetN(prhs)) || // Number of columns for ghxx (m != mxGetM(prhs)) || // Number of rows for ghuu (q*q != mxGetN(prhs)) || // Number of columns for ghuu (m != mxGetM(prhs)) || // Number of rows for ghxu (n*q != mxGetN(prhs)) // Number of rows for ghxu ) { mexErrMsgTxt("Input dimension mismatch!."); } if (nrhs>8) { if ( (n != mxGetM(prhs)) || // Number of rows for yhat_ (s != mxGetN(prhs)) || // Number of columns for yhat_ (m != mxGetM(prhs)) // Number of rows for ss ) { mexErrMsgTxt("Input dimension mismatch!."); } } // Get Input arrays. double *yhat = mxGetPr(prhs); double *epsilon = mxGetPr(prhs); double *ghx = mxGetPr(prhs); double *ghu = mxGetPr(prhs); double *constant = mxGetPr(prhs); double *ghxx = mxGetPr(prhs); double *ghuu = mxGetPr(prhs); double *ghxu = mxGetPr(prhs); double *yhat_, *ss; if (nrhs>8) { yhat_ = mxGetPr(prhs); ss = mxGetPr(prhs); } if (nrhs==8) { double *y; plhs = mxCreateDoubleMatrix(m, s, mxREAL); y = mxGetPr(plhs); ss2Iteration(y, yhat, epsilon, ghx, ghu, constant, ghxx, ghuu, ghxu, (int) m, (int) n, (int) q, (int) s); } else { double *y, *y_; plhs = mxCreateDoubleMatrix(m, s, mxREAL); plhs = mxCreateDoubleMatrix(m, s, mxREAL); y = mxGetPr(plhs); y_ = mxGetPr(plhs); ss2Iteration_pruning(y, y_, yhat, yhat_, epsilon, ghx, ghu, constant, ghxx, ghuu, ghxu, ss, (int) m, (int) n, (int) q, (int) s); } }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!