about summary refs log tree commit diff
path: root/sourcecodes/parameter_learning/runBN_initial.m
blob: c2dec164a8916ea9d8294abd12dad3aca22b419e (plain)
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 runBN_initial(pre)
sfile=strcat(pre,'structure_input.txt');
dfile=strcat(pre,'continuous_input.txt');

nnodefile=strcat(pre,'nnode.txt');
fnnode = fopen(nnodefile,'r');
nnodes = fscanf(fnnode,'%d');


mapfilename=strcat(pre,'mapdata.txt');
mapvalfilename=strcat(pre,'map.txt');

mapfile = fopen(mapfilename,'w');

mapval = fopen(mapvalfilename,'w');


Std_flag=true;
[labels,cases,bnet,node_sizes,data,labelsold]=readInput(dfile,sfile,nnodes,Std_flag);
s=std(data,0,1);
m=mean(data);

for i=1:nnodes
  fprintf(mapval,'%s\t%d\t%f\t%f\n',labelsold{i},node_sizes(i),s(i),m(i));
end

fprintf(mapfile,'%s',labels{1});
for i=2:nnodes
  fprintf(mapfile,'\t%s',labels{i});
end
fprintf(mapfile,'\n');
fclose(mapval);
fclose(mapfile);

%Need to rearrange the means and stdevs to match the new labeling.
means = cell(1,nnodes);
stdevs = cell(1,nnodes);
for i = 1:nnodes
    for j = 1:nnodes
       if strcmp(labels{i},labelsold{j})
          means{i} = m(j);
          stdevs{i} = s(j);
          break
       end
    end
end


[bnet]=parameterLearning(bnet,cases);

filename=strcat(pre,'net_figure.txt');

drawFigure(nnodes,bnet,labels,filename,cases,stdevs,means);

writeParameters(pre,nnodes,bnet,labels,cases,labelsold,s,m);

end