-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdemo5.m
139 lines (115 loc) · 2.23 KB
/
demo5.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
127
128
129
130
131
132
133
134
135
136
137
138
% simulate data from chunking experiment
clear all;
%{
h.alpha = 1.5;
% load data
D = init_Ds_from_data('exp/results/subway8_randsg');
for i = 1:length(D)
i
[samples, post] = sample(D(i), h, 10);
for j = 1:length(samples)
H(i,j) = samples(j);
P(i,j) = post(j);
end
end
save demo5_2.mat;
%}
load demo5_2.mat;
%{
% hack sanity check -- make them all like D(1)
for i = 1:length(D)
D(i) = D(1);
H(i,:) = H(1,:);
P(i,:) = P(1,:);
end
%}
% plot 5 per subject
%{
figure;
k = 5;
l = min(length(D), 10);
for i = 1:l
post = P(i,:);
[~,I] = maxk(post, k); % MAP k
%I = length(post) - k : length(post); % last k
for j = 1:k
subplot(l,k, (i-1)*k+j);
plot_H(H(i,I(j)), D(i));
if j == ceil(k/2);
%ylabel(D(i).name);
title(D(i).name);
end
set(gca, 'xtick', []);
set(gca, 'ytick', []);
end
end
%}
% plot all subjects
figure;
rows = 5;
cols = 8;
s = 1;
for i = 1:rows
for j = 1:cols
if s > length(D)
continue;
end
post = P(s,:);
[~,I] = max(post); % MAP
subplot(rows, cols, s);
plot_H(H(s,I), D(s));
set(gca, 'xtick', []);
set(gca, 'ytick', []);
s = s + 1;
end
end
% compute stats
% TODO dedupe w/ analyze_data.m
% for subway 10
start = [6 7 3 1 2 8];
goal = [1 2 8 6 7 3];
nexts = [
5 7;
8 6;
2 4;
2 10;
1 3;
9 7];
% for subway 8
start = [5 3 6];
goal = [1 7 2];
nexts = [
4 6;
2 4;
7 5
];
figure;
for t = 1:length(start)
s = start(t);
g = goal(t);
clear move;
for i = 1:length(D)
[~,I] = maxk(P(i,:), 1);
[path, hpath] = hbfs(s, g, H(i,I(1)), D(i));
move(i) = path(2);
end
% from analyze_data.m
m = nexts(t,:);
c1 = sum(move == m(1)); % count 1
c2 = sum(move == m(2)); % count 2
d = abs(c1 - c2);
n = length(D);
p = 2 * binopdf((n - d) / 2, n, 0.5);
subplot(2,3,t);
bar(1:2, [c1 c2]);
xticklabels({num2str(m(1)), num2str(m(2))});
title(sprintf('%d -> %d: p = %.3f (d = %d, n = %d)', start(t), goal(t), p, d, n));
%ylim([4 5]);
%{
if t == 1
ylabel('state chunking')
elseif t == 3
ylabel('action chunking / S-A')
end
%}
end