-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget_t_matrix.m
54 lines (51 loc) · 1.95 KB
/
get_t_matrix.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
function T = get_t_matrix(Tangle, alpha, beta)
T = zeros(Tangle.size);
for i = 1:Tangle.size
if(Tangle.Sites(i).isTip)
T(i,i)=1;
continue
else
children = [];
% only valid if children have completed PoW
for c = Tangle.Sites(i).children
if Tangle.Sites(c).isAttached
children = [children c];
end
end
% only step to parents less than max depth
parents = Tangle.Sites(i).parents;
CW = Tangle.Sites(i).cumulativeWeight(Tangle.nCW);
dCWdt = Tangle.Sites(i).dCWdt; %Tangle.lambda;
childCWs = zeros(1,length(children));
childdCWdts = zeros(1,length(children));
for j = 1:length(children)
childCWs(j) = Tangle.Sites(children(j)).cumulativeWeight(Tangle.nCW);
childdCWdts(j) = Tangle.Sites(children(j)).dCWdt;
end
if isempty(children)
for j = 1:length(parents)
T(i,parents(j)) = 1/length(parents);
end
elseif isempty(parents)
denA = exp(-alpha*(CW*ones(1, length(children))-childCWs));
denB = exp(-beta*abs(dCWdt*ones(1, length(children))-childdCWdts));
for j = 1:length(children)
numA = exp(-alpha*(CW-childCWs(j)));
numB = exp(-beta*abs(dCWdt-childdCWdts(j)));
T(i,children(j)) = numA.*numB/sum(denA.*denB);
end
else
denA = exp(-alpha*(CW*ones(1, length(children))-childCWs));
denB = exp(-beta*abs(dCWdt*ones(1, length(children))-childdCWdts));
for j = 1:length(children)
numA = exp(-alpha*(CW-childCWs(j)));
numB = exp(-beta*abs(dCWdt-childdCWdts(j)));
T(i,children(j)) = (1-Tangle.q)*numA.*numB/sum(denA.*denB);
end
for j = 1:length(parents)
T(i,parents(j)) = Tangle.q*(1/length(parents));
end
end
end
end
end