-
Notifications
You must be signed in to change notification settings - Fork 2
/
global_score_calc.m
57 lines (50 loc) · 2.12 KB
/
global_score_calc.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
function [global_Score,gs] = global_score_calc(all_node_names, bnet_updt1,Gene_Expres_list,expr_values)
global_Score.node= 1:length(all_node_names);
global_Score.parents =[];
global_Score.local_RSS = [];
global_Score.local_BIC = [];
n = size(expr_values,2);
BIC_vect=length(all_node_names);
for node=1:length(all_node_names)
node_source= all_node_names(node);
global_Score(node).node = node_source;
struct_Node= struct(bnet_updt1.CPD{node});
node_parents = parents(bnet_updt1.dag,node);
ind_ev_TarNode= find(strcmp(node_source,Gene_Expres_list)==1);
interc_tar_node= struct_Node.mean;
vect_sq_resid=[];
if ~isempty(node_parents)
parents_weights= struct_Node.weights;
ind_ev_parents=[];
for p=1:length(node_parents)
global_Score(node).parents = node_parents(p);
p_name = all_node_names(node_parents(p));
ind_ev_parents(p) = find(strcmp(p_name,Gene_Expres_list)==1);
end
% calculate RSS
for obs=1:size(expr_values,2)
tarN_evidence = expr_values(ind_ev_TarNode,obs);
vect_ps_evidence=[];
for pev=1:length(ind_ev_parents)
ev = expr_values(ind_ev_parents(pev),obs);
vect_ps_evidence= [vect_ps_evidence ev];
end
y_pred = (interc_tar_node + sum(vect_ps_evidence.*parents_weights));
vect_sq_resid(obs)= (tarN_evidence-y_pred)^2;
end
else
global_Score(node).parents=[];
for obs=1:size(expr_values,2)
tarN_evidence = expr_values(ind_ev_TarNode,obs);
vect_sq_resid(obs)= (tarN_evidence-interc_tar_node)^2;
end
end
% local RSS
RSS_local= sum(vect_sq_resid);
global_Score(node).local_RSS = RSS_local;
% local BIC
local_BIC = n*log(RSS_local/n)+length(node_parents)*log(n);
BIC_vect(node)= local_BIC;
global_Score(node).local_BIC = local_BIC;
end
gs=sum(BIC_vect);%sum of all BIC_scores