Home > matlab > get_prior_info.m

get_prior_info

PURPOSE ^

Computes various prior statistics.

SYNOPSIS ^

function get_prior_info(info,plt_flag)

DESCRIPTION ^

 Computes various prior statistics.
  
 INPUTS
   info     [integer]   scalar specifying what has to be done.
  
 OUTPUTS
   none

 SPECIAL REQUIREMENTS
   none

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function get_prior_info(info,plt_flag)
0002 % Computes various prior statistics.
0003 %
0004 % INPUTS
0005 %   info     [integer]   scalar specifying what has to be done.
0006 %
0007 % OUTPUTS
0008 %   none
0009 %
0010 % SPECIAL REQUIREMENTS
0011 %   none
0012 
0013 % Copyright (C) 2009 Dynare Team
0014 %
0015 % This file is part of Dynare.
0016 %
0017 % Dynare is free software: you can redistribute it and/or modify
0018 % it under the terms of the GNU General Public License as published by
0019 % the Free Software Foundation, either version 3 of the License, or
0020 % (at your option) any later version.
0021 %
0022 % Dynare is distributed in the hope that it will be useful,
0023 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0024 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0025 % GNU General Public License for more details.
0026 %
0027 % You should have received a copy of the GNU General Public License
0028 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
0029 global options_ M_ estim_params_ oo_
0030 
0031 if ~nargin
0032     info = 0;
0033     plt_flag = 0;
0034 end
0035 
0036 if nargin==1
0037     plt_flag = 1;
0038 end
0039 
0040 changed_qz_criterium_flag  = 0;
0041 if isempty(options_.qz_criterium)
0042     options_.qz_criterium = 1+1e-9;
0043     changed_qz_criterium_flag  = 1;
0044 end
0045 
0046 M_.dname = M_.fname;
0047 
0048 [xparam1,estim_params_,bayestopt_,lb,ub,M_] = set_prior(estim_params_,M_,options_);
0049 if plt_flag
0050     plot_priors(bayestopt_,M_,options_);
0051 end
0052 
0053 PriorNames = { 'Beta' , 'Gamma' , 'Gaussian' , 'Inverted Gamma' , 'Uniform' , 'Inverted Gamma -- 2' };
0054 
0055 if size(M_.param_names,1)==size(M_.param_names_tex,1)% All the parameters have a TeX name.
0056     fidTeX = fopen('priors_data.tex','w+');
0057     % Column 1: a string for the name of the prior distribution.
0058     % Column 2: the prior mean.
0059     % Column 3: the prior standard deviation.
0060     % Column 4: the lower bound of the prior density support.
0061     % Column 5: the upper bound of the prior density support.
0062     % Column 6: the lower bound of the interval containing 80% of the prior mass.
0063     % Column 7: the upper bound of the interval containing 80% of the prior mass.
0064     prior_trunc_backup = options_.prior_trunc ;
0065     options_.prior_trunc = (1-options_.prior_interval)/2 ;
0066     PriorIntervals = prior_bounds(bayestopt_,options_) ;
0067     options_.prior_trunc = prior_trunc_backup ;
0068     for i=1:size(bayestopt_.name,1)
0069         [tmp,TexName] = get_the_name(i,1,M_,estim_params_,options_);
0070         PriorShape = PriorNames{ bayestopt_.pshape(i) };
0071         PriorMean = bayestopt_.p1(i);
0072         PriorStandardDeviation = bayestopt_.p2(i);
0073         switch bayestopt_.pshape(i)
0074           case { 1 , 5 }
0075             LowerBound = bayestopt_.p3(i);
0076             UpperBound = bayestopt_.p4(i);
0077           case { 2 , 4 , 6 }
0078             LowerBound = bayestopt_.p3(i);
0079             UpperBound = '$\infty$';
0080           case 3
0081             if isinf(bayestopt_.p3(i))
0082                 LowerBound = '$-\infty$';
0083             else
0084                 LowerBound = bayestopt_.p3(i);
0085             end
0086             if isinf(bayestopt_.p4(i))
0087                 UpperBound = '$\infty$';
0088             else
0089                 UpperBound = bayestopt_.p4(i);
0090             end
0091           otherwise
0092             error('get_prior_info:: Dynare bug!')
0093         end
0094         format_string = build_format_string(bayestopt_,i);
0095         fprintf(fidTeX,format_string, ...
0096                 TexName, ...
0097                 PriorShape, ...
0098                 PriorMean, ...
0099                 PriorStandardDeviation, ...
0100                 LowerBound, ...
0101                 UpperBound, ...
0102                 PriorIntervals(i,1), ...
0103                 PriorIntervals(i,2) );
0104     end
0105     fclose(fidTeX);
0106 end
0107 
0108 M_.dname = M_.fname;
0109 
0110 if info==1% Prior simulations (BK).
0111     results = prior_sampler(0,M_,bayestopt_,options_,oo_);
0112     % Display prior mass info
0113     disp(['Prior mass = ' num2str(results.prior.mass)])
0114     disp(['BK indeterminacy share                = ' num2str(results.bk.indeterminacy_share)])
0115     disp(['BK unstability share                  = ' num2str(results.bk.unstability_share)])
0116     disp(['BK singularity share                  = ' num2str(results.bk.singularity_share)])
0117     disp(['Complex jacobian share                = ' num2str(results.jacobian.problem_share)])
0118     disp(['mjdgges crash share                   = ' num2str(results.dll.problem_share)])
0119     disp(['Steady state problem share            = ' num2str(results.ss.problem_share)])
0120     disp(['Complex steady state  share           = ' num2str(results.ss.complex_share)])
0121     disp(['Analytical steady state problem share = ' num2str(results.ass.problem_share)])
0122 end
0123 
0124 if info==2% Prior optimization.
0125           % Initialize to the prior mode if possible
0126     k = find(~isnan(bayestopt_.p5));
0127     xparam1(k) = bayestopt_.p5(k);
0128     % Pertubation of the initial condition.
0129     look_for_admissible_initial_condition = 1;
0130     scale = 1.0;
0131     iter  = 0;
0132     while look_for_admissible_initial_condition
0133         xinit = xparam1+scale*randn(size(xparam1));
0134         if all(xinit>bayestopt_.p3) && all(xinit<bayestopt_.p4)
0135             look_for_admissible_initial_condition = 0;
0136         else
0137             if iter == 2000;
0138                 scale = scale/1.1;
0139                 iter  = 0;
0140             else
0141                 iter = iter+1;
0142             end
0143         end
0144     end
0145     % Maximization
0146     [xparams,lpd,hessian] = ...
0147         maximize_prior_density(xinit, bayestopt_.pshape, ...
0148                                bayestopt_.p6, ...
0149                                bayestopt_.p7, ...
0150                                bayestopt_.p3, ...
0151                                bayestopt_.p4);
0152     % Display the results.
0153     disp(' ')
0154     disp(' ')
0155     disp('------------------')
0156     disp('PRIOR OPTIMIZATION')
0157     disp('------------------')
0158     disp(' ')
0159     for i = 1:length(xparams)
0160         disp(['deep parameter ' int2str(i) ': ' get_the_name(i,0,M_,estim_params_,options_) '.'])
0161         disp(['  Initial condition ....... ' num2str(xinit(i)) '.'])
0162         disp(['  Prior mode .............. ' num2str(bayestopt_.p5(i)) '.'])
0163         disp(['  Optimized prior mode .... ' num2str(xparams(i)) '.'])
0164         disp(' ')
0165     end
0166 end
0167 
0168 if info==3% Prior simulations (2nd order moments).
0169     oo_ = compute_moments_varendo('prior',options_,M_,oo_);
0170 end 
0171 
0172 if changed_qz_criterium_flag
0173     options_.qz_criterium = [];
0174 end
0175 
0176 
0177 
0178 function format_string = build_format_string(bayestopt,i)
0179 format_string = ['%s & %s & %6.4f &'];
0180 if isinf(bayestopt.p2(i))
0181     format_string = [ format_string , ' %s &'];
0182 else
0183     format_string = [ format_string , ' %6.4f &'];
0184 end
0185 if isinf(bayestopt.p3(i))
0186     format_string = [ format_string , ' %s &'];
0187 else
0188     format_string = [ format_string , ' %6.4f &'];
0189 end
0190 if isinf(bayestopt.p4(i))
0191     format_string = [ format_string , ' %s &'];
0192 else
0193     format_string = [ format_string , ' %6.4f &'];
0194 end
0195 format_string = [ format_string , ' %6.4f & %6.4f \\\\ \n'];

Generated on Mon 21-May-2012 02:42:43 by m2html © 2005