[422372]: / functions / miscfunc / loglike.m

Download this file

43 lines (37 with data), 1.2 kB

 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
29
30
31
32
33
34
35
36
37
38
39
40
41
function f=loglike(W, S)
% LOGLIKE - log likehood function to estimate dependence between components
%
% Usage: f = loglike(W, S);
%
% Computation of the log-likelihood function under the model
% that the ICs are 1/cosh(s) distributed (according to the tanh
% nonlinearity in ICA). It does not exactly match for the logistic
% nonlinearity, but should be a decent approximation
%
% negative log likelihood function
% f = -( log(abs(det(W))) - sum(sum(log( cosh(S) )))/N - M*log(pi) );
%
% With these meanings:
% W: total unmixing matrix, ie, icaweights*icasphere
% S: 2-dim Matrix of source estimates
% N: number of time points
% M: number of components
%
% Author: Arnaud Delorme and Jorn Anemuller
W = double(W);
S = double(S);
% normalize activities
stds = std(S, [], 2);
S = S./repmat(stds, [1 size(S,2)]);
W = W./repmat(stds, [1 size(W,2)]);
M = size(W,1);
if ndims(S) == 3
S = reshape(S, size(S,1), size(S,3)*size(S,2));
end
N = size(S,2);
% detect infinite and remove them
tmpcoh = log( cosh(S) );
tmpinf = find(isinf(tmpcoh));
tmpcoh(tmpinf) = [];
N = (N*M-length(tmpinf))/M;
f=-( log(abs(det(W))) - sum(sum(tmpcoh))/N - M*log(pi) );