2011-11-05 10:32:37 +01:00
|
|
|
function [ldens,Dldens,D2ldens] = lpdfnorm(x,a,b)
|
2009-04-06 16:38:37 +02:00
|
|
|
% Evaluates the logged UNIVARIATE GAUSSIAN PDF at x.
|
2005-02-18 20:54:39 +01:00
|
|
|
%
|
2017-05-16 15:10:20 +02:00
|
|
|
% INPUTS
|
2009-04-06 16:38:37 +02:00
|
|
|
% x [double] m*n matrix of locations,
|
2017-05-16 15:10:20 +02:00
|
|
|
% a [double] m*n matrix or scalar, First GAUSSIAN distribution parameters (expectation)
|
|
|
|
% b [double] m*n matrix or scalar, Second GAUSSIAN distribution parameters (standard deviation).
|
2008-08-01 14:40:33 +02:00
|
|
|
%
|
2017-05-16 15:10:20 +02:00
|
|
|
% OUTPUTS
|
2021-01-22 15:45:51 +01:00
|
|
|
% 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.
|
2017-05-16 15:10:20 +02:00
|
|
|
%
|
2008-01-11 16:57:20 +01:00
|
|
|
% SPECIAL REQUIREMENTS
|
|
|
|
% none
|
|
|
|
|
2021-01-22 15:45:51 +01:00
|
|
|
% Copyright (C) 2003-2021 Dynare Team
|
2008-08-01 14:40:33 +02:00
|
|
|
%
|
|
|
|
% This file is part of Dynare.
|
|
|
|
%
|
|
|
|
% Dynare is free software: you can redistribute it and/or modify
|
|
|
|
% it under the terms of the GNU General Public License as published by
|
|
|
|
% the Free Software Foundation, either version 3 of the License, or
|
|
|
|
% (at your option) any later version.
|
|
|
|
%
|
|
|
|
% Dynare is distributed in the hope that it will be useful,
|
|
|
|
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
% GNU General Public License for more details.
|
|
|
|
%
|
|
|
|
% You should have received a copy of the GNU General Public License
|
2021-06-09 17:33:48 +02:00
|
|
|
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
2005-02-18 20:54:39 +01:00
|
|
|
|
2009-04-06 16:38:37 +02:00
|
|
|
if nargin<3, b=1; end
|
|
|
|
if nargin<2, a=0; end
|
2011-11-05 10:32:37 +01:00
|
|
|
ldens = -log(b) -.5*log(2*pi) - .5*((x-a)./b).*((x-a)./b) ;
|
|
|
|
|
2017-05-16 15:10:20 +02:00
|
|
|
if nargout >1
|
2012-06-08 08:50:48 +02:00
|
|
|
Dldens = - (1./b).*((x-a)./b) ;
|
2011-11-05 10:32:37 +01:00
|
|
|
end
|
|
|
|
|
2017-05-16 15:10:20 +02:00
|
|
|
if nargout == 3
|
2012-06-08 08:50:48 +02:00
|
|
|
D2ldens = - (1./b).^2 ;
|
2011-11-05 10:32:37 +01:00
|
|
|
end
|