-
Notifications
You must be signed in to change notification settings - Fork 0
/
pca_cmi.m
127 lines (110 loc) · 3.51 KB
/
pca_cmi.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
% ---------------------------PAC-CMI------------------------------
% This is a MARLAB code for PCA-CMI, a novel method for inferring gene
% regulatory networks from gene expression data by path consitency algorithm
% based on conditional mutual information.
%
% Input:
% 'data' is expression of variable,in which row is varible and column is the sample;
% 'lamda' is the parameter decide the dependence;
% 'order0' is the parameter to end the program when order=order0;
%
% Output:
% 'G' is the 0-1 network or graph after pc algorith
% 'Gval' is the network with strenthness of dependence;
% 'order' is the order of the pc algorithm, here is equal to order0;
%
% If nargin==2,the algorithm will be terminated untill there is no higher order networks.
%
% Source download: http://csb.shu.edu.cn/grn
% Version Data: July 2011.
function [G,Gval,order]=pca_cmi(data,lamda,order0)
n_gene=size(data,1);
G=ones(n_gene,n_gene);
G=tril(G,-1)';
G=G+G';
Gval=G;
order=-1;t=0;
while t==0
order=order+1;
if nargin==3
if order>order0
G=tril(G,-1)'; Gval=tril(Gval,-1)';
order=order-1; % The value of order is the last order of pc algorith
return
end
end
[G,Gval,t]=edgereduce(G,Gval,order,data,t,lamda);
if t==0
disp('No edge is reduce! Algorithm finished!');
break;
else
t=0;
end
end
G=tril(G,-1)'; Gval=tril(Gval,-1)';
order=order-1; % The value of order is the last order of pc algorith
end
%% edgereduce is pca_cmi
function [G,Gval,t]=edgereduce(G,Gval,order,data,t,lamda)
if order==0
for i=1:size(G,1)-1
for j=i+1:size(G,1)
if G(i,j)~=0
cmiv=cmi(data(i,:),data(j,:));
Gval(i,j)=cmiv; Gval(j,i)=cmiv;
if cmiv<lamda
G(i,j)=0;G(j,i)=0;
end
end
end
end
t=t+1;
else
for i=1:size(G,1)-1
for j=i+1:size(G,1)
if G(i,j)~=0
adj=[] ;
for k=1:size(G,1)
if G(i,k)~=0 && G(j,k)~=0
adj=[adj,k] ;
end
end
if size(adj,2)>=order
combntnslist=combntns(adj,order);
combntnsrow=size(combntnslist,1);
cmiv=0;
v1=data(i,:);v2=data(j,:);
for k=1:combntnsrow
vcs=data(combntnslist(k,:),:);
a=cmi(v1,v2,vcs) ;
cmiv=max(cmiv,a);
end
Gval(i,j)=cmiv; Gval(j,i)=cmiv;
if cmiv<lamda
G(i,j)=0; G(j,i)=0;
end
t=t+1;
end
end
end
end
end
end
%% compute conditional mutual information of x and y
function cmiv=cmi(v1,v2,vcs)
if nargin==2
c1=det(cov(v1));
c2=det(cov(v2));
c3=det(cov(v1,v2));
cmiv=0.5*log(c1*c2/c3);
elseif nargin==3
c1=det(cov([v1;vcs]'));
c2=det(cov([v2;vcs]'));
c3=det(cov(vcs'));
c4=det(cov([v1;v2;vcs]'));
cmiv=0.5*log((c1*c2)/(c3*c4));
end
if cmiv==inf
cmiv=1;
end
end