0001 function meas_icov = calc_reciproc_error(inv_model, data )
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 try; tau = inv_model.calc_reciproc_error.tau;
0018 catch; tau = 2.5e-6; end
0019
0020 fmdl = inv_model.fwd_model;
0021
0022 data = calc_difference_data( 0, data, fmdl);
0023
0024 idx = reciprocity_idx( fmdl );
0025 if any(isnan(idx));
0026 error('not all meas have reciprocity for this stim_pattern');
0027 end
0028
0029 data = data/max(abs(data));
0030 recerr= data - data(idx,:);
0031 recerr= mean( abs(recerr), 2);
0032 s2 = exp(-recerr.^2/tau);
0033
0034 nmeas = length(idx);
0035 meas_icov= spdiags(s2(:),0,nmeas,nmeas);
0036
0037 function oldcode
0038
0039 Nel = length(inv_model.fwd_model.electrode);
0040 nframes= size(data,2);
0041 nmeas = size(data,1);
0042 if nmeas ~= Nel^2
0043 data2= zeros(Nel^2, nframes);
0044 mselect = inv_model.fwd_model.meas_select;
0045 data2(mselect,:)= data;
0046 data2= reshape( data2, Nel,Nel,nframes);
0047 else
0048 data2= reshape( data, Nel,Nel,nframes);
0049 end
0050
0051 ndata2= abs(data2)/max(abs(data2(:)));
0052 ndata2r= permute(ndata2, [2,1,3]);
0053 recerr= mean( ndata2 - ndata2r, 3);
0054 e2 = recerr.^2;
0055
0056 s2 = exp(-e2/tau);
0057
0058 if isfield(inv_model.fwd_model,'meas_select')
0059 mselect = inv_model.fwd_model.meas_select;
0060 s2= s2(mselect);
0061 nmeas = length(find(mselect));
0062 end
0063
0064 meas_icov= spdiags(s2(:),0,nmeas,nmeas);