0001 function idxr = reciprocity_idx( fmdl, opt);
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025 if ischar(fmdl) && strcmp(fmdl,'UNIT_TEST'); do_unit_test; return; end
0026
0027 sm_0= []; sm_r = [];
0028 for stim = fmdl.stimulation(:)';
0029 sp = stim.stim_pattern';
0030 nsp = sum(abs(sp))/2;
0031 mp = stim.meas_pattern;
0032 sp = ones(size(mp,1),1)*sp;
0033 sm_0= [sm_0; [sp/nsp, mp*nsp]];
0034 sm_r= [sm_r; [mp, sp]];
0035 end
0036 idxr = ones(size(sm_0,1),1);
0037 for i=1:size(idxr)
0038 sm0i= ones(size(sm_0,1),1)*sm_0(i,:);
0039 mm= all( abs(sm0i - sm_r) < 1e-10, 2);
0040 mp= all( abs(sm0i + sm_r) < 1e-10, 2);
0041 m = [find(mm), find(mp)];
0042 if length(m)>1;
0043 meas= sprintf('%d,',m);
0044 error('More than one reciprocal measure %d=>(%s). Giving up', i,meas);
0045 elseif length(m)==0;
0046 idxr(i) = NaN;
0047 else
0048 idxr(i) = m;
0049 end
0050 end
0051
0052 if nargin>=2 && strcmp(lower(opt),'reduce');
0053
0054 idxk= min([idxr,idxr(idxr)],[],2);
0055 [~,~,idxr] = unique(idxk);
0056 end
0057
0058 function do_unit_test
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069 tst.stimulation = mk_stim_patterns(8,1,[0,1],[0,1],{'rotate_meas'},1);
0070 idx = reciprocity_idx( tst ); idx = reshape(idx,5,8);
0071 unit_test_cmp('8-[01]-[01]-rotate',idx(:,[1,5]), ...
0072 [15,19,23,27,31;35,39,3,7,11]');
0073
0074 tst.stimulation = mk_stim_patterns(8,1,[0,1],[0,1],{'rotate_meas'},10);
0075 idx = reciprocity_idx( tst ); idx = reshape(idx,5,8);
0076 unit_test_cmp('8(10)-[01]-[01]-rotate',idx(:,[1,5]), ...
0077 [15,19,23,27,31;35,39,3,7,11]');
0078
0079
0080
0081
0082
0083
0084
0085
0086 tst.stimulation = mk_stim_patterns(6,1,[0,1],[0,1],{'rotate_meas'},1);
0087 idx = reciprocity_idx( tst ); idx = reshape(idx,3,6);
0088 unit_test_cmp('6-[01]-[01]-rotate',idx(:,[1,4]), [9,11,13;18 2 4]');
0089
0090
0091 idxr= reciprocity_idx( tst,'reduce' );
0092 unit_test_cmp('6-[01]-[01]-reduce-rotate',idxr,[1;2;3;4;5;6;7;8;1;9;2;4;3;5;7;6;8;9]);
0093
0094
0095 tst.stimulation = mk_stim_patterns(6,1,[0,1],[0,1],{'no_rotate_meas'},1);
0096 idx = reciprocity_idx( tst ); idx = reshape(idx,3,6);
0097 unit_test_cmp('6-[01]-[01]-no_rotate',idx(:,[1,4]), [7,10,13;2 4 18]');
0098
0099
0100
0101
0102
0103
0104
0105
0106 tst.stimulation = mk_stim_patterns(6,1,[0,2],[0,2],{'rotate_meas'},1);
0107 idx = reciprocity_idx( tst ); idx = reshape(idx,3,6);
0108 unit_test_cmp('6-[02]-[02]-rotate',idx(:,[1,4]), [6,11,16;15,2,7]');
0109
0110 tst.stimulation = mk_stim_patterns(6,1,[0,2],[0,2],{'no_rotate_meas'},1);
0111 idx = reciprocity_idx( tst ); idx = reshape(idx,3,6);
0112 unit_test_cmp('6-[02]-[02]-no_rotate',idx(:,[1,4]), [4,10,16;2,8,14]');
0113
0114 idxr= reciprocity_idx( tst,'reduce' );
0115 unit_test_cmp('6-[02]-[02]-reduce-no_rotate',idxr,[1;2;3;1;4;5;4;6;7;2;6;8;5;8;9;3;7;9]);
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125 tst.stimulation = mk_stim_patterns(6,1,[0,2],[0,2],{'meas_current','rotate_meas'},1);
0126 idx = reciprocity_idx( tst ); idx = reshape(idx,6,6);
0127 unit_test_cmp('6-[02]-[02]-mc-rotate',idx(:,[1,4]), ...
0128 [ 1,12,17,22,27,32;19,30,35,4,9,14]');
0129
0130 tst.stimulation = mk_stim_patterns(6,1,[0,2],[0,2],{'meas_current','no_rotate_meas'},1);
0131 idx = reciprocity_idx( tst ); idx = reshape(idx,6,6);
0132 unit_test_cmp('6-[02]-[02]-mc-no_rotate',idx(:,[1,4]), ...
0133 [ 1,7,13,19,25,31; 4,10,16,22,28,34]');
0134
0135 tst.stimulation = mk_stim_patterns(6,1,[0,4],[0,4],{'meas_current','no_rotate_meas'},1);
0136 idx = reciprocity_idx( tst ); idx = reshape(idx,6,6);
0137 unit_test_cmp('6-[04]-[04]-mc-no_rotate',idx(:,[1,4]), ...
0138 [ 1,7,13,19,25,31; 4,10,16,22,28,34]');