Commit 251b6c80 authored by Stéphane Adjemian (Scylla)'s avatar Stéphane Adjemian (Scylla)
Browse files

Merge branch 'master' of kirikou.dynare.org:/srv/d_kirikou/git/dynare

parents ba013638 bed8f4b6
......@@ -153,3 +153,4 @@ ylwrap
!/mex/sources/kalman/qt/test/Makefile
!/mex/sources/kalman/sylv/cc/Makefile
!/mex/sources/kalman/testing/Makefile
.DS_Store
\ No newline at end of file
......@@ -1842,7 +1842,7 @@ steady(homotopy_mode = 1, homotopy_steps = 50);
When the analytical solution of the model is known, this command can be used to help Dynare find the steady state in a more efficient and reliable way, especially during estimation where the steady state has to be recomputed for every point in the parameter space.
</para>
<para>
Each line of this block consists of a variable (either an endogenous or a temporary variable) which is assigned an expression (which can contain parameters, exogenous at the steady state, or any endogenous or temporary variable already declared above).
Each line of this block consists of a variable (either an endogenous, a temporary variable or a parameter) which is assigned an expression (which can contain parameters, exogenous at the steady state, or any endogenous or temporary variable already declared above).
</para>
<para>
Internally, Dynare will create a steady state file called <filename><replaceable>FILENAME</replaceable>_steadystate.m</filename>, using the information provided in this block.
......@@ -2158,7 +2158,11 @@ steady;
<varlistentry>
<term><option>conditional_variance_decomposition</option> = [<replaceable>INTEGER1</replaceable> <replaceable>INTEGER2</replaceable> ...]</term>
<listitem><para>Computes a conditional variance decomposition for the specified period(s). Conditional variances are given by var(y<subscript>t+k</subscript>|t). For period 1, the conditional variance decomposition provides the decomposition of the effects of shocks upon impact.</para></listitem>
</varlistentry>
</varlistentry>
<varlistentry>
<term><option>pruning</option></term>
<listitem><para>Discard higher order terms when iteratively computing simulations of the solution, as in <xref linkend="kim-kim-schaumburg-sims_2008"/>.</para></listitem>
</varlistentry>
</variablelist>
</refsect1>
......@@ -2195,7 +2199,7 @@ steady;
<refsect1>
<title>Auxiliary variables for leads and lags</title>
<para>For a stochastic model, Dynare will perform a transformation of the model so that there is only one lead and one lag on endogenous, and no lead/lag on exogenous.</para>
<para>This transformation is achieved by the creation of auxiliary variables, and corresponding equations. For example, if <literal>x(+2)</literal> exists in the model, Dynare will create one auxiliary variable <literal>AUX_ENDO_LEAD = x(+1)</literal>, and replace <literal>x(+1)</literal> by <literal>AUX_ENDO_LEAD(+1)</literal>.</para>
<para>This transformation is achieved by the creation of auxiliary variables, and corresponding equations. For example, if <literal>x(+2)</literal> exists in the model, Dynare will create one auxiliary variable <literal>AUX_ENDO_LEAD = x(+1)</literal>, and replace <literal>x(+2)</literal> by <literal>AUX_ENDO_LEAD(+1)</literal>.</para>
<para>A similar transformation is done for lags greater than 2 on endogenous (auxiliary variables will have a name beginning with <literal>AUX_ENDO_LAG</literal>), and for exogenous with leads and lags (auxiliary variables will have a name beginning with <literal>AUX_EXO_LEAG</literal> or <literal>AUX_EXO_LAG</literal> respectively).</para>
<para>Once created, all auxiliary variables are included in the set of endogenous variables. The output of decision rules (see below) is such that auxiliary variable names are replaced by the original variables they refer to.</para>
</refsect1>
......@@ -4404,5 +4408,37 @@ plot_conditional_forecast(periods = 10) e u;
</biblioentry>
<biblioentry id="kim-kim-schaumburg-sims_2008" xreflabel="Kim, Kim, Schaumburg and Sims (2008)">
<biblioset relation="article">
<authorgroup>
<author>
<surname>Kim</surname>
<firstname>Jinill</firstname>
</author>
<author>
<surname>Kim</surname>
<firstname>Sunghyun</firstname>
</author>
<author>
<surname>Schaumburg</surname>
<firstname>Ernst</firstname>
</author>
<author>
<surname>Sims</surname>
<firstname>Christopher A.</firstname>
</author>
</authorgroup>
<pubdate>2008</pubdate>
<title>Calculating and using second-order accurate solutions of discrete time dynamic equilibrium models</title>
</biblioset>
<biblioset relation="journal">
<title>Journal of Economic Dynamics and Control</title>
<volumenum>32</volumenum>
<issuenum>11</issuenum>
<pagenums>3397-3414</pagenums>
</biblioset>
</biblioentry>
</bibliography>
</book>
......@@ -305,3 +305,16 @@ License: GPL-2+ with special Autoconf exception
configuration script generated by GNU Autoconf, you may include
it under the same distribution terms that you use for the rest
of that program.
Files: m4/gsl.m4
Copyright: 2000, Christopher R. Gabriel <cgabriel@linux.it>
License: GPL-3+
GSL is free software, you can redistribute it and/or modify it under
the terms of the GNU General Public License.
.
The GNU General Public License does not permit this software to be
redistributed in proprietary programs.
.
This library 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.
# Configure path for the GNU Scientific Library
# Christopher R. Gabriel <cgabriel@linux.it>, April 2000
AC_DEFUN([AX_PATH_GSL],
[
AC_ARG_WITH(gsl-prefix,[ --with-gsl-prefix=PFX Prefix where GSL is installed (optional)],
gsl_prefix="$withval", gsl_prefix="")
AC_ARG_WITH(gsl-exec-prefix,[ --with-gsl-exec-prefix=PFX Exec prefix where GSL is installed (optional)],
gsl_exec_prefix="$withval", gsl_exec_prefix="")
AC_ARG_ENABLE(gsltest, [ --disable-gsltest Do not try to compile and run a test GSL program],
, enable_gsltest=yes)
if test "x${GSL_CONFIG+set}" != xset ; then
if test "x$gsl_prefix" != x ; then
GSL_CONFIG="$gsl_prefix/bin/gsl-config"
fi
if test "x$gsl_exec_prefix" != x ; then
GSL_CONFIG="$gsl_exec_prefix/bin/gsl-config"
fi
fi
AC_PATH_PROG(GSL_CONFIG, gsl-config, no)
min_gsl_version=ifelse([$1], ,0.2.5,$1)
AC_MSG_CHECKING(for GSL - version >= $min_gsl_version)
no_gsl=""
if test "$GSL_CONFIG" = "no" ; then
no_gsl=yes
else
GSL_CFLAGS=`$GSL_CONFIG --cflags`
GSL_LIBS=`$GSL_CONFIG --libs`
gsl_major_version=`$GSL_CONFIG --version | \
sed 's/^\([[0-9]]*\).*/\1/'`
if test "x${gsl_major_version}" = "x" ; then
gsl_major_version=0
fi
gsl_minor_version=`$GSL_CONFIG --version | \
sed 's/^\([[0-9]]*\)\.\{0,1\}\([[0-9]]*\).*/\2/'`
if test "x${gsl_minor_version}" = "x" ; then
gsl_minor_version=0
fi
gsl_micro_version=`$GSL_CONFIG --version | \
sed 's/^\([[0-9]]*\)\.\{0,1\}\([[0-9]]*\)\.\{0,1\}\([[0-9]]*\).*/\3/'`
if test "x${gsl_micro_version}" = "x" ; then
gsl_micro_version=0
fi
if test "x$enable_gsltest" = "xyes" ; then
ac_save_CFLAGS="$CFLAGS"
ac_save_LIBS="$LIBS"
CFLAGS="$CFLAGS $GSL_CFLAGS"
LIBS="$LIBS $GSL_LIBS"
rm -f conf.gsltest
AC_TRY_RUN([
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char* my_strdup (const char *str);
char*
my_strdup (const char *str)
{
char *new_str;
if (str)
{
new_str = (char *)malloc ((strlen (str) + 1) * sizeof(char));
strcpy (new_str, str);
}
else
new_str = NULL;
return new_str;
}
int main (void)
{
int major = 0, minor = 0, micro = 0;
int n;
char *tmp_version;
system ("touch conf.gsltest");
/* HP/UX 9 (%@#!) writes to sscanf strings */
tmp_version = my_strdup("$min_gsl_version");
n = sscanf(tmp_version, "%d.%d.%d", &major, &minor, &micro) ;
if (n != 2 && n != 3) {
printf("%s, bad version string\n", "$min_gsl_version");
exit(1);
}
if (($gsl_major_version > major) ||
(($gsl_major_version == major) && ($gsl_minor_version > minor)) ||
(($gsl_major_version == major) && ($gsl_minor_version == minor) && ($gsl_micro_version >= micro)))
{
exit(0);
}
else
{
exit(1);
}
}
],, no_gsl=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
CFLAGS="$ac_save_CFLAGS"
LIBS="$ac_save_LIBS"
fi
fi
if test "x$no_gsl" = x ; then
AC_MSG_RESULT(yes)
ifelse([$2], , :, [$2])
else
AC_MSG_RESULT(no)
if test "$GSL_CONFIG" = "no" ; then
echo "*** The gsl-config script installed by GSL could not be found"
echo "*** If GSL was installed in PREFIX, make sure PREFIX/bin is in"
echo "*** your path, or set the GSL_CONFIG environment variable to the"
echo "*** full path to gsl-config."
else
if test -f conf.gsltest ; then
:
else
echo "*** Could not run GSL test program, checking why..."
CFLAGS="$CFLAGS $GSL_CFLAGS"
LIBS="$LIBS $GSL_LIBS"
AC_TRY_LINK([
#include <stdio.h>
], [ return 0; ],
[ echo "*** The test program compiled, but did not run. This usually means"
echo "*** that the run-time linker is not finding GSL or finding the wrong"
echo "*** version of GSL. If it is not finding GSL, you'll need to set your"
echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
echo "*** to the installed location Also, make sure you have run ldconfig if that"
echo "*** is required on your system"
echo "***"
echo "*** If you have an old version installed, it is best to remove it, although"
echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
[ echo "*** The test program failed to compile or link. See the file config.log for the"
echo "*** exact error that occured. This usually means GSL was incorrectly installed"
echo "*** or that you have moved GSL since it was installed. In the latter case, you"
echo "*** may want to edit the gsl-config script: $GSL_CONFIG" ])
CFLAGS="$ac_save_CFLAGS"
LIBS="$ac_save_LIBS"
fi
fi
# GSL_CFLAGS=""
# GSL_LIBS=""
ifelse([$3], , :, [$3])
fi
AC_SUBST(GSL_CFLAGS)
AC_SUBST(GSL_LIBS)
rm -f conf.gsltest
])
AU_ALIAS([AM_PATH_GSL], [AX_PATH_GSL])
function [ErrorCode] = AnalyseComputationalEnviroment(DataInput)
% DESCRIPTION
% This function is used to check the user computational request.
% PARALLEL CONTEXT
% In a parallel context, this function is used to check the user computational request.
% If no error happen the function return 0.
%
% INPUT/OUTPUT description:
%
% DataInput is the strcture option_.parallel, with the follow fields:
......
function [nCPU]= GiveCPUnumber (ComputerInformations)
% DESCRIPTION
% This function return the CPUs or cores numer avaiable
% PARALLEL CONTEXT
% In a parallel context this function return the CPUs or cores numer avaiable
% on the computer used for run parallel code.
%
% INPUTS
......
......@@ -13,6 +13,10 @@ function McMCDiagnostics(options_, estim_params_, M_)
% SPECIAL REQUIREMENTS
% none
% PARALLEL CONTEXT
% See the comment in random_walk_metropolis_hastings.m funtion.
% Copyright (C) 2005-2008,2010 Dynare Team
%
% This file is part of Dynare.
......@@ -86,6 +90,9 @@ end
disp('MCMC Diagnostics: Univariate convergence diagnostic, Brooks and Gelman (1998):')
% The mandatory variables for local/remote parallel
% computing are stored in localVars struct.
localVars.MhDirectoryName = MhDirectoryName;
localVars.nblck = nblck;
localVars.NumberOfMcFilesPerBlock = NumberOfMcFilesPerBlock;
......@@ -97,10 +104,13 @@ localVars.NumberOfLines = NumberOfLines;
localVars.time = time;
localVars.M_ = M_;
% Like sequential execution!
if isnumeric(options_.parallel),
fout = McMCDiagnostics_core(localVars,1,npar,0);
UDIAG = fout.UDIAG;
clear fout
% Parallel execution!
else
ModelName = M_.fname;
if ~isempty(M_.bvar)
......
function myoutput = McMCDiagnostics_core(myinputs,fpar,npar,whoiam, ThisMatlab)
% Core functionality for MCMC Diagnostics, which can be parallelized
% PARALLEL CONTEXT
% Core functionality for MCMC Diagnostics, which can be parallelized.
% See also the comment in random_walk_metropolis_hastings_core.m funtion.
% Copyright (C) 2005-2009 Dynare Team
% INPUTS
% See See the comment in random_walk_metropolis_hastings_core.m funtion.
% OUTPUTS
% o myoutput [struc]
% Contained UDIAG.
%
% ALGORITHM
% Portion of McMCDiagnostics.m function.
%
% SPECIAL REQUIREMENTS.
% None.
% Copyright (C) 2006-2008,2010 Dynare Team
%
% This file is part of Dynare.
%
......@@ -21,8 +37,26 @@ function myoutput = McMCDiagnostics_core(myinputs,fpar,npar,whoiam, ThisMatlab)
if nargin<4,
whoiam=0;
end
struct2local(myinputs);
% Reshape 'myinputs' for local computation.
% In order to avoid confusion in the name space, the instruction struct2local(myinputs) is replaced by:
MhDirectoryName=myinputs.MhDirectoryName;
nblck=myinputs.nblck;
NumberOfMcFilesPerBlock=myinputs.NumberOfMcFilesPerBlock;
Origin=myinputs.Origin;
StepSize=myinputs.StepSize;
mh_drop=myinputs.mh_drop;
NumberOfDraws=myinputs.NumberOfDraws;
NumberOfLines=myinputs.NumberOfLines;
time=myinputs.time;
M_=myinputs.M_;
if whoiam
Parallel=myinputs.Parallel;
MasterName=myinputs.MasterName;
DyMo=myinputs.DyMo;
end
if ~exist('MhDirectoryName'),
MhDirectoryName = CheckPath('metropolis');
end
......
......@@ -11,6 +11,11 @@ function PosteriorIRF(type)
% SPECIAL REQUIREMENTS
% None
% PARALLEL CONTEXT
% This funtion has been parallelized in two different points. Then we have two core
% functions associated with it(the _core1 and _core2).
% See also the comments random_walk_metropolis_hastings.m funtion.
% Copyright (C) 2006-2008,2010 Dynare Team
%
% This file is part of Dynare.
......@@ -137,10 +142,8 @@ if MAX_nirfs_dsgevar
Companion_matrix = diag(ones(nvobs*(NumberOfLags-1),1),-nvobs);
end
%%%%%%%%% START the FIRST BLOCK of CODE EXECUTED in PARALLEL! %%%%%%%%%
%
% This portion of code is execute in parallel by PosteriorIRF_core1.m
% function.
% First block of code executed in parallel. The function devoted to do it is PosteriorIRF_core1.m
% function.
b = 0;
nosaddle = 0;
......@@ -154,13 +157,9 @@ localVars.irun = irun;
localVars.irun2=irun2;
localVars.nosaddle=nosaddle;
% It is necessary to rename 'type' to avoid conflict with
% a native matlab funtion.
localVars.typee=type;
localVars.type=type;
if strcmpi(type,'posterior'),
while b<=B
while b<B
b = b + 1;
x(b,:) = GetOneDraw(type);
end
......@@ -183,11 +182,11 @@ localVars.NumberOfIRFfiles_dsgevar=NumberOfIRFfiles_dsgevar;
localVars.ifil2=ifil2;
if isnumeric(options_.parallel),% | isunix, % for the moment exclude unix platform from parallel implementation
% Like sequential execution!
if isnumeric(options_.parallel),% | isunix, % For the moment exclude unix platform from parallel implementation.
[fout] = PosteriorIRF_core1(localVars,1,B,0);
else
% Parallel execution!
[nCPU, totCPU, nBlockPerCPU] = distributeJobs(options_.parallel, 1, B);
for j=1:totCPU-1,
nfiles = ceil(nBlockPerCPU(j)/MAX_nirfs_dsge);
......@@ -217,19 +216,14 @@ else
end
% END first parallel section!
% END parallel code!
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if nosaddle
disp(['PosteriorIRF :: Percentage of discarded posterior draws = ' num2str(nosaddle/(B+nosaddle))])
end
% if isnumeric(options_.parallel)
% close(h);
% end
ReshapeMatFiles('irf_dsge')
if MAX_nirfs_dsgevar
ReshapeMatFiles('irf_bvardsge')
......@@ -335,11 +329,10 @@ end
%%
% Second block of code executed in parallel, with the exception of file
% .tex generation always run in sequentially. This portion of code is execute in parallel by
% PosteriorIRF_core2.m function.
%%%%%%%%% START the SECOND BLOCK of CODE EXECUTED in PARALLEL! %%%%%%%%%
%
% This portion of code is execute in parallel by PosteriorIRF_core2.m
% function.
% Save the local variables.
localVars=[];
......@@ -360,7 +353,7 @@ localVars.varlist=varlist;
localVars.MaxNumberOfPlotPerFigure=MaxNumberOfPlotPerFigure;
%%% The files .TeX are genereted in sequential way!
%%% The files .TeX are genereted in sequential way always!
if options_.TeX
fidTeX = fopen([DirectoryName filesep M_.fname '_BayesianIRF.TeX'],'w');
......@@ -405,10 +398,10 @@ if options_.TeX
end
% The others format in parallel by PosteriorIRF_core2!
% The others file format are generated in parallel by PosteriorIRF_core2!
if isnumeric(options_.parallel) || (M_.exo_nbr*ceil(size(varlist,1)/MaxNumberOfPlotPerFigure))<8,% | isunix, % for the moment exclude unix platform from parallel implementation
% Comment for testing!
if isnumeric(options_.parallel) % || (M_.exo_nbr*ceil(size(varlist,1)/MaxNumberOfPlotPerFigure))<8,% | isunix, % for the moment exclude unix platform from parallel implementation
[fout] = PosteriorIRF_core2(localVars,1,M_.exo_nbr,0);
else
globalVars = struct('M_',M_, ...
......@@ -419,13 +412,10 @@ else
end
% END parallel code!
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fprintf('MH: Posterior IRFs, done!\n');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function myoutput=PosteriorIRF_core1(myinputs,fpar,npar,whoiam, ThisMatlab)
% Perfome in parallel a portion of PosteriorIRF
%
% PARALLEL CONTEXT
% This function perfom in parallel a portion of PosteriorIRF.m code.
% This is a special kind of parallel function. Unlike of other parallel functions,
% that running in parallel a 'for' cycle, this function run in parallel a
% 'while' loop! The parallelization of 'while' loop (when possible) is a more
% sophisticated procedure.
%
% See also the comment in random_walk_metropolis_hastings_core.m funtion.
%
% INPUTS
%
% ...
%
% OUTPUTS
% ...
% See the comment in random_walk_metropolis_hastings_core.m funtion.
%
% OUTPUTS
% o myoutput [struc]
% Contained:
% OutputFileName_dsge, OutputFileName_param and OutputFileName_bvardsge.
%
% ALGORITHM
% Portion of PosteriorIRF.m function. Specifically the 'while' cycle.
%
% SPECIAL REQUIREMENTS.
% None.
%
% SPECIAL REQUIREMENTS
% None
% Copyright (C) 2006-2008,2010 Dynare Team
%
% This file is part of Dynare.
......@@ -37,7 +47,37 @@ global options_ estim_params_ oo_ M_ bayestopt_
if nargin<4,
whoiam=0;
end
struct2local(myinputs);
% Reshape 'myinputs' for local computation.
% In order to avoid confusion in the name space, the instruction struct2local(myinputs) is replaced by:
% Da CONTROLLARE con MARCO!
IRUN = myinputs.IRUN;
irun =myinputs.irun;
irun2=myinputs.irun2;
nosaddle=myinputs.nosaddle;
type=myinputs.type;
if ~strcmpi(type,'prior'),
x=myinputs.x;
end
nvar=myinputs.nvar;
IndxVariables=myinputs.IndxVariables;
MAX_nirfs_dsgevar=myinputs.MAX_nirfs_dsgevar;
MAX_nirfs_dsge=myinputs.MAX_nirfs_dsge;
MAX_nruns=myinputs.MAX_nruns;
NumberOfIRFfiles_dsge=myinputs.NumberOfIRFfiles_dsge;
NumberOfIRFfiles_dsgevar=myinputs.NumberOfIRFfiles_dsgevar;
ifil2=myinputs.ifil2;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if whoiam
Parallel=myinputs.Parallel;
MasterName=myinputs.MasterName;
DyMo=myinputs.DyMo;
end
MhDirectoryName = CheckPath('metropolis');
......@@ -57,10 +97,10 @@ else
diary off;
printf('\n')
else
if strcmpi(typee,'posterior')
if strcmpi(type,'posterior')
h = waitbar(0,'Bayesian (posterior) IRFs...');
set(h,'Name','Bayesian (posterior) IRFs.');
elseif strcmpi(typee,'gsa')
elseif strcmpi(type,'gsa')
h = waitbar(0,'GSA (prior) IRFs...');
else
h = waitbar(0,'Bayesian (prior) IRFs...');
......@@ -82,14 +122,15 @@ if whoiam
NumberOfIRFfiles_dsge=NumberOfIRFfiles_dsge(whoiam);
NumberOfIRFfiles_dsgevar=NumberOfIRFfiles_dsgevar(whoiam);
end
while fpar<=npar
while fpar<npar % Parallel 'while'!!!
fpar = fpar + 1;
irun = irun+1;
irun2 = irun2+1;
if strcmpi(typee,'prior')
if strcmpi(type,'prior')
deep = GetOneDraw(typee);
deep = GetOneDraw(type);
else
deep = x(fpar,:);
......@@ -267,13 +308,12 @@ end
% Copy the rusults of computation on the call machine (specifically in the
% dyrectory on call machine that contain the model).
% directory on call machine that contain the model).
myoutput.OutputFileName = [OutputFileName_dsge;
OutputFileName_param;
OutputFileName_bvardsge];
% MhDirectoryName=TempPath;
function myoutput=PosteriorIRF_core2(myinputs,fpar,npar,whoiam, ThisMatlab)
% PARALLEL CONTEXT
% Perfome in parallel a portion of PosteriorIRF.m code.
% See also the comment in random_walk_metropolis_hastings_core.m funtion.
%
% INPUTS
% See the comment in random_walk_metropolis_hastings_core.m funtion.
%
% OUTPUTS
% o myoutput [struc]
% Contained:
% OutputFileName (i.e. the figures without the file .txt).
%
% ALGORITHM
% Portion of PosteriorIRF.m function code. Specifically the last 'for' cycle.
%
% SPECIAL REQUIREMENTS.
% None.
%
% Copyright (C) 2006-2008,2010 Dynare Team
%
% This file is part of Dynare.
......@@ -22,7 +39,30 @@ global options_ M_