0001 function meas_icov = meas_icov_rm_elecs( imdl, elec_list)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 if ischar(imdl) && strcmp(imdl,'UNIT_TEST'); do_unit_test; return; end
0029
0030 switch imdl.type,
0031 case 'inv_model'; fmdl = imdl.fwd_model;
0032 case 'fwd_model'; fmdl = imdl;
0033 imdl.meas_icov_rm_elecs.replace_value = 1;
0034 otherwise; error('meas_icov_rm_elecs: require inv- or fwd-model');
0035 end
0036
0037 if nargin< 2
0038 elec_list = imdl.meas_icov_rm_elecs.elec_list;
0039 end
0040
0041 NSR = 0;
0042 try; NSR = (imdl.meas_icov_rm_elecs.SNR)^(-1);
0043 end
0044
0045 exponent = 1;
0046 try;exponent = imdl.meas_icov_rm_elecs.exponent;
0047 end
0048
0049 replace_value = 0;
0050 try;replace_value = imdl.meas_icov_rm_elecs.replace_value;
0051 end
0052
0053
0054 meas_icov = [];
0055 for stim = fmdl.stimulation(:)'
0056 mp = stim.meas_pattern;
0057 sp = stim.stim_pattern;
0058 icovi = ones(size(mp,1),1);
0059 if any(sp(elec_list) ~= 0)
0060 icovi = 0*icovi;
0061 else
0062 icovi = ~any( mp(:,elec_list) ~= 0, 2);
0063 end
0064
0065 meas_icov = [meas_icov; icovi];
0066 end
0067
0068 n = length(meas_icov);
0069
0070 meas_icov(meas_icov == 0) = NSR;
0071 meas_icov = spdiags( meas_icov.^exponent, 0, n,n );
0072
0073 if replace_value == 0
0074 meas_icov = calc_meas_icov(imdl)*meas_icov;
0075 end
0076
0077 function do_unit_test
0078 imdl = mk_common_model('a2c0',4);
0079 covar = meas_icov_rm_elecs(imdl,1);
0080 unit_test_cmp('ire # 1', covar, zeros(size(covar)));
0081
0082 imdl = mk_common_model('a2c0',8);
0083 covar = meas_icov_rm_elecs(imdl,1);
0084 ff = find( diag(covar)~= 1);
0085 ffcmp = [1;2;3;4;5;10;11;15;16;20;21;25;26;30;31;36;37;38;39;40];
0086 unit_test_cmp('ire # 2', ff,ffcmp);
0087
0088 covar = meas_icov_rm_elecs(imdl.fwd_model,1);
0089 unit_test_cmp('ire # 3', ff,ffcmp);
0090
0091 imdl.meas_icov_rm_elecs.elec_list = 1;
0092 covar = meas_icov_rm_elecs(imdl);
0093 unit_test_cmp('ire # 4', ff,ffcmp);
0094 ff = find( diag(covar)~= 1);
0095
0096
0097 covar = meas_icov_rm_elecs(imdl,[1,2]);
0098 ff = find( diag(covar)==1);
0099 ffcmp = [12;13;14;18;19;23;24;28;29;33;34;35];
0100 unit_test_cmp('ire # 5', ff,ffcmp);
0101
0102 covar = meas_icov_rm_elecs(imdl,[1,2,3]);
0103 ff = find( diag(covar)==1);
0104 ffcmp = [18;19;24;29;34;35];
0105 unit_test_cmp('ire # 6', ff,ffcmp);
0106
0107 covar = meas_icov_rm_elecs(imdl,[1,2,3,4]);
0108 ff = find( diag(covar)==1);
0109 ffcmp = [24;35];
0110 unit_test_cmp('ire # 7', ff,ffcmp);
0111
0112
0113 imdl.meas_icov_rm_elecs.elec_list = 1:4;
0114 imdl.meas_icov_rm_elecs.exponent = 1;
0115 imdl.meas_icov_rm_elecs.SNR = 0;
0116 covar= diag( meas_icov_rm_elecs(imdl) );
0117 ffcmp = [24;35];
0118 unit_test_cmp('ire # 8', find(covar==1),ffcmp);
0119
0120 imdl.meas_icov_rm_elecs.SNR = 100;
0121 covar= diag( meas_icov_rm_elecs(imdl) );
0122 unit_test_cmp('ire # 9', find(covar==1),ffcmp);
0123 ff = find( covar~=1);
0124 unit_test_cmp('ire #10', covar(ff),1/100);
0125
0126 imdl.meas_icov_rm_elecs.exponent = -1;
0127 covar= diag( meas_icov_rm_elecs(imdl) );
0128 unit_test_cmp('ire #11', find(covar==1),ffcmp);
0129 ff = find( covar~=1);
0130 unit_test_cmp('ire #12', covar(ff),100);
0131
0132 imdl = mk_common_model('a2c0',8);
0133 imdl.meas_icov = spdiag((1:40)');
0134 covar= diag( meas_icov_rm_elecs(imdl,[]) );
0135 unit_test_cmp('ire #13', covar,(1:40)');
0136
0137 imdl.meas_icov_rm_elecs.replace_value = 0;
0138 covar= diag( meas_icov_rm_elecs(imdl,[]) );
0139 unit_test_cmp('ire #14', covar,(1:40)');
0140
0141 imdl.meas_icov_rm_elecs.replace_value = 1;
0142 covar= diag( meas_icov_rm_elecs(imdl,[]) );
0143 unit_test_cmp('ire #15', covar,1);
0144