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
0018
0019
0020
0021 try; tau = inv_model.calc_reciproc_error.tau;
0022 catch; tau = 2.5e-6; end
0023
0024 switch inv_model.type
0025 case 'inv_model'; fmdl = inv_model.fwd_model;
0026 case 'fwd_model'; fmdl = inv_model;
0027 otherwise; error('calc_reciproc_error: require model input');
0028 end
0029
0030 data = calc_difference_data( 0, data, fmdl);
0031
0032 idx = reciprocity_idx( fmdl );
0033 if any(isnan(idx));
0034 error('not all meas have reciprocity for this stim_pattern');
0035 end
0036
0037 data = data/max(abs(data));
0038 recerr= data - data(idx,:);
0039 recerr= mean( abs(recerr), 2);
0040 s2 = exp(-recerr.^2/tau);
0041
0042 nmeas = length(idx);
0043 meas_icov= spdiags(s2(:),0,nmeas,nmeas);
0044
0045 function oldcode
0046
0047 Nel = length(inv_model.fwd_model.electrode);
0048 nframes= size(data,2);
0049 nmeas = size(data,1);
0050 if nmeas ~= Nel^2
0051 data2= zeros(Nel^2, nframes);
0052 mselect = inv_model.fwd_model.meas_select;
0053 data2(mselect,:)= data;
0054 data2= reshape( data2, Nel,Nel,nframes);
0055 else
0056 data2= reshape( data, Nel,Nel,nframes);
0057 end
0058
0059 ndata2= abs(data2)/max(abs(data2(:)));
0060 ndata2r= permute(ndata2, [2,1,3]);
0061 recerr= mean( ndata2 - ndata2r, 3);
0062 e2 = recerr.^2;
0063
0064 s2 = exp(-e2/tau);
0065
0066 if isfield(inv_model.fwd_model,'meas_select')
0067 mselect = inv_model.fwd_model.meas_select;
0068 s2= s2(mselect);
0069 nmeas = length(find(mselect));
0070 end
0071
0072 meas_icov= spdiags(s2(:),0,nmeas,nmeas);