-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewmatrix.m
62 lines (56 loc) · 1.97 KB
/
newmatrix.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
function [ matrix ] = newmatrix( alphasize, ctrlcount, ctrlpwr, exppwr)
%TMATRIX Produces a matrix of transition probs given the parameters
% They are: the size of the alphabet, the number of "control" pairings,
% and the strength of the control and experimental pairings (ex .5, 1)
% make sure the input is valid
if alphasize <= ctrlcount*2
print('!!!: ctrlcount is too large!')
else if alphasize
end
end
% construct the base vector for the matrix and make it the whole matrix
matrix = zeros(alphasize);
expcount = alphasize/2-ctrlcount;
for i = 1:ctrlcount
matrix(1,i) = 1;
matrix(1,i+ctrlcount) = 1-ctrlpwr;
end
for i = (ctrlcount*2+1):(ctrlcount*2+expcount)
matrix(1,i) = 1;
matrix(1,i+expcount) = 1-exppwr;
end
for i = 2:alphasize
matrix(i,:) = matrix(1,:);
end
% correct certain rows for pairings
for i = 1:ctrlcount
matrix(i,i+ctrlcount) = ctrlpwr;
end
for i = (ctrlcount*2+1):(ctrlcount*2+expcount)
matrix(i,i+expcount) = exppwr;
end
% transform matrix into a transition matrix
for i = 1:ctrlcount
remainder = 1-matrix(i,i+ctrlcount);
matrix(i,:) = (remainder/sum(matrix(i,:)))*matrix(i,:);
end
for i = (ctrlcount+1):(ctrlcount*2)
remainder = 1;
matrix(i,:) = (remainder/sum(matrix(i,:)))*matrix(i,:);
end
for i = (ctrlcount*2+1):(ctrlcount*2+expcount)
remainder = 1-matrix(i,i+expcount);
matrix(i,:) = (remainder/sum(matrix(i,:)))*matrix(i,:);
end
for i = (ctrlcount*2+expcount+1):alphasize
remainder = 1;
matrix(i,:) = (remainder/sum(matrix(i,:)))*matrix(i,:);
end
% correct certain rows for pairings
for i = 1:ctrlcount
matrix(i,i+ctrlcount) = ctrlpwr;
end
for i = (ctrlcount*2+1):(ctrlcount*2+expcount)
matrix(i,i+expcount) = exppwr;
end
end