From 8070dc963753142bb86c4ed698d91fd623ed28e7 Mon Sep 17 00:00:00 2001 From: ziejd2 Date: Thu, 28 Sep 2017 15:04:40 -0500 Subject: 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 --- .../bnt-master/SLP/learning/learn_struct_mwst.m | 62 ++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 sourcecodes/bnt-master/SLP/learning/learn_struct_mwst.m (limited to 'sourcecodes/bnt-master/SLP/learning/learn_struct_mwst.m') diff --git a/sourcecodes/bnt-master/SLP/learning/learn_struct_mwst.m b/sourcecodes/bnt-master/SLP/learning/learn_struct_mwst.m new file mode 100644 index 00000000..8437385e --- /dev/null +++ b/sourcecodes/bnt-master/SLP/learning/learn_struct_mwst.m @@ -0,0 +1,62 @@ +function [T, score_mat] = learn_struct_mwst(data, discrete, node_sizes, node_type, scoring_fn, root) +% LEARN_STRUCT_MWST Learn an oriented tree using the MSWT algorithm +% T = learn_struct_mwst(data, discrete, node_sizes, node_type, scoring_fn, root) +% +% Input : +% data(i,m) is the node i in the case m, +% discrete = [ 1 if discret-node 0 if not ], +% node_sizes = 1 if gaussian node, +% node_type = {'tabular','gaussian',...}, +% score = 'bic' (for complete data and any node types) or 'mutual_info' (tabular nodes), +% root is the futur root-node of the tree T. +% +% Output : +% T = adjacency matrix of the tree +% +% V1.2 : 17 feb 2003 (O. Francois - francois.olivier.c.h@gmail.com, Ph. Leray - philippe.leray@univ-nantes.fr) +% +% +% See Chow&Liu 1968 for the original algorithm using Mutual Information scoring. +% Or Heckerman 1994. + +if nargin <4 + error('Requires at least 4 arguments.') +end + +if nargin == 4 + scoring_fn='bic'; root=1; +end; + +if nargin == 5 + root=1; +end; + + +N=size(data,1); +score_mat=zeros(N,N); + +switch scoring_fn +case 'bic', + for i=1:(N-1) + score2 = score_family(i, [], node_type{i}, scoring_fn, node_sizes, discrete, data,[]); + for j=(i+1):N + score1 = score_family(i, [j], node_type{i}, scoring_fn, node_sizes, discrete, data,[]); + score = score2-score1; + score_mat(i,j)=score; + score_mat(j,i)=score; + end + end +case 'mutual_info', + for i=1:(N-1) + for j=(i+1):N + score_mat(i,j)= -mutual_info_score(i,node_sizes(i),j,node_sizes(j),data); + score_mat(j,i)=score_mat(i,j); + end + end +otherwise, + error(['unrecognized scoring fn ' scoring_fn]); +end + +G = minimum_spanning_tree(score_mat); +T = mk_rooted_tree(G, root); +T=full(T); \ No newline at end of file -- cgit 1.4.1