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

prior densities: make sure derivative output has correct dimensions

(cherry picked from commit 82aa669b)
parent 75f61a75
......@@ -7,13 +7,14 @@ function [ldens,Dldens,D2ldens] = lpdfgam(x,a,b)
% b [double] m*n matrix or scalar, Second GAMMA distribution parameters (scale),
%
% 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
% none
% Copyright (C) 2003-2017 Dynare Team
% Copyright (C) 2003-2021 Dynare Team
%
% This file is part of Dynare.
%
......@@ -42,6 +43,7 @@ end
if nargout >1
Dldens = ldens ;
if length(a)==1
Dldens(idx) = (a-1)./(x(idx)) - ones(length(idx),1)/b ;
else
......@@ -50,6 +52,7 @@ if nargout >1
end
if nargout == 3
D2ldens = ldens ;
if length(a)==1
D2ldens(idx) = -(a-1)./(x(idx)).^2;
else
......
......@@ -2,19 +2,21 @@ function [ldens,Dldens,D2ldens] = lpdfgbeta(x,a,b,aa,bb)
% Evaluates the logged BETA PDF at x.
%
% 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,
% b [double] m*n matrix of Second BETA distribution parameters,
% aa [double] m*n matrix of lower bounds for (generalized) distribution,
% bb [double] m*n matrix of upper bounds for (generalized) distribution
%
% 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
% none
% Copyright (C) 2003-2017 Dynare Team
% Copyright (C) 2003-2021 Dynare Team
%
% This file is part of Dynare.
%
......@@ -42,6 +44,7 @@ end
if nargout >1
Dldens = ldens ;
if length(a)==1
Dldens(idx) = (a-1)./(x(idx)-aa) - (b-1)./(bb-x(idx)) ;
else
......@@ -51,6 +54,7 @@ end
if nargout == 3
D2ldens = ldens ;
if length(a)==1
D2ldens(idx) = -(a-1)./(x(idx)-aa).^2 - (b-1)./(bb-x(idx)).^2 ;
else
......
......@@ -13,11 +13,13 @@ function [ldens,Dldens,D2ldens] = lpdfig1(x,s,nu)
%
% OUTPUTS
% 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
% none
% Copyright (C) 2004-2017 Dynare Team
% Copyright (C) 2004-2021 Dynare Team
%
% This file is part of Dynare.
%
......@@ -44,6 +46,7 @@ else
end
if nargout >1
Dldens = ldens ;
if length(s)==1
Dldens(idx) = - (nu+1)./(x(idx)) + s./(x(idx).^3) ;
else
......@@ -52,6 +55,7 @@ if nargout >1
end
if nargout == 3
D2ldens = ldens ;
if length(s)==1
D2ldens(idx) = (nu+1)./(x(idx).^2) - 3*s(idx)./(x(idx).^4) ;
else
......
......@@ -13,11 +13,13 @@ function [ldens,Dldens,D2ldens] = lpdfig2(x,s,nu)
%
% OUTPUTS
% 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
% none
% Copyright (C) 2004-2017 Dynare Team
% Copyright (C) 2004-2021 Dynare Team
%
% This file is part of Dynare.
%
......@@ -44,6 +46,7 @@ else
end
if nargout >1
Dldens = ldens;
if length(s)==1
Dldens(idx) = - .5*(nu+2)./(x(idx)) + .5*s./x(idx).^2;
else
......@@ -52,6 +55,7 @@ if nargout >1
end
if nargout == 3
D2ldens = ldens;
if length(s)==1
D2ldens(idx) = .5*(nu+2)./(x(idx)).^2 - s./x(idx).^3;
else
......
......@@ -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).
%
% 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
% none
% Copyright (C) 2003-2017 Dynare Team
% Copyright (C) 2003-2021 Dynare Team
%
% This file is part of Dynare.
%
......
......@@ -83,8 +83,8 @@ if nargin > 6 && initialization
end
logged_prior_density = 0.0;
dlprior = 0.0;
d2lprior = 0.0;
dlprior = zeros(1,length(x));
d2lprior = dlprior;
if tt1
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