Fix gamrnd.m: for big integer values of parameter a, the gaussian approximation was incorrect (closes #67)

git-svn-id: https://www.dynare.org/svn/dynare/trunk@3281 ac1d8469-bf42-47a9-8791-bf33cf982152
time-shift
sebastien 2009-12-21 11:08:59 +00:00
parent 0011678cb5
commit c0c0d48fed
1 changed files with 2 additions and 6 deletions

View File

@ -8,7 +8,7 @@ function rnd = gamrnd(a,b,method)
%
% OUTPUT
% rnd [double] n*1 vector of independent variates from the gamma(a,b) distribution.
% rnd(i) is gamma distributed with variance a(i)b(i) and variance a(i)b(i)^2.
% rnd(i) is gamma distributed with mean a(i)b(i) and variance a(i)b(i)^2.
%
% ALGORITHMS
% Described in Bauwens, Lubrano and Richard (1999, page 316) and Devroye (1986, chapter 9).
@ -85,7 +85,7 @@ if number_of_integer_a
end
if number_of_big_a
% Gaussian approximation.
rnd(integer_idx(big_idx)) = .25*( randn(number_of_big_a,1) + sqrt(4*a(integer_idx(big_idx))-1) ).^2 ;
rnd(integer_idx(big_idx)) = sqrt(a(integer_idx(big_idx))).* b(integer_idx(big_idx)) .* randn(number_of_big_a, 1) + a(integer_idx(big_idx)) .* b(integer_idx(big_idx));
end
end
@ -130,8 +130,6 @@ if number_of_double_a
end
function gamma_variates = weibull_rejection_algorithm(a,b)
nn = length(a);
mm = nn;
@ -402,5 +400,3 @@ while mm
mm = length(index);
end
gamma_variates = X.*b;