calc_jacobian

PURPOSE ^

CALC_JACOBIAN: calculate jacobian from an inv_model

SYNOPSIS ^

function J = calc_jacobian( fwd_model, img)

DESCRIPTION ^

 CALC_JACOBIAN: calculate jacobian from an inv_model
 
  J = calc_jacobian( img )
      calc Jacobian on img.fwd_model at conductivity given
      in image (fwd_model is for forward and reconstruction)
 
 The actual work is done by the jacobian calculator specified in 
    img.fwd_model.jacobian, unless that field is numeric, in which case
    calc_jacobian returns its contents.

 For reconstructions on dual meshes, the interpolation matrix
    is defined as img.fwd_model.coarse2fine. This takes
    coarse2fine * x_coarse = x_fine

 If the underlying jacobian calculator doesn't understand dual
    meshes, then calc_jacobian will automatically postmultiply
    by fwd_model.coarse2fine.

 img       is an image structure, with 'elem_data' or
           'node_data' parameters

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function J = calc_jacobian( fwd_model, img)
0002 % CALC_JACOBIAN: calculate jacobian from an inv_model
0003 %
0004 %  J = calc_jacobian( img )
0005 %      calc Jacobian on img.fwd_model at conductivity given
0006 %      in image (fwd_model is for forward and reconstruction)
0007 %
0008 % The actual work is done by the jacobian calculator specified in
0009 %    img.fwd_model.jacobian, unless that field is numeric, in which case
0010 %    calc_jacobian returns its contents.
0011 %
0012 % For reconstructions on dual meshes, the interpolation matrix
0013 %    is defined as img.fwd_model.coarse2fine. This takes
0014 %    coarse2fine * x_coarse = x_fine
0015 %
0016 % If the underlying jacobian calculator doesn't understand dual
0017 %    meshes, then calc_jacobian will automatically postmultiply
0018 %    by fwd_model.coarse2fine.
0019 %
0020 % img       is an image structure, with 'elem_data' or
0021 %           'node_data' parameters
0022 
0023 % (C) 2005-08 Andy Adler. License: GPL version 2 or version 3
0024 % $Id: calc_jacobian.m 6083 2020-09-15 10:06:20Z aadler $
0025 
0026 
0027 if nargin == 1
0028    img= fwd_model;
0029 else
0030    warning('EIDORS:DeprecatedInterface', ...
0031       ['Calling CALC_JACOBIAN with two arguments is deprecated and will cause' ...
0032        ' an error in a future version. First argument ignored.']);
0033 end
0034 ws = warning('query','EIDORS:DeprecatedInterface');
0035 warning off EIDORS:DeprecatedInterface
0036 
0037 try 
0038    fwd_model= img.fwd_model;
0039 catch
0040    error('CALC_JACOBIAN requires an eidors image structure');
0041 end
0042 
0043 fwd_model_check(fwd_model);
0044 
0045 if isnumeric(fwd_model.jacobian)             % we have the Jacobian matrix
0046    J = fwd_model.jacobian;
0047 else                                         % we need to calculate
0048    
0049    copt.cache_obj= jacobian_cache_params( fwd_model, img );
0050    copt.fstr = 'jacobian';
0051    try
0052        fwd_model.jacobian = str2func(fwd_model.jacobian);
0053    end
0054    J = eidors_cache(fwd_model.jacobian, {fwd_model, img}, copt);
0055    
0056 end
0057 
0058 if isfield(fwd_model,'coarse2fine')
0059    c2f= fwd_model.coarse2fine;
0060    if size(J,2)==size(c2f,1)
0061 %     calc_jacobian did not take into account the coarse2fine
0062       J=J*c2f;
0063    end
0064 end
0065 
0066 warning(ws.state, 'EIDORS:DeprecatedInterface');
0067 
0068         
0069 
0070 
0071 
0072 % Make the Jacobian only depend on
0073 function cache_obj= jacobian_cache_params( fwd_model, img );
0074    img = data_mapper(img);
0075    if isfield(img, 'elem_data')
0076       cache_obj = {fwd_model, img.elem_data, img.current_params};
0077    elseif isfield(img, 'node_data')
0078       cache_obj = {fwd_model, img.node_data, img.current_params};
0079    else
0080       error('calc_jacobian: execting elem_data or node_data in image');
0081    end
0082 
0083 function fwd_model_check(fmdl)
0084    try; if fmdl.jacobian_dont_check
0085       return
0086    end; end
0087    pp = fwd_model_parameters(fmdl); % they cache, so no problem
0088    if pp.n_elec == 0
0089        error('Cannot calculate Jacobian. No electrodes found.');
0090    end
0091    if pp.n_stim == 0
0092        error('Cannot calculate Jacobian. No stimulation found.');
0093    end
0094    if pp.n_meas == 0
0095        error('Cannot calculate Jacobian. No measurements found.');
0096    end

Generated on Fri 30-Dec-2022 19:44:54 by m2html © 2005