Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
dynare
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sébastien Villemot
dynare
Commits
433a6816
Commit
433a6816
authored
6 years ago
by
Johannes Pfeifer
Committed by
Stéphane Adjemian
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
TaRB: fix bug where incorrect last posterior was returned if last draw was rejected
parent
157641ac
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
matlab/posterior_sampler_iteration.m
+38
-22
38 additions, 22 deletions
matlab/posterior_sampler_iteration.m
with
38 additions
and
22 deletions
matlab/posterior_sampler_iteration.m
+
38
−
22
View file @
433a6816
...
...
@@ -4,16 +4,29 @@ function [par, logpost, accepted, neval] = posterior_sampler_iteration(TargetFu
% posterior samplers
%
% INPUTS
% posterior_sampler_options: posterior sampler options
% TargetFun: string storing the objective function (e.g. 'dsge_likelihood.m')
% last_draw: parameter vector in last iteration
% last_posterior: value of the posterior in last iteration
% sampler_options: posterior sampler options
% dataset_: the dataset after required transformation
% dataset_info: Various informations about the dataset (descriptive statistics and missing observations).
% options_: structure storing the options
% M_: structure storing the model information
% estim_params_: structure storing information about estimated parameters
% bayestopt_: structure storing information about priors
% mh_bounds: structure containing prior bounds
% oo_: structure storing the results
%
% OUTPUTS
% posterior_sampler_options: checked posterior sampler options
% par: last accepted parameter vector
% logpost: value of the posterior after current iteration
% accepted: share of proposed draws that were accepted
% neval: number of evaluations (>1 only for slice)
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2015-1
6
Dynare Team
% Copyright (C) 2015-1
8
Dynare Team
%
% This file is part of Dynare.
%
...
...
@@ -121,6 +134,8 @@ switch posterior_sampling_method
else
logpost
=
-
inf
;
end
if
(
logpost
>
-
inf
)
%get ratio of proposal densities, required because proposal depends
%on current mode via Hessian and is thus not symmetric anymore
if
strcmpi
(
sampler_options
.
proposal_distribution
,
'rand_multivariate_normal'
)
...
...
@@ -131,8 +146,7 @@ switch posterior_sampling_method
proposal_density_proposed_move_backward
=
multivariate_student_pdf
(
par_start_current_block
',xopt_current_block'
,
proposal_covariance_Cholesky_decomposition_upper
,
n
);
end
accprob
=
logpost
-
last_posterior
+
log
(
proposal_density_proposed_move_backward
)
-
log
(
proposal_density_proposed_move_forward
);
%Formula (6), Chib/Ramamurthy
if
(
logpost
>
-
inf
)
&&
(
log
(
rand
)
<
accprob
)
if
(
log
(
rand
)
<
accprob
)
current_draw
(
indices
(
blocks
==
block_iter
,
1
))
=
proposed_par
;
last_posterior
=
logpost
;
accepted_draws_counter
=
accepted_draws_counter
+
1
;
...
...
@@ -140,9 +154,11 @@ switch posterior_sampling_method
%do nothing, keep old value
end
end
end
accepted
=
accepted_draws_counter
/
blocked_draws_counter
;
par
=
current_draw
;
neval
=
1
;
logpost
=
last_posterior
;
%make sure not a temporary draw is returned;
case
'independent_metropolis_hastings'
neval
=
1
;
ProposalFun
=
sampler_options
.
proposal_distribution
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment