ParaMonte MATLAB 3.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
getLogPDF.m
Go to the documentation of this file.
1%> \brief
2%> Return the corresponding natural logarithm(s) of Probability Density Function (PDF)
3%> of the input ``ndim``-dimensional multivariate Normal random vector(s).<br>
4%>
5%> \details
6%> This log-PDF function can be potentially faster and more flexible than the intrinsic MATLAB
7%> equivalent because it optionally accepts vectors of MVN random variates and returns the
8%> natural logarithm of the density function which avoids a costly exponentiation.<br>
9%>
10%> \param[in] x : The input vector of shape ``[ndim, nvec]`` of MATLAB ``real``,
11%> representing the set of ``nvec`` MVN vectors from the ``ndim``-dimensional MVN space.<br>
12%> \param[in] mean : The input vector of shape ``[ndim, 1]`` of MATLAB ``real``,
13%> representing the mean of a Multivariate Normal
14%> distribution in ``size(mean)`` dimensional space.<br>
15%> If the input value is empty, it is set to the default value.<br>
16%> (**optional**. default = ``zeros(ndim, 1)``.)
17%> \param[in] invcov : The input positive-definite square matrix of shape ``[ndim, ndim]`` of MATLAB ``real``,
18%> representing the inverse of the covariance matrix of the target Multivariate
19%> Normal distribution in ``numel(mean)`` dimensional space.<br>
20%> If the input value is empty, it is set to the default value.<br>
21%> Note that the inverse covariance matrix can be readily obtained from
22%> its lower or upper Cholesky factorization (``cholow`` or ``choupp``) via
23%> [pm.matlab.inv(cholow)](@ref inv) or [pm.matlab.inv(choupp')](@ref inv).<br>
24%> (**optional**. default = ``eye(ndim, ndim)``.)
25%>
26%> \return
27%> ``logPDF`` : The output column vector of MATLAB ``real`` of shape ``[nvec, 1]``
28%> containing the natural logarithm(s) of the input MVN vector(s).<br>
29%>
30%> \interface{getLogPDF}
31%> \code{.m}
32%>
33%> logPDF = pm.stats.dist.mvn.getLogPDF(x)
34%> logPDF = pm.stats.dist.mvn.getLogPDF(x, mean)
35%> logPDF = pm.stats.dist.mvn.getLogPDF(x, [], invcov)
36%> logPDF = pm.stats.dist.mvn.getLogPDF(x, mean, invcov)
37%>
38%> \endcode
39%>
40%> \example{getLogPDF}
41%> \include{lineno} example/stats/dist/mvn/getLogPDF/main.m
42%> \output{getLogPDF}
43%> \include{lineno} example/stats/dist/mvn/getLogPDF/main.out.m
44%> \vis{getLogPDF}
45%> \image html example/stats/dist/mvn/getLogPDF/mvn.getLogPDF.scatter.3d.png width=700
46%>
47%> \final{getLogPDF}
48%>
49%> \author
50%> \JoshuaOsborne, May 21 2024, 12:06 AM, University of Texas at Arlington<br>
51%> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
52%> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
53function logPDF = getLogPDF(x, mean, invcov)
54 ndim = size(x, 1);
55 nvec = size(x, 2);
56 if nargin < 3
57 invcov = [];
58 end
59 if nargin < 2
60 mean = [];
61 end
62 if isempty(invcov)
63 logDetInvCov = 0.;
64 invcov = eye(ndim, ndim);
65 else
66 logDetInvCov = log(det(invcov));
67 end
68 if isempty(mean)
69 mean = zeros(ndim, 1);
70 else
71 mean = mean(:);
72 end
73 logPDF = zeros(nvec, 1);
74 log2pi = 1.837877066409345; % log(2 * pi)
75 logNormFac = -0.5 * (ndim * log2pi - logDetInvCov);
76 for ivec = 1 : nvec
77 xnormed = x(:, ivec) - mean;
78 logPDF(ivec) = logNormFac - .5 * (xnormed' * invcov * xnormed);
79 end
80end
function getLogPDF(in x, in kappa, in invOmega, in invSigma)
Return the corresponding natural logarithm(s) of Probability Density Function (PDF) of the input rand...
function inv(in cholow)
Generate and return the inverse of a positive-definite matrix whose Lower-triangular Cholesky factori...
function which(in vendor)
Return the a MATLAB string containing the path to the first mpiexec executable binary found in system...