To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

The primary repository for this project is hosted at git://github.com/rmeddis/MAP.git .
This repository is a read-only copy which is updated automatically every hour.

Statistics Download as Zip
| Branch: | Revision:

root / multithreshold 1.46 / printReport.m @ 0:f233164f4c86

History | View | Annotate | Download (10.4 KB)

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
        % overwrite existing file just in case
30
        saveFileName=['savedData/mostRecentResults'];
31
    end
32
    experiment.minElapsed=etime(clock, betweenRuns.timeNow)/60;
33
    save(saveFileName, 'experiment', 'stimulusParameters', 'betweenRuns', 'withinRuns', 'statsModel', 'expGUIhandles')
34
    disp(['data saved as: ' saveFileName]);
35
    
36
else
37
    % reprint request
38
    printReportGuide.fileName=fileName;
39
    load(printReportGuide.fileName)
40
    saveFileName=printReportGuide.fileName;
41
    if nargin>1
42
        printReportGuide.showTracks=printTracks;
43
    else
44
        printReportGuide.showTracks=experiment.printTracks;
45
    end
46
end
47

    
48
fprintf('******** multithreshold ')
49
x=pwd; disp(['version ' x(end-3:end)])
50
fprintf('\nName:\t%s ', experiment.name)
51
fprintf('\nparadigm:\t%s ', experiment.paradigm)
52
fprintf('\nEar:\t%s ', experiment.ear)
53
method=experiment.threshEstMethod;
54
if stimulusParameters.includeCue && ~strcmp(method(1:6),'2I2AFC')
55
    method=[method '/ withCue'];
56
end
57
fprintf('\nmethod:\t%s ', method)
58
fprintf('\ndate:\t%s ', experiment.date)
59

    
60
fprintf('\n\n')
61

    
62
if isempty(betweenRuns.thresholds)
63
    disp('no thresholds found')
64
end
65

    
66
% prepare results as matrices ready to print
67
[idx1, idx2, var1values, var2values]=...
68
    sortVariables(betweenRuns.variableList1, betweenRuns.variableList2, betweenRuns.var1Sequence, betweenRuns.var2Sequence);
69

    
70
% if strcmp(betweenRuns.variableName2, 'none')
71
%     betweenRuns.variableName2=' ';
72
% end
73
header1=betweenRuns.variableName1;
74
header2=betweenRuns.variableName2;
75
header1 = strrep(header1, 'none', ' '); % none is not a useful header
76
header2 = strrep(header2, 'none', ' '); % none is not a useful header
77
headers=strvcat([header1 '/'], header2);
78

    
79
disp('thresholds')
80
msg=printTabTable(sortTablesForPrinting(idx1,idx2,var1values,var2values, betweenRuns.thresholds),  headers);
81
addToMsg(msg,0)
82
fprintf('\n')
83

    
84
% sort tracks into the same order
85
betweenRuns.levelTracks=betweenRuns.levelTracks(idx1);
86
betweenRuns.responseTracks=betweenRuns.responseTracks(idx1);
87
betweenRuns.bestThresholdTracks=betweenRuns.bestThresholdTracks(idx1);
88

    
89
betweenRuns.levelTracks=betweenRuns.levelTracks(idx2);
90
betweenRuns.responseTracks=betweenRuns.responseTracks(idx2);
91
betweenRuns.bestThresholdTracks=betweenRuns.bestThresholdTracks(idx2);
92

    
93
if printReportGuide.structures
94
    maxNoArrayValues=30;
95
    showStructureSummary(stimulusParameters, 'stimulusParameters', maxNoArrayValues)
96
    showStructureSummary(experiment, 'experiment',maxNoArrayValues)
97
    showStructureSummary(betweenRuns, 'betweenRuns',maxNoArrayValues)
98
    showStructureSummary(withinRuns, 'withinRuns')
99
    
100
    switch experiment.threshEstMethod
101
        case {'2I2AFC++', '2I2AFC+++'}
102
            showStructureSummary(LevittControl, 'LevittControl', maxNoArrayValues)
103
    end
104
    
105
    switch experiment.ear
106
        case {'statsModelLogistic','statsModelRareEvent'}
107
            showStructureSummary(statsModel, 'statsModel', maxNoArrayValues)
108
    end
109
end
110

    
111
if printReportGuide.showTracks
112
    % NB this procedure can only be used if all the tracks are present and
113
    % of equal length
114
    bigTable=[]; header=[];
115
    disp(' '); disp('Leveltracks starting from 1 response before the first reversal')
116
    for i=1:length(betweenRuns.levelTracks)
117
        if printReportGuide.HorizontalTracks
118
            printTabTable(betweenRuns.levelTracks{i});
119
        end
120
        header=strvcat(header, 'level');
121
    end
122
    
123
    disp(' '); disp('Response tracks starting from 1 response before the first reversal')
124
    for i=1:length(betweenRuns.responseTracks)
125
        if printReportGuide.HorizontalTracks
126
            printTabTable(betweenRuns.responseTracks{i});
127
        end
128
        header=strvcat(header, 'resp');
129
    end
130
    
131
    disp(' '); disp('threshold tracks starting from the first reversal')
132
    for i=1:length(betweenRuns.bestThresholdTracks)
133
        if printReportGuide.HorizontalTracks
134
        end
135
        printTabTable(betweenRuns.bestThresholdTracks{i});
136
        header=strvcat(header, 'mean');
137
    end
138
    
139
    disp(' '); disp('threshold (mean) tracks starting from the first reversal')
140
    for i=1:length(betweenRuns.bestThresholdTracks)
141
        if printReportGuide.HorizontalTracks
142
        end
143
        printTabTable(betweenRuns.bestThresholdMeanTracks{i});
144
        header=strvcat(header, 'mean');
145
    end
146
    disp(' '); disp('threshold tracks (median) starting from the first reversal')
147
    for i=1:length(betweenRuns.bestThresholdMedianTracks)
148
        if printReportGuide.HorizontalTracks
149
        end
150
        printTabTable(betweenRuns.bestThresholdTracks{i});
151
        header=strvcat(header, 'mean');
152
    end
153
    
154
end
155

    
156
switch experiment.ear
157
    case  {'MAPmodelMultiCh', 'MAPmodelSingleCh'}
158
        % show all parameters but do not compute the model
159
        nm=UTIL_paramsList(whos);
160
        for i=1:length(nm)
161
            try
162
                eval(['UTIL_showStruct(' nm{i} ', ''' nm{i} ''')'])
163
            catch
164
            end
165
        end
166
end
167

    
168
if experiment.saveData
169
    fprintf('\n')
170
    disp('To reprint this report with tracks use:')
171
    disp([ 'printReport(''' saveFileName ''',1)'])
172
end
173

    
174
% print final summary (repeat of above)
175
fprintf('\n')
176
fprintf('\n')
177
disp('thresholds')
178
msg=printTabTable(sortTablesForPrinting(idx1,idx2,var1values,var2values, betweenRuns.thresholds),  headers);
179
addToMsg(msg,0)
180
fprintf('\n')
181

    
182
if length(var1values)==1 && length(var2values)==1 && experiment.maxTrials>49
183
    [psy, levelsBinVector, binFrequencies, nNo, nYes]= ...
184
        psychometricFunction(withinRuns.levelsPhaseTwo,withinRuns.responsesPhaseTwo, experiment.psyBinWidth);
185
    disp('Psychometric function')
186
    fprintf(' level  \tfreq\tprob\n')
187
    fprintf('%6.0f\t%6.2f\t%6.0f\n', [levelsBinVector; binFrequencies; psy])
188
    fprintf('\n')
189
    fprintf('k \t %6.2f\n',logistic.bestK)
190
    fprintf('g  \t%7.5f\n',rareEvent.bestGain)
191
    fprintf('\n')
192
    
193
end
194
% resultsSoFar=[betweenRuns.var1Sequence(betweenRuns.runNumber)'...
195
%     betweenRuns.var2Sequence(betweenRuns.runNumber)'...
196
%     betweenRuns.thresholds(betweenRuns.runNumber)'    ];
197
% fprintf('%10.3f \t%10.3f \t%10.1f  \n', resultsSoFar')
198

    
199
% ------------------------------------------------------- sortTablesForPrinting
200
function table= sortTablesForPrinting(idx1,idx2, var1values,var2values, x)
201
% table converts a vector to a table
202
% after sorting according to idx1 and idx2
203
% the table is completed by adding row and column values
204
x=x(idx1);
205
x=x(idx2);
206
xMatrix=reshape(x,length(var1values),length(var2values));
207

    
208
table=[[-1000 var2values]; [var1values' xMatrix]];
209

    
210
% ------------------------------------------------------- showStructureSummary
211
function showStructureSummary(structure, name, maxNoArrayValues)
212
% showStructureSummary prints out the values of a single structure
213
% The header is the structure name and each row is a field
214
% e.g. showStructureSummary(params,'params')
215
% This not the same as 'UTIL_showstruct'
216

    
217

    
218
if nargin<3
219
    maxNoArrayValues=20;
220
end
221

    
222
fprintf('\n%s:', name)
223

    
224
fields=fieldnames(eval('structure'));
225
% for each field in the structure
226
for i=1:length(fields)
227
    y=eval([ 'structure.' fields{i}]);
228
    if isstr(y),
229
        % strings
230
        fprintf('\n%s=\t''%s''',  fields{i},y)
231
    elseif isnumeric(y)
232
        % arrays
233
        if length(y)>1
234
            % vectors
235
            [r c]=size(y);
236
            if r>c, y=y'; end
237
            
238
            [r c]=size(y);
239
            if r>1
240
                %                 fprintf('\n%s.%s=\t%g x %g matrix',name, fields{i}, r, c)
241
                fprintf('\n%s=\t%g x %g matrix',fields{i}, r, c)
242
                
243
            elseif c<maxNoArrayValues
244
                %                     fprintf('\n%s=\t[%s]',  fields{i},num2str(y))
245
                fprintf('\n%s=',  fields{i})
246
                fprintf('\t%g',y)
247
                
248
            else
249
                fprintf('\n%s=\t %g...   [%g element array]', fields{i}, y(1),c)
250
            end
251
        else
252
            % single valued arrays
253
            %             fprintf('\n%s.%s=\t%s;', name, fields{i},num2str(y))
254
            fprintf('\n%s=\t%s', fields{i},num2str(y))
255
        end
256
    elseif iscell(y)
257
        fprintf('\n%s=\t cell array', fields{i})
258
        
259
    elseif isstruct(y)
260
        fprintf('\n%s=\t structure', fields{i})
261
    end,
262
    
263
end,
264
fprintf('\n')
265

    
266

    
267
% ------------------------------------------------------- printTabTable
268
function strings= printTabTable(M, headers)
269
% printTabTable prints a matrix as a table with tabs
270
%headers are optional
271
%headers=strvcat('firstname', 'secondname')
272
%  printTabTable([1 2; 3 4],strvcat('a1','a2'));
273
stringCount=1; strings{stringCount}=[];
274

    
275
if nargin>1
276
    [r c]=size(headers);
277
    for no=1:r
278
        % print all headers in a row
279
        fprintf('%s\t',headers(no,:))
280
        strings{stringCount}=sprintf('%s\t',headers(no,:)); stringCount=stringCount+1;
281
    end
282
    fprintf('\n')
283
end
284

    
285
[r c]=size(M);
286

    
287
for row=1:r
288
    string=[];
289
    for col=1:c
290
        if row==1 & col==1 & M(1,1)==-1000
291
            %   Print nothing (tab follows below)
292
        else
293
            fprintf('%s',num2str(M(row,col)))
294
            string=[string ' ' sprintf('%s',num2str(M(row,col)))];
295
        end
296
        if col<c
297
            fprintf('\t')
298
            % 			strings{stringCount}=sprintf('\t'); stringCount=stringCount+1;
299
        end
300
    end % col
301
    strings{stringCount}=string; stringCount=stringCount+1;
302
    fprintf('\n')
303
end % row
304

    
305
% ------------------------------------------------------- sortVariables
306
function [idx1, idx2, var1values, var2values]= ...
307
    sortVariables(var1values, var2values, var1Sequence, var2Sequence)
308

    
309
[x idx1]= sort(var1Sequence);
310
var1Sequence= x;
311
var2Sequence= var2Sequence(idx1);
312
depVarName= 'th';
313

    
314
[x idx2]=sort(var2Sequence);
315
var2Sequence=x;
316
var1Sequence=var1Sequence(idx2);
317

    
318
var1values=sort(var1values);
319
var2values=sort(var2values);