about summary refs log tree commit diff
path: root/BNW_parameter_learning
diff options
context:
space:
mode:
authorziejd22018-04-25 16:43:19 -0500
committerziejd22018-04-25 16:43:19 -0500
commit74b673ba4a706085201a5610b938ff98f08f641d (patch)
treecb39006ea1a39499e00dbbb0e0097087a4567031 /BNW_parameter_learning
parenta781cb1ff2e7ae6de0f686bd02cd279261485b1e (diff)
downloadBNW-74b673ba4a706085201a5610b938ff98f08f641d.tar.gz
Bug fixes, code comments, and minor changes
Diffstat (limited to 'BNW_parameter_learning')
-rw-r--r--BNW_parameter_learning/Predictmultiple.m22
-rw-r--r--BNW_parameter_learning/Predictmultipleintervention.m107
-rw-r--r--BNW_parameter_learning/checkDiscreteNodes.m2
-rw-r--r--BNW_parameter_learning/checkStructure.m8
-rw-r--r--BNW_parameter_learning/drawFigure.m191
-rw-r--r--BNW_parameter_learning/drawFigureM.m11
-rw-r--r--BNW_parameter_learning/parameterLearning.m31
-rw-r--r--BNW_parameter_learning/prepareInput.m21
-rw-r--r--BNW_parameter_learning/readInput.m3
-rw-r--r--BNW_parameter_learning/readInputData.m4
-rw-r--r--BNW_parameter_learning/readInputStructure.m3
-rw-r--r--BNW_parameter_learning/runBN_initial.m15
-rw-r--r--BNW_parameter_learning/standardizeData.m9
-rw-r--r--BNW_parameter_learning/writeParameters.m5
-rw-r--r--BNW_parameter_learning/writeParameters_ev.m6
-rw-r--r--BNW_parameter_learning/writeParameters_int.m6
16 files changed, 245 insertions, 199 deletions
diff --git a/BNW_parameter_learning/Predictmultiple.m b/BNW_parameter_learning/Predictmultiple.m
index 781c64a4..019488a3 100644
--- a/BNW_parameter_learning/Predictmultiple.m
+++ b/BNW_parameter_learning/Predictmultiple.m
@@ -1,4 +1,18 @@
 function Predictmultiple(pre)

+% Predictmultiple is used when predicting the impact of entering

+%    evidence on the network. The 'multiple' part refers to 

+%    it working when evidence for multiple nodes is entered.

+%

+% The input is 'pre'-- the prefix for the network and data

+%      in BNW. It reads information from several files from BNW. 

+%

+% The output is ???net_figure_new.txt. It also calls 

+%      writeParameters_ev to write the parameter file.

+%

+% It is called by the run_octave_evd file in the 'sourcecodes' directory.

+

+

+

 dfile=strcat(pre,'structure_input.txt');

 sfile=dfile;

 dfile=strcat(pre,'continuous_input.txt');

@@ -28,14 +42,14 @@ mapfile = strcat(pre,'map.txt');
 fmap = fopen(mapfile,'r');

 for i=1:nnodes

     buffer = fgetl(mapfile);

-    temp = cell(1,4);

-    for j=1:4

+    temp = cell(1,3);

+    for j=1:3

         [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});

+    means_orig{i} = str2num(temp{3});

+    stdevs_orig{i} = str2num(temp{2});

 end

 fclose(fmap);

 

diff --git a/BNW_parameter_learning/Predictmultipleintervention.m b/BNW_parameter_learning/Predictmultipleintervention.m
new file mode 100644
index 00000000..7e6140a9
--- /dev/null
+++ b/BNW_parameter_learning/Predictmultipleintervention.m
@@ -0,0 +1,107 @@
+function Predictmultipleintervention(pre)
+% Predictmultipleintervention is used when predicting the impact of
+%    intervention on the network. The 'multiple' part refers to 
+%    it working when intervention for multiple nodes is entered.
+%
+% The input is 'pre'-- the prefix for the network and data
+%      in BNW. It reads information from several files from BNW. 
+%
+% The output is ???net_figure_new.txt. It also calls 
+%      writeParameters_int to write the parameter file.
+%
+% It is called by the run_octave_inv file in the 'sourcecodes' directory.
+
+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');
+
+fvarnamefile=strcat(pre,'varname.txt');
+
+varfile = fopen(fvarnamefile,'r');
+
+Std_flag=true;
+[labels,cases,bnet]=readInput(dfile,sfile,nnodes,Std_flag);
+
+[bnet]=parameterLearning(bnet,cases);
+
+fvarfile=strcat(pre,'var.txt');
+fvar = fopen(fvarfile,'r');                           
+select_var_new = fscanf(fvar,'%d');
+
+nm = numel(select_var_new);
+
+varlabels = cell(1,nm);
+varbuffer = fgetl(varfile);    %get header line as a string
+for j=1:nm
+    [varnext,varbuffer] = strtok(varbuffer);
+    varlabels{j} = varnext;
+    for i=1:nnodes    
+        if strcmp(varlabels{j},labels{i})
+            select_var_new(j)=i;
+        end
+     end    
+    
+end
+
+
+
+
+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,3);
+    for j=1:3
+        [next,buffer] = strtok(buffer);
+        temp{j} = next;
+    end
+    labels_orig{i} = temp{1};
+    means_orig{i} = str2num(temp{3});
+    stdevs_orig{i} = str2num(temp{2});
+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,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/BNW_parameter_learning/checkDiscreteNodes.m b/BNW_parameter_learning/checkDiscreteNodes.m
index 7b2a695f..919128e4 100644
--- a/BNW_parameter_learning/checkDiscreteNodes.m
+++ b/BNW_parameter_learning/checkDiscreteNodes.m
@@ -7,7 +7,9 @@ function [ ] = checkDiscreteNodes( bnet, cases)
     %   bnet: BNT bnet

     %   cases: cell array of data

     %

+% checkDiscreteNodes is called by readInput.m

 %

+

 node_sizes = bnet.node_sizes;

 dnodes = bnet.dnodes;

 ndisc = size(dnodes,2);

diff --git a/BNW_parameter_learning/checkStructure.m b/BNW_parameter_learning/checkStructure.m
index fc72e4b7..104e39e1 100644
--- a/BNW_parameter_learning/checkStructure.m
+++ b/BNW_parameter_learning/checkStructure.m
@@ -1,7 +1,7 @@
 function [ labels, cases, dag, node_sizes, ord_flag ] = checkStructure(labels, cases, dag, node_sizes)

-    %checkStructure Check to see if nodes are sorted correctly.  They must be

+    %checkStructure Check to see if nodes are sorted correctly.  Nodes must be

     %   in topological order (i.e., parents before children) before parameter

-    %   learning can take place.

+    %   learning can take place. This function performs this sorting.

     %

     %Input and output have the same meaning.  The output has just been

     %topologically ordered.

@@ -9,6 +9,10 @@ function [ labels, cases, dag, node_sizes, ord_flag ] = checkStructure(labels, c
     %   cases = cell array with the data.

     %   dag = matrix with the strucutre of the network.

     %   node_sizes = vector with the size of each node.

+%

+%   checkStructure is called by readInput.m    

+

+

 

 %make connections array

 %count how big you need the connections array to be

diff --git a/BNW_parameter_learning/drawFigure.m b/BNW_parameter_learning/drawFigure.m
index fa963a4b..599d8f3b 100644
--- a/BNW_parameter_learning/drawFigure.m
+++ b/BNW_parameter_learning/drawFigure.m
@@ -1,186 +1,17 @@
-function [] = drawFigure(nnodes,bnet,labels,filename,cases,stdevs,means,selectvar,selectdata)

+function [] = drawFigure(nnodes,bnet,labels,filename,cases,stdevs,means)

 %drawFigure writes the parameters and data that are needed to draw the

-%structure of a Bayesian network.

-

-

-if nargin < 8,

-    drawFigureNoEv(nnodes,bnet,labels,filename,cases,stdevs,means);

-else

-    drawFigureEv(nnodes,bnet,labels,filename,cases,stdevs,means,selectvar,selectdata);

-end;

-

-end

-

-

-

-function [] = drawFigureEv(nnodes,bnet,labels,filename,cases,stdevs,means,selectvar,selectdata)

-%Function to use if there is no entered evidence. 

-%         

+%structure of a Bayesian network for BNW.

+% This is the function that is called to create the initial

+%   net_figure file for the network (before evidence or intervention).

 %

-%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

-

-A=cell2mat(cases');

-Amax=max(A);

-Amin=min(A);

-

-

-evidence = cell(1,nnodes);

-engine = jtree_inf_engine(bnet);

-

-evidence{selectvar}=selectdata;

-

-[engine,loglik]=enter_evidence(engine,evidence);

-

-%Open the file, and write the nodes to a file.

-fileID = fopen(filename,'w');

-

-%%%%Evidence node

-fprintf(fileID,'%i\n',selectvar);

-%%% 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)

-

-x = x*x_dim;

-y = y*y_dim;

-for i = 1:nnodes,

-%%% The name and X- and Y-positions of each node

-    fprintf(fileID,'%s\t%i\t%i\n',labels{i},round(x(i)),round(y(i)));

-end

-

-%Get the number of parents and children for each node.

-num_par = zeros(1,nnodes);

-%For parents, sum down columns

-for i = 1:nnodes,

-    for j = 1:nnodes,

-        if bnet.dag(j,i) == 1,

-            num_par(i) = num_par(i) + 1;

-        end

-    end

-end

-num_child = zeros(1,nnodes);

-for i = 1:nnodes,

-    for j = 1:nnodes,

-        if bnet.dag(i,j) == 1,

-            num_child(i) = num_child(i) + 1;

-        end

-    end

-end

-

-

-for i = 1:nnodes,

-    %%% The name and type of each node (1=continuous, the number of states

-    %%% if it is discrete

-    fprintf(fileID,'%s\t%i\n',labels{i},bnet.node_sizes(i));

-    %%% The size of the node, I am going to keep them 

-    %%% 250(width) by 150(height) for now

-    %Could modify this to change the width based on the length of the node

-    %name

-    fprintf(fileID,'%i\t%i\n',250,150);

-    %%% The number of parents of the node, and the parents

-    if num_par(i) == 0;

-        %%% If no parents:

-        fprintf(fileID,'%i\n',num_par(i));

-    else

-        parents = zeros(1,num_par(i));

-        k = 1;

-        for j = 1:nnodes,

-           if bnet.dag(j,i) == 1,

-             parents(1,k) = j;

-             k = k + 1;

-           end

-        end

-        format = '%i\t';

-        for j = 1:num_par(i)-1,

-            format = strcat(format,'%i\t');

-        end

-        format = strcat(format,'%i\n');

-        %%%If there are parents:

-        fprintf(fileID,format,num_par(i),parents(1,:));

-    end

-    

-    

-    %%% The number of children of the node, and the children

-    if num_child(i) == 0;

-        %%% If no children:

-        fprintf(fileID,'%i\n',num_child(i));

-    else

-        children = zeros(1,num_child(i));

-        k = 1;

-        for j = 1:nnodes,

-           if bnet.dag(i,j) == 1,

-             children(1,k) = j;

-             k = k + 1;

-           end

-        end

-        format = '%i\t';

-        for j = 1:num_child(i)-1,

-            format = strcat(format,'%i\t');

-        end

-        format = strcat(format,'%i\n');

-        %%%If there are parents:

-        fprintf(fileID,format,num_child(i),children(1,:));

-    end

-    

-    predict = marginal_nodes(engine,i);

-    if isempty(evidence{i})

-      if bnet.node_sizes(i) ~= 1,

-        for j = 1:bnet.node_sizes(i),

-            %%%For discrete nodes, the state and the percent of that state

-            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

-            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;

-    else

-      fprintf(fileID,'%6.4f\t%6.4f\n',selectdata,1);

-    end

-    

-end

-%fprintf(fileID,'%s\t %\n',labels_temp{:});

-

-

-fclose(fileID);

-

-end

-

-

-

-

-

-

-function [] = drawFigureNoEv(nnodes,bnet,labels,filename,cases,stdevs,means)

-%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

+% The output is the file specified by 'filename'.

+%  For BNW, this file is called: ???net_figure.txt

+%    where ??? is the prefix.

+% 

+% drawFigure is called by runBN_intial.m

+%

+

 A=cell2mat(cases');

 Amax=max(A);

 Amin=min(A);

diff --git a/BNW_parameter_learning/drawFigureM.m b/BNW_parameter_learning/drawFigureM.m
index 9aa77d35..0e0d9b6e 100644
--- a/BNW_parameter_learning/drawFigureM.m
+++ b/BNW_parameter_learning/drawFigureM.m
@@ -1,6 +1,15 @@
 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

+%structure of a Bayesian network after adding evidence or intervention

+%It creates the net_figure_new file after evidence/intervetion.

+%

+% The output file is specified by 'filename'.

+%   For BNW, the file is named ???net_figure_new.txt

+%       where ??? is the prefix.

+%

+% drawFigureM is called by Predictmultiple.m and Predictmultipleintervention.m

+

+

 

 fileID = fopen(filename,'w');

 

diff --git a/BNW_parameter_learning/parameterLearning.m b/BNW_parameter_learning/parameterLearning.m
index d4b67c87..414ffe6c 100644
--- a/BNW_parameter_learning/parameterLearning.m
+++ b/BNW_parameter_learning/parameterLearning.m
@@ -1,5 +1,14 @@
 function [ bnet ] = parameterLearning( bnet,cases,engine_name )

 %parameterLearning Do parameter learning and inference

+% It returns the bnet with parameters learned from the data in cases.

+% 

+% This is very basic now. It could be modified to use different engine

+%  types in the future. Now, I always use the 'jtree_inf_engine'.

+% 

+%

+% parameterLearning is called by runBN_initial.m, 

+%   Predictmultiple.m, and Predictmultipleintervention.m

+

 

 %engine is an optional argument

 if nargin < 3

@@ -15,3 +24,25 @@ end
 

 end

 

+function [ bnet ] = getParams( bnet, cases )

+%getParams Code to initialize CPT and do parameter learning.

+%This will be very basic for now.  I can add more options later.

+%

+

+dnodes = bnet.dnodes;

+cnodes = bnet.cnodes;

+nnodes = size(dnodes,2)+size(cnodes,2);

+

+%make dnodes tabular_CPT

+for i = 1:size(dnodes,2)

+    bnet.CPD{dnodes(i)} = tabular_CPD(bnet,dnodes(i));

+end

+

+for i = 1:size(cnodes,2)

+    bnet.CPD{cnodes(i)} = gaussian_CPD(bnet,cnodes(i));

+end

+

+bnet = learn_params(bnet,cases);

+

+

+end

diff --git a/BNW_parameter_learning/prepareInput.m b/BNW_parameter_learning/prepareInput.m
index 28a06c15..84d2ae17 100644
--- a/BNW_parameter_learning/prepareInput.m
+++ b/BNW_parameter_learning/prepareInput.m
@@ -39,6 +39,8 @@ function  [ ] = prepareInput( pre )
    %    8-12) ???ban.txt, ???white.txt, ???k.txt, ???thr.txt, and
    %          ???parent.txt: Files with default values for structure learning. 
    %
+   % It is called by the run_prep_input script in the 'sourcecodes' directory.
+
 
 %  open file for input, include error handling
 dfile=strcat(pre,'continuous_input_orig.txt');
@@ -81,28 +83,36 @@ for j = 1:nnodes
    levels{j} = size(states{j},1);
 end
 
+reason = cell(1,nnodes);
 %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;
+        reason{j} = "It was determined to be discrete because there are a small number (<4) of possible values.";
         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;
+       reason{j} = "It was determined to be continuous because there are a large number of possible values compared to the number of cases.";
+       continue
     % If there are more than twenty unique values,
     %      I will assume that the node is continuous.
     elseif levels{j} > 20;
        levels{j} = 1;
+       reason{j} = "It was determined to be continuous because there are many (>20) possible values.";
+       continue
     % Otherwise, I will scan through the individual values.
     % If any of the values contain a '.', I will assume it is continuous.
     else
+       reason{j} = "It was determined to be discrete by default.";
        period_test = 0;
        column = data(:,j);
        k = 1;
        while period_test == 0 
            period_test = sum(cell2mat(strfind(column(k),".")));
            if period_test != 0;
+              reason{j} = "This variable was determined to be continuous because there were several possible values and at least one value contained a period(.).";
               levels{j} = 1;
            end
            k++;
@@ -131,6 +141,7 @@ if max_disc > min_cont
   labels_old = labels;
   data_old = data;
   states_old = states;
+  reason_old = reason;
   new_order = {};
   for i=1:nnodes
     if levels_old{i} > 1
@@ -145,10 +156,12 @@ if max_disc > min_cont
   labels = {};
   levels = {};
   states = {};
+  reason = {};
   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}};
+    reason{i} = reason_old{new_order{i}};
     for j=1:ncases
       data{j,i} = data_old{j,new_order{i}};
     end
@@ -228,19 +241,21 @@ 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,'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});
+       fprintf(dout,'%s is a continuous variable.\n',labels{i});
+       fprintf(dout,'%s\n',reason{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,'%s is a discrete variable with %i states.\n',labels{i},levels{i});
+       fprintf(dout,'%s\n',reason{i});
        fprintf(dout,'The states are: ');
        fprintf(dout,'%s ',states{i}{1:end-1});
        fprintf(dout,'%s\n\n',states{i}{end});
diff --git a/BNW_parameter_learning/readInput.m b/BNW_parameter_learning/readInput.m
index 2be0af29..f291b06d 100644
--- a/BNW_parameter_learning/readInput.m
+++ b/BNW_parameter_learning/readInput.m
@@ -15,6 +15,9 @@ function [ labels, cases, bnet, node_sizes, data,labelsold] = readInput( dfile,
     %   labels = cell array with the names of the nodes.

     %   cases = cell array with the data.

     %   bnet = BNT bayesian network with the input structure.

+    % 

+    %  readInput is called by runBN_initial.m

+

 

 if nargin < 4

     std_flag = false(1);

diff --git a/BNW_parameter_learning/readInputData.m b/BNW_parameter_learning/readInputData.m
index 2df158f9..d92ec015 100644
--- a/BNW_parameter_learning/readInputData.m
+++ b/BNW_parameter_learning/readInputData.m
@@ -26,6 +26,10 @@ function  [ labels , node_sizes, cases, data] = readInputData( dfile , nnodes )
     %     cases = cell array with the data.  The cases array is transposed

     %       in comparison with the input data to agree with the format of

     %       cell data used in BNT.

+    %

+    % readInputData is called by readInput.m

+

+

 

 %  open file for input, include error handling

 fin = fopen(dfile,'r');

diff --git a/BNW_parameter_learning/readInputStructure.m b/BNW_parameter_learning/readInputStructure.m
index 72c39f46..9d5e2056 100644
--- a/BNW_parameter_learning/readInputStructure.m
+++ b/BNW_parameter_learning/readInputStructure.m
@@ -21,6 +21,9 @@ function [ dag ] = readInputStructure( sfile, labels )
 	%  Output:

     %     dag = matrix with the structure.

 %

+%  readInputStructure is called by runBN_initial.m

+

+

 %   Read in first line of the structure file

 %  open file for input, include error handling

 fin = fopen(sfile,'r');

diff --git a/BNW_parameter_learning/runBN_initial.m b/BNW_parameter_learning/runBN_initial.m
index 43caf402..614accc5 100644
--- a/BNW_parameter_learning/runBN_initial.m
+++ b/BNW_parameter_learning/runBN_initial.m
@@ -1,4 +1,17 @@
 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');

 

@@ -21,7 +34,7 @@ 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));

+  fprintf(mapval,'%s\t%f\t%f\n',labelsold{i},s(i),m(i));

 end

 

 fprintf(mapfile,'%s',labels{1});

diff --git a/BNW_parameter_learning/standardizeData.m b/BNW_parameter_learning/standardizeData.m
index 449aa440..b7673a1a 100644
--- a/BNW_parameter_learning/standardizeData.m
+++ b/BNW_parameter_learning/standardizeData.m
@@ -1,7 +1,8 @@
 function [ cases ] = standardizeData( labels, node_sizes, cases )

 %standardizeData standardizes continuous nodes so they have a mean = 0

 %   and standard deviation = 1

-

+%

+% standardizeData is called by readInput.m

 

 nnodes = size(labels,2);

 

@@ -14,12 +15,6 @@ for i = 1:nnodes
     end

 end

 

-%write standardized data to file

-%fprintf(['Standardized data is written to file standardized_data.txt\n'])

-%fout = 'standardized_data.txt';

-%txt = sprintf([repmat('%s\t',1,size(labels,2))],labels{:});

-%dlmwrite(fout,txt,'');

-%dlmwrite(fout,cell2num(cases'),'-append','delimiter','\t');

 

 end

 

diff --git a/BNW_parameter_learning/writeParameters.m b/BNW_parameter_learning/writeParameters.m
index 0790a8e2..42b2a4ef 100644
--- a/BNW_parameter_learning/writeParameters.m
+++ b/BNW_parameter_learning/writeParameters.m
@@ -1,5 +1,10 @@
 function [] = writeParameters(pre,nnodes,bnet,labels,cases,labelsold,s,m)
 %Writes a file that contains the parameters of the network with no evidence.
+%
+% The file is called ???parameters.txt where ??? is the prefix in BNW
+%    for the network.
+%
+% writeParameters is called by runBN_intial.m
 
 
 %%Get the types of the nodes.
diff --git a/BNW_parameter_learning/writeParameters_ev.m b/BNW_parameter_learning/writeParameters_ev.m
index fc24e2e5..1f07c745 100644
--- a/BNW_parameter_learning/writeParameters_ev.m
+++ b/BNW_parameter_learning/writeParameters_ev.m
@@ -1,5 +1,11 @@
 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.
+%
+% The file is called ???parameters_ev.txt where ??? is the prefix in BNW 
+%     for the network.
+%
+% It is called by Predictmultiple.m
+
 
 %Read in original node labels to get node IDs.
 infile = strcat(pre,'continuous_input.txt');
diff --git a/BNW_parameter_learning/writeParameters_int.m b/BNW_parameter_learning/writeParameters_int.m
index ed92d593..69dcbb93 100644
--- a/BNW_parameter_learning/writeParameters_int.m
+++ b/BNW_parameter_learning/writeParameters_int.m
@@ -1,6 +1,10 @@
 function [] = writeParameters_int(pre,bnet,nnodes,labels,cases,stdevs,means,selectvar,selectdata)
 %Writes a file that contains the parameters of the network after intervention.
-
+%
+% The file is called ???parameters_ev.txt where ??? is the prefix in BNW
+%    for the network.
+%
+% writeParameters is called by Predictmultipleintervention.m
 
 %First read input file to get node labels to get node IDs.
 infile = strcat(pre,'continuous_input.txt');