about summary refs log tree commit diff
path: root/sourcecodes/parameter_learning/readInput.m
diff options
context:
space:
mode:
authorziejd22017-09-28 15:04:40 -0500
committerziejd22017-09-28 15:04:40 -0500
commit8070dc963753142bb86c4ed698d91fd623ed28e7 (patch)
treed0f6dd8fc46a49b819aa55c1a90faa14d8448883 /sourcecodes/parameter_learning/readInput.m
parent7cc31810d53176e805532b2789955f4eedbce6bb (diff)
downloadBNW-8070dc963753142bb86c4ed698d91fd623ed28e7.tar.gz
BNW using Octave instead of Matlab.
This version of BNW should perform the same as the original version. The only difference is that it uses Octave instead of Matlab when running BayesNet Toolbox during parameter learning.

I am calling this BNW_1.02. It can be accessed at:
compbio.uthsc.edu/BNW_1.02
Diffstat (limited to 'sourcecodes/parameter_learning/readInput.m')
-rw-r--r--sourcecodes/parameter_learning/readInput.m70
1 files changed, 70 insertions, 0 deletions
diff --git a/sourcecodes/parameter_learning/readInput.m b/sourcecodes/parameter_learning/readInput.m
new file mode 100644
index 00000000..9d4959b8
--- /dev/null
+++ b/sourcecodes/parameter_learning/readInput.m
@@ -0,0 +1,70 @@
+function [ labels, cases, bnet, node_sizes, data,labelsold] = readInput( dfile, sfile, nnodes, std_flag )
+    %readInput is to be used when reading in a network with a known structure
+    %   
+    %Input:
+	%   dfile  = name of the file containing the data (required)
+    %   sfile = name of the file containing the structure (required)
+    %   nnodes = number of nodes in the network (required)
+    %   std_flag = flag for whether or not to standardize the data.
+    %   (optional-- Default is FALSE)
+    %
+    %   See readInputData.m and readInputStructure.m for description of the
+    %       format of the dfile and sfile, respectively. 
+    %
+    %Output:
+    %   labels = cell array with the names of the nodes.
+    %   cases = cell array with the data.
+    %   bnet = BNT bayesian network with the input structure.
+
+if nargin < 4
+    std_flag = false(1);
+end
+
+    
+% read in the file with the data
+[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
+    if node_sizes(i) ~= 1
+        dcount = dcount + 1;
+    end
+end
+discrete = zeros(1,dcount);
+dcount = 0;
+for i = 1:nnodes
+    if node_sizes(i) ~= 1
+        dcount = dcount + 1;
+        discrete(dcount) = i;
+    end
+end
+
+bnet = mk_bnet(dag,node_sizes,'discrete',discrete,'names',labels);
+
+%bnet.dag
+
+checkDiscreteNodes(bnet,cases);
+
+% standardize continuous data to have a mean = 0 and std = 1
+if (std_flag)
+    [cases] = standardizeData(labels,node_sizes,cases);
+end
+        
+
+end
+%  end of readInput.m
\ No newline at end of file