a b/Demo_MLR/fop_mining.m
1
function [model] = fop_mining(net_mat,label)
2
type=4; 
3
level=3; 
4
fold_num = 1; 
5
parameter_num = 12;
6
7
if(type==4)
8
[node_num,~,net_num]=size(net_mat);
9
per_fold = round(net_num/fold_num);
10
pos_freq_cell = cell(fold_num, 1);
11
pos_subgraph_cell = cell(fold_num, 1);
12
neg_freq_cell = cell(fold_num, 1);
13
neg_subgraph_cell = cell(fold_num, 1);
14
15
pos_thres=zeros(level,1);
16
step=1.5;
17
pos_thres(1)=0.5*step;
18
for ti=2:level
19
   pos_thres(ti)=pos_thres(ti-1)*(step+0.1)*0.5;
20
end
21
pos_down_bound=0.03; 
22
pos_up_bound = 0.35;
23
    
24
25
neg_thres=zeros(level,1);
26
step=1.5;
27
neg_thres(1)=0.5*step;
28
for ti=2:level
29
   neg_thres(ti)=neg_thres(ti-1)*(step+0.1)*0.5;
30
end
31
neg_down_bound=0.03; 
32
neg_up_bound = 0.35;
33
end
34
disp('start mining.');
35
36
%%
37
for fi=1:fold_num
38
    disp(['mining the ',num2str(fi),'-th fold''s subgraphs'])
39
    if fold_num ~= 1
40
        max_idx = fi * per_fold;
41
        if fi==fold_num
42
            max_idx = net_num;
43
        end
44
        min_idx = (fi - 1) * per_fold + 1;
45
        tmp_label = label;
46
        tmp_label(min_idx:max_idx) = 0;
47
    else
48
       tmp_label = label; 
49
    end
50
    
51
    st=clock;
52
    
53
    [ neg_subgraph,neg_freq ] = frequent_weight_subgraph_mining( net_mat(:,:,tmp_label == -1),level,neg_down_bound,neg_thres);
54
 
55
    neg_subgraph_cell{fi} = neg_subgraph;
56
    neg_freq_cell{fi} = neg_freq;
57
    et=clock;
58
    disp(['The time of mining ',num2str(fi),'-th fold negative subgraphs is ',num2str(etime(et,st))]);
59
    
60
    st=clock;
61
    [ pos_subgraph,pos_freq ] = frequent_weight_subgraph_mining( net_mat(:,:,tmp_label == 1),level,pos_down_bound,pos_thres);
62
    pos_subgraph_cell{fi}=pos_subgraph;
63
    pos_freq_cell{fi} = pos_freq;
64
    et=clock;
65
    disp(['The time of mining ',num2str(fi),'-th fold positive subgraphs is ',num2str(etime(et,st))]);
66
end
67
68
model = cell(parameter_num,1);
69
model{1} = pos_subgraph_cell;
70
model{2} = pos_freq_cell;
71
model{3} = neg_subgraph_cell;
72
model{4} = neg_freq_cell;
73
model{5} = pos_thres;
74
model{6} = neg_thres;
75
model{7} = level;
76
model{8} = label;
77
model{9} = pos_up_bound;
78
model{10} = pos_down_bound;
79
model{11} = neg_up_bound;
80
model{12} = neg_down_bound;
81
82
end
83
84
85
function [ subgraph_cell,score_cell ] = frequent_weight_subgraph_mining( net_mat,level,alpha,thres)
86
[node_num,~,net_num]=size(net_mat);
87
88
edge_num=node_num*(node_num-1)/2;
89
90
global  subgraph_cell;
91
global  score_cell;
92
subgraph_cell=cell(level,1);
93
score_cell=cell(level,1);
94
95
edge2edge_weight(edge_num,edge_num,net_num)=false;
96
edge_idx1=1;
97
98
tic
99
for ni=1:node_num-1
100
    for nj=ni+1:node_num
101
        edge_idx2=1;
102
        for ni2=1:node_num-1
103
            for nj2=ni2+1:node_num                                                                           
104
                edge2edge_weight(edge_idx1,edge_idx2,:)=(net_mat(ni,nj,:)-net_mat(ni2,nj2,:)-alpha)>0;
105
                edge_idx2=edge_idx2+1;
106
            end
107
        end
108
        edge_idx1=edge_idx1+1;
109
    end
110
end
111
toc
112
113
%%
114
edge_idx_mat=zeros(node_num,node_num); 
115
idx=1;
116
for ni=1:node_num-1
117
    for nj=ni+1:node_num
118
        edge_idx_mat(ni,nj)=idx;
119
        idx=idx+1;
120
    end
121
end
122
edge_idx_mat=edge_idx_mat+edge_idx_mat';
123
124
%%
125
tic
126
for ni=1:node_num-1
127
    for nj=ni+1:node_num
128
     subgraph=[ni,nj];
129
     %disp('subgraph [' 1,2]');
130
     do_subgraph_mining(subgraph, node_num,net_num,edge2edge_weight,edge_idx_mat,level,thres);
131
     disp([ni,nj]);
132
     toc
133
    end
134
end
135
end
136
137
function do_subgraph_mining(subgraph,node_num,net_num,edge2edge_weight,edge_idx_mat,level,thres)
138
139
global  subgraph_cell;
140
global  score_cell;
141
contain_edge_num=size(subgraph,1);
142
143
if(contain_edge_num-1>=level)
144
    return;
145
end
146
contain_node=unique(subgraph);
147
contain_node_num=length(contain_node);
148
149
score= true(1,net_num);
150
for ei=1:contain_edge_num-1
151
    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);
152
end
153
new_subgraph=[subgraph;0,0];
154
155
for ni=1:contain_node_num
156
   for nj=1:node_num
157
158
      if(nj==contain_node(ni))
159
          continue;
160
      end
161
      
162
      is_contain=false;
163
      for ei=1:contain_edge_num
164
         if (sum([contain_node(ni),nj]==subgraph(ei,:))==2 || sum([nj,contain_node(ni)]==subgraph(ei,:))==2) 
165
            is_contain=true;
166
            break;
167
         end
168
      end
169
      if(is_contain)
170
          continue;
171
      end
172
      
173
      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);
174
      new_score=sum(new_score)/net_num;
175
176
      if(new_score>thres(contain_edge_num))
177
          new_subgraph(contain_edge_num+1,:)=[contain_node(ni),nj];
178
          subgraph_cell{contain_edge_num}{length(subgraph_cell{contain_edge_num})+1}=new_subgraph;
179
          score_cell{contain_edge_num}(length(score_cell{contain_edge_num})+1)=new_score;
180
          if(contain_edge_num<level)
181
             do_subgraph_mining(new_subgraph, node_num,net_num,edge2edge_weight,edge_idx_mat,level,thres);
182
          end
183
      end
184
   end
185
end
186
end
187