dynare/matlab/prior_bounds.m

105 lines
3.5 KiB
Matlab
Raw Normal View History

2023-04-28 22:58:41 +02:00
function bounds = prior_bounds(bayestopt, priortrunc)
% function bounds = prior_bounds(bayestopt)
% computes bounds for prior density.
%
% 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
%
% 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)
% Copyright © 2003-2023 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 <https://www.gnu.org/licenses/>.
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.')
pshape = bayestopt.pshape;
p3 = bayestopt.p3;
p4 = bayestopt.p4;
p6 = bayestopt.p6;
p7 = bayestopt.p7;
2023-04-28 22:58:41 +02:00
bounds.lb = zeros(size(p6));
bounds.ub = zeros(size(p6));
for i=1:length(p6)
switch pshape(i)
case 1
2023-04-28 22:58:41 +02:00
if priortrunc==0
bounds.lb(i) = p3(i);
bounds.ub(i) = p4(i);
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);
end
case 2
2023-04-28 22:58:41 +02:00
if priortrunc==0
bounds.lb(i) = p3(i);
bounds.ub(i) = Inf;
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);
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));
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));
end
case 4
2023-04-28 22:58:41 +02:00
if priortrunc==0
bounds.lb(i) = p3(i);
bounds.ub(i) = Inf;
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);
end
case 5
2023-04-28 22:58:41 +02:00
if priortrunc == 0
bounds.lb(i) = p6(i);
bounds.ub(i) = p7(i);
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;
end
case 6
2023-04-28 22:58:41 +02:00
if priortrunc == 0
bounds.lb(i) = p3(i);
bounds.ub(i) = Inf;
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);
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
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