about summary refs log tree commit diff
path: root/sourcecodes/bnt-master/graph/scc.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/scc.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/scc.m')
-rw-r--r--sourcecodes/bnt-master/graph/scc.m64
1 files changed, 64 insertions, 0 deletions
diff --git a/sourcecodes/bnt-master/graph/scc.m b/sourcecodes/bnt-master/graph/scc.m
new file mode 100644
index 00000000..9a2e8b9d
--- /dev/null
+++ b/sourcecodes/bnt-master/graph/scc.m
@@ -0,0 +1,64 @@
+function [c,v] = scc(a,tol)
+
+%       Finds the strongly connected sets of vertices
+%                in the DI-rected G-raph of A
+%          c = 0-1 matrix displaying accessibility
+%          v = displays the equivalent classes
+%
+% v(i,j) is the j'th member of the i'th equiv class (0 padded)
+%
+% http://www.math.wsu.edu/math/faculty/tsat/matlab.html
+
+[m,n] = size(a);
+if m~=n 'Not a Square Matrix', break, end
+b=abs(a); o=ones(size(a)); x=zeros(1,n);
+msg='The Matrix is Irreducible !'; v='Connected Directed Graph !';
+if (nargin==1) tol=n*eps*norm(a,'inf'); end
+
+% Create a companion matrix
+c = b>tol*o;
+if (c==o)
+  %  msg, break
+  v = 1:length(a);
+  return
+end
+
+
+% Compute accessibility in at most n-step paths
+for k=1:n
+  for j=1:n
+    for i=1:n
+      % If index i accesses j, where can you go ?
+      if c(i,j) > 0  c(i,:) = c(i,:)+c(j,:); end
+    end
+  end
+end
+% Create a 0-1 matrix with the above information
+c>zeros(size(a)); c=ans; if (c==o) msg, break, end
+
+% Identify equivalence classes
+d=c.*c'+eye(size(a)); d>zeros(size(a)); d=ans;
+v=zeros(size(a));
+for i=1:n find(d(i,:)); ans(n)=0; v(i,:)=ans; end
+
+% Eliminate displaying of identical rows
+i=1;
+while(i<n)
+  for k=i+1:n
+    if v(k,1) == v(i,1)
+      v(k,:)=x;
+    end
+  end
+  i=i+1;
+end
+j=1;
+for i=1:n
+  if v(i,1)>0
+    h(j,:)=v(i,:);
+    j=j+1;
+  end
+end
+v=h;
+
+
+