From c15f8bb3cba112e8ce6483c522cb21b7be4e0561 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Argos=29?= <stepan@adjemian.eu> Date: Mon, 11 Nov 2024 12:39:19 +0100 Subject: [PATCH] Rename method in dprior class draw() -> deviate() draws() -> sample() --- matlab/+identification/run.m | 8 ++++---- matlab/@dprior/admissible.m | 6 +++--- matlab/@dprior/density.m | 4 ++-- matlab/@dprior/{draw.m => deviate.m} | 16 ++++++++-------- matlab/@dprior/{draws.m => sample.m} | 10 +++++----- matlab/@dprior/subsref.m | 6 +++--- matlab/dseries | 2 +- matlab/estimation/PosteriorIRF_core1.m | 6 +++--- .../execute_prior_posterior_function.m | 2 +- .../estimation/online/online_auxiliary_filter.m | 4 ++-- .../posterior_sampler_initialization.m | 2 +- .../estimation/prior_posterior_statistics_core.m | 4 ++-- matlab/estimation/prior_sampler.m | 2 +- matlab/estimation/slice_sampler.m | 4 ++-- .../estimation/smc/smc_samplers_initialization.m | 2 +- preprocessor | 2 +- 16 files changed, 40 insertions(+), 40 deletions(-) rename matlab/@dprior/{draw.m => deviate.m} (96%) rename matlab/@dprior/{draws.m => sample.m} (96%) diff --git a/matlab/+identification/run.m b/matlab/+identification/run.m index 38bfe21eed..e3c1a24b20 100644 --- a/matlab/+identification/run.m +++ b/matlab/+identification/run.m @@ -45,14 +45,14 @@ function [pdraws, STO_REDUCEDFORM, STO_MOMENTS, STO_DYNAMIC, STO_si_dDYNAMIC, ST % * identification.analysis % * isoctave % * identification.plot -% * dprior.draw +% * dprior.deviate % * set_default_option % * set_prior % * skipline % * vnorm % ========================================================================= -% Copyright © 2010-2023 Dynare Team +% Copyright © 2010-2024 Dynare Team % % This file is part of Dynare. % @@ -485,7 +485,7 @@ if iload <=0 kk=0; while kk<50 && info(1) kk=kk+1; - params = Prior.draw(); + params = Prior.deviate(); options_ident.tittxt = 'Random_prior_params'; %title text for graphs and figures % perform identification analysis [ide_moments_point, ide_spectrum_point, ide_minimal_point, ide_hess_point, ide_reducedform_point, ide_dynamic_point, ~, info, error_indicator_point] = ... @@ -540,7 +540,7 @@ if iload <=0 if external_sample params = pdraws0(iteration+1,:); % loaded draws else - params = Prior.draw(); % new random draw from prior + params = Prior.deviate(); % new random draw from prior end options_ident.tittxt = []; % clear title text for graphs and figures % run identification analysis diff --git a/matlab/@dprior/admissible.m b/matlab/@dprior/admissible.m index 82cce25f3e..0bc685dae6 100644 --- a/matlab/@dprior/admissible.m +++ b/matlab/@dprior/admissible.m @@ -15,7 +15,7 @@ function b = admissible(o, d) % EXAMPLE % % >> Prior = dprior(bayestopt_, options_.prior_trunc); -% >> d = Prior.draw() +% >> d = Prior.deviate() % >> Prior.admissible(d) % ans = % @@ -23,7 +23,7 @@ function b = admissible(o, d) % % 1 -% Copyright © 2023 Dynare Team +% Copyright © 2023-2024 Dynare Team % % This file is part of Dynare. % @@ -131,7 +131,7 @@ try o = dprior(BayesInfo, prior_trunc, false); % Do simulations in a loop and estimate recursively the mean and the variance. for i = 1:ndraws - draw = o.draw(); + draw = o.deviate(); if ~o.admissible(draw) error('problem in admissible') end diff --git a/matlab/@dprior/density.m b/matlab/@dprior/density.m index 740d0b408d..805446679c 100644 --- a/matlab/@dprior/density.m +++ b/matlab/@dprior/density.m @@ -20,7 +20,7 @@ function [lpd, dlpd, d2lpd, info] = density(o, x) % >> Prior = dprior(bayestopt_, options_.prior_trunc); % >> lpd = Prior.dsensity(x) -% Copyright © 2023 Dynare Team +% Copyright © 2023-2024 Dynare Team % % This file is part of Dynare. % @@ -269,7 +269,7 @@ try % Draw random deviates in a loop and evaluate the density. LPD = NaN(10000,1); parfor i = 1:10000 - x = Prior.draw(); + x = Prior.deviate(); LPD(i) = Prior.density(x); end t(1) = true; diff --git a/matlab/@dprior/draw.m b/matlab/@dprior/deviate.m similarity index 96% rename from matlab/@dprior/draw.m rename to matlab/@dprior/deviate.m index bad82885a7..6a916c890d 100644 --- a/matlab/@dprior/draw.m +++ b/matlab/@dprior/deviate.m @@ -1,4 +1,4 @@ -function p = draw(o) +function p = deviate(o) % Return a random draw from the prior distribution. % @@ -14,9 +14,9 @@ function p = draw(o) % EXAMPLE % % >> Prior = dprior(bayestopt_, options_.prior_trunc); -% >> d = Prior.draw() +% >> d = Prior.deviate() -% Copyright © 2023 Dynare Team +% Copyright © 2023-2024 Dynare Team % % This file is part of Dynare. % @@ -178,11 +178,11 @@ try o = dprior(BayesInfo, prior_trunc, false); % Do simulations in a loop and estimate recursively the mean and the variance. for i = 1:ndraws - draw = o.draw(); - m1 = m0 + (draw-m0)/i; - m2 = m1*m1'; - v0 = v0 + ((draw*draw'-m2-v0) + (i-1)*(m0*m0'-m2'))/i; - m0 = m1; + draw = o.deviate(); + m1 = m0 + (draw-m0)/i; + m2 = m1*m1'; + v0 = v0 + ((draw*draw'-m2-v0) + (i-1)*(m0*m0'-m2'))/i; + m0 = m1; end t(1) = true; catch diff --git a/matlab/@dprior/draws.m b/matlab/@dprior/sample.m similarity index 96% rename from matlab/@dprior/draws.m rename to matlab/@dprior/sample.m index 88b92abd4a..26505b4b6a 100644 --- a/matlab/@dprior/draws.m +++ b/matlab/@dprior/sample.m @@ -1,4 +1,4 @@ -function P = draws(o, n) +function P = sample(o, n) % Return n independent random draws from the prior distribution. % @@ -14,9 +14,9 @@ function P = draws(o, n) % EXAMPLE % % >> Prior = dprior(bayestopt_, options_.prior_trunc); -% >> Prior.draws(1e6) +% >> Prior.sample(1e6) -% Copyright © 2023 Dynare Team +% Copyright © 2023-2024 Dynare Team % % This file is part of Dynare. % @@ -35,7 +35,7 @@ function P = draws(o, n) P = NaN(rows(o.lb), 1); parfor i=1:n - P(:,i) = draw(o); + P(:,i) = deviate(o); end return % --*-- Unit tests --*-- @@ -117,7 +117,7 @@ ndraws = 1e5; try % Instantiate dprior object. o = dprior(BayesInfo, prior_trunc, false); - X = o.draws(ndraws); + X = o.sample(ndraws); m = mean(X, 2); v = var(X, 0, 2); t(1) = true; diff --git a/matlab/@dprior/subsref.m b/matlab/@dprior/subsref.m index 692f813d00..b4f2915ed8 100644 --- a/matlab/@dprior/subsref.m +++ b/matlab/@dprior/subsref.m @@ -2,7 +2,7 @@ function p = subsref(o, S) % Overload subsref method. -% Copyright © 2023 Dynare Team +% Copyright © 2023-2024 Dynare Team % % This file is part of Dynare. % @@ -25,9 +25,9 @@ switch S(1).type p = builtin('subsref', o, S(1)); elseif isequal(S(1).subs, 'bounds') && length(S)==1 p = bounds(o, [], false); - elseif ismember(S(1).subs, {'draw','length'}) + elseif ismember(S(1).subs, {'deviate','length','isempty'}) p = feval(S(1).subs, o); - elseif ismember(S(1).subs, {'draws', 'density', 'densities', 'moments', 'admissible', 'bounds'}) + elseif ismember(S(1).subs, {'sample', 'density', 'densities', 'moments', 'admissible', 'bounds'}) p = feval(S(1).subs, o , S(2).subs{:}); elseif ismember(S(1).subs, {'mean', 'median', 'variance', 'mode'}) if (length(S)==2 && isempty(S(2).subs)) || length(S)==1 diff --git a/matlab/dseries b/matlab/dseries index 5436f91fe7..a456425a6f 160000 --- a/matlab/dseries +++ b/matlab/dseries @@ -1 +1 @@ -Subproject commit 5436f91fe709b7e9f31302714cc1f9a7271001c6 +Subproject commit a456425a6ff65c699f5937c0ea775de1a3348405 diff --git a/matlab/estimation/PosteriorIRF_core1.m b/matlab/estimation/PosteriorIRF_core1.m index fa29c9f4b2..68086622cc 100644 --- a/matlab/estimation/PosteriorIRF_core1.m +++ b/matlab/estimation/PosteriorIRF_core1.m @@ -23,8 +23,8 @@ function myoutput=PosteriorIRF_core1(myinputs,fpar,B,whoiam, ThisMatlab) % % SPECIAL REQUIREMENTS. % None. -% -% Copyright © 2006-2023 Dynare Team + +% Copyright © 2006-2024 Dynare Team % % This file is part of Dynare. % @@ -135,7 +135,7 @@ while fpar<B irun = irun+1; irun2 = irun2+1; if strcmpi(type,'prior') - deep = Prior.draw(); + deep = Prior.deviate(); else deep = x(fpar,:); end diff --git a/matlab/estimation/execute_prior_posterior_function.m b/matlab/estimation/execute_prior_posterior_function.m index 5bd2e98ed5..0429f8e57d 100644 --- a/matlab/estimation/execute_prior_posterior_function.m +++ b/matlab/estimation/execute_prior_posterior_function.m @@ -78,7 +78,7 @@ end if strcmpi(type, 'prior') - parameter_mat = Prior.draws(n_draws); + parameter_mat = Prior.sample(n_draws); else parameter_mat=get_posterior_subsample(M_,options_,n_draws)'; end diff --git a/matlab/estimation/online/online_auxiliary_filter.m b/matlab/estimation/online/online_auxiliary_filter.m index ebe1394ff1..3ad4520808 100644 --- a/matlab/estimation/online/online_auxiliary_filter.m +++ b/matlab/estimation/online/online_auxiliary_filter.m @@ -11,7 +11,7 @@ function online_auxiliary_filter(xparam1, dataset_, options_, M_, estim_params_, % - estim_params_ [struct] Description of the estimated parameters. % - bayestopt_ [struct] Prior definition. % - oo_ [struct] Results. -% + % Copyright © 2013-2024 Dynare Team % % This file is part of Dynare. @@ -79,7 +79,7 @@ Prior = dprior(bayestopt_, options_.prior_trunc); for i=1:number_of_particles info = 12042009; while info - candidate = Prior.draw(); + candidate = Prior.deviate(); [info, M_, options_, oo_] = solve_model_for_online_filter(false, candidate, dataset_, options_, M_, estim_params_, bayestopt_, bounds, oo_); if ~info xparam(:,i) = candidate(:); diff --git a/matlab/estimation/posterior_sampler_initialization.m b/matlab/estimation/posterior_sampler_initialization.m index 194f4c3c30..354b00916f 100644 --- a/matlab/estimation/posterior_sampler_initialization.m +++ b/matlab/estimation/posterior_sampler_initialization.m @@ -194,7 +194,7 @@ if ~options_.load_mh_file && ~options_.mh_recover trial = 1; while ~validate && trial <= 10 if isempty(d) - candidate = Prior.draw(); + candidate = Prior.deviate(); else if isfield(options_,'mh_init_scale') if trial==1 diff --git a/matlab/estimation/prior_posterior_statistics_core.m b/matlab/estimation/prior_posterior_statistics_core.m index 478dab2e60..10add4c630 100644 --- a/matlab/estimation/prior_posterior_statistics_core.m +++ b/matlab/estimation/prior_posterior_statistics_core.m @@ -30,7 +30,7 @@ function myoutput=prior_posterior_statistics_core(myinputs,fpar,B,whoiam, ThisMa % SPECIAL REQUIREMENTS. % None. -% Copyright © 2005-2023 Dynare Team +% Copyright © 2005-2024 Dynare Team % % This file is part of Dynare. % @@ -198,7 +198,7 @@ for b=fpar:B iter=1; logpo=[]; while (isempty(logpo) || isinf(logpo)) && iter<1000 - deep = Prior.draw(); + deep = Prior.deviate(); logpo = evaluate_posterior_kernel(deep, M_, estim_params_, oo_, options_, bayestopt_); iter=iter+1; end diff --git a/matlab/estimation/prior_sampler.m b/matlab/estimation/prior_sampler.m index 3521df61f3..eef835b1f7 100644 --- a/matlab/estimation/prior_sampler.m +++ b/matlab/estimation/prior_sampler.m @@ -93,7 +93,7 @@ while iteration < NumberOfSimulations dyn_waitbar(iteration/NumberOfSimulations,hh_fig,'Please wait. Prior sampler...'); end loop_indx = loop_indx+1; - params = Prior.draw(); + params = Prior.deviate(); M_ = set_all_parameters(params, estim_params_, M_); [T, R, ~, INFO, oo_.dr,M_.params] = dynare_resolve(M_, options_, oo_.dr,oo_.steady_state,oo_.exo_steady_state,oo_.exo_det_steady_state, 'restrict'); if ~INFO(1) diff --git a/matlab/estimation/slice_sampler.m b/matlab/estimation/slice_sampler.m index 326df5ff0d..fcf4a818be 100644 --- a/matlab/estimation/slice_sampler.m +++ b/matlab/estimation/slice_sampler.m @@ -24,7 +24,7 @@ function [theta, fxsim, neval] = slice_sampler(objective_function,theta,thetapri % SPECIAL REQUIREMENTS % none -% Copyright © 2015-2023 Dynare Team +% Copyright © 2015-2024 Dynare Team % % This file is part of Dynare. % @@ -82,7 +82,7 @@ while it<npar icount=0; while ~isfinite(fxold) && icount<1000 icount=icount+1; - theta = Prior.draw(); + theta = Prior.deviate(); if all(theta >= thetaprior(:,1)) && all(theta <= thetaprior(:,2)) fxold = -feval(objective_function,theta,varargin{:}); end diff --git a/matlab/estimation/smc/smc_samplers_initialization.m b/matlab/estimation/smc/smc_samplers_initialization.m index 4c17ef0ade..64041a73a4 100644 --- a/matlab/estimation/smc/smc_samplers_initialization.m +++ b/matlab/estimation/smc/smc_samplers_initialization.m @@ -56,7 +56,7 @@ t0 = tic; parfor j=1:n notvalid = true; while notvalid - candidate = Prior.draw(); + candidate = Prior.deviate(); if Prior.admissible(candidate) particles(:,j) = candidate; [tlogpostkernel(j), loglikelihood(j)] = tempered_likelihood(funobj, candidate, 0.0, Prior); diff --git a/preprocessor b/preprocessor index 86822b5e6e..a091c26ced 160000 --- a/preprocessor +++ b/preprocessor @@ -1 +1 @@ -Subproject commit 86822b5e6e8b5fc3f98673d6e6d21eed8051e2d4 +Subproject commit a091c26ced0fba215851485e824502230fccb73f -- GitLab