-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFind_CO_by_MI.m
50 lines (48 loc) · 1.25 KB
/
Find_CO_by_MI.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
function K = Find_CO_by_MI(C,Len,X,Latent_Number,Cov_M)
%Find the causal order by Mutual Information
addpath(genpath('.\Kernel Mutual Information'));
Tem_L=1:Latent_Number;
K=[];
Iter=0;%
while 1
MI=[];
LLL=length(Tem_L);
MI=zeros(LLL,LLL);
Iter=Iter+1;
for i=1:LLL %P
P_X=[];
P_Z=[];
for k=1:length(Len(Tem_L(i),:))
Tem_C_X=C{Tem_L(i),k};
P_X=[P_X Tem_C_X(1:Len(Tem_L(i),k))];
if k==1
P_Z=Tem_C_X(Len(Tem_L(i),k)+1:end);%
else
P_Z=[P_Z Tem_C_X(Len(Tem_L(i),k)+1:2*Len(Tem_L(i),k))];
end
end
for j=1:LLL%Q
if i~=j
Tem_C_Z=C{Tem_L(j),1};
Tem_P_X=[Tem_C_Z(1,1) P_X];
%test P_Z-->P_X
Tem_MI = GIN_Condition_Test_MI(X,Tem_P_X,P_Z,Cov_M);
MI(i,j)=Tem_MI;
end
end
end
MI_sum=sum(MI,2);%
[P_a,P_b]=min(MI_sum);
K=[ K Tem_L(P_b)];
Tem_L(P_b)=[];
if LLL==2
K=[K Tem_L];
break;
end
%update the CLuster
for kkk=Tem_L
C{kkk,length(K)+1}=C{K(end),1};
Len(kkk,length(K)+1)=Len(K(end),1);
end
end
end