comparison Copy_of_multithreshold 1.46/printReport.m @ 28:02aa9826efe0

mainly multiThreshold
author Ray Meddis <rmeddis@essex.ac.uk>
date Fri, 01 Jul 2011 12:59:47 +0100
parents
children
comparison
equal deleted inserted replaced
27:d4a7675b0413 28:02aa9826efe0
1 function printReport(fileName, printTracks)
2
3 % End of run report (no args)
4 % *or*
5 % reprint previous report from file
6
7 global experiment stimulusParameters betweenRuns withinRuns statsModel audio
8 global LevittControl expGUIhandles
9
10
11 global inputStimulusParams OMEParams DRNLParams
12 global IHC_VResp_VivoParams IHCpreSynapseParams AN_IHCsynapseParams
13 global MacGregorParams MacGregorMultiParams filteredSACFParams
14 global experiment % used by calls from multiThreshold only
15 global IHC_cilia_RPParams
16
17
18 printReportGuide.structures=1;
19 printReportGuide.showPsychometric=0;
20 printReportGuide.HorizontalTracks=1;
21
22 if nargin==0
23 % print new report
24 printReportGuide.showTracks=experiment.printTracks;
25 printReportGuide.fileName=[];
26 if experiment.saveData
27 saveFileName=['savedData/' experiment.name '_' experiment.date '_' experiment.paradigm];
28 else
29 % save this data (just in case)
30 saveFileName=['savedData/mostRecentResults'];
31 end
32 experiment.minElapsed=etime(clock, betweenRuns.timeNow)/60;
33 save(saveFileName, 'experiment', 'stimulusParameters',...
34 'betweenRuns', 'withinRuns', 'statsModel', 'expGUIhandles')
35 disp(['data saved as: ' saveFileName]);
36
37 else
38 % reprint request (i.e print out old data)
39 printReportGuide.fileName=fileName;
40 load(printReportGuide.fileName)
41 saveFileName=printReportGuide.fileName;
42 if nargin>1
43 printReportGuide.showTracks=printTracks;
44 else
45 printReportGuide.showTracks=experiment.printTracks;
46 end
47 end
48
49 fprintf('******** multithreshold ')
50
51 x=pwd; disp(['version ' x(end-3:end)])
52 fprintf('\nName:\t%s ', experiment.name)
53 fprintf('\nparadigm:\t%s ', experiment.paradigm)
54 fprintf('\nEar:\t%s ', experiment.ear)
55
56 method=experiment.threshEstMethod;
57 if stimulusParameters.includeCue && ~strcmp(method(1:6),'2I2AFC')
58 method=[method '/ withCue'];
59 end
60 fprintf('\nmethod:\t%s ', method)
61 fprintf('\ndate:\t%s ', experiment.date)
62 fprintf('\n\n')
63
64 if isempty(betweenRuns.thresholds)
65 disp('no thresholds found')
66 end
67
68 % prepare results as matrices ready to print
69 % first sort the actual sequence into a more readable sequence
70 [idx1, idx2, var1values, var2values]=...
71 sortVariables(betweenRuns.variableList1, betweenRuns.variableList2,...
72 betweenRuns.var1Sequence, betweenRuns.var2Sequence);
73
74 header1=betweenRuns.variableName1;
75 header2=betweenRuns.variableName2;
76 header1 = strrep(header1, 'none', ' '); % none is not a useful header
77 header2 = strrep(header2, 'none', ' '); % none is not a useful header
78 headers=strvcat([header1 '/'], header2);
79
80 disp('thresholds')
81 msg=printTabTable(sortTablesForPrinting(idx1,idx2,...
82 var1values,var2values, betweenRuns.thresholds), headers);
83 addToMsg(msg,0)
84 fprintf('\n')
85
86 % sort tracks into the same order
87 betweenRuns.levelTracks=betweenRuns.levelTracks(idx1);
88 betweenRuns.responseTracks=betweenRuns.responseTracks(idx1);
89 betweenRuns.bestThresholdTracks=betweenRuns.bestThresholdTracks(idx1);
90 betweenRuns.levelTracks=betweenRuns.levelTracks(idx2);
91 betweenRuns.responseTracks=betweenRuns.responseTracks(idx2);
92 betweenRuns.bestThresholdTracks=betweenRuns.bestThresholdTracks(idx2);
93
94 if printReportGuide.structures
95 maxNoArrayValues=30;
96 showStructureSummary(stimulusParameters, 'stimulusParameters', maxNoArrayValues)
97 showStructureSummary(experiment, 'experiment',maxNoArrayValues)
98 showStructureSummary(betweenRuns, 'betweenRuns',maxNoArrayValues)
99 showStructureSummary(withinRuns, 'withinRuns')
100
101 switch experiment.threshEstMethod
102 case {'2I2AFC++', '2I2AFC+++'}
103 showStructureSummary(LevittControl, 'LevittControl', maxNoArrayValues)
104 end
105
106 switch experiment.ear
107 case {'statsModelLogistic','statsModelRareEvent'}
108 showStructureSummary(statsModel, 'statsModel', maxNoArrayValues)
109 end
110 end
111
112 if printReportGuide.showTracks
113 % NB this procedure can only be used if all the tracks are present and
114 % of equal length
115 bigTable=[]; header=[];
116 disp(' '); disp('Leveltracks starting from 1 response before the first reversal')
117 for i=1:length(betweenRuns.levelTracks)
118 if printReportGuide.HorizontalTracks
119 printTabTable(betweenRuns.levelTracks{i});
120 end
121 header=strvcat(header, 'level');
122 end
123
124 disp(' '); disp('Response tracks starting from 1 response before the first reversal')
125 for i=1:length(betweenRuns.responseTracks)
126 if printReportGuide.HorizontalTracks
127 printTabTable(betweenRuns.responseTracks{i});
128 end
129 header=strvcat(header, 'resp');
130 end
131
132 disp(' '); disp('threshold tracks starting from the first reversal')
133 for i=1:length(betweenRuns.bestThresholdTracks)
134 if printReportGuide.HorizontalTracks
135 end
136 printTabTable(betweenRuns.bestThresholdTracks{i});
137 header=strvcat(header, 'mean');
138 end
139
140 end
141
142 switch experiment.ear
143 case {'MAPmodelMultiCh', 'MAPmodelSingleCh'}
144 % show all parameters but do not compute the model
145 nm=UTIL_paramsList(whos);
146 for i=1:length(nm)
147 try
148 eval(['UTIL_showStruct(' nm{i} ', ''' nm{i} ''')'])
149 catch
150 end
151 end
152 end
153
154 if experiment.saveData
155 fprintf('\n')
156 disp('To reprint this report with tracks use:')
157 disp([ 'printReport(''' saveFileName ''',1)'])
158 end
159
160 % print final summary (repeat of above)
161 fprintf('\n')
162 fprintf('\n')
163 disp('thresholds')
164 msg=printTabTable(sortTablesForPrinting(idx1,idx2,var1values,var2values, betweenRuns.thresholds), headers);
165 addToMsg(msg,0)
166 fprintf('\n')
167
168 if length(var1values)==1 && length(var2values)==1 && experiment.maxTrials>49
169 [psy, levelsBinVector, binFrequencies, nNo, nYes]= ...
170 psychometricFunction(withinRuns.levelsPhaseTwo,withinRuns.responsesPhaseTwo, experiment.psyBinWidth);
171 disp('Psychometric function')
172 fprintf(' level \tfreq\tprob\n')
173 fprintf('%6.0f\t%6.2f\t%6.0f\n', [levelsBinVector; binFrequencies; psy])
174 fprintf('\n')
175 fprintf('k \t %6.2f\n',logistic.bestK)
176 fprintf('g \t%7.5f\n',rareEvent.bestGain)
177 fprintf('\n')
178
179 end
180
181 fprintf('\nparadigm:\t%s\n ', experiment.paradigm)
182
183 % ------------------------------------------------------- sortTablesForPrinting
184 function table= sortTablesForPrinting(idx1,idx2, var1values,var2values, x)
185 % table converts a vector to a table
186 % after sorting according to idx1 and idx2
187 % the table is completed by adding row and column values
188 x=x(idx1);
189 x=x(idx2);
190 xMatrix=reshape(x,length(var1values),length(var2values));
191
192 table=[[-1000 var2values]; [var1values' xMatrix]];
193
194 % ------------------------------------------------------- showStructureSummary
195 function showStructureSummary(structure, name, maxNoArrayValues)
196 % showStructureSummary prints out the values of a single structure
197 % The header is the structure name and each row is a field
198 % e.g. showStructureSummary(params,'params')
199 % This not the same as 'UTIL_showstruct'
200
201
202 if nargin<3
203 maxNoArrayValues=20;
204 end
205
206 fprintf('\n%s:', name)
207
208 fields=fieldnames(eval('structure'));
209 % for each field in the structure
210 for i=1:length(fields)
211 y=eval([ 'structure.' fields{i}]);
212 if isstr(y),
213 % strings
214 fprintf('\n%s=\t''%s''', fields{i},y)
215 elseif isnumeric(y)
216 % arrays
217 if length(y)>1
218 % vectors
219 [r c]=size(y);
220 if r>c, y=y'; end
221
222 [r c]=size(y);
223 if r>1
224 % fprintf('\n%s.%s=\t%g x %g matrix',name, fields{i}, r, c)
225 fprintf('\n%s=\t%g x %g matrix',fields{i}, r, c)
226
227 elseif c<maxNoArrayValues
228 % fprintf('\n%s=\t[%s]', fields{i},num2str(y))
229 fprintf('\n%s=', fields{i})
230 fprintf('\t%g',y)
231
232 else
233 fprintf('\n%s=\t %g... [%g element array]', fields{i}, y(1),c)
234 end
235 else
236 % single valued arrays
237 % fprintf('\n%s.%s=\t%s;', name, fields{i},num2str(y))
238 fprintf('\n%s=\t%s', fields{i},num2str(y))
239 end
240 elseif iscell(y)
241 fprintf('\n%s=\t cell array', fields{i})
242
243 elseif isstruct(y)
244 fprintf('\n%s=\t structure', fields{i})
245 end,
246
247 end,
248 fprintf('\n')
249
250
251 % ------------------------------------------------------- printTabTable
252 function strings= printTabTable(M, headers)
253 % printTabTable prints a matrix as a table with tabs
254 %headers are optional
255 %headers=strvcat('firstname', 'secondname')
256 % printTabTable([1 2; 3 4],strvcat('a1','a2'));
257 stringCount=1; strings{stringCount}=[];
258
259 if nargin>1
260 [r c]=size(headers);
261 for no=1:r
262 % print all headers in a row
263 fprintf('%s\t',headers(no,:))
264 strings{stringCount}=sprintf('%s\t',headers(no,:)); stringCount=stringCount+1;
265 end
266 fprintf('\n')
267 end
268
269 [r c]=size(M);
270
271 for row=1:r
272 string=[];
273 for col=1:c
274 if row==1 & col==1 & M(1,1)==-1000
275 % Print nothing (tab follows below)
276 else
277 fprintf('%s',num2str(M(row,col)))
278 string=[string ' ' sprintf('%s',num2str(M(row,col)))];
279 end
280 if col<c
281 fprintf('\t')
282 % strings{stringCount}=sprintf('\t'); stringCount=stringCount+1;
283 end
284 end % col
285 strings{stringCount}=string; stringCount=stringCount+1;
286 fprintf('\n')
287 end % row
288
289 % ------------------------------------------------------- sortVariables
290 function [idx1, idx2, var1values, var2values]= ...
291 sortVariables(var1values, var2values, var1Sequence, var2Sequence)
292
293 [x idx1]= sort(var1Sequence);
294 var1Sequence= x;
295 var2Sequence= var2Sequence(idx1);
296 depVarName= 'th';
297
298 [x idx2]=sort(var2Sequence);
299 var2Sequence=x;
300 var1Sequence=var1Sequence(idx2);
301
302 var1values=sort(var1values);
303 var2values=sort(var2values);