From e95defd117b03fe175fbd8d41b17b435457671e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Fri, 4 Feb 2011 11:55:54 +0100 Subject: [PATCH] Implement workaround for ticket #161 --- matlab/draw_prior_density.m | 41 +++++++++++++++++++++++++++++------ matlab/prior_bounds.m | 43 ++++++++++++++++++++++++++++++------- 2 files changed, 69 insertions(+), 15 deletions(-) diff --git a/matlab/draw_prior_density.m b/matlab/draw_prior_density.m index 20d751a59..3552a6033 100644 --- a/matlab/draw_prior_density.m +++ b/matlab/draw_prior_density.m @@ -14,7 +14,7 @@ function [x,f,abscissa,dens,binf,bsup] = draw_prior_density(indx,bayestopt_); % bsup: [double] Scalar, last element of x -% Copyright (C) 2004-2009 Dynare Team +% Copyright (C) 2004-2011 Dynare Team % % This file is part of Dynare. % @@ -50,8 +50,17 @@ switch pshape(indx) dens = density(abscissa,p6(indx),p7(indx),p3(indx),p4(indx)); case 2% Generalized Gamma prior density = @(x,a,b,c) gampdf(x-c,a,b); - infbound = gaminv(truncprior,p6(indx),p7(indx))+p3(indx); - supbound = gaminv(1-truncprior,p6(indx),p7(indx))+p3(indx); + try + infbound = gaminv(truncprior,p6(indx),p7(indx))+p3(indx); + supbound = gaminv(1-truncprior,p6(indx),p7(indx))+p3(indx); + catch + % Workaround for ticket #161 + if exist('OCTAVE_VERSION') + error(['Due to a bug in Octave, you must choose other values for mean and/or variance of your prior on ' bayestopt_.name{indx} ', or use another shape']) + else + rethrow(lasterror) + end + end stepsize = (supbound-infbound)/steps; abscissa = infbound:stepsize:supbound; dens = density(abscissa,p6(indx),p7(indx),p3(indx)); @@ -62,8 +71,17 @@ switch pshape(indx) abscissa = infbound:stepsize:supbound; dens = normpdf(abscissa,p6(indx),p7(indx)); case 4% Inverse-gamma of type 1 prior - infbound = 1/sqrt(gaminv(1-10*truncprior, p7(indx)/2, 2/p6(indx)))+p3(indx); - supbound = 1/sqrt(gaminv(10*truncprior, p7(indx)/2, 2/p6(indx)))+p3(indx); + try + infbound = 1/sqrt(gaminv(1-10*truncprior, p7(indx)/2, 2/p6(indx)))+p3(indx); + supbound = 1/sqrt(gaminv(10*truncprior, p7(indx)/2, 2/p6(indx)))+p3(indx); + catch + % Workaround for ticket #161 + if exist('OCTAVE_VERSION') + error(['Due to a bug in Octave, you must choose other values for mean and/or variance of your prior on ' bayestopt_.name{indx} ', or use another shape']) + else + rethrow(lasterror) + end + end stepsize = (supbound-infbound)/steps; abscissa = infbound:stepsize:supbound; dens = exp(lpdfig1(abscissa-p3(indx),p6(indx),p7(indx))); @@ -74,8 +92,17 @@ switch pshape(indx) abscissa = infbound:stepsize:supbound; dens = ones(1, steps) / (supbound-infbound); case 6% Inverse-gamma of type 2 prior - infbound = 1/(gaminv(1-10*truncprior, p7(indx)/2, 2/p6(indx)))+p3(indx); - supbound = 1/(gaminv(10*truncprior, p7(indx)/2, 2/p6(indx)))+p3(indx); + try + infbound = 1/(gaminv(1-10*truncprior, p7(indx)/2, 2/p6(indx)))+p3(indx); + supbound = 1/(gaminv(10*truncprior, p7(indx)/2, 2/p6(indx)))+p3(indx); + catch + % Workaround for ticket #161 + if exist('OCTAVE_VERSION') + error(['Due to a bug in Octave, you must choose other values for mean and/or variance of your prior on ' bayestopt_.name{indx} ', or use another shape']) + else + rethrow(lasterror) + end + end stepsize = (supbound-infbound)/steps ; abscissa = infbound:stepsize:supbound; dens = exp(lpdfig2(abscissa-p3(indx),p6(indx),p7(indx))); diff --git a/matlab/prior_bounds.m b/matlab/prior_bounds.m index 0043ef762..72eaa7672 100644 --- a/matlab/prior_bounds.m +++ b/matlab/prior_bounds.m @@ -11,7 +11,7 @@ function bounds = prior_bounds(bayestopt) % SPECIAL REQUIREMENTS % none -% Copyright (C) 2003-2009 Dynare Team +% Copyright (C) 2003-2011 Dynare Team % % This file is part of Dynare. % @@ -55,8 +55,17 @@ for i=1:length(p6) bounds(i,1) = p3(i); bounds(i,2) = Inf; else - bounds(i,1) = gaminv(prior_trunc,p6(i),p7(i))+p3(i); - bounds(i,2) = gaminv(1-prior_trunc,p6(i),p7(i))+p3(i); + try + bounds(i,1) = gaminv(prior_trunc,p6(i),p7(i))+p3(i); + bounds(i,2) = gaminv(1-prior_trunc,p6(i),p7(i))+p3(i); + catch + % Workaround for ticket #161 + if exist('OCTAVE_VERSION') + error(['Due to a bug in Octave, you must choose other values for mean and/or variance of your prior on ' bayestopt.name{i} ', or use another shape']) + else + rethrow(lasterror) + end + end end case 3 if prior_trunc == 0 @@ -71,9 +80,18 @@ for i=1:length(p6) bounds(i,1) = p3(i); bounds(i,2) = Inf; else - bounds(i,1) = 1/sqrt(gaminv(1-prior_trunc, p7(i)/2, 2/p6(i)))+p3(i); - bounds(i,2) = 1/sqrt(gaminv(prior_trunc, p7(i)/2, ... - 2/p6(i)))+p3(i); + try + bounds(i,1) = 1/sqrt(gaminv(1-prior_trunc, p7(i)/2, 2/p6(i)))+p3(i); + bounds(i,2) = 1/sqrt(gaminv(prior_trunc, p7(i)/2, ... + 2/p6(i)))+p3(i); + catch + % Workaround for ticket #161 + if exist('OCTAVE_VERSION') + error(['Due to a bug in Octave, you must choose other values for mean and/or variance of your prior on ' bayestopt.name{i} ', or use another shape']) + else + rethrow(lasterror) + end + end end case 5 if prior_trunc == 0 @@ -88,8 +106,17 @@ for i=1:length(p6) bounds(i,1) = p3(i); bounds(i,2) = Inf; else - bounds(i,1) = 1/gaminv(1-prior_trunc, p7(i)/2, 2/p6(i))+p3(i); - bounds(i,2) = 1/gaminv(prior_trunc, p7(i)/2, 2/p6(i))+ p3(i); + try + bounds(i,1) = 1/gaminv(1-prior_trunc, p7(i)/2, 2/p6(i))+p3(i); + bounds(i,2) = 1/gaminv(prior_trunc, p7(i)/2, 2/p6(i))+ p3(i); + catch + % Workaround for ticket #161 + if exist('OCTAVE_VERSION') + error(['Due to a bug in Octave, you must choose other values for mean and/or variance of your prior on ' bayestopt.name{i} ', or use another shape']) + else + rethrow(lasterror) + end + end end otherwise error(sprintf('prior_bounds: unknown distribution shape (index %d, type %d)', i, pshape(i)));