0001 function imgs= moving_tank_objs(data_sel, inv_sel, options)
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
0029
0030
0031
0032
0033
0034
0035
0036
0037 clim= [];
0038
0039 if nargin<1; data_sel = 10; end
0040 if nargin<2; inv_sel = 1; end
0041
0042 if isnumeric(data_sel) & size(data_sel)==[1,1]
0043 switch data_sel
0044 case 10
0045 load montreal_data_1995;
0046 vh= zc_h_demo4;
0047 vi= zc_demo4;
0048 filename= 'target-across';
0049
0050 case 20
0051 load montreal_data_1995;
0052 vh= zc_h_demo3;
0053 vi= zc_demo3;
0054 filename= 'target-around';
0055
0056 case 21
0057 load montreal_data_1995;
0058 vh= zc_h_demo3;
0059 vi= zc_demo3(:,1:2:20);
0060 filename= 'target-around10';
0061
0062 case 22
0063 load iirc_data_2006
0064 vh= real(v_reference);
0065 vi= real(v_rotate(:,1:30));
0066 filename= 'iirc-around-clean';
0067
0068 case 22.1
0069 load iirc_data_2006
0070 vh= v_reference;
0071 vi= v_rotate(:,11:20);
0072 filename= 'iirc-around-clean';
0073
0074 case 23
0075 load iirc_data_2006
0076 vh= v_reference;
0077 vi= v_rotate(:,1:30);
0078 [vi,vh]= add_noise(vi,vh,2)
0079 filename= 'iirc-around-noise';
0080
0081 case 24
0082 load iirc_data_2006
0083 vh= v_reference;
0084 vi= v_rotate;
0085 filename= 'iirc-around-clean';
0086
0087
0088 case 30
0089 load netgen_moving_ball
0090 vh= homg_tank;
0091 vi= target_spiral;
0092 filename= 'netgen-spiral';
0093
0094 case 31
0095 load netgen_moving_ball
0096 vh= homg_tank;
0097 vi= target_spiral(40:60);
0098 filename= 'netgen-spiral-part';
0099
0100 case 32
0101 load netgen_moving_ball
0102 vh= homg_tank;
0103 vi= target_spirograph_slow;
0104 filename= 'netgen-spirograph-slow';
0105
0106 case 33
0107 load netgen_moving_ball
0108 vh= homg_tank;
0109 vi= target_spirograph_slow([31:52,72:90]);
0110 randn('seed',20);
0111 for i=1:length(vi)
0112
0113 end
0114 filename= 'netgen-spirograph-slow-part';
0115
0116 otherwise
0117 error('Don''t recognize data_sel');
0118 end
0119 else
0120 vh= data_sel(:,1);
0121 vi= data_sel(:,2:end);
0122 filename= 'user-data';
0123 end
0124
0125
0126
0127
0128 try; if inv_sel.type=='inv_model'
0129 imdl= inv_sel;
0130 inv_sel= 'set'
0131 end; end
0132
0133 switch inv_sel
0134 case 'set'
0135 eidors_msg('Using imdl=%s',imdl.name,2);
0136
0137 case 1
0138 imdl= set_basic( 'b2c' );
0139
0140 case 1.1
0141 imdl= set_basic( 'c2c' );
0142
0143 case 1.2
0144 imdl= set_basic( 'd2c' );
0145
0146 case 2
0147 imdl= set_basic( 'b2c' );
0148 imdl.solve= @inv_solve_diff_kalman;
0149
0150 case 2.1
0151 imdl= set_basic( 'c2c' );
0152 imdl.solve= @inv_solve_diff_kalman;
0153
0154 case 3
0155 imdl= set_basic( 'b2c' );
0156 imdl.solve= @aa_inv_conj_grad;
0157
0158 case 4
0159 imdl= set_basic( 'b2c', 'temporal', [3, .6] );
0160
0161 case 4.1
0162 imdl= set_basic( 'c2c', 'temporal', [3, .6] );
0163
0164 case 5
0165 imdl= set_basic( 'b2c', 'temporal', [8, 1] );
0166
0167 case 11
0168 imdl= set_basic( 'b2c' );
0169
0170 vi = extract_subframes(vi,4);
0171 vi = repack_subframes(vi,4);
0172
0173 case 11.1
0174 imdl= set_basic( 'c2c' );
0175
0176 vi = extract_subframes(vi,4);
0177 vi = repack_subframes(vi,4);
0178
0179 case 12
0180 imdl= set_basic( 'b2c' );
0181 imdl.solve= @inv_solve_diff_kalman;
0182 [imdl.fwd_model.stimulation(:).delta_time]=deal(1);
0183
0184 vi = extract_subframes(vi,4);
0185
0186 case 12.1
0187 imdl= set_basic( 'c2c' );
0188 imdl.solve= @inv_solve_diff_kalman;
0189 [imdl.fwd_model.stimulation(:).delta_time]=deal(1);
0190
0191 vi = extract_subframes(vi,4);
0192
0193 case 14
0194 imdl= set_basic( 'b2c' );
0195 time_steps= 3;
0196
0197 imdl.RtR_prior= @prior_time_smooth;
0198 imdl.prior_time_smooth.space_prior= @prior_noser;
0199 imdl.prior_time_smooth.time_weight= .5;
0200 imdl.prior_time_smooth.time_steps= time_steps;
0201
0202 imdl.solve= @inv_solve_time_prior;
0203 imdl.inv_solve_time_prior.time_steps= time_steps;
0204
0205 [imdl.fwd_model.stimulation(:).delta_time]=deal(1);
0206
0207 vi = extract_subframes(vi,4);
0208
0209 otherwise
0210 error(['inv_sel (' inv_sel ') not recognized']);
0211 end
0212
0213
0214 if nargin>=3
0215 if length(options) >=1 if ~isnan(options(1))
0216 imdl= rmfield(imdl,'hyperparameter');
0217 imdl.hyperparameter.func= @choose_noise_figure;
0218 imdl.hyperparameter.tgt_elems= [1:4];
0219 imdl.hyperparameter.noise_figure= options(1);
0220 filename = sprintf('%s-hp=%g', filename, options(1));
0221 end; end
0222 if length(options) >=2 if ~isnan(options(2))
0223 imdl.prior_time_smooth.time_steps= options(2);
0224 imdl.inv_solve_time_prior.time_steps= options(2);
0225 filename = sprintf('%s-ts=%d', filename, options(2));
0226 end; end
0227 if length(options) >=3 if ~isnan(options(3))
0228 imdl.prior_time_smooth.time_weight= options(3);
0229 filename = sprintf('%s-tw=%4.2f', filename, options(3));
0230 end; end
0231 end
0232
0233 t=cputime;
0234 imgs= inv_solve(imdl,vh,vi);
0235 fprintf('solve time=%f\n',cputime-t);
0236 animate_reconstructions(filename, imgs);
0237
0238
0239
0240
0241
0242
0243
0244
0245
0246
0247
0248
0249
0250
0251 function ve= extract_subframes( vv, subseq)
0252 vv= remove_curr_elecs(vv);
0253
0254 ve= zeros( size(vv,1), floor(size(vv,2)*subseq/16) );
0255 dst=0; src=0;
0256 for k=0:16*size(ve,2)-1;
0257 pat = (1:13) + 13*rem(k,16);
0258 if 0==rem(k,16); dst= dst+1; end
0259 if 0==rem(k,subseq); src= src+1; end
0260 ve(pat,dst) = vv(pat, src);
0261 end
0262
0263
0264
0265
0266
0267
0268
0269
0270
0271
0272
0273
0274
0275
0276
0277
0278
0279 function ve = repack_subframes(vv,subseq);
0280 vv= remove_curr_elecs(vv);
0281
0282
0283 ve= zeros( size(vv,1), floor(size(vv,2)*16/subseq) );
0284 vv= vv(:,[1:end,end]);
0285 dst=0; src=0;
0286 pat = (1:208)';
0287 for i=1:size(ve,2)
0288 for k=rem(subseq*i + (-subseq:-1),16);
0289 pat(13*k + (1:13)) = pat(13*k + (1:13)) + 208;
0290 end
0291 ve(:,i) = vv(pat);
0292 end
0293
0294
0295 function vv= remove_curr_elecs(vv)
0296 if isstruct(vv);
0297 vv= [vv(:).meas];
0298 end
0299 [st, els]= mk_stim_patterns(16, 1, '{ad}','{ad}', {}, 10);
0300
0301
0302 if size(vv,1)==size(els,1)
0303 vv= vv(els,:);
0304 end
0305
0306 function imdl= set_basic( shape_str, type, vals )
0307 imdl = mk_common_model( shape_str, 16 );
0308 imdl.RtR_prior= @prior_noser;
0309 imdl.prior_noser.exponent= .5;
0310 imdl.solve= @np_inv_solve;
0311 imdl.hyperparameter.value= 1e-1;
0312
0313 if nargin==1; return; end
0314
0315 switch type
0316 case 'temporal'
0317 time_steps= vals(1);
0318 time_weight= vals(2);
0319
0320 imdl.RtR_prior= @prior_time_smooth;
0321 imdl.prior_time_smooth.space_prior= @prior_noser;
0322 imdl.prior_time_smooth.time_weight= time_weight;
0323 imdl.prior_time_smooth.time_steps= time_steps;
0324
0325 imdl.solve= @inv_solve_time_prior;
0326 imdl.inv_solve_time_prior.time_steps= time_steps;
0327 imdl.hyperparameter.value= 1e-1;
0328
0329 otherwise
0330 error('dont understand parameter');
0331 end
0332
0333
0334 function [vi,vh]= add_noise(vi,vh,snr_mult)
0335 ll= size(vi,2);
0336 snr= norm(vi)/norm(vi - vh(:,ones(1,ll)));
0337 rand('seed',50);
0338 vh= vh+snr*snr_mult*randn(size(vh));
0339 vi= vi+snr*snr_mult*randn(size(vi));