0001 function J= aa_e_move_jacobian( fwd_model, img)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 pp= aa_fwd_parameters( fwd_model );
0019 delta= 1e-6;
0020
0021
0022 if isfield(fwd_model,'conductivity_jacobian')
0023 Jc= feval(fwd_model.conductivity_jacobian, fwd_model, img );
0024 else
0025 Jc= conductivity_jacobian_perturb( pp, delta, img );
0026 end
0027
0028 Jm= movement_jacobian( pp, delta, img );
0029 J= [Jc,Jm];
0030
0031
0032 if pp.normalize
0033 data= fwd_solve( img );
0034 J= J ./ (data.meas(:)*ones(1,size(J,2)));
0035 end
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050 function J= conductivity_jacobian_perturb( pp, delta, img );
0051
0052 J = zeros( pp.n_meas, pp.n_elem );
0053
0054 elem_data = img.elem_data;
0055 d0= fwd_solve( img );
0056 for i=1:pp.n_elem
0057 img.elem_data = elem_data;
0058 img.elem_data(i)= elem_data(i) + delta;
0059 di= fwd_solve( img );
0060 J(:,i) = (1/delta) * (di.meas - d0.meas);
0061 end
0062
0063
0064 function J= movement_jacobian( pp, delta, img )
0065
0066 J = zeros( pp.n_meas, pp.n_elec*pp.n_dims );
0067
0068 node0= img.fwd_model.nodes;
0069 d0= fwd_solve( img );
0070 for d= 1:pp.n_dims
0071 for i= 1:pp.n_elec
0072 idx= img.fwd_model.electrode(i).nodes;
0073
0074 img.fwd_model.nodes( idx, d)= node0(idx,d) + delta;
0075 di= fwd_solve( img );
0076 img.fwd_model.nodes( idx, d)= node0(idx,d);
0077
0078 J_idx = pp.n_elec*(d-1) + i;
0079 J(:,J_idx) = (1/delta) * (di.meas - d0.meas);
0080 end
0081 end