From bd60a5beef7149f4f0b342398d9b0dc586e4e334 Mon Sep 17 00:00:00 2001 From: Michel Juillard Date: Sun, 1 Jan 2012 20:12:51 +0100 Subject: [PATCH] made inverse_gamma_specification robust for a larger set of parameter values --- matlab/distributions/inverse_gamma_specification.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/matlab/distributions/inverse_gamma_specification.m b/matlab/distributions/inverse_gamma_specification.m index bbd6d06fb..57c3e747b 100644 --- a/matlab/distributions/inverse_gamma_specification.m +++ b/matlab/distributions/inverse_gamma_specification.m @@ -99,7 +99,7 @@ elseif type == 1; % Inverse Gamma 1 end end % Solve for nu using the secant method. - while abs(nu2-nu1) > 1e-8 + while abs(nu2/nu1-1) > 1e-14 if err > 0 nu1 = nu; if nu < nu2 @@ -117,10 +117,10 @@ elseif type == 1; % Inverse Gamma 1 end s = (sigma2+mu2)*(nu-2); if check_solution_flag - if abs(mu-sqrt(s/2)*gamma((nu-1)/2)/gamma(nu/2))>1e-9 + if abs(log(mu)-log(sqrt(s/2))-gammaln((nu-1)/2)+gammaln(nu/2))>1e-7 error('inverse_gamma_specification:: Failed in solving for the hyperparameters!'); end - if abs(sigma-sqrt(s/(nu-2)-mu^2))>1e-9 + if abs(sigma-sqrt(s/(nu-2)-mu^2))>1e-7 error('inverse_gamma_specification:: Failed in solving for the hyperparameters!'); end end