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-bf33cf982152time-shift
parent
0011678cb5
commit
c0c0d48fed
|
@ -8,7 +8,7 @@ function rnd = gamrnd(a,b,method)
|
||||||
%
|
%
|
||||||
% OUTPUT
|
% OUTPUT
|
||||||
% rnd [double] n*1 vector of independent variates from the gamma(a,b) distribution.
|
% 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
|
% ALGORITHMS
|
||||||
% Described in Bauwens, Lubrano and Richard (1999, page 316) and Devroye (1986, chapter 9).
|
% Described in Bauwens, Lubrano and Richard (1999, page 316) and Devroye (1986, chapter 9).
|
||||||
|
@ -85,7 +85,7 @@ if number_of_integer_a
|
||||||
end
|
end
|
||||||
if number_of_big_a
|
if number_of_big_a
|
||||||
% Gaussian approximation.
|
% 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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -130,8 +130,6 @@ if number_of_double_a
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function gamma_variates = weibull_rejection_algorithm(a,b)
|
function gamma_variates = weibull_rejection_algorithm(a,b)
|
||||||
nn = length(a);
|
nn = length(a);
|
||||||
mm = nn;
|
mm = nn;
|
||||||
|
@ -402,5 +400,3 @@ while mm
|
||||||
mm = length(index);
|
mm = length(index);
|
||||||
end
|
end
|
||||||
gamma_variates = X.*b;
|
gamma_variates = X.*b;
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue