-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_ideal_entropy_v2.m
185 lines (93 loc) · 4.53 KB
/
get_ideal_entropy_v2.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
function [ideal_entropy] = get_ideal_entropy_v2(trial_presentations)
%trial_presentations contains the combination of cards presented on each
%trial
%this variables is extracted from the task behavioral output file
total_rule_list = {'S1'; 'T1'; 'C1'; 'Q1'; 'B2'; 'Y2'; 'G2'; 'M2'; 'L3'; 'P3'; 'S3'; 'R3'};
%dim1 = shape, dim2 = color, dim3 = texture;
curr_prob = 1 / numel(total_rule_list);
curr_prob_distr(1:numel(total_rule_list)) = curr_prob;
start_entropy = -sum(curr_prob_distr.*(log2(curr_prob_distr))); %calculates Shannon entropy based on initial conditions
%initial conditions means the probability distribution containing 12
%equally probable rules
ideal_entropy = zeros(1, size(trial_presentations, 1));
if exist('curr_buffer') == 1
clear curr_buffer;
end
for i = 1:1
for ii = 1:4
curr_trial = trial_presentations{i, ii}(1:3);
for j = 1:numel(curr_trial)
curr_trial_all(ii).bmp{j} = sprintf('%s%d', curr_trial(j), j);
end
end
%%
%on the first trial, choice is random, as all the choices reduce the
%uncertainty equally
r = randi([1, 4], 1, 1);
curr_chosen_rule = curr_trial_all(r).bmp;
for x = 1:numel(curr_chosen_rule)
curr_buffer(x, :) = curr_chosen_rule{x};
end
end
items_left = numel(total_rule_list) - size(curr_buffer, 1); %adjust the number of remaining rules by subtracting the 3 rules tested on the first trial
curr_prob = 1 / items_left;
curr_prob_distr = [];
curr_prob_distr(1:items_left) = curr_prob; %calculates the probability distribution after the 1st trial
ideal_entropy(i) = start_entropy;
%%
%
for i = 2:size(trial_presentations, 1) %calculates the overlap between the buffer and each of the 4 cards presented on i-th trial
if min(ideal_entropy) >= 0
for ii = 1:4
curr_trial = trial_presentations{i, ii}(1:3);
for j = 1:numel(curr_trial)
curr_trial_all(ii).bmp{j} = sprintf('%s%d', curr_trial(j), j);
end
for xx = 1:numel(curr_trial_all)
curr_rule = curr_trial_all(xx).bmp';
overlap(xx) = 0;
for xxx = 1:numel(curr_rule)
curr_subrule = curr_rule{xxx};
for y = 1:size(curr_buffer, 1)
if strcmp(curr_buffer(y, :), curr_subrule) == 1
overlap(xx) = overlap(xx) + 1;
end
end
end
end
end
min_overlap = find(overlap == min(overlap)); %as this function computes the entropy based on the ideal observer, this line
%finds the card with the MINIMAL overlap w buffer, which is selected as
%an ideal observer choice on this trial. choosing the card with minimal
%overlap w buffer allows for the most efficient search through remaining
%rules
if numel(min_overlap) > 1 %if more than one card contains minimal overlap, the chosen card on i-th trial is selected randomly
%between the set of cards with minimal overlap
r = randi([1, numel(min_overlap)], 1, 1);
min_overlap = min_overlap(r);
curr_chosen_card = curr_trial_all(min_overlap).bmp;
elseif numel(min_overlap) == 1
curr_chosen_card = curr_trial_all(min_overlap).bmp;
end
%%
%loops through the 3 rules tested on i-th trial and checks if a given
%rule is not already in the buffer, it gets added
for iii = 1:numel(curr_chosen_card)
curr_subfeature = curr_chosen_card{iii};
new_item = 0;
for ix = 1:size(curr_buffer, 1)
if strcmp(curr_buffer(ix, :), curr_subfeature) == 1
new_item = new_item + 1;
end
end
if new_item == 0
curr_buffer(size(curr_buffer, 1)+1, :) = curr_subfeature;
end
end
items_left = numel(total_rule_list) - size(curr_buffer, 1); %calculates the number of remaining rules
curr_prob = 1 / items_left;
curr_prob_distr = [];
curr_prob_distr(1:items_left) = curr_prob; %creates the probability distribution of remaining rules
ideal_entropy(i) = -sum(curr_prob_distr.*(log2(curr_prob_distr))); %calculates the Shannon entropy on i-th trial
end
end