From 4dd3ee8546220c920ee400a36e65377b69a91a30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Ry=C3=BBk=29?= Date: Tue, 14 Dec 2021 14:40:07 +0100 Subject: [PATCH] Add CLI for some routines. - steady, - check, - evaluate_likelihood, - evaluate_posterior_kernel, and - evaluate_prior. *Example* After running a mod file, on the Matlab's command line: >> cli.check EIGENVALUES: Modulus Real Imaginary 0 0 0 1.389e-16 1.389e-16 0 0.6452 0.6452 0 0.9707 0.9707 0 1.038 1.038 0 1.271e+16 1.271e+16 0 2.33e+17 2.33e+17 0 There are 3 eigenvalue(s) larger than 1 in modulus for 3 forward-looking variable(s) The rank condition is verified. --- matlab/cli/+cli/check.m | 40 +++++++++++++++++++++ matlab/cli/+cli/evaluate_likelihood.m | 37 +++++++++++++++++++ matlab/cli/+cli/evaluate_posterior_kernel.m | 37 +++++++++++++++++++ matlab/cli/+cli/evaluate_prior.m | 37 +++++++++++++++++++ matlab/cli/+cli/steady.m | 40 +++++++++++++++++++++ 5 files changed, 191 insertions(+) create mode 100644 matlab/cli/+cli/check.m create mode 100644 matlab/cli/+cli/evaluate_likelihood.m create mode 100644 matlab/cli/+cli/evaluate_posterior_kernel.m create mode 100644 matlab/cli/+cli/evaluate_prior.m create mode 100644 matlab/cli/+cli/steady.m diff --git a/matlab/cli/+cli/check.m b/matlab/cli/+cli/check.m new file mode 100644 index 000000000..afadaa2b8 --- /dev/null +++ b/matlab/cli/+cli/check.m @@ -0,0 +1,40 @@ +function check(printflag) + +% Computes and displays the generalized eigenvalues. Also checks BK conditions. +% +% INPUTS +% - printflag [logical] scalar, print eigenvalues if true (default value is true). +% +% OUTPUTS +% None + +% Copyright (C) 2021 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 . + +global options_ M_ oo_ + +if ~nargin || isempty(printflag) + printflag = true; +end + +noprint = options_.noprint; + +options_.noprint = ~printflag; + +check(M_, options_, oo_); + +options_.noprint = noprint; \ No newline at end of file diff --git a/matlab/cli/+cli/evaluate_likelihood.m b/matlab/cli/+cli/evaluate_likelihood.m new file mode 100644 index 000000000..0801fd245 --- /dev/null +++ b/matlab/cli/+cli/evaluate_likelihood.m @@ -0,0 +1,37 @@ +function llik = evaluate_likelihood(parameters) + +% Evaluates the likelihood function. +% +% INPUTS +% - parameters [char,double] If row char array, possible values are 'posterior mode', 'posterior mean', +% 'posterior median', 'prior mode' or 'prior mean'. Otherwise, parmaters must +% be a vector of doubles (arbitrary values for the parameters). +% +% OUTPUTS +% None + +% Copyright (C) 2021 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 . + +global M_ estim_params_ oo_ options_ bayestopt_ + +llik = evaluate_likelihood(parameters, M_, estim_params_, oo_, options_, bayestopt_); + +if ~nargout + dprintf('\nValue of the log-likelihood: %20.6f\n', llik); + clear ('llik'); % Do not display the value returned by the function. +end \ No newline at end of file diff --git a/matlab/cli/+cli/evaluate_posterior_kernel.m b/matlab/cli/+cli/evaluate_posterior_kernel.m new file mode 100644 index 000000000..b7a2dddb4 --- /dev/null +++ b/matlab/cli/+cli/evaluate_posterior_kernel.m @@ -0,0 +1,37 @@ +function lpk = evaluate_posterior_kernel(parameters) + +% Evaluates the posterior kernel function. +% +% INPUTS +% - parameters [char,double] If row char array, possible values are 'posterior mode', 'posterior mean', +% 'posterior median', 'prior mode' or 'prior mean'. Otherwise, parmaters must +% be a vector of doubles (arbitrary values for the parameters). +% +% OUTPUTS +% None + +% Copyright (C) 2021 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 . + +global M_ estim_params_ oo_ options_ bayestopt_ + +lpk = evaluate_posterior_kernel(parameters, M_, estim_params_, oo_, options_, bayestopt_); + +if ~nargout + dprintf('\nValue of the logged posterior kernel: %20.6f\n', lpk); + clear ('lpk'); % Do not display the value returned by the function. +end \ No newline at end of file diff --git a/matlab/cli/+cli/evaluate_prior.m b/matlab/cli/+cli/evaluate_prior.m new file mode 100644 index 000000000..fc470b6b9 --- /dev/null +++ b/matlab/cli/+cli/evaluate_prior.m @@ -0,0 +1,37 @@ +function ldens = evaluate_prior(parameters) + +% Evaluates the posterior kernel function. +% +% INPUTS +% - parameters [char,double] If row char array, possible values are 'posterior mode', 'posterior mean', +% 'posterior median', 'prior mode' or 'prior mean'. Otherwise, parmaters must +% be a vector of doubles (arbitrary values for the parameters). +% +% OUTPUTS +% None + +% Copyright (C) 2021 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 . + +global M_ estim_params_ oo_ options_ bayestopt_ + +ldens = evaluate_prior(parameters, M_, estim_params_, oo_, options_, bayestopt_); + +if ~nargout + dprintf('\nValue of the logged prior density: %20.6f\n', ldens); + clear ('ldens'); % Do not display the value returned by the function. +end \ No newline at end of file diff --git a/matlab/cli/+cli/steady.m b/matlab/cli/+cli/steady.m new file mode 100644 index 000000000..f69a5c900 --- /dev/null +++ b/matlab/cli/+cli/steady.m @@ -0,0 +1,40 @@ +function steady(printflag) + +% Computes and prints the steady state. +% +% INPUTS +% - printflag [logical] scalar, print steady state if true (default value is true). +% +% OUTPUTS +% None + +% Copyright (C) 2021 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 . + +global options_ + +if ~nargin || isempty(printflag) + printflag = true; +end + +noprint = options_.noprint; + +options_.noprint = ~printflag; + +steady(); + +options_.noprint = noprint; \ No newline at end of file