2017-05-16 12:42:01 +02:00
|
|
|
function density = multivariate_normal_pdf(X,Mean,Sigma_upper_chol,n)
|
2008-09-10 10:41:53 +02:00
|
|
|
% Evaluates the density of a multivariate gaussian, with expectation Mean
|
|
|
|
% and variance Sigma_upper_chol'*Sigma_upper_chol, at X.
|
|
|
|
%
|
|
|
|
%
|
2017-05-16 15:10:20 +02:00
|
|
|
% INPUTS
|
|
|
|
%
|
|
|
|
% X [double] 1*n vector
|
2008-09-10 10:41:53 +02:00
|
|
|
% Mean [double] 1*n vector, expectation of the multivariate random variable.
|
|
|
|
% Sigma_upper_chol [double] n*n matrix, upper triangular Cholesky decomposition of Sigma (the covariance matrix).
|
|
|
|
% n [integer] dimension.
|
2017-05-16 15:10:20 +02:00
|
|
|
%
|
|
|
|
% OUTPUTS
|
|
|
|
% density [double] density
|
|
|
|
%
|
2008-09-10 10:41:53 +02:00
|
|
|
% SPECIAL REQUIREMENTS
|
|
|
|
|
2017-05-16 14:11:15 +02:00
|
|
|
% Copyright (C) 2003-2017 Dynare Team
|
2008-09-10 10:41:53 +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/>.
|
2017-05-16 15:10:20 +02:00
|
|
|
density = (2*pi)^(-.5*n) * ...
|
2009-12-16 18:17:34 +01:00
|
|
|
prod(diag(Sigma_upper_chol))^(-1) * ...
|
|
|
|
exp(-.5*(X-Mean)*(Sigma_upper_chol\(transpose(Sigma_upper_chol)\transpose(X-Mean))));
|