Commit 8917d410 authored by adjemian's avatar adjemian
Browse files

Added multivariate student as a proposal distribution for the metropolis hastings.

git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@1743 ac1d8469-bf42-47a9-8791-bf33cf982152
parent d6e004e9
......@@ -868,9 +868,9 @@ if (any(bayestopt_.pshape >0 ) & options_.mh_replic) | ...
if options_.mh_replic
if ~options_.load_mh_file
if ~options_.bvar_dsge
metropolis('DsgeLikelihood',xparam1,invhess,bounds,gend,data);
random_walk_metropolis_hastings('DsgeLikelihood','rand_multivariate_normal',xparam1,invhess,bounds,gend,data);
else
metropolis('DsgeVarLikelihood',xparam1,invhess,bounds,gend);
random_walk_metropolis_hastings('DsgeVarLikelihood','rand_multivariate_normal',xparam1,invhess,bounds,gend);
end
else
if options_.use_mh_covariance_matrix
......
function global_initialization()
% function global_initialization()
% initializes global variables and options for DYNARE
%
% INPUTS
......@@ -14,8 +12,6 @@ function global_initialization()
%
% part of DYNARE, copyright Dynare Team (2003-2008)
% Gnu Public License.
global oo_ M_ options_ ct_ endval_ rplottype_
ct_=0;
......@@ -147,9 +143,10 @@ function global_initialization()
options_.markowitz = 0.5;
options_.simulation_method = 0;
options_.cutoff = 1e-12;
options_.student_degrees_of_freedom = 3;
% Misc
options_.conf_sig = 0.9;
options_.conf_sig = 0.6;
oo_.exo_simul = [];
oo_.endo_simul = [];
oo_.dr = [];
......@@ -164,5 +161,4 @@ function global_initialization()
M_.bvar = [];
% rplot
options_.dsample = 0;
\ No newline at end of file
options_.dsample = 0;
\ No newline at end of file
This diff is collapsed.
......@@ -75,9 +75,9 @@ if ~options_.load_mh_file & ~options_.mh_recover
validate = 0;
init_iter = 0;
trial = 1;
while validate == 0 & trial <= 10
candidate = options_.mh_init_scale*randn(1,npar)*d + transpose(xparam1);
if all(candidate' > mh_bounds(:,1)) & all(candidate' < mh_bounds(:,2))
while validate == 0 & trial <= 10
candidate = rand_multivariate_normal( transpose(xparam1), d * options_.mh_init_scale, npar);
if all(candidate(:) > mh_bounds(:,1)) & all(candidate(:) < mh_bounds(:,2))
ix2(j,:) = candidate;
ilogpo2(j) = - feval(TargetFun,ix2(j,:)',varargin{:});
fprintf(fidlog,[' Blck ' int2str(j) ':\n']);
......
function draw = rand_multivariate_normal(Mean,Sigma_upper_chol,n)
% Pseudo random draws from a multivariate normal distribution,
% \mathcal N_n(Mean,Sigma), with expectation Mean and variance Sigma.
%
% INPUTS
%
% Mean [double] 1*n vector, expectation of the multivariate random variable.
% Sigma_upper_chol [double] n*n matrix, upper triangular Cholesky decomposition of Sigma (the covariance matrix).
% n [integer] dimension.
%
% OUTPUTS
% draw [double] 1*n vector drawn from a multivariate normal distribution with expectation Mean and
% covariance Sigma
%
% SPECIAL REQUIREMENTS
%
% part of DYNARE, copyright Dynare Team (2003-2008)
% Gnu Public License.
draw = Mean + randn(1,n) * Sigma_upper_chol;
\ No newline at end of file
function draw = rand_multivariate_student(Mean,Sigma_upper_chol,df)
% Pseudo random draws from a multivariate student distribution,
% with expectation Mean, variance Sigma*df/(df-2) and degrees of freedom df>0.
%
% INPUTS
%
% Mean [double] 1*n vector, expectation of the multivariate random variable.
% Sigma_upper_chol [double] n*n matrix, upper triangular Cholesky decomposition of Sigma
% (the covariance matrix up to a factor df/(df-2)).
% df [integer] degrees of freedom.
%
% OUTPUTS
% draw [double] 1*n vector drawn from a multivariate normal distribution with expectation Mean and
% covariance Sigma.
%
% REMARK This is certainly not the most efficient way...
%
% NOTE See Zellner (appendix B.2, 1971) for a definition.
%
% part of DYNARE, copyright Dynare Team (2003-2008)
% Gnu Public License.
n = length(Mean);
draw = Mean + randn(1,n) * Sigma_upper_chol * sqrt(df/sum(randn(df,1).^2));
\ No newline at end of file
function random_walk_metropolis_hastings(TargetFun,xparam1,vv,mh_bounds,varargin)
function random_walk_metropolis_hastings(TargetFun,ProposalFun,xparam1,vv,mh_bounds,varargin)
% Random walk Metropolis-Hastings algorithm.
%
% INPUTS
......@@ -25,14 +25,20 @@ global M_ options_ bayestopt_
%%%% Initialization of the random walk metropolis-hastings chains.
%%%%
[ ix2, ilogpo2, ModelName, MhDirectoryName, fblck, fline, npar, nblck, nruns, NewFile, MAX_nruns, d ] = ...
metropolis_hastings_initialization(TargetFun,xparam1,vv,mh_bounds,varargin{:});
metropolis_hastings_initialization(TargetFun, xparam1, vv, mh_bounds, varargin{:});
options_.lik_algo = 1;
OpenOldFile = ones(nblck,1);
if strcmpi(ProposalFun,'rand_multivariate_normal')
n = npar;
elseif strcmpi(ProposalFun,'rand_multivariate_student')
n = options_.student_degrees_of_freedom;
end
load([MhDirectoryName '/' ModelName '_mh_history'],'record');
%%%%
%%%% NOW i run the (nblck-fblck+1) metropolis-hastings chains
%%%%
InitSizeArray = min([MAX_nruns*ones(nblck) nruns],[],2);
jscale = diag(bayestopt_.jscale);
for b = fblck:nblck
if (options_.load_mh_file~=0) & (fline(b)>1) & OpenOldFile(b)
load(['./' MhDirectoryName '/' ModelName '_mh' int2str(NewFile(b)) ...
......@@ -51,15 +57,14 @@ for b = fblck:nblck
irun = fline(b);
j = 1;
while j <= nruns(b)
par = randn(1,npar)*d;
par = par.*bayestopt_.jscale' + ix2(b,:);
if all(par'>mh_bounds(:,1)) & all(par'<mh_bounds(:,2))
logpost = - feval(TargetFun,par',varargin{:});
par = feval(ProposalFun, ix2(b,:), d * jscale, n);
if all( par(:) > mh_bounds(:,1) ) & all( par(:) < mh_bounds(:,2) )
logpost = - feval(TargetFun, par(:), varargin{:});
else
logpost = -inf;
end
if (logpost > -inf) & (log(rand) < logpost-ilogpo2(b))
x2(irun,:) = par;
x2(irun,:) = par;
ix2(b,:) = par;
logpo2(irun) = logpost;
ilogpo2(b) = logpost;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment