Verified Commit 82aa669b authored by Johannes Pfeifer 's avatar Johannes Pfeifer Committed by Stéphane Adjemian

prior densities: make sure derivative output has correct dimensions

parent 2b7dbff4
...@@ -7,13 +7,14 @@ function [ldens,Dldens,D2ldens] = lpdfgam(x,a,b) ...@@ -7,13 +7,14 @@ function [ldens,Dldens,D2ldens] = lpdfgam(x,a,b)
% b [double] m*n matrix or scalar, Second GAMMA distribution parameters (scale), % b [double] m*n matrix or scalar, Second GAMMA distribution parameters (scale),
% %
% OUTPUTS % OUTPUTS
% ldens [double] m*n matrix of logged GAMMA densities evaluated at x. % ldens [double] m*n matrix of logged GAMMA densities evaluated at x.
% % Dldens [double] m*n matrix of first derivatives of logged GAMMA densities.
% D2ldens [double] m*n matrix of second derivatives of logged matrix of logged GAMMA densities.
% %
% SPECIAL REQUIREMENTS % SPECIAL REQUIREMENTS
% none % none
% Copyright (C) 2003-2017 Dynare Team % Copyright (C) 2003-2021 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
...@@ -42,6 +43,7 @@ end ...@@ -42,6 +43,7 @@ end
if nargout >1 if nargout >1
Dldens = ldens ;
if length(a)==1 if length(a)==1
Dldens(idx) = (a-1)./(x(idx)) - ones(length(idx),1)/b ; Dldens(idx) = (a-1)./(x(idx)) - ones(length(idx),1)/b ;
else else
...@@ -50,6 +52,7 @@ if nargout >1 ...@@ -50,6 +52,7 @@ if nargout >1
end end
if nargout == 3 if nargout == 3
D2ldens = ldens ;
if length(a)==1 if length(a)==1
D2ldens(idx) = -(a-1)./(x(idx)).^2; D2ldens(idx) = -(a-1)./(x(idx)).^2;
else else
......
...@@ -2,19 +2,21 @@ function [ldens,Dldens,D2ldens] = lpdfgbeta(x,a,b,aa,bb) ...@@ -2,19 +2,21 @@ function [ldens,Dldens,D2ldens] = lpdfgbeta(x,a,b,aa,bb)
% Evaluates the logged BETA PDF at x. % Evaluates the logged BETA PDF at x.
% %
% INPUTS % INPUTS
% x [double] m*n matrix of loactions, % x [double] m*n matrix of locations,
% a [double] m*n matrix of First BETA distribution parameters, % a [double] m*n matrix of First BETA distribution parameters,
% b [double] m*n matrix of Second BETA distribution parameters, % b [double] m*n matrix of Second BETA distribution parameters,
% aa [double] m*n matrix of lower bounds for (generalized) distribution, % aa [double] m*n matrix of lower bounds for (generalized) distribution,
% bb [double] m*n matrix of upper bounds for (generalized) distribution % bb [double] m*n matrix of upper bounds for (generalized) distribution
% %
% OUTPUTS % OUTPUTS
% ldens [double] m*n matrix of logged (generalized) BETA densities. % ldens [double] m*n matrix of logged (generalized) BETA densities.
% Dldens [double] m*n matrix of first derivatives of logged (generalized) BETA densities.
% D2ldens [double] m*n matrix of second derivatives of logged matrix of logged (generalized) BETA densities.
% %
% SPECIAL REQUIREMENTS % SPECIAL REQUIREMENTS
% none % none
% Copyright (C) 2003-2017 Dynare Team % Copyright (C) 2003-2021 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
...@@ -42,6 +44,7 @@ end ...@@ -42,6 +44,7 @@ end
if nargout >1 if nargout >1
Dldens = ldens ;
if length(a)==1 if length(a)==1
Dldens(idx) = (a-1)./(x(idx)-aa) - (b-1)./(bb-x(idx)) ; Dldens(idx) = (a-1)./(x(idx)-aa) - (b-1)./(bb-x(idx)) ;
else else
...@@ -51,6 +54,7 @@ end ...@@ -51,6 +54,7 @@ end
if nargout == 3 if nargout == 3
D2ldens = ldens ;
if length(a)==1 if length(a)==1
D2ldens(idx) = -(a-1)./(x(idx)-aa).^2 - (b-1)./(bb-x(idx)).^2 ; D2ldens(idx) = -(a-1)./(x(idx)-aa).^2 - (b-1)./(bb-x(idx)).^2 ;
else else
......
...@@ -13,11 +13,13 @@ function [ldens,Dldens,D2ldens] = lpdfig1(x,s,nu) ...@@ -13,11 +13,13 @@ function [ldens,Dldens,D2ldens] = lpdfig1(x,s,nu)
% %
% OUTPUTS % OUTPUTS
% ldens [double] m*n matrix of logged INVERSE-GAMMA-1 densities evaluated at x. % ldens [double] m*n matrix of logged INVERSE-GAMMA-1 densities evaluated at x.
% Dldens [double] m*n matrix of first derivatives of logged INVERSE-GAMMA-1 densities.
% D2ldens [double] m*n matrix of second derivatives of logged matrix of logged INVERSE-GAMMA-1 densities.
% %
% SPECIAL REQUIREMENTS % SPECIAL REQUIREMENTS
% none % none
% Copyright (C) 2004-2017 Dynare Team % Copyright (C) 2004-2021 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
...@@ -44,6 +46,7 @@ else ...@@ -44,6 +46,7 @@ else
end end
if nargout >1 if nargout >1
Dldens = ldens ;
if length(s)==1 if length(s)==1
Dldens(idx) = - (nu+1)./(x(idx)) + s./(x(idx).^3) ; Dldens(idx) = - (nu+1)./(x(idx)) + s./(x(idx).^3) ;
else else
...@@ -52,6 +55,7 @@ if nargout >1 ...@@ -52,6 +55,7 @@ if nargout >1
end end
if nargout == 3 if nargout == 3
D2ldens = ldens ;
if length(s)==1 if length(s)==1
D2ldens(idx) = (nu+1)./(x(idx).^2) - 3*s(idx)./(x(idx).^4) ; D2ldens(idx) = (nu+1)./(x(idx).^2) - 3*s(idx)./(x(idx).^4) ;
else else
......
...@@ -13,11 +13,13 @@ function [ldens,Dldens,D2ldens] = lpdfig2(x,s,nu) ...@@ -13,11 +13,13 @@ function [ldens,Dldens,D2ldens] = lpdfig2(x,s,nu)
% %
% OUTPUTS % OUTPUTS
% ldens [double] m*n matrix of logged INVERSE-GAMMA-2 densities evaluated at x. % ldens [double] m*n matrix of logged INVERSE-GAMMA-2 densities evaluated at x.
% Dldens [double] m*n matrix of first derivatives of logged INVERSE-GAMMA-2 densities.
% D2ldens [double] m*n matrix of second derivatives of logged matrix of logged INVERSE-GAMMA-2 densities.
% %
% SPECIAL REQUIREMENTS % SPECIAL REQUIREMENTS
% none % none
% Copyright (C) 2004-2017 Dynare Team % Copyright (C) 2004-2021 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
...@@ -44,6 +46,7 @@ else ...@@ -44,6 +46,7 @@ else
end end
if nargout >1 if nargout >1
Dldens = ldens;
if length(s)==1 if length(s)==1
Dldens(idx) = - .5*(nu+2)./(x(idx)) + .5*s./x(idx).^2; Dldens(idx) = - .5*(nu+2)./(x(idx)) + .5*s./x(idx).^2;
else else
...@@ -52,6 +55,7 @@ if nargout >1 ...@@ -52,6 +55,7 @@ if nargout >1
end end
if nargout == 3 if nargout == 3
D2ldens = ldens;
if length(s)==1 if length(s)==1
D2ldens(idx) = .5*(nu+2)./(x(idx)).^2 - s./x(idx).^3; D2ldens(idx) = .5*(nu+2)./(x(idx)).^2 - s./x(idx).^3;
else else
......
...@@ -7,13 +7,14 @@ function [ldens,Dldens,D2ldens] = lpdfnorm(x,a,b) ...@@ -7,13 +7,14 @@ function [ldens,Dldens,D2ldens] = lpdfnorm(x,a,b)
% b [double] m*n matrix or scalar, Second GAUSSIAN distribution parameters (standard deviation). % b [double] m*n matrix or scalar, Second GAUSSIAN distribution parameters (standard deviation).
% %
% OUTPUTS % OUTPUTS
% ldens [double] m*n matrix of logged GAUSSIAN densities evaluated at x. % ldens [double] m*n matrix of logged GAUSSIAN densities evaluated at x.
% % Dldens [double] m*n matrix of first derivatives of logged GAUSSIAN densities.
% D2ldens [double] m*n matrix of second derivatives of logged matrix of GAUSSIAN densities.
% %
% SPECIAL REQUIREMENTS % SPECIAL REQUIREMENTS
% none % none
% Copyright (C) 2003-2017 Dynare Team % Copyright (C) 2003-2021 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
......
...@@ -83,8 +83,8 @@ if nargin > 6 && initialization ...@@ -83,8 +83,8 @@ if nargin > 6 && initialization
end end
logged_prior_density = 0.0; logged_prior_density = 0.0;
dlprior = 0.0; dlprior = zeros(1,length(x));
d2lprior = 0.0; d2lprior = dlprior;
if tt1 if tt1
logged_prior_density = logged_prior_density + sum(lpdfgbeta(x(id1),p6(id1),p7(id1),p3(id1),p4(id1))) ; logged_prior_density = logged_prior_density + sum(lpdfgbeta(x(id1),p6(id1),p7(id1),p3(id1),p4(id1))) ;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment