forked from PRML/PRMLT
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
12 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,21 +7,13 @@ | |
% Output: | ||
% y: 1 x n probability density in logrithm scale y=log p(x) | ||
% Written by Mo Chen ([email protected]). | ||
[d,k] = size(mu); | ||
if all(size(sigma)==d) && k==1 % one mu and one dxd sigma | ||
X = bsxfun(@minus,X,mu); | ||
[R,p]= chol(sigma); | ||
if p ~= 0 | ||
error('ERROR: sigma is not PD.'); | ||
end | ||
Q = R'\X; | ||
q = dot(Q,Q,1); % quadratic term (M distance) | ||
c = d*log(2*pi)+2*sum(log(diag(R))); % normalization constant | ||
y = -0.5*(c+q); | ||
elseif size(sigma,1)==1 && size(sigma,2)==size(mu,2) % k mu and (k or one) scalar sigma | ||
X2 = repmat(dot(X,X,1)',1,k); | ||
D = bsxfun(@plus,X2-2*X'*mu,dot(mu,mu,1)); | ||
q = bsxfun(@times,D,1./sigma); % M distance | ||
c = d*(log(2*pi)+2*log(sigma)); % normalization constant | ||
y = -0.5*bsxfun(@plus,q,c); | ||
end | ||
d = size(X,1); | ||
X = X-mu; | ||
[U,p]= chol(sigma); | ||
if p ~= 0 | ||
error('ERROR: sigma is not PD.'); | ||
end | ||
Q = U'\X; | ||
q = dot(Q,Q,1); % quadratic term (M distance) | ||
c = d*log(2*pi)+2*sum(log(diag(U))); % normalization constant | ||
y = -(c+q)/2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters