2005-02-18 20:54:39 +01:00
|
|
|
function y = rndprior(bayestopt_)
|
|
|
|
|
2008-01-29 14:20:25 +01:00
|
|
|
|
|
|
|
% function y = rndprior(bayestopt_)
|
|
|
|
% Draws random number from the prior density
|
|
|
|
%
|
|
|
|
% INPUTS
|
|
|
|
% bayestopt_: structure characterizing priors
|
|
|
|
%
|
|
|
|
% OUTPUTS
|
|
|
|
% y: drawn numbers vector
|
|
|
|
%
|
|
|
|
% SPECIAL REQUIREMENTS
|
|
|
|
% none
|
|
|
|
%
|
|
|
|
% part of DYNARE, copyright Dynare Team (2003-2007)
|
|
|
|
% Gnu Public License.
|
|
|
|
|
|
|
|
|
2005-02-18 20:54:39 +01:00
|
|
|
pshape=bayestopt_.pshape;
|
|
|
|
pmean=bayestopt_.pmean;
|
2006-11-05 14:46:26 +01:00
|
|
|
p1=bayestopt_.p1;
|
2005-02-18 20:54:39 +01:00
|
|
|
p2=bayestopt_.p2;
|
|
|
|
p3=bayestopt_.p3;
|
|
|
|
p4=bayestopt_.p4;
|
|
|
|
|
|
|
|
for i=1:length(pmean),
|
|
|
|
|
|
|
|
switch pshape(i)
|
|
|
|
|
|
|
|
case 1 %'beta'
|
|
|
|
mu = (pmean(i)-p3(i))/(p4(i)-p3(i));
|
|
|
|
stdd = p2(i)/(p4(i)-p3(i));
|
|
|
|
A = (1-mu)*mu^2/stdd^2 - mu;
|
|
|
|
B = A*(1/mu - 1);
|
|
|
|
y(1,i) = beta_rnd(1, A, B);
|
|
|
|
y(1,i) = y(1,i) * (p4(i)-p3(i)) + p3(i);
|
|
|
|
|
|
|
|
case 2 %'gamma'
|
|
|
|
mu = pmean(i)-p3(i);
|
|
|
|
B = mu/p2(i)^2; %gamm_rnd uses 1/B instead of B as param.
|
2006-11-05 14:46:26 +01:00
|
|
|
A = mu*B;
|
|
|
|
y(1,i) = gamm_rnd(1, A, B) + p3(i);
|
2005-02-18 20:54:39 +01:00
|
|
|
|
|
|
|
case 3 %'normal'
|
|
|
|
MU = pmean(i);
|
|
|
|
SIGMA = p2(i);
|
|
|
|
y(1,i) = randn*SIGMA+ MU;
|
|
|
|
|
|
|
|
case 4 %'invgamma'
|
|
|
|
nu = p2(i);
|
2006-11-05 14:46:26 +01:00
|
|
|
s = p1(i);
|
|
|
|
y(1,i) = 1/sqrt(gamm_rnd(1, nu/2, s/2)); %gamm_rnd uses 1/B
|
|
|
|
%instead of B as param.
|
2005-02-18 20:54:39 +01:00
|
|
|
|
|
|
|
case 5 %'uniform'
|
2006-11-05 14:46:26 +01:00
|
|
|
y(1,i) = rand*(p2(i)-p1(i)) + p1(i);
|
2005-02-18 20:54:39 +01:00
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
% initial version by Marco Ratto
|
|
|
|
|