Merge branch 'master' into rmExtraExo

time-shift
Houtan Bastani 2015-04-01 15:22:10 +02:00
commit 3ca0fcfb31
52 changed files with 920 additions and 201 deletions

3
.gitignore vendored
View File

@ -113,8 +113,7 @@ mex/build/matlab/run_m2html.m
/preprocessor/doc/
# MATLAB dir
/matlab/dynare_m
/matlab/dynare_m.exe
/matlab/preprocessor*
/matlab/dynare_version.m
# DLL rules

View File

@ -35,17 +35,25 @@ EXTRA_DIST = \
dist-hook:
rm -rf `find $(distdir)/matlab $(distdir)/examples -name *~`
rm -f $(distdir)/matlab/dynare_m$(EXEEXT) $(distdir)/matlab/dynare_version.m
rm -rf $(distdir)/matlab/preprocessor* $(distdir)/matlab/dynare_version.m
$(MKDIR_P) $(distdir)/mex/matlab $(distdir)/mex/octave
rm -rf `find $(distdir)/contrib -name '.git*'`
install-exec-local:
$(MKDIR_P) $(DESTDIR)$(pkglibdir)/contrib/ms-sbvar/TZcode
cp -r contrib/ms-sbvar/TZcode/MatlabFiles $(DESTDIR)$(pkglibdir)/contrib/ms-sbvar/TZcode
cp -r examples $(DESTDIR)$(pkglibdir)
cp -r matlab $(DESTDIR)$(pkglibdir)
rm -f $(DESTDIR)$(pkglibdir)/matlab/dynare_m
cp preprocessor/dynare_m $(DESTDIR)$(pkglibdir)/matlab
cp -r contrib/ms-sbvar/TZcode/MatlabFiles $(DESTDIR)$(pkglibdir)/contrib/ms-sbvar/TZcode
rm -rf $(DESTDIR)$(pkglibdir)/matlab/preprocessor*
{ \
if [ -z "`file preprocessor/dynare_m | grep x86.64`" ]; then \
ARCH="32"; \
else \
ARCH="64"; \
fi; \
mkdir -p $(DESTDIR)$(pkglibdir)/matlab/preprocessor$$ARCH; \
cp preprocessor/dynare_m $(DESTDIR)$(pkglibdir)/matlab/preprocessor$$ARCH; \
}
uninstall-local:
rm -f $(DESTDIR)$(bindir)/dynare++

View File

@ -793,6 +793,15 @@ graph
@item nointeractive
Instructs Dynare to not request user input
@item nopathchange
By default Dynare will change Matlab/Octave's path if
@file{dynare/matlab} directory is not on top and if Dynare's routines
are overriden by routines provided in other toolboxes. If one wishes to
override Dynare's routines, the @code{nopathchange} options can be
used. Alternatively, the path can be temporarly modified by the user at
the top of the @file{*.mod} file (using Matlab/Octave's @code{addpath}
command).
@item cygwin
Tells Dynare that your MATLAB is configured for compiling MEX files with
Cygwin (@pxref{Software requirements}). This option is only available
@ -2428,7 +2437,7 @@ The command accepts three file formats:
@item
M-file (extension @file{.m}): for each endogenous and exogenous
variable, the file must contain a row vector of the same name.
variable, the file must contain a row or column vector of the same name. Their length must be @code{periods+M_.maximum_lag+M_.maximum_lead}
@item
MAT-file (extension @file{.mat}): same as for M-files.
@ -4855,7 +4864,9 @@ Uses Chris Sims's @code{csminwel}
@item 5
Uses Marco Ratto's @code{newrat}. This value is not compatible with non
linear filters or DSGE-VAR models
linear filters or DSGE-VAR models.
This is a slice optimizer: most iterations are a sequence of univariate optimization step, one for each estimated parameter or shock.
Uses @code{csminwel} for line search in each step.
@item 6
Uses a Monte-Carlo based optimization routine (see
@ -4974,6 +4985,25 @@ Initial approximation for the inverse of the Hessian matrix of the posterior ker
@end table
@item 5
Available options are:
@table @code
@item 'MaxIter'
Maximum number of iterations. Default: @code{1000}
@item 'Hessian'
Triggers three types of Hessian computations. @code{0}: outer product gradient; @code{1} default DYNARE Hessian routine; @code{2} 'mixed' outer product gradient, where diagonal elements are obtained using second order derivation formula and outer product is used for correlation structure.
Both @{0@} and @{2@} options require univariate filters, to ensure using maximum number of individual densities and a positive definite Hessian.
Both @{0@} and @{2@} are quicker than default DYNARE numeric Hessian, but provide decent starting values for Metropolis for large models (option @{2@} being more accurate than @{0@}).
Default: @code{1}.
@item 'TolFun'
Stopping criteria. Default: @code{1e-5} for numerical derivatives @code{1e-7} for analytic derivatives.
@end table
@item 6
Available options are:
@ -5555,7 +5585,7 @@ and end of the sample for which no forecasts can be made, e.g. entries (1,5,1) a
the variables will be ordered in the order of declaration after the estimation
command (or in general declaration order if no variables are specified here). In case
of running the classical smoother, the variables will always be ordered in general
declaration order. If the @xref{selected_variables_only} option is specified with the classical smoother,
declaration order. If the @ref{selected_variables_only} option is specified with the classical smoother,
non-requested variables will be simply left out in this order.
@end defvr

View File

@ -101,7 +101,7 @@ void SystemResources::getRUS(double& load_avg, long int& pg_avail,
majflt = -1;
#endif
#if !defined(__MINGW32__) && !defined(__CYGWIN32__)
#if !defined(__MINGW32__) && !defined(__CYGWIN32__) && !defined(__CYGWIN__) && !defined(__MINGW64__) && !defined(__CYGWIN64__)
getloadavg(&load_avg, 1);
#else
load_avg = -1.0;

View File

@ -341,6 +341,12 @@ int DynamicAtoms::index(const char* name, int ll) const
return -1;
}
bool DynamicAtoms::is_referenced(const char* name) const
{
Tvarmap::const_iterator it = vars.find(name);
return it != vars.end();
}
const DynamicAtoms::Tlagmap& DynamicAtoms::lagmap(const char* name) const
{
Tvarmap::const_iterator it = vars.find(name);

View File

@ -182,6 +182,9 @@ namespace ogp {
/** Return index of the variable described by the variable
* name and lag/lead. If it doesn't exist, return -1. */
int index(const char* name, int ll) const;
/** Return true if a variable is referenced, i.e. it has lag
* map. */
bool is_referenced(const char* name) const;
/** Return the lag map for the variable name. */
const Tlagmap& lagmap(const char* name) const;
/** Return the variable name for the tree index. It throws an

View File

@ -41,15 +41,14 @@ void StaticAtoms::import_atoms(const DynamicAtoms& da, OperationTree& otree, Tin
register_name(name);
int tnew = otree.add_nulary();
assign(name, tnew);
try {
const DynamicAtoms::Tlagmap& lmap = da.lagmap(name);
if (da.is_referenced(name)) {
const DynamicAtoms::Tlagmap& lmap = da.lagmap(name);
for (DynamicAtoms::Tlagmap::const_iterator it = lmap.begin();
it != lmap.end(); ++it) {
int told = (*it).second;
tmap.insert(Tintintmap::value_type(told, tnew));
}
} catch (const ogu::Exception& e) {
}
}
}
}

View File

@ -1,5 +1,6 @@
// Copyright (C) 2005-2011, Ondra Kamenik
#include "utils/cc/exception.h"
#include "tree.h"
@ -55,7 +56,7 @@ int OperationTree::add_unary(code_t code, int op)
code == SQRT ||
code == ERF))
return zero;
if (op == zero && code == LOG || op == nan)
if ((op == zero && code == LOG) || op == nan)
return nan;
if (op == zero && (code == EXP ||
code == COS ||
@ -86,39 +87,43 @@ int OperationTree::add_binary(code_t code, int op1, int op2)
if (op1 == nan || op2 == nan)
return nan;
// for plus
if (code == PLUS)
if (code == PLUS) {
if (op1 == zero && op2 == zero)
return zero;
else if (op1 == zero)
return op2;
else if (op2 == zero)
return op1;
}
// for minus
if (code == MINUS)
if (code == MINUS) {
if (op1 == zero && op2 == zero)
return zero;
else if (op1 == zero)
return add_unary(UMINUS, op2);
else if (op2 == zero)
return op1;
}
// for times
if (code == TIMES)
if (code == TIMES) {
if (op1 == zero || op2 == zero)
return zero;
else if (op1 == one)
return op2;
else if (op2 == one)
return op1;
}
// for divide
if (code == DIVIDE)
if (code == DIVIDE) {
if (op1 == op2)
return one;
else if (op1 == zero)
return zero;
else if (op2 == zero)
return nan;
}
// for power
if (code == POWER)
if (code == POWER) {
if (op1 == zero && op2 == zero)
return nan;
else if (op1 == zero)
@ -129,6 +134,7 @@ int OperationTree::add_binary(code_t code, int op1, int op2)
return one;
else if (op2 == one)
return op1;
}
// order operands of commutative operations
if (code == TIMES || code == PLUS)

View File

@ -135,22 +135,19 @@ void DynareAtomValues::setValues(ogp::EvalTree& et) const
// set parameteres
for (unsigned int i = 0; i < atoms.get_params().size(); i++) {
try {
if (atoms.is_referenced(atoms.get_params()[i])) {
const ogp::DynamicAtoms::Tlagmap& lmap = atoms.lagmap(atoms.get_params()[i]);
for (ogp::DynamicAtoms::Tlagmap::const_iterator it = lmap.begin();
it != lmap.end(); ++it) {
int t = (*it).second;
et.set_nulary(t, paramvals[i]);
}
} catch (const ogu::Exception& e) {
// ignore non-referenced parameters; there is no
// lagmap for them
}
}
// set endogenous
for (unsigned int outer_i = 0; outer_i < atoms.get_endovars().size(); outer_i++) {
try {
if (atoms.is_referenced(atoms.get_endovars()[outer_i])) {
const ogp::DynamicAtoms::Tlagmap& lmap = atoms.lagmap(atoms.get_endovars()[outer_i]);
for (ogp::DynamicAtoms::Tlagmap::const_iterator it = lmap.begin();
it != lmap.end(); ++it) {
@ -165,15 +162,12 @@ void DynareAtomValues::setValues(ogp::EvalTree& et) const
else
et.set_nulary(t, yyp[i-atoms.nstat()-atoms.npred()]);
}
} catch (const ogu::Exception& e) {
// ignore non-referenced endogenous variables; there is no
// lagmap for them
}
}
// set exogenous
for (unsigned int outer_i = 0; outer_i < atoms.get_exovars().size(); outer_i++) {
try {
if (atoms.is_referenced(atoms.get_exovars()[outer_i])) {
const ogp::DynamicAtoms::Tlagmap& lmap = atoms.lagmap(atoms.get_exovars()[outer_i]);
for (ogp::DynamicAtoms::Tlagmap::const_iterator it = lmap.begin();
it != lmap.end(); ++it) {
@ -184,8 +178,6 @@ void DynareAtomValues::setValues(ogp::EvalTree& et) const
et.set_nulary(t, xx[i]);
}
}
} catch (const ogu::Exception& e) {
// ignore non-referenced variables
}
}
}

View File

@ -1,5 +1,6 @@
// Copyright (C) 2006-2011, Ondra Kamenik
#include "forw_subst_builder.h"
using namespace ogdyn;
@ -47,18 +48,20 @@ void ForwSubstBuilder::substitute_for_term(int t, int i, int j)
// first make lagsubst be substitution setting f(x(+4)) to f(x(+1))
// this is lag = -3 (1-mlead)
map<int,int> lagsubst;
model.variable_shift_map(model.eqs.nulary_of_term(t), 1-mlead, lagsubst);
unordered_set<int> nult = model.eqs.nulary_of_term(t);// make copy of nult!
model.variable_shift_map(nult, 1-mlead, lagsubst);
int lagt = model.eqs.add_substitution(t, lagsubst);
// now maxlead of lagt is +1
// add AUXLD_*_*_1 = f(x(+1)) to the model
char name[100];
sprintf(name, "AUXLD_%d_%d_%d", i, j, 1);
model.atoms.register_uniq_endo(name);
info.num_aux_variables++;
const char* ss = model.atoms.get_name_storage().query(name);
int auxt = model.eqs.add_nulary(name);
model.eqs.add_formula(model.eqs.add_binary(ogp::MINUS, auxt, lagt));
aux_map.insert(Tsubstmap::value_type(ss, lagt));
// now maxlead of lagt is +1
// add AUXLD_*_*_1 = f(x(+1)) to the model
char name[100];
sprintf(name, "AUXLD_%d_%d_%d", i, j, 1);
model.atoms.register_uniq_endo(name);
info.num_aux_variables++;
const char* ss = model.atoms.get_name_storage().query(name);
int auxt = model.eqs.add_nulary(name);
model.eqs.add_formula(model.eqs.add_binary(ogp::MINUS, auxt, lagt));
aux_map.insert(Tsubstmap::value_type(ss, lagt));
// now add variables and equations
// AUXLD_*_*_2 = AUXLD_*_*_1(+1) through
// AUXLD_*_*_{mlead-1} = AUXLD_*_*_{mlead-2}(+1)
@ -82,7 +85,9 @@ void ForwSubstBuilder::substitute_for_term(int t, int i, int j)
aux_map.insert(Tsubstmap::value_type(ss, lagt));
}
// now we have to substitute AUXLEAD_*_*{mlead-1}(+1) for t
// now we have to substitute AUXLD_*_*{mlead-1}(+1) for t
sprintf(name, "AUXLD_%d_%d_%d", i, j, mlead-1);
ss = model.atoms.get_name_storage().query(name);
model.substitute_atom_for_term(ss, +1, t);
}
}

View File

@ -327,11 +327,11 @@ MultInitSS::MultInitSS(const PlannerBuilder& pb, const Vector& pvals, Vector& yy
ogp::FormulaCustomEvaluator fe(builder.static_tree, terms);
fe.eval(dssav, *this);
// solve overdetermined system b+F*lambda=0 => lambda=-(F^T*F)^{-1}*F^T*b
GeneralMatrix FtF(F, "transpose", F);
Vector lambda(builder.diff_f_static.dim2());
F.multVecTrans(0.0, lambda, -1.0, b);
ConstGeneralMatrix(FtF).multInvLeft(lambda);
// solve overdetermined system b+F*lambda=0 using SVD decomposition
SVDDecomp decomp(F);
Vector lambda(builder.diff_f_static.dim2());
decomp.solve(b, lambda);
lambda.mult(-1);
// take values of lambda and put it to yy
for (int fi = 0; fi < builder.diff_f_static.dim2(); fi++) {

View File

@ -481,3 +481,76 @@ void ConstGeneralMatrix::print() const
printf("\n");
}
}
void SVDDecomp::construct(const GeneralMatrix& A)
{
// quick exit if empty matrix
if (minmn == 0) {
U.unit();
VT.unit();
conv = true;
return;
}
// make copy of the matrix
GeneralMatrix AA(A);
lapack_int m = AA.numRows();
lapack_int n = AA.numCols();
double* a = AA.base();
lapack_int lda = AA.getLD();
double* s = sigma.base();
double* u = U.base();
lapack_int ldu = U.getLD();
double* vt = VT.base();
lapack_int ldvt = VT.getLD();
double tmpwork;
lapack_int lwork = -1;
lapack_int info;
lapack_int* iwork = new lapack_int[8*minmn];
// query for optimal lwork
dgesdd("A", &m, &n, a, &lda, s, u, &ldu, vt, &ldvt, &tmpwork,
&lwork, iwork, &info);
lwork = (lapack_int)tmpwork;
Vector work(lwork);
// do the decomposition
dgesdd("A", &m, &n, a, &lda, s, u, &ldu, vt, &ldvt, work.base(),
&lwork, iwork, &info);
delete [] iwork;
if (info < 0)
throw SYLV_MES_EXCEPTION("Internal error in SVDDecomp constructor");
if (info == 0)
conv = true;
}
void SVDDecomp::solve(const GeneralMatrix& B, GeneralMatrix& X) const
{
if (B.numRows() != U.numRows())
throw SYLV_MES_EXCEPTION("Incompatible number of rows ");
// reciprocal condition number for determination of zeros in the
// end of sigma
double rcond = 1e-13;
// solve U: B = U^T*B
GeneralMatrix UTB(U, "trans", B);
// determine nz=number of zeros in the end of sigma
int nz = 0;
while (nz < minmn && sigma[minmn-1-nz] < rcond*sigma[0])
nz++;
// take relevant B for sigma inversion
int m = U.numRows();
int n = VT.numCols();
GeneralMatrix Bprime(UTB, m-minmn, 0, minmn-nz, B.numCols());
// solve sigma
for (int i = 0; i < minmn-nz; i++)
Vector(i, Bprime).mult(1.0/sigma[i]);
// solve VT
X.zeros();
//- copy Bprime to right place of X
for (int i = 0; i < minmn-nz; i++)
Vector(n-minmn+i, X) = ConstVector(i, Bprime);
//- multiply with VT
X.multLeftTrans(VT);
}

View File

@ -7,6 +7,8 @@
#include "Vector.h"
#include <algorithm>
class GeneralMatrix;
class ConstGeneralMatrix {
@ -272,6 +274,40 @@ private:
static int md_length;
};
class SVDDecomp {
protected:
/** Minimum of number of rows and columns of the decomposed
* matrix. */
const int minmn;
/** Singular values. */
Vector sigma;
/** Orthogonal matrix U. */
GeneralMatrix U;
/** Orthogonal matrix V^T. */
GeneralMatrix VT;
/** Convered flag. */
bool conv;
public:
SVDDecomp(const GeneralMatrix& A)
: minmn(std::min<int>(A.numRows(), A.numCols())),
sigma(minmn),
U(A.numRows(), A.numRows()),
VT(A.numCols(), A.numCols()),
conv(false)
{construct(A);}
const GeneralMatrix& getU() const
{return U;}
const GeneralMatrix& getVT() const
{return VT;}
void solve(const GeneralMatrix& B, GeneralMatrix& X) const;
void solve(const Vector& b, Vector& x) const
{
GeneralMatrix xmat(x.base(), x.length(), 1);
solve(GeneralMatrix(b.base(), b.length(), 1), xmat);
}
private:
void construct(const GeneralMatrix& A);
};

View File

@ -1,4 +1,4 @@
dnl Copyright (C) 2009-2014 Dynare Team
dnl Copyright (C) 2009-2015 Dynare Team
dnl
dnl This file is part of Dynare.
dnl
@ -22,6 +22,9 @@ AC_REQUIRE([AX_MATLAB])
AC_MSG_CHECKING([for MATLAB version])
if test "x$MATLAB_VERSION" != "x"; then
case $MATLAB_VERSION in
*2015a | *2015A)
MATLAB_VERSION="8.5"
;;
*2014b | *2014B)
MATLAB_VERSION="8.4"
;;

View File

@ -0,0 +1,89 @@
function mexpath = add_path_to_mex_files(dynareroot, modifypath)
% Copyright (C) 2015 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 <http://www.gnu.org/licenses/>.
if nargin<2
modifypath = true;
end
if isoctave
mexpath = {[dynareroot '../mex/octave/']};
if modifypath
addpath(mexpath{1});
end
else
% Add win32 specific paths for Dynare Windows package
if strcmp(computer, 'PCWIN')
tmp = [dynareroot '../mex/matlab/win32-7.5-8.4/'];
if exist(tmp, 'dir')
mexpath = tmp;
if modifypath
addpath(mexpath);
end
end
end
% Add win64 specific paths for Dynare Windows package
if strcmp(computer, 'PCWIN64')
if matlab_ver_less_than('7.8')
tmp = [dynareroot '../mex/matlab/win64-7.5-7.7/'];
if exist(tmp, 'dir')
mexpath = tmp;
if modifypath
addpath(mexpath);
end
end
else
tmp = [dynareroot '../mex/matlab/win64-7.8-8.5/'];
if exist(tmp, 'dir')
mexpath = tmp;
if modifypath
addpath(mexpath);
end
end
end
end
% Add OS X 32bits specific paths for Dynare Mac package
if strcmp(computer, 'MACI')
tmp = [dynareroot '../mex/matlab/osx32-7.5-7.11/'];
if exist(tmp, 'dir')
mexpath = tmp;
if modifypath && exist(mexpath, 'dir')
addpath(mexpath);
end
end
end
% Add OS X 64bits specific paths for Dynare Mac package
if strcmp(computer, 'MACI64')
tmp = [dynareroot '../mex/matlab/osx64/'];
if exist(tmp, 'dir')
mexpath = tmp;
if modifypath && exist(mexpath, 'dir')
addpath(mexpath);
end
end
end
% Add generic MATLAB path (with higher priority than the previous ones)
if exist('mexpath')
mexpath = { mexpath, [dynareroot '../mex/matlab/'] };
else
mexpath = { [dynareroot '../mex/matlab/'] };
end
if modifypath
addpath([dynareroot '../mex/matlab/']);
end
end

150
matlab/check_matlab_path.m Normal file
View File

@ -0,0 +1,150 @@
function check_matlab_path(change_path_flag)
% Copyright (C) 2015 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 <http://www.gnu.org/licenses/>.
if ~nargin || isempty(change_path_flag)
change_path_flag = true;
end
% Get path to dynare/matlab folder.
DYNARE_PATH = strrep(which('dynare'),'dynare.m','');
if isempty(DYNARE_PATH)
% Nothing to do here (this case should not happen)
disp('dynare.m is not in the Matlab''s path.')
return
else
% Removes trailing slash.
DYNARE_PATH = DYNARE_PATH(1:end-1);
end
% Get matlab path
MATLAB_PATH = path();
% Position of DYNARE_PATH in MATLAB_PATH
idDYNARE = strfind(MATLAB_PATH,DYNARE_PATH);
if isempty(idDYNARE)
disp('dynare.m is not in the Matlab''s path.')
return
else
if isequal(length(idDYNARE),1)
if isequal(idDYNARE, 1)
% Dynare is on top of matlab's path! Nothing to do here...
return
else
str0 = sprintf('Dynare is not on top of matlab''s path!');
% Check that this will not create a problem
MATLAB_PATH_ = path2cell(MATLAB_PATH);
DYNARE_ROUTINES = getallroutinenames(DYNARE_PATH, getalldirectories(DYNARE_PATH));
MATLAB_ROUTINES = {};
for i=1:position(idDYNARE, MATLAB_PATH)
TMP_MATLAB_ROUTINES = getallroutinenames(MATLAB_PATH_{i});
MATLAB_ROUTINES = { MATLAB_ROUTINES{:} TMP_MATLAB_ROUTINES{:} };
end
COMMON_ROUTINES = intersect(MATLAB_ROUTINES, DYNARE_ROUTINES);
if ~isempty(COMMON_ROUTINES)
warning off backtrace
skipline()
if length(COMMON_ROUTINES)==1
warning(sprintf('%s This can cause problems because the Dynare version of %s will be overriden.', str0, COMMON_ROUTINES{1}));
else
str1 = repmat('%s, ', 1, length(COMMON_ROUTINES)-1);
str2 = 'and %s ';
str3 = sprintf(['%s This can cause problems because the Dynare versions of ' str1, str2, 'will be overriden.'], str0, COMMON_ROUTINES{:});
warning(str3);
end
if change_path_flag
skipline()
msg = sprintf('I put %s on top of your matlab''s path. Note that this is a', DYNARE_PATH);
msg = sprintf(' %s a temporary change (ie will not affect future matlab''s session).', msg);
msg = sprintf(' %s If the ordering was intentional, ie if you really want to override the routines distributed with Dynare,', msg);
msg = sprintf(' %s you can change this behaviour using option nopathchange (see the reference manual).', msg);
warning(msg);
skipline()
rmpath(DYNARE_PATH)
addpath(DYNARE_PATH)
end
warning on backtrace
end
end
else
% Check that the user did not put all the subfolders in the path.
% => If DYNARE_PATH/qz is in the path while mjdgges dll is available
% it most likely means that user wrongly put all subfolders in the
% matlab's path!
mexpath = add_path_to_mex_files([DYNARE_PATH filesep], false);
MATLAB_PATH = path2cell(MATLAB_PATH);
for i=1:length(mexpath)
if exist([mexpath{i} filesep 'mjdgges.' mexext],'file') && ismember([DYNARE_PATH filesep 'qz'],MATLAB_PATH)
msg = sprintf(['You put all the dynare/matlab subfolders in matlab''s path! Only ' ...
'the dynare/matlab folder (without subfolders)\nshould be in the ' ...
'path, Dynare will automatically add any required subfolders in the ' ...
'path.']);
error(msg)
end
end
end
end
function q = path2cell(p)
% Converts the output of path() to a cell
s = strfind(p,pathsep);
n = length(s)+1;
q = cell(n,1);
q(1) = {p(1:s(1)-1)};
q(n) = {p(s(end)+1:end)};
for i=2:n-1
q(i) = {p(s(i-1)+1:s(i)-1)};
end
function flist = getallroutinenames(p, excludedsubfolders)
if nargin<2
excludedsubfolders = {};
end
dd = dir(p);
flist = {};
for f=1:length(dd)
if ~(isequal(dd(f).name,'.') || isequal(dd(f).name,'..'))
if dd(f).isdir
if ~ismember(dd(f).name, excludedsubfolders)
r = getallroutinenames([ p filesep dd(f).name]);
flist = { flist{:} r{:} };
end
else
% Filter out files without m extension.
if isequal(dd(f).name(end-1:end),'.m')
flist{length(flist)+1} = [dd(f).name];
end
end
end
end
function dlist = getalldirectories(p)
dd = dir(p);
dlist = {};
for f = 1:length(dd)
if ~(isequal(dd(f).name,'.') || isequal(dd(f).name,'..'))
if dd(f).isdir
dlist{length(dlist)+1} = [dd(f).name];
end
end
end
function n = position(i, currentpath)
n = length(strfind(currentpath(1:i), pathsep));

View File

@ -315,13 +315,17 @@ for i = 1:Size;
dr.eigval = [dr.eigval ; data(i).eigval];
case 6
%% ------------------------------------------------------------------
%Solve Forward complete
%Solve Forward complete
if (maximum_lag > 0)
ghx = - jacob(: , n_pred + 1 : n_pred + n_static ...
+ n_pred + n_both) \ jacob(: , 1 : n_pred);
else
ghx = 0;
end;
if maximum_lag > 0 && n_pred > 0
data(i).eigval = eig(- jacob(: , 1 : n_pred) / ...
jacob(: , (n_pred + n_static + 1 : n_pred + n_static + n_pred )));
data(i).eigval = -eig(ghx(n_static+1:end,:));
data(i).rank = 0;
full_rank = (rcond(jacob(: , (n_pred + n_static + 1 : n_pred ...
+ n_static + n_pred ))) > 1e-9);
full_rank = (rcond(ghx(n_static+1:end,:)) > 1e-9);
else
data(i).eigval = [];
data(i).rank = 0;
@ -330,11 +334,6 @@ for i = 1:Size;
dr.eigval = [dr.eigval ; data(i).eigval];
dr.full_rank = dr.full_rank && full_rank;
if task ~= 1
if (maximum_lag > 0)
ghx = - jacob(: , 1 : n_pred) / jacob(: , n_pred + n_static + 1 : n_pred + n_static + n_pred + n_both);
else
ghx = 0;
end;
if other_endo_nbr
fx = data(i).g1_o;
% retrieves the derivatives with respect to endogenous

View File

@ -16,7 +16,7 @@ function dynare(fname, varargin)
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2001-2014 Dynare Team
% Copyright (C) 2001-2015 Dynare Team
%
% This file is part of Dynare.
%
@ -44,7 +44,22 @@ if strcmpi(fname,'help')
return
end
% detect if MEX files are present; if not, use alternative M-files
% Set default local options
change_path_flag = true;
% Filter out some options.
if nargin>1
id = strfind(varargin,'nopathchange');
if ~isempty(id)
change_path_flag = false;
varargin(id{1}) = [];
end
end
% Check matlab path
check_matlab_path(change_path_flag);
% Detect if MEX files are present; if not, use alternative M-files
dynareroot = dynare_config;
warning_config()
@ -145,9 +160,23 @@ if exist(fname(1:end-4),'dir') && exist([fname(1:end-4) filesep 'hooks'],'dir')
run([fname(1:end-4) filesep 'hooks/priorprocessing'])
end
command = ['"' dynareroot 'dynare_m" ' fname] ;
for i=2:nargin
command = [command ' ' varargin{i-1}];
if ispc
arch = getenv('PROCESSOR_ARCHITECTURE');
else
[junk, arch] = system('uname -m');
end
if isempty(strfind(arch, '64'))
arch_ext = '32';
disp('Using 32-bit preprocessor');
else
arch_ext = '64';
disp('Using 64-bit preprocessor');
end
command = ['"' dynareroot 'preprocessor' arch_ext filesep 'dynare_m" ' fname] ;
for i=1:length(varargin)
command = [command ' ' varargin{i}];
end
[status, result] = system(command);
@ -164,8 +193,8 @@ end
% Save preprocessor result in logfile (if `no_log' option not present)
no_log = 0;
for i=2:nargin
no_log = no_log || strcmp(varargin{i-1}, 'nolog');
for i=1:length(varargin)
no_log = no_log || strcmp(varargin{i}, 'nolog');
end
if ~no_log
logname = [fname(1:end-4) '.log'];

View File

@ -35,6 +35,7 @@ function dynareroot = dynare_config(path_to_dynare,verbose)
if nargin && ~isempty(path_to_dynare)
addpath(path_to_dynare);
end
dynareroot = strrep(which('dynare'),'dynare.m','');
origin = pwd();
@ -44,7 +45,6 @@ if ~nargin || nargin==1
verbose = 1;
end
addpath([dynareroot '/distributions/'])
addpath([dynareroot '/kalman/'])
addpath([dynareroot '/kalman/likelihood'])
@ -90,8 +90,8 @@ if isoctave
addpath([dynareroot '/missing/ordeig'])
end
% ilu is missing in Octave
if isoctave
% ilu is missing in Octave < 4.0
if isoctave && octave_ver_less_than('4.0')
addpath([dynareroot '/missing/ilu'])
end
@ -114,49 +114,7 @@ if (isoctave && ~user_has_octave_forge_package('statistics')) ...
end
% Add path to MEX files
if isoctave
addpath([dynareroot '../mex/octave/']);
else
% Add win32 specific paths for Dynare Windows package
if strcmp(computer, 'PCWIN')
mexpath = [dynareroot '../mex/matlab/win32-7.5-8.4'];
if exist(mexpath, 'dir')
addpath(mexpath)
end
end
% Add win64 specific paths for Dynare Windows package
if strcmp(computer, 'PCWIN64')
if matlab_ver_less_than('7.8')
mexpath = [dynareroot '../mex/matlab/win64-7.5-7.7'];
if exist(mexpath, 'dir')
addpath(mexpath)
end
else
mexpath = [dynareroot '../mex/matlab/win64-7.8-8.4'];
if exist(mexpath, 'dir')
addpath(mexpath)
end
end
end
if strcmp(computer, 'MACI')
mexpath = [dynareroot '../mex/matlab/osx32-7.5-7.11'];
if exist(mexpath, 'dir')
addpath(mexpath)
end
end
if strcmp(computer, 'MACI64')
mexpath = [dynareroot '../mex/matlab/osx64'];
if exist(mexpath, 'dir')
addpath(mexpath)
end
end
% Add generic MATLAB path (with higher priority than the previous ones)
addpath([dynareroot '../mex/matlab/']);
end
add_path_to_mex_files(dynareroot);
%% Set mex routine names
mex_status = cell(1,3);

View File

@ -233,7 +233,7 @@ end
if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation
%prepare settings for newrat
if options_.mode_compute==5
%get whether analytical Hessian with non-analytical mode-finding is requested
%get whether outer product Hessian is requested
newratflag=[];
if ~isempty(options_.optim_opt)
options_list = read_key_value_string(options_.optim_opt);
@ -246,19 +246,14 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation
if options_.analytic_derivation,
options_analytic_derivation_old = options_.analytic_derivation;
options_.analytic_derivation = -1;
if ~isempty(newratflag) && newratflag~=0 %gradient explicitly specified
if ~isempty(newratflag) && newratflag~=0 %numerical hessian explicitly specified
error('newrat: analytic_derivation is incompatible with numerical Hessian.')
else %use default
newratflag=0; %use analytical gradient
newratflag=0; %exclude DYNARE numerical hessian
end
elseif ~options_.analytic_derivation
if isempty(newratflag)
newratflag=options_.newrat.hess; %use default gradient
end
if newratflag==0 %Analytic Hessian wanted, but not automatically computed by newrat itself
if ~((options_.kalman_algo == 2) || (options_.kalman_algo == 4)) %kalman_algo not compatible
error('Analytical Hessian with non-analytical mode-finding requires kalman_algo=2 or 4.')
end
newratflag=options_.newrat.hess; %use default numerical dynare hessian
end
end
end
@ -281,11 +276,39 @@ if ~isequal(options_.mode_compute,0) && ~options_.mh_posterior_mode_estimation
[junk1, junk2, hh] = feval(objective_function,xparam1, ...
dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_);
options_.analytic_derivation = ana_deriv_old;
elseif ~(isequal(options_.mode_compute,5) && newratflag==0),
elseif ~(isequal(options_.mode_compute,5) && newratflag~=1),
% with flag==0, we force to use the hessian from outer
% product gradient of optimizer 5
hh = reshape(hessian(objective_function,xparam1, ...
options_.gstep,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,bounds,oo_),nx,nx);
elseif isequal(options_.mode_compute,5)
% other numerical hessian options available with optimizer 5
%
% if newratflag == 0
% compute outer product gradient of optimizer 5
%
% if newratflag == 2
% compute 'mixed' outer product gradient of optimizer 5
% with diagonal elements computed with numerical second order derivatives
%
% uses univariate filters, so to get max # of available
% densitities for outer product gradient
kalman_algo0 = options_.kalman_algo;
compute_hessian = 1;
if ~((options_.kalman_algo == 2) || (options_.kalman_algo == 4)),
options_.kalman_algo=2;
if options_.lik_init == 3,
options_.kalman_algo=4;
end
elseif newratflag==0, % hh already contains outer product gradient with univariate filter
compute_hessian = 0;
end
if compute_hessian,
crit = options_.newrat.tolerance.f;
newratflag = newratflag>0;
hh = reshape(mr_hessian(0,xparam1,objective_function,newratflag,crit,dataset_, dataset_info, options_,M_,estim_params_,bayestopt_,bounds,oo_), nx, nx);
end
options_.kalman_algo = kalman_algo0;
end
end
end

View File

@ -363,7 +363,7 @@ estimation_info.structural_innovation_corr_prior_index = {};
estimation_info.structural_innovation_corr_options_index = {};
estimation_info.structural_innovation_corr.range_index = {};
estimation_info.joint_parameter_prior_index = {};
estimation_info.joint_parameter = cell2table(cell(0,11));
estimation_info.joint_parameter = {'index','domain','interval','mean','median','mode','shape','shift','stdev','truncate','variance'};
options_.initial_period = NaN; %dates(1,1);
options_.dataset.file = [];
options_.dataset.series = [];
@ -481,7 +481,7 @@ csminwel.maxiter=1000;
options_.csminwel=csminwel;
%newrat optimization routine
newrat.hess=1; %analytic hessian
newrat.hess=1; % dynare numerical hessian
newrat.tolerance.f=1e-5;
newrat.tolerance.f_analytic=1e-7;
newrat.maxiter=1000;

View File

@ -64,6 +64,7 @@ switch (extension)
load(basename);
case { '.xls', '.xlsx' }
[data_,names_v_]=xlsread(fullname); % Octave needs the extension explicitly
series_=0;
otherwise
error(['Unsupported extension for datafile: ' extension])
end
@ -75,27 +76,35 @@ oo_.exo_simul = [];
for i_=1:size(M_.endo_names,1)
if series_ == 1
x_ = eval(M_.endo_names(i_,:));
oo_.endo_simul = [oo_.endo_simul; x_'];
if size(x_,2)>size(x_,1) %oo_.endo_simul must be collection of row vectors
oo_.endo_simul = [oo_.endo_simul; x_];
else %transpose if column vector
oo_.endo_simul = [oo_.endo_simul; x_'];
end
else
k_ = strmatch(upper(M_.endo_names(i_,:)),names_v_,'exact');
k_ = strmatch(deblank(M_.endo_names(i_,:)),names_v_,'exact');
if isempty(k_)
error(['INITVAL_FILE: ' M_.endo_names(i_,:) ' not found'])
error(['INITVAL_FILE: ' deblank(M_.endo_names(i_,:)) ' not found'])
end
x_ = data_(:,k_);
oo_.endo_simul = [oo_.endo_simul; x_'];
oo_.endo_simul = [oo_.endo_simul; x_'];
end
end
for i_=1:size(M_.exo_names,1)
if series_ == 1
x_ = eval(M_.exo_names(i_,:) );
oo_.exo_simul = [oo_.exo_simul x_];
if size(x_,2)>size(x_,1) %oo_.endo_simul must be collection of row vectors
oo_.exo_simul = [oo_.exo_simul x_'];
else %if column vector
oo_.exo_simul = [oo_.exo_simul x_];
end
else
k_ = strmatch(upper(M_.exo_names(i_,:)),names_v_,'exact');
k_ = strmatch(deblank(M_.exo_names(i_,:)),names_v_,'exact');
if isempty(k_)
error(['INITVAL_FILE: ' M_.exo_names(i_,:) ' not found'])
error(['INITVAL_FILE: ' deblank(M_.exo_names(i_,:)) ' not found'])
end
x_ = data_(:,k_);
oo_.exo_simul = [oo_.exo_simul x_];
oo_.exo_simul = [oo_.exo_simul x_];
end
end
end

View File

@ -1,4 +1,4 @@
function [Ui,Vi,n0,np,ixmC0Pres] = exclusions(nvar,nexo,options_ms)
function [Ui,Vi,n0,np,ixmC0Pres,Qi] = exclusions(nvar,nexo,options_ms)
% function [Ui,Vi,n0,np,ixmC0Pres] = exclusions(nvar,nexo,options_ms)
%
% INPUTS

View File

@ -0,0 +1,77 @@
function indent = sbvar_global_identification_check(options_)
% function sbvar_global_identification_check(options_.ms)
%
% INPUTS
% options_ms: (struct) options
%
% OUTPUTS
% ident: (boolean) false = not identified; true = identified
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2015 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 <http://www.gnu.org/licenses/>.
ident = false;
if isequal(options_.ms.restriction_fname, 'upper_cholesky') || ...
isequal(options_.ms.restriction_fname, 'lower_cholesky')
ident = true;
if ~options_.noprint
disp(' ')
disp('SBVAR: Cholesky identification is always identified')
disp(' ')
end
return
end
nvar = length(options_.varobs); % number of endogenous variables
nexo = 1;
[Uiconst,Viconst,n0,np,ixmC0Pres,Qi] = exclusions(nvar,nexo,options_.ms );
% order column constraints by rank
Qranks = zeros(nvar,2);
for j=1:nvar
Qranks(j,:) = [j,rank(Qi{j})];
end
Qranks = sortrows(Qranks,-2);
ident = true;
for j=1:nvar
i = Qranks(j,1);
for k=1:1
M = [Qi{i}*rand(size(Qi{i},1),nvar);[eye(j) zeros(j,nvar- ...
j)]];
disp([j,k,rank(M)])
if rank(M) < nvar
ident = false
break
end
end
end
if ~options_.noprint
disp(' ')
if ident
disp('The sufficient condition for SBVAR identification is met')
else
disp('WARNGING: The sufficient condition for SBVAR identification is not met')
end
disp(' ')
end

View File

@ -177,10 +177,9 @@ switch minimizer_algorithm
end
end
[opt_par_values,hessian_mat,gg,fval,invhess] = newrat(objective_function,start_par_value,analytic_grad,crit,nit,0,varargin{:});
%hessian_mat is the plain outer product gradient Hessian
if options_.analytic_derivation %Hessian is already analytic one, reset option
options_.analytic_derivation = ana_deriv;
elseif ~options_.analytic_derivation && newratflag ==0 %Analytic Hessian wanted, but not computed yet
hessian_mat = reshape(mr_hessian(0,opt_par_values,objective_function,1,crit,varargin{:}), n_params, n_params);
end
case 6
[opt_par_values, hessian_mat, Scale, fval] = gmhmaxlik(objective_function, start_par_value, ...

View File

@ -41,10 +41,22 @@ end
if isempty(DynareResults.endo_simul) || any(size(DynareResults.endo_simul) ~= [ DynareModel.endo_nbr, DynareModel.maximum_lag+DynareOptions.periods+DynareModel.maximum_lead ])
error('perfect_foresight_solver:ArgCheck','PERFECT_FORESIGHT_SOLVER: ''oo_.endo_simul'' has wrong size. Did you run ''perfect_foresight_setup'' ?')
if options_.initval_file
disp(sprintf('PERFECT_FORESIGHT_SOLVER: ''oo_.endo_simul'' has wrong size. Check whether your initval-file provides %d periods.',M_.maximum_endo_lag+options_.periods+M_.maximum_endo_lead))
error('perfect_foresight_solver:ArgCheck','PERFECT_FORESIGHT_SOLVER: ''oo_.endo_simul'' has wrong size. Did you run ''perfect_foresight_setup'' ?')
else
error('perfect_foresight_solver:ArgCheck','PERFECT_FORESIGHT_SOLVER: ''oo_.endo_simul'' has wrong size. Did you run ''perfect_foresight_setup'' ?')
end
end
if (DynareModel.exo_nbr > 0) && (isempty(DynareResults.exo_simul) || ...
any(size(DynareResults.exo_simul) ~= [ DynareModel.maximum_lag+DynareOptions.periods+DynareModel.maximum_lead, DynareModel.exo_nbr ]))
if (DynareModel.exo_nbr > 0) && ...
(isempty(DynareResults.exo_simul) || any(size(DynareResults.exo_simul) ~= [ DynareModel.maximum_lag+DynareOptions.periods+DynareModel.maximum_lead, DynareModel.exo_nbr ]))
if options_.initval_file
disp(sprintf('PERFECT_FORESIGHT_SOLVER: ''oo_.exo_simul'' has wrong size. Check whether your initval-file provides %d periods.',M_.maximum_endo_lag+options_.periods+M_.maximum_endo_lead))
error('perfect_foresight_solver:ArgCheck','PERFECT_FORESIGHT_SOLVER: ''oo_.exo_simul'' has wrong size.')
else
error('perfect_foresight_solver:ArgCheck','PERFECT_FORESIGHT_SOLVER: ''oo_.exo_simul'' has wrong size. Did you run ''perfect_foresight_setup'' ?')
end
error('perfect_foresight_solver:ArgCheck','PERFECT_FORESIGHT_SOLVER: ''oo_.exo_simul'' has wrong size. Did you run ''perfect_foresight_setup'' ?')
end

View File

@ -37,7 +37,7 @@ function oo_ = sim1_purely_forward(options_, M_, oo_)
1, options_.gstep, options_.solve_tolf, ...
options_.solve_tolx, options_.simul.maxit, ...
options_.debug,oo_.exo_simul, M_.params, oo_.steady_state, ...
it);
it+M_.maximum_lag);
if info
oo_.deterministic_simulation.status = 0;

View File

@ -82,7 +82,7 @@ else
[oo_.dr,info,M_,options_,oo_] = resol(0,M_,options_,oo_);
end
if options_.loglinear %log steady state for correct display of decision rules and simulations
if options_.loglinear && isfield(oo_.dr,'ys') %log steady state for correct display of decision rules and simulations
oo_.dr.ys=log(oo_.dr.ys);
oo_.steady_state=log(oo_.steady_state);
options_old.logged_steady_state = 1;

View File

@ -10,7 +10,7 @@ function warning_config()
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2008-2013 Dynare Team
% Copyright (C) 2008-2015 Dynare Team
%
% This file is part of Dynare.
%
@ -34,7 +34,11 @@ warning('on', 'backtrace');
if isoctave
warning('off', 'Octave:separator-insert');
warning('off', 'Octave:matlab-incompatible');
if octave_ver_less_than('4.0')
warning('off', 'Octave:matlab-incompatible');
else
warning('off', 'Octave:language-extension');
end
warning('off', 'Octave:single-quote-string');
warning('off', 'Octave:missing-semicolon');
warning('off', 'Octave:empty-list-elements');
@ -43,11 +47,7 @@ if isoctave
warning('off', 'Octave:str-to-num');
warning('off', 'Octave:array-as-scalar');
warning('off', 'Octave:array-as-vector');
if octave_ver_less_than('3.6')
warning('off', 'Octave:string-concat');
else
warning('off', 'Octave:mixed-string-concat');
end
warning('off', 'Octave:mixed-string-concat');
warning('off', 'Octave:variable-switch-label');
warning('off', 'Octave:fortran-indexing');
else

View File

@ -2,12 +2,16 @@ ACLOCAL_AMFLAGS = -I ../../../m4
# libdynare++ must come before gensylv, k_order_perturbation, dynare_simul_
if DO_SOMETHING
SUBDIRS = mjdgges kronecker bytecode libdynare++ gensylv qzcomplex ordschur block_kalman_filter sobol local_state_space_iterations
SUBDIRS = mjdgges kronecker bytecode libdynare++ gensylv qzcomplex block_kalman_filter sobol local_state_space_iterations
if COMPILE_LINSOLVE
SUBDIRS += linsolve
endif
if COMPILE_ORDSCHUR
SUBDIRS += ordschur
endif
if HAVE_MATIO
SUBDIRS += k_order_perturbation dynare_simul_
endif

View File

@ -1,6 +1,6 @@
dnl Process this file with autoconf to produce a configure script.
dnl Copyright (C) 2009-2014 Dynare Team
dnl Copyright (C) 2009-2015 Dynare Team
dnl
dnl This file is part of Dynare.
dnl
@ -34,9 +34,11 @@ if test "x$MKOCTFILE" != "x"; then
OCTAVE_VERSION=`$MKOCTFILE -v 2>&1 | sed 's/mkoctfile, version //'`
AX_COMPARE_VERSION([$OCTAVE_VERSION], [lt], [3.6], [AC_MSG_ERROR([Your Octave is too old, please upgrade to version 3.6 at least.])])
AX_COMPARE_VERSION([$OCTAVE_VERSION], [ge], [3.8], [OCTAVE38=yes])
AX_COMPARE_VERSION([$OCTAVE_VERSION], [ge], [4.0], [OCTAVE40=yes])
fi
AM_CONDITIONAL([COMPILE_LINSOLVE], [test "$OCTAVE38" != "yes"])
AM_CONDITIONAL([COMPILE_ORDSCHUR], [test "$OCTAVE40" != "yes"])
CFLAGS="$CFLAGS -Wall -Wno-parentheses"
FFLAGS="$FFLAGS -Wall"
@ -121,6 +123,12 @@ else
BUILD_LINSOLVE_OCTAVE="no (Octave >= 3.8)"
fi
if test -n "$MKOCTFILE" -a "$OCTAVE40" != "yes"; then
BUILD_ORDSCHUR_OCTAVE="yes"
else
BUILD_ORDSCHUR_OCTAVE="no (Octave >= 4.0)"
fi
AC_ARG_ENABLE([openmp], AS_HELP_STRING([--enable-openmp], [use OpenMP for parallelization of some MEX files]), [
if test "x$enable_openmp" = "xyes"; then
CPPFLAGS="$CPPFLAGS -DUSE_OMP"
@ -139,6 +147,7 @@ Binaries (with "make"):
Kalman Steady State MEX file for Octave: $BUILD_KALMAN_STEADY_STATE_OCTAVE
Estimation, k-order and dynare_simul MEX for Octave: $BUILD_ESTIMATION_KORDER_DYNSIMUL_MEX_OCTAVE
Linsolve for Octave: $BUILD_LINSOLVE_OCTAVE
Ordschur for Octave: $BUILD_ORDSCHUR_OCTAVE
])

View File

@ -730,17 +730,14 @@ DynareSensitivityStatement::writeOutput(ostream &output, const string &basename)
output << "dynare_sensitivity(options_gsa);" << endl;
}
RplotStatement::RplotStatement(const SymbolList &symbol_list_arg,
const OptionsList &options_list_arg) :
symbol_list(symbol_list_arg),
options_list(options_list_arg)
RplotStatement::RplotStatement(const SymbolList &symbol_list_arg) :
symbol_list(symbol_list_arg)
{
}
void
RplotStatement::writeOutput(ostream &output, const string &basename) const
{
options_list.writeOutput(output);
symbol_list.writeOutput("var_list_", output);
output << "rplot(var_list_);" << endl;
}
@ -2369,7 +2366,7 @@ JointPriorStatement::writeOutput(ostream &output, const string &basename) const
writeOutputHelper(output, "truncate", lhs_field);
writeOutputHelper(output, "variance", lhs_field);
output << "estimation_info.joint_parameter_tmp = table(key, ..." << endl
output << "estimation_info.joint_parameter_tmp = [key, ..." << endl
<< " " << lhs_field << ".domain , ..." << endl
<< " " << lhs_field << ".interval , ..." << endl
<< " " << lhs_field << ".mean , ..." << endl
@ -2379,15 +2376,9 @@ JointPriorStatement::writeOutput(ostream &output, const string &basename) const
<< " " << lhs_field << ".shift , ..." << endl
<< " " << lhs_field << ".stdev , ..." << endl
<< " " << lhs_field << ".truncate , ..." << endl
<< " " << lhs_field << ".variance, ..." << endl
<< " 'VariableNames',{'index','domain','interval','mean','median','mode','shape','shift','stdev','truncate','variance'});" << endl;
output << "if height(estimation_info.joint_parameter)" << endl
<< " estimation_info.joint_parameter = [estimation_info.joint_parameter; estimation_info.joint_parameter_tmp];" << endl
<< "else" << endl
<< " estimation_info.joint_parameter = estimation_info.joint_parameter_tmp;" << endl
<< "end" << endl
<< "clear estimation_info.joint_parameter_tmp;" << endl;
<< " " << lhs_field << ".variance];" << endl
<< "estimation_info.joint_parameter = [estimation_info.joint_parameter; estimation_info.joint_parameter_tmp];" << endl
<< "estimation_info=rmfield(estimation_info, 'joint_parameter_tmp');" << endl;
}
void
@ -2395,10 +2386,14 @@ JointPriorStatement::writeOutputHelper(ostream &output, const string &field, con
{
OptionsList::num_options_t::const_iterator itn = options_list.num_options.find(field);
output << lhs_field << "." << field << " = {";
if (field=="variance")
output << "{";
if (itn != options_list.num_options.end())
output << itn->second;
else
output << "{}";
if (field=="variance")
output << "}";
output << "};" << endl;
}

View File

@ -155,10 +155,8 @@ class RplotStatement : public Statement
{
private:
const SymbolList symbol_list;
const OptionsList options_list;
public:
RplotStatement(const SymbolList &symbol_list_arg,
const OptionsList &options_list_arg);
RplotStatement(const SymbolList &symbol_list_arg);
virtual void writeOutput(ostream &output, const string &basename) const;
};

View File

@ -187,6 +187,10 @@ DynamicModel::computeTemporaryTermsOrdered()
it->second->collectTemporary_terms(temporary_terms, temporary_terms_in_use, block);
for (derivative_t::const_iterator it = derivative_other_endo[block].begin(); it != derivative_other_endo[block].end(); it++)
it->second->collectTemporary_terms(temporary_terms, temporary_terms_in_use, block);
for (derivative_t::const_iterator it = derivative_exo[block].begin(); it != derivative_exo[block].end(); it++)
it->second->collectTemporary_terms(temporary_terms, temporary_terms_in_use, block);
for (derivative_t::const_iterator it = derivative_exo_det[block].begin(); it != derivative_exo_det[block].end(); it++)
it->second->collectTemporary_terms(temporary_terms, temporary_terms_in_use, block);
v_temporary_terms_inuse[block] = temporary_terms_in_use;
}
computeTemporaryTermsMapping();

View File

@ -851,6 +851,8 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2
string token;
yylval->vector_string_val = new vector<string *>;
bool dynare_statement = true;
while(getline(ss, token, ','))
if (driver.symbol_exists_and_is_not_modfile_local_or_external_function(token.c_str()))
yylval->vector_string_val->push_back(new string(token));
@ -862,9 +864,10 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2
delete yylval->vector_string_val;
BEGIN NATIVE;
yyless(0);
dynare_statement = false;
break;
}
if (yylval->vector_string_val->size() > 0)
if (dynare_statement)
{
BEGIN DYNARE_STATEMENT;
return token::SYMBOL_VEC;

View File

@ -68,8 +68,14 @@ DynareFlex.cc FlexLexer.h: DynareFlex.ll
DynareBison.cc DynareBison.hh location.hh stack.hh position.hh: DynareBison.yy
$(YACC) -o DynareBison.cc DynareBison.yy
all-local:
cd ../matlab && $(LN_S) -f $(abs_srcdir)/$(PROGRAMS) $(PROGRAMS)
all-local: $(PROGRAMS)
if [ -z "`file $(PROGRAMS) | grep x86.64`" ]; then \
ARCH="32"; \
else \
ARCH="64"; \
fi; \
mkdir -p ../matlab/preprocessor$$ARCH ; \
cd ../matlab/preprocessor$$ARCH && $(LN_S) -f $(abs_srcdir)/$(PROGRAMS) $(PROGRAMS)
if HAVE_DOXYGEN
html-local:
@ -77,7 +83,7 @@ html-local:
endif
clean-local:
cd ../matlab && rm -f $(PROGRAMS)
rm -rf ../matlab/preprocessor*
rm -rf doc/html/
EXTRA_DIST = $(BUILT_SOURCES) Doxyfile

View File

@ -1186,8 +1186,7 @@ ParsingDriver::add_in_symbol_list(string *tmp_var)
void
ParsingDriver::rplot()
{
mod_file->addStatement(new RplotStatement(symbol_list, options_list));
options_list.clear();
mod_file->addStatement(new RplotStatement(symbol_list));
symbol_list.clear();
}

View File

@ -39,7 +39,7 @@ MODFILES = \
optimal_policy/Ramsey/ramsey_ex_initval_AR2.mod \
optimal_policy/Ramsey/ramsey_ex_aux.mod \
discretionary_policy/dennis_1.mod \
ramst_initval_file.mod \
initval_file/ramst_initval_file.mod \
ramst_normcdf_and_friends.mod \
ramst_vec.mod \
example1_varexo_det.mod \
@ -211,6 +211,8 @@ XFAIL_MODFILES = ramst_xfail.mod \
estim_param_in_shock_value.mod \
optimal_policy/Ramsey/ramsey_ex_wrong_ss_file.mod
MFILES = initval_file/ramst_initval_file_data.m
# Dependencies
example1_use_dll.m.trs: example1.m.trs
example1_use_dll.o.trs: example1.o.trs
@ -285,6 +287,11 @@ deterministic_simulations/rbc_det_exo_lag_2c.m.trs: deterministic_simulations/rb
deterministic_simulations/rbc_det_exo_lag_2b.o.trs: deterministic_simulations/rbc_det_exo_lag_2a.o.trs
deterministic_simulations/rbc_det_exo_lag_2c.o.trs: deterministic_simulations/rbc_det_exo_lag_2a.o.trs
initval_file/ramst_initval_file.m.trs: initval_file/ramst_initval_file_data.m.tls
initval_file/ramst_initval_file.o.trs: initval_file/ramst_initval_file_data.o.tls
# Matlab TRS Files
M_TRS_FILES = $(patsubst %.mod, %.m.trs, $(MODFILES))
M_TRS_FILES += run_block_byte_tests_matlab.m.trs run_reporting_test_matlab.m.trs run_all_unitary_tests.m.trs
@ -295,12 +302,21 @@ O_TRS_FILES = $(patsubst %.mod, %.o.trs, $(MODFILES))
O_TRS_FILES += run_block_byte_tests_octave.o.trs run_reporting_test_octave.o.trs run_all_unitary_tests.o.trs
O_XFAIL_TRS_FILES = $(patsubst %.mod, %.o.trs, $(XFAIL_MODFILES))
# Matlab TLS Files
M_TLS_FILES = $(patsubst %.m, %.m.tls, $(MFILES))
# Octave TLS Files
O_TLS_FILES = $(patsubst %.m, %.o.tls, $(MFILES))
EXTRA_DIST = \
read_trs_files.sh \
run_test_matlab.m \
run_test_octave.m \
$(MODFILES) \
$(XFAIL_MODFILES) \
$(MFILES) \
run_block_byte_tests_matlab.m \
run_block_byte_tests_octave.m \
run_reporting_test_matlab.m \
@ -321,8 +337,7 @@ EXTRA_DIST = \
fs2000_ssfile_aux.m \
printMakeCheckMatlabErrMsg.m \
printMakeCheckOctaveErrMsg.m \
ramst_initval_file_data.m \
test.m \
fataltest.m \
AIM/data_ca1.m \
AIM/fs2000_b1L1L_AIM_steadystate.m \
AIM/fs2000_b1L1L_steadystate.m \
@ -419,10 +434,22 @@ check-octave: $(O_XFAIL_TRS_FILES) $(O_TRS_FILES)
DYNARE_VERSION="$(PACKAGE_VERSION)" TOP_TEST_DIR="$(PWD)" \
$(OCTAVE) --no-init-file --silent --no-history $< > $*.o.log 2>&1
%.m.tls : %.m
TOP_TEST_DIR="$(PWD)" FILESTEM="$*" \
$(MATLAB)/bin/matlab -nosplash -nodisplay -r run_m_script
touch $*.m.tls
%.o.tls : %.m
TOP_TEST_DIR="$(PWD)" FILESTEM="$*" \
$(OCTAVE) --no-init-file --silent --no-history run_o_script.m 2>&1
clean-local:
rm -f $(M_TRS_FILES) \
$(M_TLS_FILES) \
$(M_XFAIL_TRS_FILES) \
$(O_TRS_FILES) \
$(O_TLS_FILES) \
$(O_XFAIL_TRS_FILES) \
$(patsubst %.trs, %.log, $(M_TRS_FILES)) \
$(patsubst %.trs, %.log, $(M_XFAIL_TRS_FILES)) \
@ -489,3 +516,5 @@ clean-local:
ms-sbvar/tmv_rr_tr
rm -f estimation/test_matrix.mat
rm -f initval_file/ramst_initval_file_data_col_vec_mat.mat initval_file/ramst_initval_file_data_row_vec_mat.mat initval_file/ramst_initval_file_excel.xls

View File

@ -77,4 +77,4 @@ rplot Capital;
O=load('rbc_det_exo_lag_2a_results');
test(oo_.endo_simul(:,2:end),O.oo_.endo_simul);
fataltest(oo_.endo_simul(:,2:end),O.oo_.endo_simul);

View File

@ -77,4 +77,4 @@ rplot Capital;
O=load('rbc_det_exo_lag_2a_results');
test(oo_.endo_simul(:,2:end),O.oo_.endo_simul);
fataltest(oo_.endo_simul(:,2:end),O.oo_.endo_simul);

View File

@ -23,12 +23,25 @@ c = aa*k^alph-delt*k;
end;
initval_file(filename = ramst_initval_file_data);
steady;
perfect_foresight_setup(periods=200);
perfect_foresight_solver;
check;
simul(periods=200);
initval_file(filename = ramst_initval_file_data_row_vec_mat);
steady;
perfect_foresight_setup(periods=200);
perfect_foresight_solver;
rplot c;
rplot k;
initval_file(filename = ramst_initval_file_data_col_vec_mat);
steady;
perfect_foresight_setup(periods=200);
perfect_foresight_solver;
if ispc()
initval_file(filename = ramst_initval_file_excel);
steady;
perfect_foresight_setup(periods=200);
perfect_foresight_solver;
end

View File

@ -0,0 +1,14 @@
x = vertcat([ 1; 1.2 ], repmat(1, 200, 1));
k = repmat(12.7551, 202, 1);
c = repmat(1.53061, 202, 1);
save('ramst_initval_file_data_col_vec_mat.mat');
if ispc()
xlswrite('ramst_initval_file_excel',[x k c],1,'A2');
xlswrite('ramst_initval_file_excel',{'x' 'k' 'c'},1,'A1');
end
c=c';
k=k';
x=x';
save('ramst_initval_file_data_row_vec_mat.mat');

View File

@ -0,0 +1,16 @@
// same as test_lower_cholesky.mod, but using exclusion syntax
var R Pie Y;
varobs Y Pie R;
svar_identification;
exclusion lag 0;
equation 1, Pie, Y;
exclusion lag 1;
equation 2, Y;
end;
sbvar_global_identification_check(options_);
sbvar(datafile = data,freq=4,initial_year=1959,final_year=2005,nlags=4);

View File

@ -0,0 +1,15 @@
// same as test_lower_cholesky.mod, but using exclusion syntax
var R Pie Y;
varobs Y Pie R;
svar_identification;
exclusion lag 0;
equation 1, Pie, Y;
equation 2, Y;
end;
sbvar_global_identification_check(options_);
sbvar(datafile = data,freq=4,initial_year=1959,final_year=2005,nlags=4);

View File

@ -28,7 +28,7 @@ options_.nograph=1;
options_.nocorr=1;
osr_params gammax0 gammac0 gamma_y_ gamma_inf_;
if ~isoctave
optim_weights;
inflation 1;
y 1;
@ -107,3 +107,4 @@ end
if max(abs((cell2mat(struct2cell(oo_.osr.optim_params))-cell2mat(struct2cell(oo_covar_single.osr.optim_params)))./cell2mat(struct2cell(oo_.osr.optim_params))))>1e-4
error('Parameters should be identical')
end
end

View File

@ -41,6 +41,7 @@ gammac0 = 1.5;
gamma_y_ = 8;
gamma_inf_ = 3;
if ~isoctave
osr(opt_algo=7);
%compute objective function manually
objective=oo_.var(strmatch('y',M_.endo_names,'exact'),strmatch('y',M_.endo_names,'exact'))+oo_.var(strmatch('inflation',M_.endo_names,'exact'),strmatch('inflation',M_.endo_names,'exact'))+oo_.var(strmatch('dummy_var',M_.endo_names,'exact'),strmatch('dummy_var',M_.endo_names,'exact'));
@ -107,3 +108,4 @@ end
if max(abs((cell2mat(struct2cell(oo_.osr.optim_params))-cell2mat(struct2cell(oo_covar_single.osr.optim_params)))./cell2mat(struct2cell(oo_.osr.optim_params))))>1e-4
error('Parameters should be identical')
end
end

View File

@ -1,3 +0,0 @@
x = vertcat([ 1; 1.2 ], repmat(1, 200, 1));
k = repmat(12.7551, 202, 1);
c = repmat(1.53061, 202, 1);

52
tests/run_m_script.m Normal file
View File

@ -0,0 +1,52 @@
% Copyright (C) 2015 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 <http://www.gnu.org/licenses/>.
top_test_dir = getenv('TOP_TEST_DIR');
[mfile, name] = strtok(getenv('FILESTEM'));
[directory, mscript, ext] = fileparts([top_test_dir '/' mfile]);
cd(directory);
try
mscript;
testFailed = false;
catch exception
printMakeCheckMatlabErrMsg(strtok(getenv('FILESTEM')), exception);
testFailed = true;
end
cd(top_test_dir);
name = strtok(getenv('FILESTEM'));
fid = fopen([name '.m.tls'], 'w');
if fid < 0
wd = pwd
filestep = getenv('FILESTEM')
error(['ERROR: problem opening file ' name '.m.tls for writing....']);
end
if testFailed
fprintf(fid,':test-result: FAIL\n');
fprintf(fid,':number-tests: 1\n');
fprintf(fid,':number-failed-tests: 1\n');
fprintf(fid,':list-of-failed-tests: %s\n', [name '.m']);
else
fprintf(fid,':test-result: PASS\n');
fprintf(fid,':number-tests: 1\n');
fprintf(fid,':number-failed-tests: 0\n');
fprintf(fid,':list-of-passed-tests: %s\n', [name '.m']);
end
fclose(fid);
exit;

52
tests/run_o_script.m Normal file
View File

@ -0,0 +1,52 @@
## Copyright (C) 2015 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 <http://www.gnu.org/licenses/>.
top_test_dir = getenv('TOP_TEST_DIR');
[mfile, name] = strtok(getenv('FILESTEM'));
[directory, mscript, ext] = fileparts([top_test_dir '/' mfile]);
cd(directory);
try
mscript;
testFailed = false;
catch
printMakeCheckOctaveErrMsg(getenv('FILESTEM'), lasterror);
testFailed = true;
end_try_catch
cd(top_test_dir);
name = strtok(getenv('FILESTEM'));
fid = fopen([name '.o.tls'], 'w+');
if testFailed
fprintf(fid,':test-result: FAIL\n');
fprintf(fid,':number-tests: 1\n');
fprintf(fid,':number-failed-tests: 1\n');
fprintf(fid,':list-of-failed-tests: %s\n', [name '.m']);
else
fprintf(fid,':test-result: PASS\n');
fprintf(fid,':number-tests: 1\n');
fprintf(fid,':number-failed-tests: 0\n');
fprintf(fid,':list-of-passed-tests: %s\n', [name '.m']);
end
fclose(fid);
exit;
## Local variables:
## mode: Octave
## End:

View File

@ -28,10 +28,10 @@ stoch_simul(nomoments,nocorr,ar=0,irf=0);
global dr_
load objectives/sgu_ex1;
test(oo_.dr.ghx,dr_obj_.ghx,1);
test(oo_.dr.ghu,dr_obj_.ghu,2);
test(oo_.dr.ghxx,dr_obj_.ghxx,3);
test(oo_.dr.ghxu,dr_obj_.ghxu,4);
test(oo_.dr.ghuu,dr_obj_.ghuu,5);
fataltest(oo_.dr.ghx,dr_obj_.ghx,1);
fataltest(oo_.dr.ghu,dr_obj_.ghu,2);
fataltest(oo_.dr.ghxx,dr_obj_.ghxx,3);
fataltest(oo_.dr.ghxu,dr_obj_.ghxu,4);
fataltest(oo_.dr.ghuu,dr_obj_.ghuu,5);
disp('TESTS OK');
disp('TESTS OK');

View File

@ -58,7 +58,12 @@ Section "Dynare core (preprocessor and M-files)"
SetOutPath $INSTDIR\matlab
File /r ..\matlab\*.m
File ..\matlab\dynare_m.exe
SetOutPath $INSTDIR\matlab\preprocessor32
File ..\matlab\preprocessor32\dynare_m.exe
SetOutPath $INSTDIR\matlab\preprocessor64
File ..\matlab\preprocessor64\dynare_m.exe
SetOutPath $INSTDIR\contrib
File /r ..\contrib\*.m
@ -83,9 +88,9 @@ SectionEnd
SectionGroup "MEX files for MATLAB"
Section "MEX files for MATLAB 32-bit, version 7.5 to 8.4 (R2007b to R2014b)"
SetOutPath $INSTDIR\mex\matlab\win32-7.5-8.4
File ..\mex\matlab\win32-7.5-8.4\*.mexw32
Section "MEX files for MATLAB 32-bit, version 7.5 to 8.5 (R2007b to R2015a)"
SetOutPath $INSTDIR\mex\matlab\win32-7.5-8.5
File ..\mex\matlab\win32-7.5-8.5\*.mexw32
SectionEnd
Section "MEX files for MATLAB 64-bit, version 7.5 to 7.7 (R2007b to R2008b)"
@ -93,9 +98,9 @@ Section "MEX files for MATLAB 64-bit, version 7.5 to 7.7 (R2007b to R2008b)"
File ..\mex\matlab\win64-7.5-7.7\*.mexw64
SectionEnd
Section "MEX files for MATLAB 64-bit, version 7.8 to 8.4 (R2009a to R2014b)"
SetOutPath $INSTDIR\mex\matlab\win64-7.8-8.4
File ..\mex\matlab\win64-7.8-8.4\*.mexw64
Section "MEX files for MATLAB 64-bit, version 7.8 to 8.5 (R2009a to R2015a)"
SetOutPath $INSTDIR\mex\matlab\win64-7.8-8.5
File ..\mex\matlab\win64-7.8-8.5\*.mexw64
SectionEnd
SectionGroupEnd