Home > . > posterior_distribution.m

posterior_distribution

PURPOSE ^

stephane.adjemian@cepremap.cnrs.fr [07-15-2004]

SYNOPSIS ^

function [borneinf,bornesup,x1,x2,f1,f2,top,nam,texnam] =posterior_distribution(indx,number_of_mh_files,first_mh_file,first_line,number_of_blocks,number_of_simulations,number_of_simulations_per_file,TeX);

DESCRIPTION ^

 stephane.adjemian@cepremap.cnrs.fr [07-15-2004]

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [borneinf,bornesup,x1,x2,f1,f2,top,nam,texnam] = ...
0002     posterior_distribution(indx,number_of_mh_files,first_mh_file,first_line,...
0003                     number_of_blocks,number_of_simulations,...
0004                     number_of_simulations_per_file,TeX);
0005 % stephane.adjemian@cepremap.cnrs.fr [07-15-2004]
0006 
0007 global M_ bayestopt_ estim_params_ options_
0008 
0009 number_of_grid_points = 2^9;      % 2^9 = 512 !... Must be a power of two.
0010 bandwidth = 0;                    % Rule of thumb optimal bandwidth parameter.
0011 kernel_function = 'gaussian';     % Gaussian kernel for Fast Fourrier Transform approximaton.
0012              
0013 
0014 mcsimulations = zeros(number_of_simulations,1);
0015 
0016 if number_of_blocks == 1
0017     EndOfFile = number_of_simulations_per_file(first_mh_file+1)-first_line+1;
0018     instr = [M_.fname '_mh' int2str(first_mh_file)];
0019     eval(['load ' instr]);
0020     clear post2 logpo2;
0021     mcsimulations(1:EndOfFile) = x2(first_line:end,indx);
0022     OldEndOfFile = EndOfFile;
0023     for f = first_mh_file+1:number_of_mh_files
0024         NewEndOfFile = number_of_simulations_per_file(f+1);
0025            instr = [M_.fname '_mh' int2str(f)];
0026         eval(['load ' instr]);
0027         clear post2 logpo2;
0028         mcsimulations(OldEndOfFile+1:OldEndOfFile+NewEndOfFile) = x2(:,indx);
0029         OldEndOfFile = OldEndOfFile + NewEndOfFile;
0030     end
0031     clear x2;
0032 else
0033     EndOfFile = number_of_simulations_per_file(first_mh_file+1)-first_line+1;
0034     NewStartLine = 0;
0035     inst = [M_.fname '_mh' int2str(first_mh_file)];
0036     for b = 1:number_of_blocks
0037         instr = [inst '_blck' int2str(b)];
0038         eval(['load ' instr]);
0039         clear post2 logpo2;
0040            mcsimulations(NewStartLine+1:NewStartLine+EndOfFile,1) = x2(first_line:end,indx);
0041         NewStartLine = NewStartLine + EndOfFile;
0042     end
0043     for f = first_mh_file+1:number_of_mh_files
0044         EndOfFile = number_of_simulations_per_file(f+1);
0045            inst = [M_.fname '_mh' int2str(f)];
0046         for B = 1:number_of_blocks
0047             instr = [inst '_blck' int2str(b)];
0048             eval(['load ' instr]);
0049             clear post2 logpo2;
0050             mcsimulations(NewStartLine+1:NewStartLine+EndOfFile,1) = x2(:,indx);
0051             NewStartLine = NewStartLine + EndOfFile;
0052         end
0053     end
0054     clear x2;
0055 end
0056 
0057 [nam,texnam] = get_the_name(indx,TeX);
0058 
0059 %% Kernel estimator of the posterior density:
0060 optimal_bandwidth = mh_optimal_bandwidth(mcsimulations,number_of_simulations,bandwidth,kernel_function); 
0061 [x1,f1] = kernel_density_estimate(mcsimulations,number_of_grid_points,...
0062     optimal_bandwidth,kernel_function);
0063 binf1 = x1(1);
0064 bsup1 = x1(length(x1));
0065 
0066 %% Prior density:
0067 [x2,f2,abscissa,dens,binf2,bsup2] = draw_prior_density(indx);
0068 clear abscissa dens;
0069 
0070 borneinf = min(binf1,binf2);
0071 bornesup = max(bsup1,bsup2);
0072 top      = max([max(f1);max(f2)]);

Generated on Fri 16-Jun-2006 09:09:06 by m2html © 2003