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
|
function runBN_initial(pre)
% runBN_initial is used to create the net_figure file
% for a network without entered evidence or intervention.
%
% The input is 'pre'-- the prefix for the network and data
% in BNW. It uses this identifier to read several files from
% BNW.
%
% The output is ???net_figure.txt. It also calls writeParameters
% to write the parameter file.
%
% runBN_initial is called by run_octave in the 'sourcecodes' directory.
%
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%f\t%f\n',labelsold{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,pre);
writeParameters(pre,nnodes,bnet,labels,cases,labelsold,s,m);
end
|