2023-04-28 22:58:41 +02:00
|
|
|
|
function bounds = prior_bounds(bayestopt, priortrunc)
|
2011-09-14 23:40:23 +02:00
|
|
|
|
|
2008-01-10 15:53:41 +01:00
|
|
|
|
% function bounds = prior_bounds(bayestopt)
|
2009-02-17 18:19:47 +01:00
|
|
|
|
% computes bounds for prior density.
|
2008-01-10 15:53:41 +01:00
|
|
|
|
%
|
|
|
|
|
% INPUTS
|
2023-04-28 22:58:41 +02:00
|
|
|
|
% - bayestopt [struct] characterizing priors (shape, mean, p1..p4)
|
|
|
|
|
% - priortrunc [double] scalar, probability mass in the tails to be removed
|
2017-05-16 15:10:20 +02:00
|
|
|
|
%
|
2008-01-10 15:53:41 +01:00
|
|
|
|
% OUTPUTS
|
2023-04-28 22:58:41 +02:00
|
|
|
|
% - bounds [struct] prior bounds (lb, lower bounds, and ub, upper bounds, fields are n×1 vectors)
|
2008-01-10 15:53:41 +01:00
|
|
|
|
|
2023-03-16 15:33:42 +01:00
|
|
|
|
% Copyright © 2003-2023 Dynare Team
|
2008-08-01 14:40:33 +02:00
|
|
|
|
%
|
|
|
|
|
% 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
|
2021-06-09 17:33:48 +02:00
|
|
|
|
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
2008-01-10 15:53:41 +01:00
|
|
|
|
|
2023-04-28 22:58:41 +02:00
|
|
|
|
if nargin<2, priortrunc = 0.0; end
|
|
|
|
|
|
|
|
|
|
assert(priortrunc>=0 && priortrunc<=1, 'Second input argument must be non negative and not larger than one.')
|
|
|
|
|
|
2005-02-18 20:54:39 +01:00
|
|
|
|
pshape = bayestopt.pshape;
|
|
|
|
|
p3 = bayestopt.p3;
|
|
|
|
|
p4 = bayestopt.p4;
|
2009-04-06 16:38:37 +02:00
|
|
|
|
p6 = bayestopt.p6;
|
|
|
|
|
p7 = bayestopt.p7;
|
2005-02-18 20:54:39 +01:00
|
|
|
|
|
2023-04-28 22:58:41 +02:00
|
|
|
|
bounds.lb = zeros(size(p6));
|
|
|
|
|
bounds.ub = zeros(size(p6));
|
2005-02-18 20:54:39 +01:00
|
|
|
|
|
2009-04-06 16:38:37 +02:00
|
|
|
|
for i=1:length(p6)
|
2009-12-16 18:17:34 +01:00
|
|
|
|
switch pshape(i)
|
|
|
|
|
case 1
|
2023-04-28 22:58:41 +02:00
|
|
|
|
if priortrunc==0
|
2014-10-20 16:18:54 +02:00
|
|
|
|
bounds.lb(i) = p3(i);
|
|
|
|
|
bounds.ub(i) = p4(i);
|
2009-12-16 18:17:34 +01:00
|
|
|
|
else
|
2023-04-28 22:58:41 +02:00
|
|
|
|
bounds.lb(i) = betainv(priortrunc, p6(i), p7(i))*(p4(i)-p3(i))+p3(i);
|
|
|
|
|
bounds.ub(i) = betainv(1.0-priortrunc, p6(i), p7(i))*(p4(i)-p3(i))+p3(i);
|
2009-12-16 18:17:34 +01:00
|
|
|
|
end
|
|
|
|
|
case 2
|
2023-04-28 22:58:41 +02:00
|
|
|
|
if priortrunc==0
|
2014-10-20 16:18:54 +02:00
|
|
|
|
bounds.lb(i) = p3(i);
|
|
|
|
|
bounds.ub(i) = Inf;
|
2009-12-16 18:17:34 +01:00
|
|
|
|
else
|
2023-04-28 22:58:41 +02:00
|
|
|
|
bounds.lb(i) = gaminv(priortrunc, p6(i), p7(i))+p3(i);
|
|
|
|
|
bounds.ub(i) = gaminv(1.0-priortrunc, p6(i), p7(i))+p3(i);
|
2009-12-16 18:17:34 +01:00
|
|
|
|
end
|
|
|
|
|
case 3
|
|
|
|
|
if prior_trunc == 0
|
2023-04-28 22:58:41 +02:00
|
|
|
|
bounds.lb(i) = max(-Inf, p3(i));
|
|
|
|
|
bounds.ub(i) = min(Inf, p4(i));
|
2009-12-16 18:17:34 +01:00
|
|
|
|
else
|
2023-04-28 22:58:41 +02:00
|
|
|
|
bounds.lb(i) = max(norminv(prior_trunc, p6(i), p7(i)), p3(i));
|
|
|
|
|
bounds.ub(i) = min(norminv(1-prior_trunc, p6(i), p7(i)), p4(i));
|
2009-12-16 18:17:34 +01:00
|
|
|
|
end
|
|
|
|
|
case 4
|
2023-04-28 22:58:41 +02:00
|
|
|
|
if priortrunc==0
|
2014-10-20 16:18:54 +02:00
|
|
|
|
bounds.lb(i) = p3(i);
|
|
|
|
|
bounds.ub(i) = Inf;
|
2009-12-16 18:17:34 +01:00
|
|
|
|
else
|
2023-04-28 22:58:41 +02:00
|
|
|
|
bounds.lb(i) = 1.0/sqrt(gaminv(1.0-priortrunc, p7(i)/2.0, 2.0/p6(i)))+p3(i);
|
|
|
|
|
bounds.ub(i) = 1.0/sqrt(gaminv(priortrunc, p7(i)/2.0, 2.0/p6(i)))+p3(i);
|
2009-12-16 18:17:34 +01:00
|
|
|
|
end
|
|
|
|
|
case 5
|
2023-04-28 22:58:41 +02:00
|
|
|
|
if priortrunc == 0
|
2014-10-20 16:18:54 +02:00
|
|
|
|
bounds.lb(i) = p6(i);
|
|
|
|
|
bounds.ub(i) = p7(i);
|
2009-12-16 18:17:34 +01:00
|
|
|
|
else
|
2023-04-28 22:58:41 +02:00
|
|
|
|
bounds.lb(i) = p6(i)+(p7(i)-p6(i))*priortrunc;
|
|
|
|
|
bounds.ub(i) = p7(i)-(p7(i)-p6(i))*priortrunc;
|
2009-12-16 18:17:34 +01:00
|
|
|
|
end
|
|
|
|
|
case 6
|
2023-04-28 22:58:41 +02:00
|
|
|
|
if priortrunc == 0
|
2014-10-20 16:18:54 +02:00
|
|
|
|
bounds.lb(i) = p3(i);
|
|
|
|
|
bounds.ub(i) = Inf;
|
2009-12-16 18:17:34 +01:00
|
|
|
|
else
|
2023-04-28 22:58:41 +02:00
|
|
|
|
bounds.lb(i) = 1.0/gaminv(1.0-priortrunc, p7(i)/2.0, 2.0/p6(i))+p3(i);
|
|
|
|
|
bounds.ub(i) = 1.0/gaminv(priortrunc, p7(i)/2.0, 2.0/p6(i))+ p3(i);
|
2009-12-16 18:17:34 +01:00
|
|
|
|
end
|
2015-12-04 14:50:44 +01:00
|
|
|
|
case 8
|
2023-04-28 22:58:41 +02:00
|
|
|
|
if priortrunc == 0
|
2015-12-04 14:50:44 +01:00
|
|
|
|
bounds.lb(i) = p3(i);
|
|
|
|
|
bounds.ub(i) = Inf;
|
|
|
|
|
else
|
2023-04-28 22:58:41 +02:00
|
|
|
|
bounds.lb(i) = p3(i)+wblinv(priortrunc, p6(i), p7(i));
|
|
|
|
|
bounds.ub(i) = p3(i)+wblinv(1.0-priortrunc, p6(i), p7(i));
|
2015-12-04 14:50:44 +01:00
|
|
|
|
end
|
2009-12-16 18:17:34 +01:00
|
|
|
|
otherwise
|
|
|
|
|
error(sprintf('prior_bounds: unknown distribution shape (index %d, type %d)', i, pshape(i)));
|
|
|
|
|
end
|
2023-04-28 22:58:41 +02:00
|
|
|
|
end
|