-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdishonest_casino.m
61 lines (58 loc) · 2.24 KB
/
dishonest_casino.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
% training data for the occasionally dishonest casino
rng(224); % standardise seed
% b1 = string of die rolls
% h1 = sequence of hidden states. 1=fair, 2=loaded
b1 = [6,4,3,4,3,1,2,1,2,2,3,1,6,6,3,3,4,6,4,2,6,4,3,5,1,2,6,6,6,1,3,4,6,1,1,2,6,6,6,5,4,2,4,5,2,1,2,2,3,4];
h1 = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1];
%split into fair and loaded arrays
b1_prav = [];
b1_neprav = [];
for i = 1:length(b1)
switch h1(1,i)
case 1
b1_prav = [b1_prav,b1(i)];
case 2
b1_neprav = [b1_neprav,b1(i)];
otherwise
assert(false)
end
end
%split h1 into dimers
h1_dimers = cell(1,length(h1)-1);
for i = 1:length(h1)-1
h1_dimers{i} = [h1(1,i),h1(1,i+1)];
end
%split b1 into dimers
%b1_dimers = cell(1,length(b1));
%for i = 1:length(b1)-1
% b1_dimers{i} = {b1(1,i),b1(1,i+1)};
%end
%pseudoemission calcs
[b1_prav_counts,b1_prav_elements] = groupcounts(transpose(b1_prav));
[b1_neprav_counts,b1_neprav_elements] = groupcounts(transpose(b1_neprav));
%pseudotransmission calcs
h1_dimers_mat = cell2mat(transpose(h1_dimers));
h1_dimers_mat_cat = strcat(string(h1_dimers_mat(:,1)),string(h1_dimers_mat(:,2)));
[h1_dimers_counts,h1_dimers_elements] = groupcounts(h1_dimers_mat_cat);
%[f->f,f->l;l->f;l->l]
lap_pt = [h1_dimers_counts(1),h1_dimers_counts(2);h1_dimers_counts(3),h1_dimers_counts(4)]+1; % (+1 to all for laplacian)
agg_pt = [h1_dimers_counts(1),h1_dimers_counts(2);h1_dimers_counts(3),h1_dimers_counts(4)]*10;
%[count of 1,2,3,4,5,6 for fair; count of 1,2,3,4,5,6 for loaded]
lap_pe = [transpose(b1_prav_counts);transpose(b1_neprav_counts)]+1; % (+1 to all for laplacian)
agg_pe = [transpose(b1_prav_counts);transpose(b1_neprav_counts)]*10;
[P,E] = hmmestimate(b1,h1,...
'Pseudotransitions',...
lap_pt,...
'Pseudoemissions',...
lap_pe);
% die rolls generated by unknown sequence of hidden states
b2 = [2,2,6,1,3,2,6,5,6,3,6,6,1,6,6,1,6,6,6,2,4,6,6,4,5,3,3,5,1,1,2,3,5,5,1,3,4,3,4,4,2,3,1,6,2,1,3,2,3,3];
P2 = [.6,.4;.4,.6];
h2_p1 = hmmviterbi(b2,P,E);
h2_p2 = hmmviterbi(b2,P2,E);
[aggP,aggE] = hmmestimate(b1,h1,...
'Pseudotransitions',...
agg_pt,...
'Pseudoemissions',...
agg_pe);
agg_h2_p1 = hmmviterbi(b2,aggP,aggE);