-
Notifications
You must be signed in to change notification settings - Fork 2
/
runEquiMotionPlot.m
169 lines (159 loc) · 5.05 KB
/
runEquiMotionPlot.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
function runEquiMotionPlot()
% loads and plots a MAT file generated by the EquiMotion.mlapp
[f, p] = uigetfile('*.mat','Load EquiMotion MAT File...');
cd(p);
out = load(f);
ana = out.ana;
seq = out.seq;
maxLuminances = [25.5484 102.9958 18.1265];
fixC = find(ana.colorFixed == max(ana.colorFixed));
switch fixC
case 1
fixLabel ='Red';
case 2
fixLabel ='Green';
case 3
fixLabel ='Blue';
end
varC = find(ana.colorEnd == max(ana.colorEnd));
switch varC
case 1
varLabel ='Red';
case 2
varLabel ='Green';
case 3
varLabel ='Blue';
end
for i = 1:length(seq.nVar(1).values)
variableVals(i) = max(seq.nVar(1).values{i});
end
variableVals = variableVals .* maxLuminances(varC);
varLabels = arrayfun(@(a) num2str(a,3),variableVals,'UniformOutput',false);
LEFT = 1; RIGHT = 2; UNSURE = 3; REDO = -10; BREAKFIX = -1;
if isa(seq,'StimulusSequence')
map = analysisCore.optimalColours(seq.minBlocks);
else
map = analysisCore.optimalColours(seq.minTrials);
end
if ~ana.isMOC
fixCol = ana.colorFixed(fixC) * maxLuminances(fixC);
colours = cell2mat(ana.colours);
varcolour = colours(:,varC);
varCol = varcolour * maxLuminances(varC);
tit = ['Data: ' f];
tit=regexprep(tit,'_','-');
h = figure('Name',tit,'Units','normalized',...
'Position',[0.25 0.25 0.5 0.6],...
'Color',[1 1 1],...
'PaperType','A4','PaperUnits','centimeters');
tiledlayout flow
[m,e]=analysisCore.stderr(varCol);
[mr,er]=analysisCore.stderr(varcolour);
ratv = (fixCol ./ varCol);
[mrr,err]=analysisCore.stderr(ratv);
nexttile
boxplot(varCol,'Colors','k','Notch','marker');
line([0,2],[fixCol, fixCol]);
ratio = fixCol / m;
tit = sprintf('Match %s=%.3f -> %s=%.3f+-%.3f (%.3f+-%.3f) RATIO = %.3f (%.3f+-%.3f)',...
fixLabel,fixCol,varLabel,m,e,mr,er,ratio,mrr,err);
title(tit);
ylabel('Luminance (cd/m2)')
nexttile
%boxplot(ratv,'Colors','k','Notch','marker');
raincloud_plot(ratv, 'box_on', 1);
line([1,1],[-2 2],'Linewidth',2);
title(tit);
ylabel('Ratio')
return
end
% to plot the psychometric function
PF = @PAL_Quick;
maxbeta = 30;
space.alpha = linspace(min(variableVals), max(variableVals), 200);
space.beta = linspace(0, maxbeta, 200);
%space.beta = maxbeta;
space.gamma = linspace(0, 0.1, 10);
space.lambda = linspace(0, 0.1, 10);
fixP = [1 0 0 0];
pfx = linspace(min(variableVals),max(variableVals),300);
tit = ['Data: ' f];
tit=regexprep(tit,'_','-');
h = figure('Name',tit,'Units','normalized',...
'Position',[0.25 0.25 0.5 0.6],...
'Color',[1 1 1],...
'PaperType','A4','PaperUnits','centimeters');
tl = tiledlayout(h,2,1);
tl.Title.String = tit;
tl.Title.FontName = 'Fira Code';
tl.Title.FontWeight = 'bold';
ax=nexttile(1);
for i = 1:length(ana.trial)
v = ana.trial(i).variable;
r = ana.trial(i).response;
p = [];
if r == LEFT
p = 'k-<';
elseif r == RIGHT
p = 'k->';
elseif r == UNSURE
p = 'k-x';
end
if ~isempty(p)
hold on;
pl=plot(v,i,p,'Color',map(v,:),'MarkerSize',8,'MarkerFaceColor', map(v,:));
end
end
ax.FontName = 'Fira Code';
ylabel('Trial Number');
fprintf('%s fixed raw: %s\n',fixLabel,num2str(ana.colorFixed,'%.3f '));
title([fixLabel ' Fixed Value: ' num2str(ana.colorFixed .* maxLuminances)]);
xticks(1:length(varLabels));
xlim([0.5 length(varLabels)+0.5]);
xticklabels(varLabels); box on; grid on;
pl(1).Parent.XTickLabelRotation=45;
fixVal = ana.colorFixed(fixC) * maxLuminances(fixC);
ax = nexttile(2);
responseVals = ana.trial(end).responseVals;
totalVals = ana.trial(end).totalVals;
try
hold on;
try scatter(variableVals,(responseVals./totalVals),(totalVals+1).*20,...
'filled','MarkerFaceAlpha',0.5); end
[pv,ll,scenario] = PAL_PFML_Fit(variableVals,responseVals,totalVals,space,fixP,PF);
if scenario < 0; warning('PF did NOT fit!!!!!!'); end
fprintf('FIT: %.2f %.2f %.2f %.2f | LL: %.2f | scenario: %i\n',...
pv(1),pv(2),pv(3),pv(4),ll,scenario);
if isinf(pv(1))
warning('Weibull didn''t fit, change to Logistic!!!!!');
PF = @PAL_Logistic;
maxbeta = 20;
space.beta = linspace(0, maxbeta, 25);
[pv,ll,scenario] = PAL_PFML_Fit(variableVals,responseVals,totalVals,space,[1 1 1 1],PF);
fprintf('FIT: %.2f %.2f %.2f %.2f | LL: %.2f | scenario: %i\n',...
pv(1),pv(2),pv(3),pv(4),ll,scenario);
end
if isinf(pv(2)); pv(2) = maxbeta; end
pfvals = PF(pv,pfx);
pl=plot(pfx,pfvals,'k-');
pl(1).Parent.XTickLabelRotation=45;
ylabel('Proportion LEFT Choices');
ratio = (ana.colorFixed(fixC)*maxLuminances(fixC))/pv(1);
tit=sprintf('%s Threshold:%.2f | Slope:%.2f | Trials:%i| Ratio:%.2f',...
char(PF),pv(1),pv(2),sum(totalVals),ratio);
tit=regexprep(tit,'_','-');
title(tit);
line([fixVal fixVal],[0 1],'Color',[.3 .3 .3],'LineStyle','--','LineWidth',2);
fprintf('%s var raw: %s\n',varLabel,num2str(pv(1)/maxLuminances(varC),'%.3f '));
end
xticks(variableVals);
xticklabels(varLabels);
ax.FontName = 'Fira code';
xlim([min(variableVals)-(max(variableVals)/20) max(variableVals)+(max(variableVals)/20)]);
ylim([-0.05 1.05]);
box on; grid on;
tl.XLabel.String = [varLabel ' Variable Color Value'];
tl.XLabel.FontName = 'Fira code';
[~,f,~] = fileparts(f);
exportgraphics(tl,[pwd filesep f '.pdf']);
end