0001 function J= jacobian_movement_perturb( fwd_model, img)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 if nargin == 1
0019 img= fwd_model;
0020 elseif strcmp(getfield(warning('query','EIDORS:DeprecatedInterface'),'state'),'on')
0021 warning('EIDORS:DeprecatedInterface', ...
0022 ['Calling JACOBIAN_MOVEMENT with two arguments is deprecated and will cause' ...
0023 ' an error in a future version. First argument ignored.']);
0024 warning off EIDORS:DeprecatedInterface
0025
0026 end
0027 fwd_model= img.fwd_model;
0028
0029 pp= fwd_model_parameters( fwd_model, 'skip_VOLUME' );
0030 delta= 1e-6;
0031
0032
0033 if isfield(fwd_model,'conductivity_jacobian')
0034
0035
0036 tmp = img;
0037 tmp.fwd_model = rmfield(tmp.fwd_model,'conductivity_jacobian');
0038 tmp.fwd_model.jacobian = fwd_model.conductivity_jacobian;
0039 Jc = calc_jacobian(tmp);
0040
0041 else
0042 fwd_model.jacobian_perturb.delta = delta;
0043 fwd_model = mdl_normalize(fwd_model,0);
0044 Jc = jacobian_perturb(fwd_model, img);
0045
0046 end
0047
0048 Jm= movement_jacobian( pp, delta, img );
0049 J= [Jc,Jm];
0050
0051
0052 if pp.normalize
0053 data= fwd_solve( img );
0054 J= J ./ (data.meas(:)*ones(1,size(J,2)));
0055 end
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070 function J= conductivity_jacobian_perturb( pp, delta, img );
0071
0072 J = zeros( pp.n_meas, pp.n_elem );
0073
0074 elem_data = img.elem_data;
0075 d0= fwd_solve( img );
0076 for i=1:pp.n_elem
0077 img.elem_data = elem_data;
0078 img.elem_data(i)= elem_data(i) + delta;
0079 di= fwd_solve( img );
0080 J(:,i) = (1/delta) * (di.meas - d0.meas);
0081 end
0082
0083
0084 function J= movement_jacobian( pp, delta, img )
0085
0086 J = zeros( pp.n_meas, pp.n_elec*pp.n_dims );
0087
0088 node0= img.fwd_model.nodes;
0089 d0= fwd_solve_halfspace( img );
0090 for d= 1:pp.n_dims
0091 for i= 1:pp.n_elec
0092 idx= img.fwd_model.electrode(i).nodes;
0093
0094 img.fwd_model.nodes( idx, d)= node0(idx,d) + delta;
0095 di= fwd_solve_halfspace( img );
0096 img.fwd_model.nodes( idx, d)= node0(idx,d);
0097
0098 J_idx = pp.n_elec*(d-1) + i;
0099 J(:,J_idx) = (1/delta) * (di.meas - d0.meas);
0100 end
0101 end