0001 function get_prior_info(info,plt_flag)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
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)
0056 fidTeX = fopen('priors_data.tex','w+');
0057
0058
0059
0060
0061
0062
0063
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
0111 results = prior_sampler(0,M_,bayestopt_,options_,oo_);
0112
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
0125
0126 k = find(~isnan(bayestopt_.p5));
0127 xparam1(k) = bayestopt_.p5(k);
0128
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
0146 [xparams,lpd,hessian] = ...
0147 maximize_prior_density(xinit, bayestopt_.pshape, ...
0148 bayestopt_.p6, ...
0149 bayestopt_.p7, ...
0150 bayestopt_.p3, ...
0151 bayestopt_.p4);
0152
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
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'];