[edb3de]: / Demo_MLR / fop_mining.m

Download this file

188 lines (158 with data), 5.1 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
 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
function [model] = fop_mining(net_mat,label)
type=4;
level=3;
fold_num = 1;
parameter_num = 12;
if(type==4)
[node_num,~,net_num]=size(net_mat);
per_fold = round(net_num/fold_num);
pos_freq_cell = cell(fold_num, 1);
pos_subgraph_cell = cell(fold_num, 1);
neg_freq_cell = cell(fold_num, 1);
neg_subgraph_cell = cell(fold_num, 1);
pos_thres=zeros(level,1);
step=1.5;
pos_thres(1)=0.5*step;
for ti=2:level
pos_thres(ti)=pos_thres(ti-1)*(step+0.1)*0.5;
end
pos_down_bound=0.03;
pos_up_bound = 0.35;
neg_thres=zeros(level,1);
step=1.5;
neg_thres(1)=0.5*step;
for ti=2:level
neg_thres(ti)=neg_thres(ti-1)*(step+0.1)*0.5;
end
neg_down_bound=0.03;
neg_up_bound = 0.35;
end
disp('start mining.');
%%
for fi=1:fold_num
disp(['mining the ',num2str(fi),'-th fold''s subgraphs'])
if fold_num ~= 1
max_idx = fi * per_fold;
if fi==fold_num
max_idx = net_num;
end
min_idx = (fi - 1) * per_fold + 1;
tmp_label = label;
tmp_label(min_idx:max_idx) = 0;
else
tmp_label = label;
end
st=clock;
[ neg_subgraph,neg_freq ] = frequent_weight_subgraph_mining( net_mat(:,:,tmp_label == -1),level,neg_down_bound,neg_thres);
neg_subgraph_cell{fi} = neg_subgraph;
neg_freq_cell{fi} = neg_freq;
et=clock;
disp(['The time of mining ',num2str(fi),'-th fold negative subgraphs is ',num2str(etime(et,st))]);
st=clock;
[ pos_subgraph,pos_freq ] = frequent_weight_subgraph_mining( net_mat(:,:,tmp_label == 1),level,pos_down_bound,pos_thres);
pos_subgraph_cell{fi}=pos_subgraph;
pos_freq_cell{fi} = pos_freq;
et=clock;
disp(['The time of mining ',num2str(fi),'-th fold positive subgraphs is ',num2str(etime(et,st))]);
end
model = cell(parameter_num,1);
model{1} = pos_subgraph_cell;
model{2} = pos_freq_cell;
model{3} = neg_subgraph_cell;
model{4} = neg_freq_cell;
model{5} = pos_thres;
model{6} = neg_thres;
model{7} = level;
model{8} = label;
model{9} = pos_up_bound;
model{10} = pos_down_bound;
model{11} = neg_up_bound;
model{12} = neg_down_bound;
end
function [ subgraph_cell,score_cell ] = frequent_weight_subgraph_mining( net_mat,level,alpha,thres)
[node_num,~,net_num]=size(net_mat);
edge_num=node_num*(node_num-1)/2;
global subgraph_cell;
global score_cell;
subgraph_cell=cell(level,1);
score_cell=cell(level,1);
edge2edge_weight(edge_num,edge_num,net_num)=false;
edge_idx1=1;
tic
for ni=1:node_num-1
for nj=ni+1:node_num
edge_idx2=1;
for ni2=1:node_num-1
for nj2=ni2+1:node_num
edge2edge_weight(edge_idx1,edge_idx2,:)=(net_mat(ni,nj,:)-net_mat(ni2,nj2,:)-alpha)>0;
edge_idx2=edge_idx2+1;
end
end
edge_idx1=edge_idx1+1;
end
end
toc
%%
edge_idx_mat=zeros(node_num,node_num);
idx=1;
for ni=1:node_num-1
for nj=ni+1:node_num
edge_idx_mat(ni,nj)=idx;
idx=idx+1;
end
end
edge_idx_mat=edge_idx_mat+edge_idx_mat';
%%
tic
for ni=1:node_num-1
for nj=ni+1:node_num
subgraph=[ni,nj];
%disp('subgraph [' 1,2]');
do_subgraph_mining(subgraph, node_num,net_num,edge2edge_weight,edge_idx_mat,level,thres);
disp([ni,nj]);
toc
end
end
end
function do_subgraph_mining(subgraph,node_num,net_num,edge2edge_weight,edge_idx_mat,level,thres)
global subgraph_cell;
global score_cell;
contain_edge_num=size(subgraph,1);
if(contain_edge_num-1>=level)
return;
end
contain_node=unique(subgraph);
contain_node_num=length(contain_node);
score= true(1,net_num);
for ei=1:contain_edge_num-1
score=score & reshape(edge2edge_weight(edge_idx_mat(subgraph(ei,1),subgraph(ei,2)),edge_idx_mat(subgraph(ei+1,1),subgraph(ei+1,2)),:),1,net_num);
end
new_subgraph=[subgraph;0,0];
for ni=1:contain_node_num
for nj=1:node_num
if(nj==contain_node(ni))
continue;
end
is_contain=false;
for ei=1:contain_edge_num
if (sum([contain_node(ni),nj]==subgraph(ei,:))==2 || sum([nj,contain_node(ni)]==subgraph(ei,:))==2)
is_contain=true;
break;
end
end
if(is_contain)
continue;
end
new_score=score & reshape(edge2edge_weight(edge_idx_mat(subgraph(contain_edge_num,1),subgraph(contain_edge_num,2)),edge_idx_mat(contain_node(ni),nj),:),1,net_num);
new_score=sum(new_score)/net_num;
if(new_score>thres(contain_edge_num))
new_subgraph(contain_edge_num+1,:)=[contain_node(ni),nj];
subgraph_cell{contain_edge_num}{length(subgraph_cell{contain_edge_num})+1}=new_subgraph;
score_cell{contain_edge_num}(length(score_cell{contain_edge_num})+1)=new_score;
if(contain_edge_num<level)
do_subgraph_mining(new_subgraph, node_num,net_num,edge2edge_weight,edge_idx_mat,level,thres);
end
end
end
end
end