Home > matlab > rndprior.m

rndprior

PURPOSE ^

function y = rndprior(bayestopt_)

SYNOPSIS ^

function y = rndprior(bayestopt_)

DESCRIPTION ^

 function y = rndprior(bayestopt_)
 Draws random number from the prior density

 INPUTS
   bayestopt_:    structure characterizing priors
    
 OUTPUTS
   y:             drawn numbers vector              

 SPECIAL REQUIREMENTS
    none

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function y = rndprior(bayestopt_)
0002 % function y = rndprior(bayestopt_)
0003 % Draws random number from the prior density
0004 %
0005 % INPUTS
0006 %   bayestopt_:    structure characterizing priors
0007 %
0008 % OUTPUTS
0009 %   y:             drawn numbers vector
0010 %
0011 % SPECIAL REQUIREMENTS
0012 %    none
0013 
0014 % Copyright (C) 2003-2009 Dynare Team
0015 %
0016 % This file is part of Dynare.
0017 %
0018 % Dynare is free software: you can redistribute it and/or modify
0019 % it under the terms of the GNU General Public License as published by
0020 % the Free Software Foundation, either version 3 of the License, or
0021 % (at your option) any later version.
0022 %
0023 % Dynare is distributed in the hope that it will be useful,
0024 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0025 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0026 % GNU General Public License for more details.
0027 %
0028 % You should have received a copy of the GNU General Public License
0029 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
0030 
0031 pshape=bayestopt_.pshape;
0032 p3=bayestopt_.p3;
0033 p4=bayestopt_.p4;
0034 p6=bayestopt_.p6;
0035 p7=bayestopt_.p7;
0036 
0037 y = NaN(1,length(pshape)); 
0038 
0039 for i=1:length(pshape)
0040     switch pshape(i)
0041       case 1 % Beta
0042         y(i) = betarnd(p6(i),p7(i));
0043         y(i) = y(1,i) * (p4(i)-p3(i)) + p3(i);
0044       case 2 % Generalized gamma
0045         y(i) = gamrnd(p6(i),p7(i)) + p3(i);
0046       case 3 % Gaussian
0047         y(i) = randn*p7(i) + p6(i) ;
0048       case 4 % Inverse-gamma type 1
0049         y(i) = 1/sqrt(gamrnd(p7(i)/2, 2/p6(i))) + p3(i);
0050       case 5 % Uniform
0051         y(i) = rand*(p4(i)-p3(i)) + p3(i);
0052       case 6 % Inverse-gamma type 2
0053         y(i) = 1/gamrnd(p7(i)/2, 2/p6(i)) + p3(i); 
0054       otherwise
0055         error(sprintf('rndprior: unknown distribution shape (index %d, type %d)', i, pshape(i)));
0056     end
0057 end

Generated on Tue 22-May-2012 02:40:23 by m2html © 2005