-
Notifications
You must be signed in to change notification settings - Fork 4
/
ICA_loglikelihood.m
29 lines (26 loc) · 975 Bytes
/
ICA_loglikelihood.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function [ll] = ICA_loglikelihood(X, model)
% Calculate the log likelihood of X, given an ICA model.
%
% The model assumes each column of X is independently generated by a
% mixture model with parameters theta.
%
% Arguments
% X - A DxM matrix, whose every column corresponds to a patch in D
% dimensions (typically D=64).
% model - A struct with fields:
% P - mixing matrix of sources (P: D ind. sources -> D signals)
% vars - a DxK matrix whose (d,k) element correponsds to the
% variance of the k'th component in dimension d.
% mix - a DxK matrix whose (d,k) element correponsds to the
% mixing weight of the k'th component in dimension d.
%
[D, K] = size(model.mix);
S = model.P \ X;
ll = 0;
for i=1:D
S_i = S(i,:);
theta_i.means = zeros(K, 1);
theta_i.covs = reshape(model.vars(i,:), 1, 1, K);
theta_i.mix = model.mix(i,:)';
ll = ll + GMM_loglikelihood(S_i, theta_i);
end