diff options
Diffstat (limited to 'sourcecodes/parameter_learning')
19 files changed, 876 insertions, 1184 deletions
diff --git a/sourcecodes/parameter_learning/Predictmultiple.m b/sourcecodes/parameter_learning/Predictmultiple.m index 692c6b24..f03568ef 100644 --- a/sourcecodes/parameter_learning/Predictmultiple.m +++ b/sourcecodes/parameter_learning/Predictmultiple.m @@ -1,57 +1,72 @@ function Predictmultiple(pre) - dfile=strcat(pre,'structure_input.txt'); sfile=dfile; dfile=strcat(pre,'continuous_input.txt'); nnodefile=strcat(pre,'nnode.txt'); + fnnode = fopen(nnodefile,'r'); nnodes = fscanf(fnnode,'%d'); - - -%nnodes=5; Std_flag=true; [labels,cases,bnet]=readInput(dfile,sfile,nnodes,Std_flag); - -%name -%labels -%map - [bnet]=parameterLearning(bnet,cases); -%[predict_mean,predict_sd,q_sq]=looCrossValid(bnet,cases); -fvarfile=strcat(pre,'var.txt'); -fvar = fopen(fvarfile,'r'); - +fvarfile=strcat(pre,'var.txt'); +fvar = fopen(fvarfile,'r'); select_var_new = fscanf(fvar,'%d'); fvardfile=strcat(pre,'vardata.txt'); - fvard = fopen(fvardfile,'r'); - select_var_data_new = fscanf(fvard,'%f'); +means_orig = cell(1,nnodes); +stdevs_orig = cell(1,nnodes); +labels_orig = cell(1,nnodes); +%Read in original means and standard deviations +mapfile = strcat(pre,'map.txt'); +fmap = fopen(mapfile,'r'); +for i=1:nnodes + buffer = fgetl(mapfile); + temp = cell(1,4); + for j=1:4 + [next,buffer] = strtok(buffer); + temp{j} = next; + end + labels_orig{i} = temp{1}; + means_orig{i} = str2num(temp{4}); + stdevs_orig{i} = str2num(temp{3}); +end +fclose(fmap); + +%Need to map the means and stdevs to the correct labels +means = cell(1,nnodes); +stdevs = cell(1,nnodes); +%Read in labels in new order. +labelsnew = cell(1,nnodes); +mapdatafile = strcat(pre,'mapdata.txt'); +fmapdata = fopen(mapdatafile,'r'); +buffer = fgetl(fmapdata); +for i = 1:nnodes + [next,buffer ] = strtok(buffer); + labelsnew{i} = next; +end +fclose(fmapdata); +for i = 1:nnodes + for j = 1:nnodes + if strcmp(labelsnew{i},labels_orig{j}) + means{i} = means_orig{j}; + stdevs{i} = stdevs_orig{j}; + break + end + end +end + + filename=strcat(pre,'net_figure_new.txt'); -drawFigureM(nnodes,bnet,labels,filename,cases,select_var_new,select_var_data_new); - -%quit force; -%marginal_nodes(engine,2) -%marginal_nodes(engine,3) -%marginal_nodes(engine,4) -%marginal_nodes(engine,5) -%evidence{1}=2; -%[engine,loglik]=enter_evidence(engine,evidence) -%marginal_nodes(engine,1) -%marginal_nodes(engine,2) -%marginal_nodes(engine,3) -%marginal_nodes(engine,4) -%marginal_nodes(engine,5) -%evidence{2}=0.6; -%evidence{1}=[]; -%[engine,loglik]=enter_evidence(engine,evidence); -%marginal_nodes(engine,3); -%marginal_nodes(engine,4); -%marginal_nodes(engine,5); -end \ No newline at end of file +drawFigureM(nnodes,bnet,labels,filename,cases,stdevs,means,select_var_new,select_var_data_new); + +writeParameters_ev(pre,bnet,nnodes,labels,cases,stdevs,means,select_var_new,select_var_data_new); + +end diff --git a/sourcecodes/parameter_learning/Predictmultipleintrvention.m b/sourcecodes/parameter_learning/Predictmultipleintrvention.m index d3d509cb..1b9fa2f4 100644 --- a/sourcecodes/parameter_learning/Predictmultipleintrvention.m +++ b/sourcecodes/parameter_learning/Predictmultipleintrvention.m @@ -11,17 +11,13 @@ fvarnamefile=strcat(pre,'varname.txt'); varfile = fopen(fvarnamefile,'r'); -%nnodes=5; Std_flag=true; [labels,cases,bnet]=readInput(dfile,sfile,nnodes,Std_flag); -[bnet]=parameterLearning(bnet,cases); - -%[predict_mean,predict_sd,q_sq]=looCrossValid(bnet,cases); +[bnet]=parameterLearning(bnet,cases); fvarfile=strcat(pre,'var.txt'); -fvar = fopen(fvarfile,'r'); - +fvar = fopen(fvarfile,'r'); select_var_new = fscanf(fvar,'%d'); nm = numel(select_var_new); @@ -48,26 +44,52 @@ fvard = fopen(fvardfile,'r'); select_var_data_new = fscanf(fvard,'%f'); +means_orig = cell(1,nnodes); +stdevs_orig = cell(1,nnodes); +labels_orig = cell(1,nnodes); +%Read in original means and standard deviations +mapfile = strcat(pre,'map.txt'); +fmap = fopen(mapfile,'r'); +for i=1:nnodes + buffer = fgetl(mapfile); + temp = cell(1,4); + for j=1:4 + [next,buffer] = strtok(buffer); + temp{j} = next; + end + labels_orig{i} = temp{1}; + means_orig{i} = str2num(temp{4}); + stdevs_orig{i} = str2num(temp{3}); +end +fclose(fmap); + +%Need to map the means and stdevs to the correct labels +means = cell(1,nnodes); +stdevs = cell(1,nnodes); +%Read in labels in new order. +labelsnew = cell(1,nnodes); +mapdatafile = strcat(pre,'mapdata.txt'); +fmapdata = fopen(mapdatafile,'r'); +buffer = fgetl(fmapdata); +for i = 1:nnodes + [next,buffer ] = strtok(buffer); + labelsnew{i} = next; +end +fclose(fmapdata); +for i = 1:nnodes + for j = 1:nnodes + if strcmp(labelsnew{i},labels_orig{j}) + means{i} = means_orig{j}; + stdevs{i} = stdevs_orig{j}; + break + end + end +end + filename=strcat(pre,'net_figure_new.txt'); -drawFigureM(nnodes,bnet,labels,filename,cases,select_var_new,select_var_data_new); - -%quit force; -%marginal_nodes(engine,2) -%marginal_nodes(engine,3) -%marginal_nodes(engine,4) -%marginal_nodes(engine,5) -%evidence{1}=2; -%[engine,loglik]=enter_evidence(engine,evidence) -%marginal_nodes(engine,1) -%marginal_nodes(engine,2) -%marginal_nodes(engine,3) -%marginal_nodes(engine,4) -%marginal_nodes(engine,5) -%evidence{2}=0.6; -%evidence{1}=[]; -%[engine,loglik]=enter_evidence(engine,evidence); -%marginal_nodes(engine,3); -%marginal_nodes(engine,4); -%marginal_nodes(engine,5); -end \ No newline at end of file +drawFigureM(nnodes,bnet,labels,filename,cases,stdevs,means,select_var_new,select_var_data_new); + +writeParameters_int(pre,bnet,nnodes,labels,cases,stdevs,means,select_var_new,select_var_data_new); + +end diff --git a/sourcecodes/parameter_learning/drawFigure.m b/sourcecodes/parameter_learning/drawFigure.m index 76979b3e..404a65f7 100644 --- a/sourcecodes/parameter_learning/drawFigure.m +++ b/sourcecodes/parameter_learning/drawFigure.m @@ -1,18 +1,19 @@ -function [] = drawFigure(nnodes,bnet,labels,filename,cases,selectvar,selectdata) +function [] = drawFigure(nnodes,bnet,labels,filename,cases,stdevs,means,selectvar,selectdata) %drawFigure writes the parameters and data that are needed to draw the %structure of a Bayesian network. -if nargin < 6, - drawFigureNoEv(nnodes,bnet,labels,filename,cases); + +if nargin < 8, + drawFigureNoEv(nnodes,bnet,labels,filename,cases,stdevs,means); else - drawFigureEv(nnodes,bnet,labels,filename,cases,selectvar,selectdata); + drawFigureEv(nnodes,bnet,labels,filename,cases,stdevs,means,selectvar,selectdata); end; end -function [] = drawFigureEv(nnodes,bnet,labels,filename,cases,selectvar,selectdata) +function [] = drawFigureEv(nnodes,bnet,labels,filename,cases,stdevs,means,selectvar,selectdata) %Function to use if there is no entered evidence. % % @@ -152,6 +153,8 @@ for i = 1:nnodes, [x_vals,y_vals] = calcGaussian(predict.mu,predict.Sigma,Amax(i),Amin(i)); %%%For continuous nodes, print x and the pdf of a normal curve. for j = 1:101, + %%Undo standardization + xvals(j,1) = xvals(j,1)*stdevs{i}+means{i} fprintf(fileID,'%6.4f\t%6.4f\n',x_vals(j,1),y_vals(j,1)); end; end; @@ -172,7 +175,7 @@ end -function [] = drawFigureNoEv(nnodes,bnet,labels,filename,cases) +function [] = drawFigureNoEv(nnodes,bnet,labels,filename,cases,stdevs,means) %Function to use if there is no entered evidence. % % @@ -302,6 +305,8 @@ for i = 1:nnodes, [x_vals,y_vals] = calcGaussian(predict.mu,predict.Sigma,Amax(i),Amin(i)); %%%For continuous nodes, print x and the pdf of a normal curve. for j = 1:101, + %%Undo standardization + x_vals(j,1) = x_vals(j,1)*stdevs{i}+means{i}; fprintf(fileID,'%6.4f\t%6.4f\n',x_vals(j,1),y_vals(j,1)); end; end; diff --git a/sourcecodes/parameter_learning/drawFigureM.m b/sourcecodes/parameter_learning/drawFigureM.m index 95a27634..91b8698f 100644 --- a/sourcecodes/parameter_learning/drawFigureM.m +++ b/sourcecodes/parameter_learning/drawFigureM.m @@ -1,21 +1,6 @@ -function [] = drawFigureM(nnodes,bnet,labels,filename,cases,selectvar,selectdata) -%drawFigure writes the parameters and data that are needed to draw the -%structure of a Bayesian network. - - -%Function to use if there is no entered evidence. -% -% -%Before each printed line, I will have a line that starts with %%% -% that describes what will be on that line - -%Create an empty evidence cell array. - -%val=cases; -%for i = 1:nnodes -% val(i,1)=val(i,2); - -%end +function [] = drawFigureM(nnodes,bnet,labels,filename,cases,stdevs,means,selectvar,selectdata) +%drawFigureM writes the parameters and data that are needed to draw the +%structure of a Bayesian network after added evidence or intervention fileID = fopen(filename,'w'); @@ -30,49 +15,35 @@ engine = jtree_inf_engine(bnet); m = size(selectvar,1); - ev_dat = zeros(1,nnodes); -%For parents, sum down columns for i = 1:m, di=selectvar(i,1); ev_dat(di)=selectdata(i,1); - +%Need to standardized evidence for continuous nodes. + if bnet.node_sizes(di) == 1 + ev_dat(di) = (ev_dat(di) - means{di}) / stdevs{di}; + end evidence{di}=ev_dat(di); fprintf(fileID,'%i\t',di); end -fprintf(fileID,'\n'); - -%ev_dat -% select_var = selectvar(1,1) -% -% select_var_data = selectdata(1,1) -% -% -% evidence{select_var}=select_var_data; +fprintf(fileID,'\n'); [engine,loglik]=enter_evidence(engine,evidence); %Open the file, and write the nodes to a file. - - -%%%%Evidence node - %%% The number of nodes fprintf(fileID,'%i\n',nnodes); %Get canvas size labels_temp = cellstr(labels); [x,y] = make_layout(bnet.dag); - x = x - min(x); y = 1 - y; y = y - min(y); - [x_dim,y_dim] = canvasSize(nnodes,x,y); %%% The dimensions of the canvas for the javascript code -fprintf(fileID,'%i\t%i\t\n',x_dim,y_dim) - +fprintf(fileID,'%i\t%i\t\n',x_dim,y_dim); x = x*x_dim; y = y*y_dim; for i = 1:nnodes, @@ -99,7 +70,6 @@ for i = 1:nnodes, end end - for i = 1:nnodes, %%% The name and type of each node (1=continuous, the number of states %%% if it is discrete @@ -162,23 +132,25 @@ for i = 1:nnodes, fprintf(fileID,'%i\t%6.4f\n',j,predict.T(j)); end; else - [x_vals,y_vals] = calcGaussian(predict.mu,predict.Sigma,Amax(i),Amin(i)); %%%For continuous nodes, print x and the pdf of a normal curve. for j = 1:101, + %%Undo standardization + x_vals(j,1) = x_vals(j,1)*stdevs{i}+means{i}; fprintf(fileID,'%6.4f\t%6.4f\n',x_vals(j,1),y_vals(j,1)); end; end; else - fprintf(fileID,'%6.4f\t%6.4f\n',ev_dat(i),1); + if bnet.node_sizes(i) == 1, + fprintf(fileID,'%6.4f\t%6.4f\n',ev_dat(i)*stdevs{i}+means{i},1); + else + fprintf(fileID,'%6.4f\t%6.4f\n',ev_dat(i),1); + endif end end -%fprintf(fileID,'%s\t %\n',labels_temp{:}); - fclose(fileID); - end diff --git a/sourcecodes/parameter_learning/prepareInput.m b/sourcecodes/parameter_learning/prepareInput.m new file mode 100644 index 00000000..28a06c15 --- /dev/null +++ b/sourcecodes/parameter_learning/prepareInput.m @@ -0,0 +1,281 @@ +function [ ] = prepareInput( pre ) + % + % This function takes files that are uploaded to BNW and creates output + % files that can be used for structure and parameter learning. + % It replaces php code that was previously in bn_file_load_gom.php. + % There are several improvements in performance and ease of use: + % 1) Loading files is significantly (~5x) faster for large input files. + % 2) The allowed values for discrete variables are more flexible. + % (e.g., A genotype variable be 'B' and 'D' instead of having + % to replace to make them '1' and '2'.) + % 3) Continuous variables may be identified as continuous in some cases + % even if there is not a period. + % 4) The states of discrete variables should be correctly ordered in + % almost all cases. + % 5) An additional output file is written that will let users check if + % the input file has been uploaded and parsed correctly. + % 6) Future updates to this code should be easier than updating the php. + % + % + % Input: ???continuous_input_orig.txt + % This is the input file that is uploaded to BNW. + % It is directly written out by the BNW php code with no modification. + % The file format is a header line containing the variable names + % followed by the data, with each case in a row. + % + % Output: There are many output files. + % 1) The main output file is ???continuous_input.txt that can be + % used by the structure learning code and parameter learning codes. + % The first line is variable names, the second line is the node type + % (continuous nodes should have 1, discrete nodes have the number + % of states), and the rest is the data. + % 2) A new output file is ???input_desc.txt, a file that describes the + % data so users can check that it has been parsed correctly. + % 3) ???nlevels.txt: The states of discrete variables. + % 4) ???name.txt: The names of the variables as uploaded. + % 5) ???type.txt: The number of states for each variables + % (1 indicates a continuous variable.) + % 6/7) ???nnode.txt and ???nrows.txt: number of nodes and cases + % 8-12) ???ban.txt, ???white.txt, ???k.txt, ???thr.txt, and + % ???parent.txt: Files with default values for structure learning. + % + +% open file for input, include error handling +dfile=strcat(pre,'continuous_input_orig.txt'); + +fin = fopen(dfile,'r'); +if fin < 0 + error(['Could not open ',dfile,' for input']); +end + +% Get the number of cases (the number of rows in the file excluding the header) +ncases = fskipl(fin,Inf) - 1; + +frewind(fin); + +% Read in first line to get the number of nodes and the node labels. +buffer = fgetl(fin); %get header line as a string +nnodes = numel(strfind(buffer,"\t")) + 1; +labels = cell(1,nnodes); +for j=1:nnodes + [next,buffer] = strtok(buffer); + labels{j} = next; +end + +% Read in the data +data = cell(ncases,nnodes); +for i = 1:ncases + buffer = fgetl(fin); + for j = 1:nnodes + [next,buffer] = strtok(buffer); + data{i,j} = next; + end +end + +% Determine whether or not the nodes are continuous or discrete. +% First, treat them as all discrete and get the states and number of stats(levels). +levels = cell(1,nnodes); +states = []; +for j = 1:nnodes + states{end+1} = unique(data(:,j)); + levels{j} = size(states{j},1); +end + +%Now do some checks to see if nodes are discrete or continuous +for j = 1:nnodes + % If there are 3 or less unique values, I will assume that the node is discrete. + if levels{j} < 4; + continue + % If there are as many unique values as a third of the number of cases, + % I will assume that the node is continuous. + elseif levels{j} > ncases/3; + levels{j} = 1; + % If there are more than twenty unique values, + % I will assume that the node is continuous. + elseif levels{j} > 20; + levels{j} = 1; + % Otherwise, I will scan through the individual values. + % If any of the values contain a '.', I will assume it is continuous. + else + period_test = 0; + column = data(:,j); + k = 1; + while period_test == 0 + period_test = sum(cell2mat(strfind(column(k),"."))); + if period_test != 0; + levels{j} = 1; + end + k++; + if k > ncases + break + end + end + end +end + +%I need to check if any discrete nodes are listed after continuous nodes. +%If so, I need to rearrange the columns. +max_disc = 0; +min_cont = nnodes + 1; +for i = 1:nnodes + if levels{i} > 1 + max_disc = i; + elseif min_cont == nnodes+1 + min_cont = i; + end +end +%If max_disc > min_cont, you need to rearrange the nodes +% to put the discrete nodes first. +if max_disc > min_cont + levels_old = levels; + labels_old = labels; + data_old = data; + states_old = states; + new_order = {}; + for i=1:nnodes + if levels_old{i} > 1 + new_order{end+1} = i; + end + end + for i=1:nnodes + if levels_old{i} == 1 + new_order{end+1} = i; + end + end + labels = {}; + levels = {}; + states = {}; + for i =1:nnodes + labels{i} = labels_old{new_order{i}}; + levels{i} = levels_old{new_order{i}}; + states{i} = states_old{new_order{i}}; + for j=1:ncases + data{j,i} = data_old{j,new_order{i}}; + end + end + +endif + + +%Write other files that are used by BNW for this key. +%The first group of files establish default settings for structure learning. +outfile = strcat(pre,'white.txt'); +fout = fopen(outfile,'w'); +fprintf(fout,'From\tTo\n'); +fclose(fout); + +outfile = strcat(pre,'ban.txt'); +fout = fopen(outfile,'w'); +fprintf(fout,'From\tTo\n'); +fclose(fout); + +outfile = strcat(pre,'k.txt'); +fout = fopen(outfile,'w'); +fprintf(fout,'1\n'); +fclose(fout); + +outfile = strcat(pre,'parent.txt'); +fout = fopen(outfile,'w'); +fprintf(fout,'4\n'); +fclose(fout); + +outfile = strcat(pre,'thr.txt'); +fout = fopen(outfile,'w'); +fprintf(fout,'0.5\n'); +fclose(fout); + + +%The next group of files have information about the uploaded file. +outfile = strcat(pre,'name.txt'); +fout = fopen(outfile,'w'); +fprintf(fout,'%s\t',labels{1:end-1}); +fprintf(fout,'%s\n',labels{end}); +fclose(fout); + +outfile = strcat(pre,'nnode.txt'); +fout = fopen(outfile,'w'); +fprintf(fout,'%i\n',nnodes); +fclose(fout); + +outfile = strcat(pre,'nrows.txt'); +fout = fopen(outfile,'w'); +fprintf(fout,'%i\n',ncases); +fclose(fout); + +outfile = strcat(pre,'type.txt'); +fout = fopen(outfile,'w'); +fprintf(fout,'%s\t',labels{1:end-1}); +fprintf(fout,'%s\n',labels{end}); +fprintf(fout,'%i\t',levels{1:end-1}); +fprintf(fout,'%i\n',levels{end}); +fclose(fout); + +%This output file contains the states for discrete nodes. +% The unique matlab function already sorts the states. +outfile = strcat(pre,'nlevels.txt'); +fout = fopen(outfile,'w'); +for i = 1:nnodes + if levels{i} > 1 + fprintf(fout,'%s\t',labels{i},states{i}{1:end-1}); + fprintf(fout,'%s\n',states{i}{end}); + end +end +fclose(fout); + + +%Print a file with a short description of the input. +descfile = strcat(pre,'input_desc.txt'); +dout = fopen(descfile,'w'); +fprintf(dout,['As loaded, the input file had the following properties:\n\n']); +dout = fopen(descfile,'a'); +fprintf(dout,'There are %i variables and %i cases(rows)\n',size(labels,2),ncases); +fprintf(dout,'The variable names are:\n'); +fprintf(dout,'%s\t',labels{1:end-1}); +fprintf(dout,'%s\n\n',labels{end}); +for i=1:nnodes + if levels{i} == 1 + fprintf(dout,'%s is a continuous variable\n',labels{i}); + column = str2double(data(:,i)); + colmean = mean(column); + colstd = std(column); + fprintf(dout,'It has a mean of %6.3f and a standard deviation of %6.3f\n\n',mean(column),std(column)) + else + fprintf(dout,'%s is a discrete variable with %i states\n',labels{i},levels{i}); + fprintf(dout,'The states are: '); + fprintf(dout,'%s ',states{i}{1:end-1}); + fprintf(dout,'%s\n\n',states{i}{end}); + end +end +fclose(fout); + +outfile = strcat(pre,'continuous_input.txt'); +fout = fopen(outfile,'w'); +fprintf(fout,'%s\t',labels{1:end-1}); +fprintf(fout,'%s\n',labels{end}); +fprintf(fout,'%i\t',levels{1:end-1}); +fprintf(fout,'%i\n',levels{end}); +%Need to replace states in discrete variables with integers for BNT +for i = 1:nnodes + if levels{i} > 1 + for j = 1:ncases + for k=1:size(states{i},1) + if data{j,i} == states{i}{k} + data{j,i} = sprintf('%i',num2cell(k){1});; + break + end + end + end + end +end +for i = 1:ncases + fprintf(fout,'%s\t',data{i,1:end-1}); + fprintf(fout,'%s\n',data{i,end}); +end +fclose(fout); + + + + + +end +% end of prepareInput.m \ No newline at end of file diff --git a/sourcecodes/parameter_learning/readInput.m b/sourcecodes/parameter_learning/readInput.m index 9d4959b8..891d7f36 100644 --- a/sourcecodes/parameter_learning/readInput.m +++ b/sourcecodes/parameter_learning/readInput.m @@ -25,19 +25,12 @@ end [labelsold,node_sizes,cases, data] = readInputData(dfile,nnodes); - - % read in the file with the structure [dag] = readInputStructure(sfile,labelsold); % check the ordering of the nodes and reorder if necessary [labels,cases,dag,node_sizes,ord_flag] = checkStructure(labelsold,cases,dag,node_sizes); -%draw_graph(dag,labels); -%if ord_flag == 1 -% fprintf(['Order of nodes was changed to agree with topological order\n']) -%end -%fprintf(['The structure of the network should be correctly displayed in a figure\n']) dcount = 0; for i = 1:nnodes @@ -67,4 +60,4 @@ end end -% end of readInput.m \ No newline at end of file +% end of readInput.m diff --git a/sourcecodes/parameter_learning/runBN_initial.m b/sourcecodes/parameter_learning/runBN_initial.m index 789b4260..c2dec164 100644 --- a/sourcecodes/parameter_learning/runBN_initial.m +++ b/sourcecodes/parameter_learning/runBN_initial.m @@ -15,84 +15,43 @@ mapfile = fopen(mapfilename,'w'); mapval = fopen(mapvalfilename,'w'); -%nnodes=5; Std_flag=true; [labels,cases,bnet,node_sizes,data,labelsold]=readInput(dfile,sfile,nnodes,Std_flag); -s = std(data,0,1); +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 - -% for j=1:nnodes -% [next,buffer] = strtok(buffer); -% name{j}=next; -% for i=1:nnodes -% if strcmp(name{j},labels{i}) -% map{j}=i; -% fprintf(mapfile,'%d\t',i); -% end -% end -% end -%name -%labels -%map 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); -%[predict_mean,predict_sd,q_sq]=looCrossValid(bnet,cases); -%engine=jtree_inf_engine(bnet); -%evidence=cell(1,nnodes); - -%varfile='var.txt'; -%fvar = fopen(varfile,'r'); -%select_var = fscanf(fvar,'%d'); -%select_var=map{select_var}; -%varfiled='vardata.txt'; -%fvard = fopen(varfiled,'r'); -%select_var_data = fscanf(fvard,'%f'); - -%evidence{select_var}=select_var_data; -%[engine,loglik]=enter_evidence(engine,evidence); - -%outdata='prediction.txt'; -%fout = fopen(outdata,'w'); - -%for ii = 1:nnodes - % i=map{ii}; - % data=marginal_nodes(engine,i); - % fprintf(fout,'%d\t%d\t%f\t%f\t%f\n',ii,data.domain,data.T,data.mu,data.Sigma); - %fprintf(1,'%d\n',i); -% end filename=strcat(pre,'net_figure.txt'); -drawFigure(nnodes,bnet,labels,filename,cases); - -%quit force; -%marginal_nodes(engine,2) -%marginal_nodes(engine,3) -%marginal_nodes(engine,4) -%marginal_nodes(engine,5) -%evidence{1}=2; -%[engine,loglik]=enter_evidence(engine,evidence) -%marginal_nodes(engine,1) -%marginal_nodes(engine,2) -%marginal_nodes(engine,3) -%marginal_nodes(engine,4) -%marginal_nodes(engine,5) -%evidence{2}=0.6; -%evidence{1}=[]; -%[engine,loglik]=enter_evidence(engine,evidence); -%marginal_nodes(engine,3); -%marginal_nodes(engine,4); -%marginal_nodes(engine,5); -fclose(mapval); -fclose(mapfile); -end \ No newline at end of file + +drawFigure(nnodes,bnet,labels,filename,cases,stdevs,means); + +writeParameters(pre,nnodes,bnet,labels,cases,labelsold,s,m); + +end diff --git a/sourcecodes/parameter_learning/standardizeData.m b/sourcecodes/parameter_learning/standardizeData.m index 61ea280e..db5e04c7 100644 --- a/sourcecodes/parameter_learning/standardizeData.m +++ b/sourcecodes/parameter_learning/standardizeData.m @@ -1,7 +1,7 @@ function [ cases ] = standardizeData( labels, node_sizes, cases ) %standardizeData standardizes continuous nodes so they have a mean = 0 % and standard deviation = 1 -% Detailed explanation goes here + nnodes = size(labels,2); diff --git a/sourcecodes/parameter_learning/test/Agbcontinuous_input.txt b/sourcecodes/parameter_learning/test/Agbcontinuous_input.txt deleted file mode 100644 index bcd9b88c..00000000 --- a/sourcecodes/parameter_learning/test/Agbcontinuous_input.txt +++ /dev/null @@ -1,103 +0,0 @@ -GenotypeA GenotypeB Gene1 Gene2 Gene3 Gene4 -2 2 1 1 1 1 -1 1 0.0735451012188 0.807744827105 -0.141557122166 0.871977046116 -2 1 0.0783291492541 0.784023461068 0.501395957396 1.20598627055 -2 1 0.786243065384 0.978600201012 1.10615045137 0.91427570527 -2 1 -0.133165253244 1.09368397217 0.943147613583 1.28625182746 -2 1 0.849732696834 0.701697179341 1.1597647359 1.10898527576 -2 1 0.117358779641 1.27641582521 1.07600246132 0.837957699405 -1 2 0.260845541489 0.126507267356 0.134953769296 1.05166904426 -2 1 0.277734881926 1.07193390309 0.282304188176 1.11305323003 -1 2 0.23482774261 1.22992089679 0.0929753295409 1.16341704702 -1 2 0.948183366714 0.133267523413 -0.218162396333 0.906540379337 -2 1 -0.116613369121 1.14203606435 0.109901766308 0.729527128692 -1 1 -0.179825551391 0.10619275827 0.937787825497 1.03567603615 -2 1 0.293022973091 1.08721255661 -0.175473007708 0.887010836361 -2 1 -0.0489346771642 0.968137836317 0.107834185199 0.896061918536 -1 2 0.236140871956 -0.0428030926592 -0.318492104268 0.570552965391 -2 2 -0.0800211950407 0.69984329873 0.188143588172 1.31042305844 -1 1 -0.0036838396465 0.115049518621 1.23342471413 -0.0310668924648 -1 2 0.821596343182 -0.206883091797 -0.176745465075 1.00503814188 -2 1 0.968136985881 0.17393492998 1.10355204542 1.50730341194 -1 1 -0.2529273487 1.15825296446 -0.296758267158 0.334353609539 -2 2 0.996924729837 0.79867304131 -0.0654588195254 1.14114632703 -1 1 1.11517699739 1.04475472944 1.01515337419 -0.114835981744 -1 1 1.13306628335 0.212806963119 -0.331850695159 1.3262481351 -2 1 -0.202717212277 1.16180466017 0.698481134231 0.837229654056 -2 1 1.09703628172 0.988374730515 0.632905281073 0.871944778559 -1 1 0.0877178138353 0.92193353301 0.0882061186606 -0.109998053824 -2 2 -0.0465657805556 1.0562741142 0.203076906226 0.947081854544 -1 1 0.253626344342 0.774666759107 0.160237735682 0.137119974017 -2 2 0.958504778114 0.696202219462 0.837104986151 1.22862239026 -2 1 0.0190762231091 1.07363361357 0.836517352782 1.13138357074 -1 2 1.04546343625 1.22248653304 -0.177641501681 0.938273372293 -1 1 -0.356538939133 0.926691569307 -0.0141334158342 -0.333256032191 -2 2 -0.271616290794 1.02237907773 -0.0893323176884 1.13812703435 -1 1 0.112310230451 0.96903715979 0.735229019751 0.0718376819618 -2 2 -0.0541760888203 0.910562906664 0.237421737724 1.12792106072 -2 1 0.140510085427 1.14598129626 0.684754216604 1.37711161908 -1 2 0.673132921769 1.16156481777 0.828299174842 1.23484148864 -1 1 -0.36576911038 1.22402806897 0.985794473424 0.371258195776 -2 1 1.30745593323 -0.305709792671 1.18778090128 0.773246386727 -2 2 -0.530650832006 1.12852174836 -0.242830565653 0.83833485032 -1 1 -0.291997112416 -0.0207658889693 0.172776752193 0.36694855027 -1 2 -0.161225357475 1.16418585274 0.00727443800449 1.1352882361 -2 2 1.30343435031 0.732902323978 -0.172844997755 0.874662524376 -2 2 0.85539635481 1.29119106621 0.016024964511 1.13160810191 -1 2 0.839799562146 -0.0698184772979 0.064736024742 0.888230930115 -1 2 0.95789577351 -0.0042439536723 0.0555580748795 1.07993651996 -1 1 1.32802494815 -0.214047314771 0.329813058688 0.728172901439 -1 1 -0.200890919169 1.1000313421 1.04401630691 0.0521627161216 -2 2 0.937448394951 1.08384634906 -0.0899239635102 1.07443211017 -2 1 -0.0666111295973 0.607978461697 0.178977027858 0.996958995079 -2 1 0.98988279173 0.936124382141 1.16162098 0.953396718798 -1 1 0.783923131778 -0.185782423384 0.234091790401 1.05701020406 -1 1 0.761503655241 1.10820714005 0.784532435857 -0.125970126396 -2 1 -0.0961115621732 0.992263342859 0.660910916217 0.963055169574 -2 2 -0.154764213109 0.730891518005 -0.109545565909 1.12272967655 -2 2 0.0479283751395 0.928564948748 0.0947967021058 0.98105799191 -2 2 1.39168552274 0.128331277089 0.10146975109 1.24231428304 -1 1 0.976982771784 -0.146928630221 -0.0608841220423 0.972841874016 -2 1 1.15485099166 0.935197552788 0.965011443377 1.34264634759 -1 2 -0.166427006522 0.213464027262 -0.031343375005 0.8119490745 -2 1 0.602325327176 1.47360525321 1.40368030116 0.887287145417 -1 2 1.12050355207 1.18852964108 0.0704081979976 1.19584630693 -2 1 0.702485774332 1.15988608636 0.294782678413 0.751491248655 -1 2 0.155516690813 0.251086517248 0.975388704705 0.688269967741 -1 2 0.038035346805 0.682904829816 0.0951645619842 0.665389726903 -1 1 0.339450864189 0.116879724658 -0.170951058396 -0.370117675216 -2 2 -0.108372250446 0.696218715139 -0.00428297700477 0.961335352653 -2 2 0.0146712646232 1.12798531635 0.778687243129 1.27150673153 -1 2 0.704617012215 1.08526662881 0.799187464816 1.13063944956 -1 1 1.10224639633 1.09684843311 1.13580106237 0.186395861041 -1 1 1.13687210336 0.592984795387 0.20048850526 -0.0553656796539 -1 2 0.0632700472019 0.864610771614 -0.242802029698 0.848811159682 -2 1 0.0451786925492 1.33573290418 0.92973441898 -0.344011193096 -1 2 1.26061879295 1.09499325896 0.0222202420765 0.847629840625 -1 2 0.91681254794 0.290800393334 -0.0719474399104 0.926496648214 -2 1 1.2172426262 0.951648627857 1.25202262128 0.233889527648 -1 2 1.05048646769 0.172566561404 0.0550162349302 0.750079764855 -1 2 0.675366500637 -0.0673050997098 0.1645804156 0.781063579107 -2 1 0.204088201674 0.886512802356 1.05795947541 0.185790058971 -2 1 -0.100901351663 0.714436170991 -0.505529978858 0.647306701065 -1 2 0.907207625417 1.16174653049 -0.155199134127 0.747382222584 -1 2 0.0672106257479 0.603637849323 -0.140625204522 1.08080017243 -2 1 1.2385313097 1.0695347389 -0.176990709153 0.848256839162 -1 2 0.186923583294 0.119157644078 0.0349289573077 0.744803259527 -1 2 1.09352177593 0.194715059877 0.0236391004662 0.499673191061 -2 1 -0.376369481804 0.985546924317 0.0945527339598 0.948918281956 -1 1 1.18474855816 -0.115831486698 0.283152200427 0.970403352935 -2 2 1.15179008534 1.11293520284 0.221811798026 0.999871011204 -1 2 -0.270193067228 1.1546656712 -0.244378116913 0.671654326382 -2 2 0.439331185377 1.12197569445 0.258362973013 1.11146143747 -2 2 1.01095806207 0.745930460781 -0.0409015639874 1.14791250376 -2 1 -0.26402775558 1.0189980863 0.0142629520115 0.959203836932 -1 1 1.1622683144 -0.0120889455187 1.07714267283 -0.177584275215 -1 1 0.942340790264 0.254818931717 0.0587741977709 0.980453538135 -2 2 0.106324819492 0.79161883369 -0.16526611256 0.916230483749 -2 1 1.19278065887 0.913551161988 -0.0956615348665 1.05953140511 -1 1 0.99020996204 -0.0516709802571 0.785783698942 1.47690006823 -2 1 1.1566705292 1.05878794929 0.0968404106402 0.827720917511 -1 2 0.05207115921 -0.252341077617 -0.0848699551554 1.19139462554 -2 2 0.991086851115 -0.301180892331 -0.00253197995383 1.46608138294 - diff --git a/sourcecodes/parameter_learning/test/Agbmap.txt b/sourcecodes/parameter_learning/test/Agbmap.txt deleted file mode 100644 index bb1dd64f..00000000 --- a/sourcecodes/parameter_learning/test/Agbmap.txt +++ /dev/null @@ -1,6 +0,0 @@ -GenotypeA 2 0.502519 1.500000 -GenotypeB 1 0.500908 1.460000 -Gene1 2 0.553536 0.475371 -Gene2 1 0.485907 0.701417 -Gene3 1 0.485352 0.313494 -Gene4 1 0.435265 0.819489 diff --git a/sourcecodes/parameter_learning/test/Agbmapdata.txt b/sourcecodes/parameter_learning/test/Agbmapdata.txt deleted file mode 100644 index fa8be0bd..00000000 --- a/sourcecodes/parameter_learning/test/Agbmapdata.txt +++ /dev/null @@ -1 +0,0 @@ -GenotypeB Gene3 GenotypeA Gene2 Gene4 Gene1 diff --git a/sourcecodes/parameter_learning/test/Agbnet_figure.txt b/sourcecodes/parameter_learning/test/Agbnet_figure.txt deleted file mode 100644 index 8243b7d9..00000000 --- a/sourcecodes/parameter_learning/test/Agbnet_figure.txt +++ /dev/null @@ -1,440 +0,0 @@ -6 -1200 1200 -GenotypeB 0 0 -Gene3 120 300 -GenotypeA 400 0 -Gene2 520 300 -Gene4 0 600 -Gene1 400 600 -GenotypeB 2 -250 150 -0 -2 2 5 -1 0.5400 -2 0.4600 -Gene3 1 -250 150 -1 1 -0 --2.6875 0.0108 --2.6281 0.0126 --2.5688 0.0147 --2.5095 0.0171 --2.4501 0.0198 --2.3908 0.0229 --2.3315 0.0263 --2.2721 0.0302 --2.2128 0.0345 --2.1535 0.0393 --2.0941 0.0445 --2.0348 0.0503 --1.9754 0.0567 --1.9161 0.0636 --1.8568 0.0712 --1.7974 0.0793 --1.7381 0.0881 --1.6788 0.0975 --1.6194 0.1075 --1.5601 0.1181 --1.5008 0.1294 --1.4414 0.1412 --1.3821 0.1535 --1.3227 0.1663 --1.2634 0.1796 --1.2041 0.1932 --1.1447 0.2072 --1.0854 0.2214 --1.0261 0.2357 --0.9667 0.2500 --0.9074 0.2643 --0.8480 0.2784 --0.7887 0.2923 --0.7294 0.3058 --0.6700 0.3187 --0.6107 0.3311 --0.5514 0.3427 --0.4920 0.3535 --0.4327 0.3633 --0.3734 0.3721 --0.3140 0.3797 --0.2547 0.3862 --0.1953 0.3914 --0.1360 0.3953 --0.0767 0.3978 --0.0173 0.3989 -0.0420 0.3986 -0.1013 0.3969 -0.1607 0.3938 -0.2200 0.3894 -0.2793 0.3837 -0.3387 0.3767 -0.3980 0.3686 -0.4574 0.3593 -0.5167 0.3491 -0.5760 0.3380 -0.6354 0.3260 -0.6947 0.3134 -0.7540 0.3002 -0.8134 0.2866 -0.8727 0.2726 -0.9320 0.2584 -0.9914 0.2441 -1.0507 0.2297 -1.1101 0.2154 -1.1694 0.2014 -1.2287 0.1875 -1.2881 0.1740 -1.3474 0.1609 -1.4067 0.1483 -1.4661 0.1362 -1.5254 0.1246 -1.5848 0.1136 -1.6441 0.1033 -1.7034 0.0935 -1.7628 0.0844 -1.8221 0.0759 -1.8814 0.0680 -1.9408 0.0607 -2.0001 0.0540 -2.0594 0.0479 -2.1188 0.0423 -2.1781 0.0372 -2.2375 0.0326 -2.2968 0.0285 -2.3561 0.0249 -2.4155 0.0216 -2.4748 0.0187 -2.5341 0.0161 -2.5935 0.0138 -2.6528 0.0118 -2.7121 0.0101 -2.7715 0.0086 -2.8308 0.0073 -2.8902 0.0061 -2.9495 0.0052 -3.0088 0.0043 -3.0682 0.0036 -3.1275 0.0030 -3.1868 0.0025 -3.2462 0.0021 -GenotypeA 2 -250 150 -0 -2 4 5 -1 0.5000 -2 0.5000 -Gene2 1 -250 150 -1 3 -2 5 6 --3.0727 0.0036 --3.0161 0.0042 --2.9594 0.0050 --2.9028 0.0059 --2.8462 0.0069 --2.7896 0.0081 --2.7330 0.0095 --2.6763 0.0111 --2.6197 0.0129 --2.5631 0.0149 --2.5065 0.0172 --2.4499 0.0198 --2.3933 0.0228 --2.3366 0.0260 --2.2800 0.0297 --2.2234 0.0337 --2.1668 0.0381 --2.1102 0.0431 --2.0535 0.0484 --1.9969 0.0543 --1.9403 0.0607 --1.8837 0.0677 --1.8271 0.0752 --1.7705 0.0832 --1.7138 0.0919 --1.6572 0.1011 --1.6006 0.1108 --1.5440 0.1211 --1.4874 0.1320 --1.4307 0.1434 --1.3741 0.1552 --1.3175 0.1675 --1.2609 0.1802 --1.2043 0.1932 --1.1476 0.2065 --1.0910 0.2200 --1.0344 0.2336 --0.9778 0.2473 --0.9212 0.2610 --0.8646 0.2745 --0.8079 0.2878 --0.7513 0.3008 --0.6947 0.3134 --0.6381 0.3255 --0.5815 0.3369 --0.5248 0.3476 --0.4682 0.3575 --0.4116 0.3665 --0.3550 0.3746 --0.2984 0.3816 --0.2418 0.3875 --0.1851 0.3922 --0.1285 0.3957 --0.0719 0.3979 --0.0153 0.3989 -0.0413 0.3986 -0.0980 0.3970 -0.1546 0.3942 -0.2112 0.3901 -0.2678 0.3849 -0.3244 0.3785 -0.3810 0.3710 -0.4377 0.3625 -0.4943 0.3531 -0.5509 0.3428 -0.6075 0.3317 -0.6641 0.3200 -0.7208 0.3077 -0.7774 0.2949 -0.8340 0.2818 -0.8906 0.2683 -0.9472 0.2547 -1.0039 0.2410 -1.0605 0.2274 -1.1171 0.2138 -1.1737 0.2003 -1.2303 0.1872 -1.2869 0.1743 -1.3436 0.1618 -1.4002 0.1497 -1.4568 0.1381 -1.5134 0.1269 -1.5700 0.1163 -1.6267 0.1063 -1.6833 0.0967 -1.7399 0.0878 -1.7965 0.0794 -1.8531 0.0716 -1.9097 0.0644 -1.9664 0.0577 -2.0230 0.0516 -2.0796 0.0459 -2.1362 0.0407 -2.1928 0.0360 -2.2495 0.0318 -2.3061 0.0279 -2.3627 0.0245 -2.4193 0.0214 -2.4759 0.0186 -2.5326 0.0161 -2.5892 0.0140 -Gene4 1 -250 150 -3 1 3 4 -0 --3.7331 0.0009 --3.6699 0.0011 --3.6068 0.0014 --3.5437 0.0016 --3.4805 0.0020 --3.4174 0.0024 --3.3543 0.0029 --3.2911 0.0035 --3.2280 0.0042 --3.1649 0.0050 --3.1017 0.0059 --3.0386 0.0070 --2.9755 0.0083 --2.9123 0.0097 --2.8492 0.0114 --2.7861 0.0133 --2.7229 0.0154 --2.6598 0.0179 --2.5967 0.0206 --2.5335 0.0238 --2.4704 0.0273 --2.4073 0.0312 --2.3441 0.0355 --2.2810 0.0403 --2.2179 0.0455 --2.1547 0.0513 --2.0916 0.0577 --2.0285 0.0645 --1.9653 0.0720 --1.9022 0.0800 --1.8391 0.0886 --1.7759 0.0978 --1.7128 0.1075 --1.6497 0.1178 --1.5865 0.1287 --1.5234 0.1401 --1.4603 0.1519 --1.3971 0.1642 --1.3340 0.1768 --1.2709 0.1897 --1.2077 0.2029 --1.1446 0.2162 --1.0815 0.2296 --1.0183 0.2430 --0.9552 0.2563 --0.8921 0.2693 --0.8290 0.2820 --0.7658 0.2943 --0.7027 0.3061 --0.6396 0.3172 --0.5764 0.3275 --0.5133 0.3371 --0.4502 0.3456 --0.3870 0.3532 --0.3239 0.3597 --0.2608 0.3650 --0.1976 0.3691 --0.1345 0.3719 --0.0714 0.3735 --0.0082 0.3737 -0.0549 0.3727 -0.1180 0.3703 -0.1812 0.3667 -0.2443 0.3618 -0.3074 0.3558 -0.3706 0.3486 -0.4337 0.3404 -0.4968 0.3312 -0.5600 0.3212 -0.6231 0.3103 -0.6862 0.2988 -0.7494 0.2867 -0.8125 0.2741 -0.8756 0.2612 -0.9388 0.2480 -1.0019 0.2347 -1.0650 0.2213 -1.1282 0.2079 -1.1913 0.1947 -1.2544 0.1816 -1.3176 0.1689 -1.3807 0.1565 -1.4438 0.1445 -1.5070 0.1329 -1.5701 0.1219 -1.6332 0.1113 -1.6964 0.1014 -1.7595 0.0920 -1.8226 0.0831 -1.8858 0.0749 -1.9489 0.0673 -2.0120 0.0602 -2.0752 0.0536 -2.1383 0.0477 -2.2014 0.0422 -2.2646 0.0372 -2.3277 0.0327 -2.3908 0.0287 -2.4540 0.0250 -2.5171 0.0218 -2.5802 0.0189 -Gene1 1 -250 150 -1 4 -0 --2.8174 0.0076 --2.7627 0.0088 --2.7080 0.0102 --2.6533 0.0119 --2.5985 0.0137 --2.5438 0.0158 --2.4891 0.0181 --2.4343 0.0207 --2.3796 0.0236 --2.3249 0.0268 --2.2702 0.0304 --2.2154 0.0344 --2.1607 0.0387 --2.1060 0.0435 --2.0512 0.0488 --1.9965 0.0545 --1.9418 0.0607 --1.8871 0.0674 --1.8323 0.0746 --1.7776 0.0823 --1.7229 0.0906 --1.6682 0.0994 --1.6134 0.1087 --1.5587 0.1185 --1.5040 0.1289 --1.4492 0.1397 --1.3945 0.1510 --1.3398 0.1627 --1.2851 0.1748 --1.2303 0.1872 --1.1756 0.2000 --1.1209 0.2129 --1.0661 0.2260 --1.0114 0.2392 --0.9567 0.2524 --0.9020 0.2656 --0.8472 0.2786 --0.7925 0.2914 --0.7378 0.3038 --0.6830 0.3158 --0.6283 0.3273 --0.5736 0.3383 --0.5189 0.3485 --0.4641 0.3580 --0.4094 0.3667 --0.3547 0.3744 --0.2999 0.3811 --0.2452 0.3869 --0.1905 0.3915 --0.1358 0.3950 --0.0810 0.3974 --0.0263 0.3985 -0.0284 0.3985 -0.0832 0.3973 -0.1379 0.3949 -0.1926 0.3913 -0.2473 0.3867 -0.3021 0.3809 -0.3568 0.3741 -0.4115 0.3663 -0.4663 0.3577 -0.5210 0.3481 -0.5757 0.3379 -0.6304 0.3269 -0.6852 0.3154 -0.7399 0.3033 -0.7946 0.2909 -0.8493 0.2781 -0.9041 0.2651 -0.9588 0.2519 -1.0135 0.2387 -1.0683 0.2255 -1.1230 0.2124 -1.1777 0.1995 -1.2324 0.1867 -1.2872 0.1743 -1.3419 0.1622 -1.3966 0.1505 -1.4514 0.1393 -1.5061 0.1285 -1.5608 0.1181 -1.6155 0.1083 -1.6703 0.0990 -1.7250 0.0902 -1.7797 0.0820 -1.8345 0.0743 -1.8892 0.0671 -1.9439 0.0604 -1.9986 0.0543 -2.0534 0.0486 -2.1081 0.0433 -2.1628 0.0386 -2.2176 0.0342 -2.2723 0.0303 -2.3270 0.0267 -2.3817 0.0235 -2.4365 0.0206 -2.4912 0.0180 -2.5459 0.0157 -2.6007 0.0136 -2.6554 0.0118 diff --git a/sourcecodes/parameter_learning/test/Agbnet_figure.txt.bk b/sourcecodes/parameter_learning/test/Agbnet_figure.txt.bk deleted file mode 100644 index 8243b7d9..00000000 --- a/sourcecodes/parameter_learning/test/Agbnet_figure.txt.bk +++ /dev/null @@ -1,440 +0,0 @@ -6 -1200 1200 -GenotypeB 0 0 -Gene3 120 300 -GenotypeA 400 0 -Gene2 520 300 -Gene4 0 600 -Gene1 400 600 -GenotypeB 2 -250 150 -0 -2 2 5 -1 0.5400 -2 0.4600 -Gene3 1 -250 150 -1 1 -0 --2.6875 0.0108 --2.6281 0.0126 --2.5688 0.0147 --2.5095 0.0171 --2.4501 0.0198 --2.3908 0.0229 --2.3315 0.0263 --2.2721 0.0302 --2.2128 0.0345 --2.1535 0.0393 --2.0941 0.0445 --2.0348 0.0503 --1.9754 0.0567 --1.9161 0.0636 --1.8568 0.0712 --1.7974 0.0793 --1.7381 0.0881 --1.6788 0.0975 --1.6194 0.1075 --1.5601 0.1181 --1.5008 0.1294 --1.4414 0.1412 --1.3821 0.1535 --1.3227 0.1663 --1.2634 0.1796 --1.2041 0.1932 --1.1447 0.2072 --1.0854 0.2214 --1.0261 0.2357 --0.9667 0.2500 --0.9074 0.2643 --0.8480 0.2784 --0.7887 0.2923 --0.7294 0.3058 --0.6700 0.3187 --0.6107 0.3311 --0.5514 0.3427 --0.4920 0.3535 --0.4327 0.3633 --0.3734 0.3721 --0.3140 0.3797 --0.2547 0.3862 --0.1953 0.3914 --0.1360 0.3953 --0.0767 0.3978 --0.0173 0.3989 -0.0420 0.3986 -0.1013 0.3969 -0.1607 0.3938 -0.2200 0.3894 -0.2793 0.3837 -0.3387 0.3767 -0.3980 0.3686 -0.4574 0.3593 -0.5167 0.3491 -0.5760 0.3380 -0.6354 0.3260 -0.6947 0.3134 -0.7540 0.3002 -0.8134 0.2866 -0.8727 0.2726 -0.9320 0.2584 -0.9914 0.2441 -1.0507 0.2297 -1.1101 0.2154 -1.1694 0.2014 -1.2287 0.1875 -1.2881 0.1740 -1.3474 0.1609 -1.4067 0.1483 -1.4661 0.1362 -1.5254 0.1246 -1.5848 0.1136 -1.6441 0.1033 -1.7034 0.0935 -1.7628 0.0844 -1.8221 0.0759 -1.8814 0.0680 -1.9408 0.0607 -2.0001 0.0540 -2.0594 0.0479 -2.1188 0.0423 -2.1781 0.0372 -2.2375 0.0326 -2.2968 0.0285 -2.3561 0.0249 -2.4155 0.0216 -2.4748 0.0187 -2.5341 0.0161 -2.5935 0.0138 -2.6528 0.0118 -2.7121 0.0101 -2.7715 0.0086 -2.8308 0.0073 -2.8902 0.0061 -2.9495 0.0052 -3.0088 0.0043 -3.0682 0.0036 -3.1275 0.0030 -3.1868 0.0025 -3.2462 0.0021 -GenotypeA 2 -250 150 -0 -2 4 5 -1 0.5000 -2 0.5000 -Gene2 1 -250 150 -1 3 -2 5 6 --3.0727 0.0036 --3.0161 0.0042 --2.9594 0.0050 --2.9028 0.0059 --2.8462 0.0069 --2.7896 0.0081 --2.7330 0.0095 --2.6763 0.0111 --2.6197 0.0129 --2.5631 0.0149 --2.5065 0.0172 --2.4499 0.0198 --2.3933 0.0228 --2.3366 0.0260 --2.2800 0.0297 --2.2234 0.0337 --2.1668 0.0381 --2.1102 0.0431 --2.0535 0.0484 --1.9969 0.0543 --1.9403 0.0607 --1.8837 0.0677 --1.8271 0.0752 --1.7705 0.0832 --1.7138 0.0919 --1.6572 0.1011 --1.6006 0.1108 --1.5440 0.1211 --1.4874 0.1320 --1.4307 0.1434 --1.3741 0.1552 --1.3175 0.1675 --1.2609 0.1802 --1.2043 0.1932 --1.1476 0.2065 --1.0910 0.2200 --1.0344 0.2336 --0.9778 0.2473 --0.9212 0.2610 --0.8646 0.2745 --0.8079 0.2878 --0.7513 0.3008 --0.6947 0.3134 --0.6381 0.3255 --0.5815 0.3369 --0.5248 0.3476 --0.4682 0.3575 --0.4116 0.3665 --0.3550 0.3746 --0.2984 0.3816 --0.2418 0.3875 --0.1851 0.3922 --0.1285 0.3957 --0.0719 0.3979 --0.0153 0.3989 -0.0413 0.3986 -0.0980 0.3970 -0.1546 0.3942 -0.2112 0.3901 -0.2678 0.3849 -0.3244 0.3785 -0.3810 0.3710 -0.4377 0.3625 -0.4943 0.3531 -0.5509 0.3428 -0.6075 0.3317 -0.6641 0.3200 -0.7208 0.3077 -0.7774 0.2949 -0.8340 0.2818 -0.8906 0.2683 -0.9472 0.2547 -1.0039 0.2410 -1.0605 0.2274 -1.1171 0.2138 -1.1737 0.2003 -1.2303 0.1872 -1.2869 0.1743 -1.3436 0.1618 -1.4002 0.1497 -1.4568 0.1381 -1.5134 0.1269 -1.5700 0.1163 -1.6267 0.1063 -1.6833 0.0967 -1.7399 0.0878 -1.7965 0.0794 -1.8531 0.0716 -1.9097 0.0644 -1.9664 0.0577 -2.0230 0.0516 -2.0796 0.0459 -2.1362 0.0407 -2.1928 0.0360 -2.2495 0.0318 -2.3061 0.0279 -2.3627 0.0245 -2.4193 0.0214 -2.4759 0.0186 -2.5326 0.0161 -2.5892 0.0140 -Gene4 1 -250 150 -3 1 3 4 -0 --3.7331 0.0009 --3.6699 0.0011 --3.6068 0.0014 --3.5437 0.0016 --3.4805 0.0020 --3.4174 0.0024 --3.3543 0.0029 --3.2911 0.0035 --3.2280 0.0042 --3.1649 0.0050 --3.1017 0.0059 --3.0386 0.0070 --2.9755 0.0083 --2.9123 0.0097 --2.8492 0.0114 --2.7861 0.0133 --2.7229 0.0154 --2.6598 0.0179 --2.5967 0.0206 --2.5335 0.0238 --2.4704 0.0273 --2.4073 0.0312 --2.3441 0.0355 --2.2810 0.0403 --2.2179 0.0455 --2.1547 0.0513 --2.0916 0.0577 --2.0285 0.0645 --1.9653 0.0720 --1.9022 0.0800 --1.8391 0.0886 --1.7759 0.0978 --1.7128 0.1075 --1.6497 0.1178 --1.5865 0.1287 --1.5234 0.1401 --1.4603 0.1519 --1.3971 0.1642 --1.3340 0.1768 --1.2709 0.1897 --1.2077 0.2029 --1.1446 0.2162 --1.0815 0.2296 --1.0183 0.2430 --0.9552 0.2563 --0.8921 0.2693 --0.8290 0.2820 --0.7658 0.2943 --0.7027 0.3061 --0.6396 0.3172 --0.5764 0.3275 --0.5133 0.3371 --0.4502 0.3456 --0.3870 0.3532 --0.3239 0.3597 --0.2608 0.3650 --0.1976 0.3691 --0.1345 0.3719 --0.0714 0.3735 --0.0082 0.3737 -0.0549 0.3727 -0.1180 0.3703 -0.1812 0.3667 -0.2443 0.3618 -0.3074 0.3558 -0.3706 0.3486 -0.4337 0.3404 -0.4968 0.3312 -0.5600 0.3212 -0.6231 0.3103 -0.6862 0.2988 -0.7494 0.2867 -0.8125 0.2741 -0.8756 0.2612 -0.9388 0.2480 -1.0019 0.2347 -1.0650 0.2213 -1.1282 0.2079 -1.1913 0.1947 -1.2544 0.1816 -1.3176 0.1689 -1.3807 0.1565 -1.4438 0.1445 -1.5070 0.1329 -1.5701 0.1219 -1.6332 0.1113 -1.6964 0.1014 -1.7595 0.0920 -1.8226 0.0831 -1.8858 0.0749 -1.9489 0.0673 -2.0120 0.0602 -2.0752 0.0536 -2.1383 0.0477 -2.2014 0.0422 -2.2646 0.0372 -2.3277 0.0327 -2.3908 0.0287 -2.4540 0.0250 -2.5171 0.0218 -2.5802 0.0189 -Gene1 1 -250 150 -1 4 -0 --2.8174 0.0076 --2.7627 0.0088 --2.7080 0.0102 --2.6533 0.0119 --2.5985 0.0137 --2.5438 0.0158 --2.4891 0.0181 --2.4343 0.0207 --2.3796 0.0236 --2.3249 0.0268 --2.2702 0.0304 --2.2154 0.0344 --2.1607 0.0387 --2.1060 0.0435 --2.0512 0.0488 --1.9965 0.0545 --1.9418 0.0607 --1.8871 0.0674 --1.8323 0.0746 --1.7776 0.0823 --1.7229 0.0906 --1.6682 0.0994 --1.6134 0.1087 --1.5587 0.1185 --1.5040 0.1289 --1.4492 0.1397 --1.3945 0.1510 --1.3398 0.1627 --1.2851 0.1748 --1.2303 0.1872 --1.1756 0.2000 --1.1209 0.2129 --1.0661 0.2260 --1.0114 0.2392 --0.9567 0.2524 --0.9020 0.2656 --0.8472 0.2786 --0.7925 0.2914 --0.7378 0.3038 --0.6830 0.3158 --0.6283 0.3273 --0.5736 0.3383 --0.5189 0.3485 --0.4641 0.3580 --0.4094 0.3667 --0.3547 0.3744 --0.2999 0.3811 --0.2452 0.3869 --0.1905 0.3915 --0.1358 0.3950 --0.0810 0.3974 --0.0263 0.3985 -0.0284 0.3985 -0.0832 0.3973 -0.1379 0.3949 -0.1926 0.3913 -0.2473 0.3867 -0.3021 0.3809 -0.3568 0.3741 -0.4115 0.3663 -0.4663 0.3577 -0.5210 0.3481 -0.5757 0.3379 -0.6304 0.3269 -0.6852 0.3154 -0.7399 0.3033 -0.7946 0.2909 -0.8493 0.2781 -0.9041 0.2651 -0.9588 0.2519 -1.0135 0.2387 -1.0683 0.2255 -1.1230 0.2124 -1.1777 0.1995 -1.2324 0.1867 -1.2872 0.1743 -1.3419 0.1622 -1.3966 0.1505 -1.4514 0.1393 -1.5061 0.1285 -1.5608 0.1181 -1.6155 0.1083 -1.6703 0.0990 -1.7250 0.0902 -1.7797 0.0820 -1.8345 0.0743 -1.8892 0.0671 -1.9439 0.0604 -1.9986 0.0543 -2.0534 0.0486 -2.1081 0.0433 -2.1628 0.0386 -2.2176 0.0342 -2.2723 0.0303 -2.3270 0.0267 -2.3817 0.0235 -2.4365 0.0206 -2.4912 0.0180 -2.5459 0.0157 -2.6007 0.0136 -2.6554 0.0118 diff --git a/sourcecodes/parameter_learning/test/Agbnnode.txt b/sourcecodes/parameter_learning/test/Agbnnode.txt deleted file mode 100644 index 1e8b3149..00000000 --- a/sourcecodes/parameter_learning/test/Agbnnode.txt +++ /dev/null @@ -1 +0,0 @@ -6 diff --git a/sourcecodes/parameter_learning/test/Agbstructure_input.txt b/sourcecodes/parameter_learning/test/Agbstructure_input.txt deleted file mode 100644 index 10766f0c..00000000 --- a/sourcecodes/parameter_learning/test/Agbstructure_input.txt +++ /dev/null @@ -1,7 +0,0 @@ -GenotypeA GenotypeB Gene1 Gene2 Gene3 Gene4 -0 0 0 1 0 1 -0 0 0 0 1 1 -0 0 0 0 0 0 -0 0 1 0 0 1 -0 0 0 0 0 0 -0 0 0 0 0 0 diff --git a/sourcecodes/parameter_learning/test/octave-core b/sourcecodes/parameter_learning/test/octave-core deleted file mode 100644 index 678fda92..00000000 --- a/sourcecodes/parameter_learning/test/octave-core +++ /dev/null Binary files differdiff --git a/sourcecodes/parameter_learning/writeParameters.m b/sourcecodes/parameter_learning/writeParameters.m new file mode 100644 index 00000000..0790a8e2 --- /dev/null +++ b/sourcecodes/parameter_learning/writeParameters.m @@ -0,0 +1,106 @@ +function [] = writeParameters(pre,nnodes,bnet,labels,cases,labelsold,s,m) +%Writes a file that contains the parameters of the network with no evidence. + + +%%Get the types of the nodes. +typefile = strcat(pre,'type.txt'); +ftype = fopen(typefile,'r'); +types = cell(1,nnodes); +buffer = fgetl(ftype); +buffer = fgetl(ftype); +for j = 1:nnodes + [next,buffer] = strtok(buffer); + types{j} = uint16(str2num(next)); +end + +max_states = 0; +disc_nodes = 0; +for j = 1:nnodes + if types{j} > max_states + max_states = types{j}; + end + if types{j} > 1 + disc_nodes = disc_nodes + 1; + end +end + +%Add 1 to max_states to account for node name +max_states = max_states + 1; + +%%Get mapping of discrete levels. +levelfile = strcat(pre,'nlevels.txt'); +flevels = fopen(levelfile,'r'); +levels = cell(disc_nodes,max_states); +ndisc_nodes = 0; +for i=1:disc_nodes + ndisc_nodes = ndisc_nodes + 1; + buffer = fgetl(flevels); + for j = 1:max_states + [next,buffer] = strtok(buffer); + if j == 1 + levels{i,j} = next; + else +% levels{i,j} = uint16(str2num(next)); + levels{i,j} = next; + end + if length(buffer) < 1 + break + end + end +end + + +evidence = cell(1,nnodes); +engine = jtree_inf_engine(bnet); +[engine,loglik] = enter_evidence(engine,evidence); + +%Open output file. +filename = strcat(pre,'parameters.txt'); +fileID = fopen(filename,'w'); + +for i = 1:nnodes + for j = 1:nnodes + if strcmp(labelsold{i},labels{j}); + nodeid = j; + break + end + end + predict = marginal_nodes(engine,nodeid); + %%%Print the name of the node + fprintf(fileID,'%s\n',labels{nodeid}); + %%%Print the type of node + if bnet.node_sizes(nodeid) == 1; + line = 'Continuous node\n'; + fprintf(fileID,line); + %%% 'i' in the line below is correct: m and s are had original node labeling + adj_mu = predict.mu*s(i)+m(i); + adj_sigma = s(i)*predict.Sigma; + fprintf(fileID,'%6.4f\t%6.4f\n\n',adj_mu,adj_sigma); + else + line = 'Discrete node with %i states\n'; + fprintf(fileID,line,bnet.node_sizes(nodeid)); + %line = 'Probability of each state\n'; + %fprintf(fileID,line); + nodeid2 = 0; + for k = 1:ndisc_nodes, + if strcmp(levels{k,1},labels{nodeid}), + nodeid2 = k; + break + end + end + for j = 1:bnet.node_sizes(nodeid), + %%%For discrete nodes, the state and the percent of that state +% fprintf(fileID,'%i\t%6.4f\n',levels{nodeid2,j+1},predict.T(j)); + fprintf(fileID,'%s\t%6.4f\n',levels{nodeid2,j+1},predict.T(j)); + end; + fprintf(fileID,'\n') + + end +end + + + +fclose(fileID); + +end + diff --git a/sourcecodes/parameter_learning/writeParameters_ev.m b/sourcecodes/parameter_learning/writeParameters_ev.m new file mode 100644 index 00000000..fc24e2e5 --- /dev/null +++ b/sourcecodes/parameter_learning/writeParameters_ev.m @@ -0,0 +1,151 @@ +function [] = writeParameters_ev(pre,bnet,nnodes,labels,cases,stdevs,means,selectvar,selectdata) +%Writes a file that contains the parameters of the network after entering evidence. + +%Read in original node labels to get node IDs. +infile = strcat(pre,'continuous_input.txt'); +fin = fopen(infile,'r'); +labelsold = cell(1,nnodes); +buffer = fgetl(fin); +for j = 1:nnodes + [next,buffer] = strtok(buffer); + labelsold{j} = next; +end +fclose(fin); + + +evidence = cell(1,nnodes); +engine = jtree_inf_engine(bnet); + +m = size(selectvar,1); + +%%Get the types of the nodes. +typefile = strcat(pre,'type.txt'); +ftype = fopen(typefile,'r'); +types = cell(1,nnodes); +buffer = fgetl(ftype); +buffer = fgetl(ftype); +for j = 1:nnodes + [next,buffer] = strtok(buffer); + types{j} = uint16(str2num(next)); +end + +max_states = 0; +disc_nodes = 0; +for j = 1:nnodes + if types{j} > max_states + max_states = types{j}; + end + if types{j} > 1 + disc_nodes = disc_nodes + 1; + end +end + +%Add 1 to max_states to account for node name +max_states = max_states + 1; + +%%Get mapping of discrete levels. +levelfile = strcat(pre,'nlevels.txt'); +flevels = fopen(levelfile,'r'); +levels = cell(disc_nodes,max_states); +ndisc_nodes = 0; +for i=1:disc_nodes + ndisc_nodes = ndisc_nodes + 1; +buffer = fgetl(flevels); +for j = 1:max_states + [next,buffer] = strtok(buffer); + if j == 1 + levels{i,j} = next; + else +% levels{i,j} = uint16(str2num(next)); + levels{i,j} = next; + end + if length(buffer) < 1 + break + end + end +end + + +ev_dat = zeros(1,nnodes); +for i = 1:m, + di=selectvar(i,1); + ev_dat(di)=selectdata(i,1); +%Need to standardize evidence for continuous nodes. + if bnet.node_sizes(di) == 1, + ev_dat(di) = (ev_dat(di) - means{di})/stdevs{di}; + end + evidence{di} = ev_dat(di); +end + +[engine,loglik]=enter_evidence(engine,evidence); + +%Open output file. +filename = strcat(pre,'parameters_ev.txt'); +fileID = fopen(filename,'w'); + +for i = 1:nnodes + for j = 1:nnodes + if strcmp(labelsold{i},labels{j}); + nodeid = j; + break + end + end + %%%Print the name of the node + fprintf(fileID,'%s\n',labels{nodeid}); + predict = marginal_nodes(engine,nodeid); + if isempty(evidence{nodeid}) + %%%Print the type of node + if bnet.node_sizes(nodeid) == 1; + line = 'Continuous parameters considering evidence:\n'; + fprintf(fileID,line); + %line = 'Mean and standard deviation of Gaussian distribution\n'; + %fprintf(fileID,line); + adj_mu = predict.mu*stdevs{nodeid}+means{nodeid}; + adj_sigma = stdevs{nodeid}*predict.Sigma; + fprintf(fileID,'%6.4f\t%6.4f\n\n',adj_mu,adj_sigma); + else + line = 'Probability of states considering evidence:\n'; + fprintf(fileID,line); + nodeid2 = 0; + for k = 1:ndisc_nodes, + if strcmp(levels{k,1},labels{nodeid}), + nodeid2 = k; + break + end + end + for j = 1:bnet.node_sizes(nodeid), + %%%For discrete nodes, the state and the percent of that state +% fprintf(fileID,'%i\t%6.4f\n',levels{nodeid2,j+1},predict.T(j)); + fprintf(fileID,'%s\t%6.4f\n',levels{nodeid2,j+1},predict.T(j)); + end; + fprintf(fileID,'\n') + end + else + if bnet.node_sizes(nodeid) == 1; + line = 'Evidence was observed for this node. The observed value was:\n'; + fprintf(fileID,line); + adj_mu = ev_dat(nodeid)*stdevs{nodeid}+means{nodeid}; + fprintf(fileID,'%6.4f\n\n',adj_mu); + else + nodeid2 = 0; + for k = 1:ndisc_nodes, + if strcmp(levels{k,1},labels{nodeid}), + nodeid2 = k; + break + end + end + line = 'Evidence was observed for this node. The observed state was:\n'; + fprintf(fileID,line); + state_ev = uint16(ev_dat(nodeid)); +% fprintf(fileID,'%i\n\n',levels{nodeid2,state_ev+1}); + fprintf(fileID,'%s\n\n',levels{nodeid2,state_ev+1}); + end + end +end + + + +fclose(fileID); + +end + diff --git a/sourcecodes/parameter_learning/writeParameters_int.m b/sourcecodes/parameter_learning/writeParameters_int.m new file mode 100644 index 00000000..ed92d593 --- /dev/null +++ b/sourcecodes/parameter_learning/writeParameters_int.m @@ -0,0 +1,186 @@ +function [] = writeParameters_int(pre,bnet,nnodes,labels,cases,stdevs,means,selectvar,selectdata) +%Writes a file that contains the parameters of the network after intervention. + + +%First read input file to get node labels to get node IDs. +infile = strcat(pre,'continuous_input.txt'); +fin = fopen(infile,'r'); +labelsold = cell(1,nnodes); +buffer = fgetl(fin); +for j = 1:nnodes + [next,buffer] = strtok(buffer); + labelsold{j} = next; +end + +evidence = cell(1,nnodes); +engine = jtree_inf_engine(bnet); + +m = size(selectvar,1); + +%%Get the types of the nodes. +typefile = strcat(pre,'type.txt'); +ftype = fopen(typefile,'r'); +types = cell(1,nnodes); +buffer = fgetl(ftype); +buffer = fgetl(ftype); +for j = 1:nnodes + [next,buffer] = strtok(buffer); + types{j} = uint16(str2num(next)); +end + +max_states = 0; +disc_nodes = 0; +for j = 1:nnodes + if types{j} > max_states + max_states = types{j}; + end + if types{j} > 1 + disc_nodes = disc_nodes + 1; + end +end + +%Add 1 to max_states to account for node name +max_states = max_states + 1; + +%%Get mapping of discrete levels. +levelfile = strcat(pre,'nlevels.txt'); +flevels = fopen(levelfile,'r'); +levels = cell(disc_nodes,max_states); +ndisc_nodes = 0; +for i=1:disc_nodes + ndisc_nodes = ndisc_nodes + 1; +buffer = fgetl(flevels); +for j = 1:max_states + [next,buffer] = strtok(buffer); + if j == 1 + levels{i,j} = next; + else +% levels{i,j} = uint16(str2num(next)); + levels{i,j} = next; + end + if length(buffer) < 1 + break + end + end +end + + +ev_dat = zeros(1,nnodes); +for i = 1:m, + di=selectvar(i,1); + ev_dat(di)=selectdata(i,1); +%Need to standardize evidence for continuous nodes. + if bnet.node_sizes(di) == 1, + ev_dat(di) = (ev_dat(di) - means{di})/stdevs{di}; + end + evidence{di} = ev_dat(di); +end + +[engine,loglik]=enter_evidence(engine,evidence); + +%Get list of nodes that are children, grandchildren, etc. of intervened nodes +%int_nodes contains the list of these children nodes +int_nodes = zeros(1,nnodes); +%new_nodes is just a temporary array to know when to keep looking +new_nodes = zeros(1,nnodes); +for i = 1:nnodes + if !isempty(evidence{i}); + new_nodes(i) = 1; + int_nodes(i) = 1; + end +end +while sum(new_nodes) != 0 + new_nodes_old = new_nodes; + new_nodes = zeros(1,nnodes); + for i = 1:nnodes + if new_nodes_old(i) == 1 + for j = 1:nnodes + if int_nodes(j) == 0 + if bnet.dag(i,j) == 1, + new_nodes(j) = 1; + end + end + end + end + end + for i = 1:nnodes + if new_nodes(i) == 1; + int_nodes(i) = 1; + end + end +end + + +%Open output file. +filename = strcat(pre,'parameters_ev.txt'); +fileID = fopen(filename,'w'); + +for i = 1:nnodes + for j = 1:nnodes + if strcmp(labelsold{i},labels{j}); + nodeid = j; + break + end + end + %check to see if this is a node impacted by intervention + if int_nodes(nodeid) == 1 + %%%Print the name of the node + fprintf(fileID,'%s\n',labels{nodeid}); + predict = marginal_nodes(engine,nodeid); + if isempty(evidence{nodeid}) + %%%Print the type of node + if bnet.node_sizes(nodeid) == 1; + line = 'Continuous parameters considering intervention:\n'; + fprintf(fileID,line); + %line = 'Mean and standard deviation of Gaussian distribution\n'; + %fprintf(fileID,line); + adj_mu = predict.mu*stdevs{nodeid}+means{nodeid}; + adj_sigma = stdevs{nodeid}*predict.Sigma; + fprintf(fileID,'%6.4f\t%6.4f\n\n',adj_mu,adj_sigma); + else + line = 'Probability of states considering intervention:\n'; + fprintf(fileID,line); + nodeid2 = 0; + for k = 1:ndisc_nodes, + if strcmp(levels{k,1},labels{nodeid}), + nodeid2 = k; + break + end + end + for j = 1:bnet.node_sizes(nodeid), + %%%For discrete nodes, the state and the percent of that state +% fprintf(fileID,'%i\t%6.4f\n',levels{nodeid2,j+1},predict.T(j)); + fprintf(fileID,'%s\t%6.4f\n',levels{nodeid2,j+1},predict.T(j)); + end; + fprintf(fileID,'\n') + end + else + if bnet.node_sizes(nodeid) == 1; + line = 'Intervention on this node assigned the following value:\n'; + fprintf(fileID,line); + adj_mu = ev_dat(nodeid)*stdevs{nodeid}+means{nodeid}; + fprintf(fileID,'%6.4f\n\n',adj_mu); + else + nodeid2 = 0; + for k = 1:ndisc_nodes, + if strcmp(levels{k,1},labels{nodeid}), + nodeid2 = k; + break + end + end + line = 'Intervention on this node assigned the following state:\n'; + fprintf(fileID,line); + state_ev = uint16(ev_dat(nodeid)); +% fprintf(fileID,'%i\n\n',levels{nodeid2,state_ev+1}); + fprintf(fileID,'%s\n\n',levels{nodeid2,state_ev+1}); + end + end + end +end + + + +fclose(fileID); + +end + |
