forked from cultpenguin/mGstat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcovar_prob.m
71 lines (58 loc) · 1.79 KB
/
covar_prob.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
% covar_prob : THIS SHOULD BE CALLED FROM VISIM_PRIOR_PROB
%
% [Lmean,L,Ldim]=covar_prob(VaExpU,VaExpC,options)
function [Lmean,L,Ldim]=covar_prob(VaExpU,VaExpC,options)
if nargin<3
options.null='';
end
if isfield(options,'nocross')==1, nocross=options.nocross; else nocross=0; end
ndim=length(VaExpU.g);
for i=1:ndim
iuse{i}=find(~isnan(sum(VaExpU.g{i}')));
g{i}=VaExpU.g{i}(iuse{i},:);
gcc{i}=cov([g{i}']);
g0_{i}=mean(VaExpU.g{i}');
if i==1,
gcc_cross=g{i}';
g0=g0_{i}(iuse{i});
else
gcc_cross=[gcc_cross,g{i}'];
g0=[g0 g0_{i}(iuse{i})];
end
end
gcc_cross=cov(gcc_cross);
% NO USE OF CROSS CORRELATION
if nocross==1
disp(sprintf('Ignoring Cross correlation of variance !',mfilename))
gcc_cross2=0.*gcc_cross;
for i=1:size(gcc_cross,1);
gcc_cross2(i,i)=gcc_cross(i,i);
end
gcc_cross=gcc_cross2;
end
gcc_cross_diag=diag(gcc_cross);
nsim=size(VaExpC.g{1},2);
L=zeros(1,nsim);
for is=1:nsim
for i=1:ndim
g_est_{i}=VaExpC.g{i}(:,is)'; % COND
if i==1,
g_est=g_est_{i}(iuse{i});
else
try
g_est=[g_est g_est_{i}(iuse{i})];
catch
keyboard
end
end
end
dg=g0-g_est;
L(is)=-.5*dg*inv(gcc_cross)*dg';
% JOINT PROBABILITY
for i=1:ndim
dg_dim{i}=g0_{i}(iuse{i})-g_est_{i}(iuse{i});
Ldim{i}(is)=-.5*dg_dim{i}*inv(gcc{i})*dg_dim{i}';
end
end
%Lmean=log(mean(exp(L)));
Lmean=log(mean(exp(L)));