about summary refs log tree commit diff
path: root/sourcecodes/bnt-master/KPMtools/ind2subvKPM.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/KPMtools/ind2subvKPM.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/KPMtools/ind2subvKPM.m')
-rw-r--r--sourcecodes/bnt-master/KPMtools/ind2subvKPM.m57
1 files changed, 57 insertions, 0 deletions
diff --git a/sourcecodes/bnt-master/KPMtools/ind2subvKPM.m b/sourcecodes/bnt-master/KPMtools/ind2subvKPM.m
new file mode 100644
index 00000000..da178c7b
--- /dev/null
+++ b/sourcecodes/bnt-master/KPMtools/ind2subvKPM.m
@@ -0,0 +1,57 @@
+function sub = ind2subvKPM(siz, ndx)
+% IND2SUBV Like the built-in ind2sub, but returns the answer as a row vector.
+% sub = ind2subv(siz, ndx)
+%
+% siz and ndx can be row or column vectors.
+% sub will be of size length(ndx) * length(siz).
+%
+% Example
+% ind2subv([2 2 2], 1:8) returns
+%  [1 1 1
+%   2 1 1
+%   ...
+%   2 2 2]
+% That is, the leftmost digit toggle fastest.
+%
+% See also SUBV2IND
+
+n = length(siz);
+
+
+if  n==0
+  sub = ndx;
+  return;
+end  
+
+if all(siz==2)
+  sub = dec2bitv(ndx-1, n);
+  sub = sub(:,n:-1:1)+1;
+  return;
+end
+
+cp = [1 cumprod(siz(:)')];
+ndx = ndx(:) - 1;
+sub = zeros(length(ndx), n);
+for i = n:-1:1 % i'th digit
+  sub(:,i) = floor(ndx/cp(i))+1;
+  ndx = rem(ndx,cp(i));
+end
+
+
+
+%%%%%%%%%%
+
+function bits = dec2bitv(d,n)
+% DEC2BITV Convert a decimal integer to a bit vector.
+% bits = dec2bitv(d,n) is just like the built-in dec2bin, except the answer is a vector, not a string.
+% n is an optional minimum length on the bit vector.
+% If d is a vector,  each row of the output array will be a bit vector.
+
+
+if (nargin<2)
+  n=1; % Need at least one digit even for 0.
+end
+d = d(:);
+
+[f,e]=log2(max(d)); % How many digits do we need to represent the numbers?
+bits=rem(floor(d*pow2(1-max(n,e):0)),2);