-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgenLightChainData.m~
126 lines (110 loc) · 2.73 KB
/
genLightChainData.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
function [totData] = genLightChainData(numTraj)
cellData = {};
cellLabels = {};
totData = struct;
curr = [];
step = 0.25;
for rep = 1:numTraj
data = [];
labels = [];
%Choose light locations
%targ = [1 1 ; 4 9 ; 9 2];
% targ(1,1) = rand * 10;
% targ(1,2) = rand * 10;
% targ(2,1) = rand * 10;
% targ(2,2) = rand * 10;
% targ(3,1) = rand * 10;
% targ(3,2) = rand * 10;
targ(1,1) = 1 + rand;
targ(1,2) = 1 + rand;
targ(2,1) = 1 + rand;
targ(2,2) = 1 + rand;
targ(3,1) = 1 + rand;
targ(3,2) = 1 + rand;
%Choose starting location
curr(1,1) = rand*10; %5;
curr(1,2) = rand*10; %0;
%order = randperm(3);
order = [1 2 3];
for ind=1:3
t = order(ind);
while(norm(curr(1,:)-targ(t,:)) > 1)
diff = targ(t,:) - curr(1,:);
if(abs(diff(1,1)) >= step)
xdiff = sign(diff(1,1)) * step;
else
xdiff = 0;
end
if(abs(diff(1,2)) >= step)
ydiff = sign(diff(1,2)) * step;
else
ydiff = 0;
end
%Determine the action
if(xdiff > 0)
if(ydiff > 0)
act = 1;
elseif(ydiff < 0)
act = 2;
else
act = 3;
end
elseif(xdiff < 0)
if(ydiff > 0)
act = 4;
elseif(ydiff < 0)
act = 5;
else
act = 6;
end
else
if(ydiff > 0)
act = 7;
elseif(ydiff < 0)
act = 8;
else
act = 9;
end
end
agentSpace(1,1) = curr(1,1) - targ(1,1);
agentSpace(2,1) = curr(1,2) - targ(1,2);
agentSpace(3,1) = curr(1,1) - targ(2,1);
agentSpace(4,1) = curr(1,2) - targ(2,2);
agentSpace(5,1) = curr(1,1) - targ(3,1);
agentSpace(6,1) = curr(1,2) - targ(3,2);
%agentSpace(3,1) = act;
data = [data agentSpace];
%data = [data [curr]'];
labels = [labels t];
curr = curr + [xdiff ydiff];
end
end
%cellData = [cellData ; {data}];
%cellLabels = [cellLabels ; {labels}];
totData(rep).obs = data;
totData(rep).true_labels = labels;
end
%Calc duration stats
% durs = [];
% i = 1;
% while(i<=T)
% currLabel = labels(i);
% currDur = 1;
% i = i+1;
%
% while(i<=T)
% nextLabel = labels(i);
%
% if(nextLabel == currLabel)
% i = i+1;
% currDur = currDur + 1;
% else
% break;
% end
% end
%
% durs = [durs currDur];
% end
% mean(durs)
% var(durs)
end