-
Notifications
You must be signed in to change notification settings - Fork 1
/
runUncertainty.m
339 lines (333 loc) · 11.3 KB
/
runUncertainty.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
% runUncertainty.m
% MATLAB script to run NoiseDiscrimination.m
% Copyright 2019 Denis G. Pelli, [email protected]
% December 10, 2019
% 646-258-7524
% Efficiency with uncertainty of 1 and 100. Also runs the ideal on the same
% conditions.
mainFolder=fileparts(mfilename('fullpath')); % Folder this m file is in.
addpath(fullfile(mainFolder,'lib')); % lib folder in that folder.
clear KbWait
clear o oo ooo
ooo={};
if IsWin
o.useNative11Bit=false;
end
% o.useFractionOfScreenToDebug=0.4; % USE ONLY FOR DEBUGGING.
% o.skipScreenCalibration=true; % USE ONLY FOR DEBUGGING.
o.isTargetFullResolution=true;
o.askForPartingComments=true;
o.isGazeRecorded=false;
o.experiment='uncertainty';
o.eccentricityXYDeg=[0 0];
o.targetHeightDeg=6;
o.contrast=-1;
o.noiseType='gaussian';
o.setNearPointEccentricityTo='fixation';
o.nearPointXYInUnitSquare=[0.5 0.5];
o.fixationBlankingRadiusReTargetHeight=0;
o.fixationBlankingRadiusReEccentricity=0;
o.targetKind='letter';
o.targetHeightDeg=4;
o.thresholdParameter='contrast';
o.flankerSpacingDeg=0.2; % Used only for fixation check.
o.observer='';
o.trialsDesired=40;
o.brightnessSetting=0.87;
o.conditionName='Sloan';
o.targetFont='Sloan';
o.minimumTargetHeightChecks=8;
o.alphabet='';
o.borderLetter='';
o.areAnswersLabeled=false;
o.getAlphabetFromDisk=false;
o.isFixationCheck=false;
o.isFixationBlankedNearTarget=true;
o.fixationOnsetAfterNoiseOffsetSecs=0.6;
o.fixationMarkDrawnOnStimulus=false;
o.isTargetFullResolution=false;
o.useFlankers=false;
o.flankerContrast=-1;
% o.printGrayLuminance=false;
% o.assessGray=true;
% o.assessLoadGamma=true;
% o.printContrastBounds=true;
o.isLuminanceRangeSymmetric=true; % False for maximum brightness.
o.desiredLuminanceFactor=1; % 1.8 for maximize brightness.
o.viewingDistanceCm=40;
o.alphabetPlacement='top'; % 'top' 'bottom' 'right' or 'left' while awaiting response.
o.counterPlacement='bottomRight';
o.instructionPlacement='bottomLeft'; % 'topLeft' 'bottomLeft'
o.brightnessSetting=0.87;
o.askExperimenterToSetDistance=true;
o.isLuminanceRangeSymmetric=true; % False for maximum brightness.
o.desiredLuminanceFactor=1; % 1.8 to maximize brightness.
o.saveSnapshot=false;
if true
% Put target at a grid of locations in rectangular area centered on fixation.
for targetKindCell={'gabor' 'letter'}
targetKind=targetKindCell{1};
MM=[100 1];
for iM=1:length(MM)
M=MM(iM);
o.showUncertainty=true;
o.uncertainParameter={'eccentricityXYDeg'};
% Uncertainty is M equally spaced positions in grid filling square.
o.uncertainDisplayDotDeg=0.5;
radiusDeg=10;
r=Screen('Rect',0);
% Create rectangle of dot locations with same aspect ratio as
% screen.
ratio=RectWidth(r)/RectHeight(r);
n=round(sqrt(ratio*M));
m=round(M/n);
s=o.targetHeightDeg;
x=(1:n)*s;
x=x-mean(x);
y=(1:m)*s;
y=y-mean(y);
list={};
for i=1:n
for j=1:m
list{end+1}=[x(i) y(j)];
end
end
o.uncertainValues={list};
M=length(o.uncertainValues{1});
o.conditionName=sprintf('%s;M=%d',targetKind,M);
o.targetFont='Sloan';
o.minimumTargetHeightChecks=8;
o.targetKind=targetKind;
switch o.targetKind
case 'gabor'
o.targetGaborPhaseDeg=0; % Phase offset of sinewave in deg at center of gabor.
o.targetGaborSpaceConstantCycles=0.75; % The 1/e space constant of the gaussian envelope in cycles of the sinewave.
o.targetGaborCycles=3; % cycles of the sinewave in targetHeight
o.targetCyclesPerDeg=nan;
o.targetGaborOrientationsDeg=[0 90]; % Orientations relative to vertical.
o.responseLabels='VH'; % One for each targetGaborOrientationsDeg.
o.alphabet='VH';
% o.areAnswersLabeled=true;
o.pThreshold=0.75;
case 'letter'
o.borderLetter='X';
o.alphabet='DHKNORSVZ'; % Sloan alphabet, excluding C
% o.saveSnapshot=true;
% o.alphabet='CDHKNORSVZ'; % As in Pelli et al. (2006)
% o.getAlphabetFromDisk=false; % No "C" on disk.
% o.pThreshold=0.64; % As in Pelli et al. (2006).
o.pThreshold=0.75;
o.areAnswersLabeled=false;
end
o.alternatives=length(o.alphabet);
o.alphabetPlacement='right'; % 'top' or 'right';
o.areAnswersLabeled=false;
o.contrast=-1;
o.viewingDistanceCm=25;
ooo{end+1}=o;
o.fixationMarkDrawnOnStimulus=false;
o.fixationOnsetAfterNoiseOffsetSecs=0.6;
o.uncertainParameter={};
o.uncertainValues={};
o.showUncertainty=false;
end
end
end
if false
% Put target at various locations on circle.
MM=[2 2 2 2 16 16];
AA=[0 45 90 135 0 0];
for iM=1:length(MM)
M=MM(iM);
a0=AA(iM);
% Sloan with uncertainty
o.conditionName='Sloan';
o.showUncertainty=true;
o.uncertainParameter={'eccentricityXYDeg'};
% Uncertainty is M equally spaced positions along a ring with radiusDeg.
o.uncertainDisplayDotDeg=0.5;
radiusDeg=10;
list=cell(1,M);
for i=1:M
a=a0+360*i/M;
list{i}=radiusDeg*[cosd(a) sind(a)];
end
o.uncertainValues={list};
o.targetFont='Sloan';
o.minimumTargetHeightChecks=8;
o.alphabet='DHKNORSVZ'; % Sloan alphabet, excluding C
o.targetKind='letter';
o.borderLetter='X';
o.alphabetPlacement='right'; % 'top' or 'right';
o.areAnswersLabeled=false;
o.getAlphabetFromDisk=true;
o.contrast=-1;
o.alternatives=length(o.alphabet);
o.viewingDistanceCm=30;
o.fixationMarkDrawnOnStimulus=true;
ooo{end+1}=o;
o.uncertainParameter={};
o.fixationMarkDrawnOnStimulus=false;
o.uncertainParameter={};
o.uncertainValues={};
o.showUncertainty=false;
end
end
if true
% Test with zero and high noise, interleaved.
for block=1:length(ooo)
oo=ooo{block};
for oi=1:length(oo)
maxNoiseSD=MaxNoiseSD(oo(oi).noiseType);
if ismember(oo(oi).targetKind,{'image'})
maxNoiseSD=0.8*maxNoiseSD;
end
oo(oi).noiseCheckDeg=oo(oi).targetHeightDeg/40;
oo(oi).setNearPointEccentricityTo='fixation';
oo(oi).nearPointXYInUnitSquare=[0.5 0.5];
oo(oi).noiseSD=maxNoiseSD;
end
ooNoNoise=oo;
[ooNoNoise.noiseSD]=deal(0);
ooo{block}=[oo ooNoNoise];
end
end
if false
% Measure threshold size at +/-10 deg. No noise.
% Randomly interleave testing left and right.
% Add fixation check.
for block=1:length(ooo)
o=ooo{block}(1);
o.noiseSD=0;
o.uncertainParameter={};
o.uncertainValues={};
o.isTargetFullResolution=true;
o.targetHeightDeg=10;
o.brightnessSetting=0.87;
o.thresholdParameter='size';
o.setNearPointEccentricityTo='fixation';
o.nearPointXYInUnitSquare=[0.5 0.5];
o.viewingDistanceCm=30;
o.eccentricityXYDeg=[10 0];
o.isFixationBlankedNearTarget=false;
o.fixationOnsetAfterNoiseOffsetSecs=0.5;
o.fixationMarkDrawnOnStimulus=false;
oo=o;
o.eccentricityXYDeg=-o.eccentricityXYDeg;
oo(2)=o;
% FIXATION TEST
o.conditionName='Fixation check';
o.targetKind='letter';
o.isFixationCheck=true;
o.eccentricityXYDeg=[0 0];
o.thresholdParameter='spacing';
o.useFlankers=true;
o.targetHeightDeg=0.4;
o.flankerSpacingDeg=1.4*o.targetHeightDeg;
o.flankerContrast=-1;
o.contrast=-1;
o.targetFont='Sloan';
o.minimumTargetHeightChecks=8;
o.alphabet='DHKNORSVZ'; % Sloan alphabet, excluding C
o.targetKind='letter';
o.alphabetPlacement='right'; % 'top' or 'right';
o.areAnswersLabeled=false;
o.getAlphabetFromDisk=false;
o.alternatives=length(o.alphabet);
oo(3)=o;
ooo{end+1}=oo;
end
end
if true
% Retest contrast thresholds with ideal observer.
for block=1:length(ooo)
oo=ooo{block};
if ~ismember(oo(1).thresholdParameter,{'contrast'})
continue
end
for oi=1:length(oo)
oo(oi).observer='ideal';
oo(oi).trialsDesired=200;
end
ooo{end+1}=oo;
end
end
%% ESTIMATED TIME TO COMPLETION
endsAtMin=0;
for block=1:length(ooo)
oo=ooo{block};
for oi=1:length(oo)
if ~ismember(oo(oi).observer,{'ideal'})
endsAtMin=endsAtMin+[oo(oi).trialsDesired]/10;
end
end
[ooo{block}(:).endsAtMin]=deal(endsAtMin);
end
%% COMPUTE MAX VIEWING DISTANCE IN REMAINING BLOCKS
maxCm=0;
for block=length(ooo):-1:1
maxCm=max([maxCm ooo{block}(1).viewingDistanceCm]);
[ooo{block}(:).maxViewingDistanceCm]=deal(maxCm);
end
%% MAKE SURE NEEDED FONTS ARE AVAILABLE
CheckExperimentFonts(ooo)
%% INTERLEAVED CONDITIONS MUST HAVE CONSISTENT CLUTS
bad={};
for block=1:length(ooo)
if ~all([oo.isLuminanceRangeSymmetric]) && any([oo.isLuminanceRangeSymmetric])
warning('block %d, o.isLuminanceRangeSymmetric must be consistent among all interleaved conditions.',block);
bad{end+1}='o.isLuminanceRangeSymmetric';
end
if length(unique([oo.desiredLuminanceFactor]))>1
warning('block %d, o.desiredLuminanceFactor must be consistent among all interleaved conditions.',block);
bad{end+1}='o.desiredLuminanceFactor';
end
end
bad=unique(bad);
if ~isempty(bad)
error('Make %s consistent within each block. ',bad{:});
end
%% PRINT TABLE OF CONDITIONS, ONE ROW PER THRESHOLD.
oo=[];
ok=true;
for block=1:length(ooo)
[ooo{block}(:).block]=deal(block);
end
for block=2:length(ooo)
% Demand perfect agreement in fields between all blocks.
fBlock1=fieldnames(ooo{1});
fBlock=fieldnames(ooo{block});
if isfield(ooo{block},'conditionName')
cond=[ooo{block}(1).conditionName ' '];
else
cond='';
end
for i=1:length(fBlock1)
f=fBlock1{i};
if ~ismember(f,fBlock)
fprintf('%sBlock %d is missing field ''%s'', present in block 1.\n',cond,block,f);
ok=false;
end
end
for i=1:length(fBlock)
f=fBlock{i};
if ~ismember(f,fBlock1)
fprintf('%sBlock %d has field ''%s'', missing in block 1.\n',cond,block,f);
ok=false;
end
end
end
if ~ok
error('Please fix this script %s so all blocks have the same set of fields.',mfilename);
end
for block=1:length(ooo)
oo=[oo ooo{block}];
end
t=struct2table(oo,'AsArray',true);
disp(t(:,{'block' 'experiment' 'targetKind' 'thresholdParameter'...
'uncertainParameter' ...
'contrast' 'conditionName' 'observer' 'endsAtMin' 'noiseSD' ...
'targetHeightDeg' 'eccentricityXYDeg' 'areAnswersLabeled'})); % Print the conditions in the Command Window.
% return
%% Measure threshold, one block per iteration.
ooo=RunExperiment(ooo);