about summary refs log tree commit diff
path: root/sourcecodes/bnt-master/graph/triangulate.m
diff options
context:
space:
mode:
authorziejd22017-09-28 15:04:40 -0500
committerziejd22017-09-28 15:04:40 -0500
commit8070dc963753142bb86c4ed698d91fd623ed28e7 (patch)
treed0f6dd8fc46a49b819aa55c1a90faa14d8448883 /sourcecodes/bnt-master/graph/triangulate.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/bnt-master/graph/triangulate.m')
-rw-r--r--sourcecodes/bnt-master/graph/triangulate.m42
1 files changed, 42 insertions, 0 deletions
diff --git a/sourcecodes/bnt-master/graph/triangulate.m b/sourcecodes/bnt-master/graph/triangulate.m
new file mode 100644
index 00000000..8725c62e
--- /dev/null
+++ b/sourcecodes/bnt-master/graph/triangulate.m
@@ -0,0 +1,42 @@
+function [G, cliques, fill_ins] = triangulate(G, order)
+% TRIANGULATE Ensure G is triangulated (chordal), i.e., every cycle of length > 3 has a chord.
+% [G, cliques, fill_ins, cliques_containing_node] = triangulate(G, order)
+% 
+% cliques{i} is the i'th maximal complete subgraph of the triangulated graph.
+% fill_ins(i,j) = 1 iff we add a fill-in arc between i and j.
+%
+% To find the maximal cliques, we save each induced cluster (created by adding connecting
+% neighbors) that is not a subset of any previously saved cluster. (A cluster is a complete,
+% but not necessarily maximal, set of nodes.)
+
+MG = G;
+n = length(G);
+eliminated = zeros(1,n);
+cliques = {};
+for i=1:n
+  u = order(i);
+  U = find(~eliminated); % uneliminated
+  nodes = myintersect(neighbors(G,u), U); % look up neighbors in the partially filled-in graph
+  nodes = myunion(nodes, u); % the clique will always contain at least u
+  G(nodes,nodes) = 1; % make them all connected to each other
+  G = setdiag(G,0);  
+  eliminated(u) = 1;
+  
+  exclude = 0;
+  for c=1:length(cliques)
+    if mysubset(nodes,cliques{c}) % not maximal
+      exclude = 1;
+      break;
+    end
+  end
+  if ~exclude
+    cnum = length(cliques)+1;
+    cliques{cnum} = nodes;
+  end
+end
+
+fill_ins = sparse(triu(max(0, G - MG), 1));
+
+%assert(check_triangulated(G)); % takes 72% of the time!
+
+