forked from ilya-shmulevich/pbn-matlab-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbnAsparse.m
31 lines (23 loc) · 907 Bytes
/
bnAsparse.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
function [A,Avec] = bnAsparse(F,varF,nv)
% [A,Avec] = bnAsparse(F,varF,nv) - sparse state transition matrix of a Boolean network
% This function creates the state transition matrix A of a Boolean network,
% stored as a sparse matrix. An optional output is A in vector form (Avec)
% The inputs F, varF and nv are the same as for PBNs (see pbnA)
% Functions used: bnNextState.m
% Ilya Shmulevich; 9/9/02
% Modified May 13, 2003 by HL.
n = length(nv); % number of genes
j = zeros(2^n,1);
bits = [n:-1:1];
b = 2.^(bits'-1); % Used to convert binary number to decimal numbers.
for i = 1:2^n
x = bitget(i-1,bits); % The state (minus one) as binary number.
y = bnNextState(x,F,varF,nv);
d = y*b + 1; % Output as a decimal number.
j(i) = d;
end % for i = 1:2^n
i = [1:2^n]';
A = sparse(i,j,1,2^n,2^n);
if nargout == 2
Avec = j;
end