inv_solve_abs_GN

PURPOSE ^

function img= inv_solve_abs_GN( inv_model, data1);

SYNOPSIS ^

function img= inv_solve_abs_GN( inv_model, data1);

DESCRIPTION ^

function img= inv_solve_abs_GN( inv_model, data1);
 INV_SOLVE_ABS_GN
 This function calls INV_SOLVE_ABS_CORE to find a Gauss-Newton
 iterative solution.

 img = inv_solve_abs_GN( inv_model, data1 )
   img        => output image data (or vector of images)
   inv_model  => inverse model struct
   data1      => measurements

 Example:
  imdl=mk_common_model('a2c');
  imdl.reconst_type='absolute'; % ***
  imdl.solve=@inv_solve_abs_GN; % ***
  fimg=mk_image(imdl,1);
  fimg.elem_data(5:10)=1.1;
  vi=fwd_solve(fimg);
  img=inv_solve(imdl,vi); % ***
  show_fem(img,1);

 See INV_SOLVE_ABS_CORE for arguments, options and parameters.

 (C) 2014 Alistair Boyle
 License: GPL version 2 or version 3
 $Id: inv_solve_abs_GN.m 4916 2015-05-07 18:58:28Z alistair_boyle $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function img= inv_solve_abs_GN( inv_model, data1);
0002 %function img= inv_solve_abs_GN( inv_model, data1);
0003 % INV_SOLVE_ABS_GN
0004 % This function calls INV_SOLVE_ABS_CORE to find a Gauss-Newton
0005 % iterative solution.
0006 %
0007 % img = inv_solve_abs_GN( inv_model, data1 )
0008 %   img        => output image data (or vector of images)
0009 %   inv_model  => inverse model struct
0010 %   data1      => measurements
0011 %
0012 % Example:
0013 %  imdl=mk_common_model('a2c');
0014 %  imdl.reconst_type='absolute'; % ***
0015 %  imdl.solve=@inv_solve_abs_GN; % ***
0016 %  fimg=mk_image(imdl,1);
0017 %  fimg.elem_data(5:10)=1.1;
0018 %  vi=fwd_solve(fimg);
0019 %  img=inv_solve(imdl,vi); % ***
0020 %  show_fem(img,1);
0021 %
0022 % See INV_SOLVE_ABS_CORE for arguments, options and parameters.
0023 %
0024 % (C) 2014 Alistair Boyle
0025 % License: GPL version 2 or version 3
0026 % $Id: inv_solve_abs_GN.m 4916 2015-05-07 18:58:28Z alistair_boyle $
0027 
0028 %--------------------------
0029 % UNIT_TEST?
0030 if isstr(inv_model) && strcmp(inv_model,'UNIT_TEST'); img = do_unit_test; return; end
0031 
0032 %if isfield(inv_model, 'inv_solve_abs_core') && isfield(inv_model, 'inv_solve_abs_GN')
0033 %   error('merging inv_solve_abs_core and inv_solve_abs_GN options is broken, please use only one method');
0034 %end
0035 %% merge legacy options locations
0036 inv_model = deprecate_imdl_opt(inv_model, 'parameters');
0037 inv_model = deprecate_imdl_opt(inv_model, 'inv_solve');
0038 inv_model = deprecate_imdl_opt(inv_model, 'inv_solve_abs_core');
0039 
0040 % inv_model.inv_solve_abs_GN -> inv_solve_abs_core
0041 if isfield(inv_model, 'inv_solve_abs_GN')
0042    if isfield(inv_model, 'inv_solve_abs_core')
0043       error('inv_model.inv_solve_abs_GN replaces inv_model.inv_solve_abs_core, parameters will be lost');
0044    end
0045    inv_model.inv_solve_abs_core = inv_model.inv_solve_abs_GN;
0046    inv_model = rmfield(inv_model, 'inv_solve_abs_GN');
0047 end
0048 
0049 img = inv_solve_abs_core(inv_model, data1);
0050 
0051 if isfield(img, 'inv_solve_abs_core')
0052   img.inv_solve_abs_GN = img.inv_solve_abs_core;
0053   img=rmfield(img, 'inv_solve_abs_core');
0054 end
0055 
0056 function imdl = deprecate_imdl_opt(imdl,opt)
0057    if ~isfield(imdl, opt)
0058       return;
0059    end
0060    if ~isstruct(imdl.(opt))
0061       error(['unexpected inv_model.' opt ' where ' opt ' is not a struct... i do not know what to do']);
0062    end
0063 
0064    % warn on anything but inv_model.inv_solve.calc_solution_error
0065    Af = fieldnames(imdl.(opt));
0066    if ~strcmp(opt, 'inv_solve') || (length(Af(:)) ~= 1) || ~strcmp(Af(:),'calc_solution_error')
0067       disp(imdl)
0068       disp(imdl.(opt))
0069       warning('EIDORS:deprecatedParameters',['INV_SOLVE inv_model.' opt '.* are deprecated in favor of inv_model.inv_solve_abs_GN.* as of 30-Apr-2014.']);
0070    end
0071 
0072    if ~isfield(imdl, 'inv_solve_abs_GN')
0073       imdl.inv_solve_abs_GN = imdl.(opt);
0074    else % we merge
0075       % merge struct trick from:
0076       %  http://stackoverflow.com/questions/38645
0077       for i = fieldnames(imdl.(opt))'
0078          imdl.inv_solve_abs_GN.(i{1})=imdl.(opt).(i{1});
0079       end
0080    end
0081    imdl = rmfield(imdl, opt);
0082 
0083 function pass = do_unit_test()
0084    pass=1;
0085    imdl=mk_common_model('a2c');
0086    imdl.reconst_type='absolute'; % ***
0087    imdl.solve=@inv_solve_abs_GN; % ***
0088    fimg=mk_image(imdl,1);
0089    fimg.elem_data(5:10)=1.1;
0090    vi=fwd_solve(fimg);
0091    img=inv_solve(imdl,vi); % ***
0092    clf; subplot(121); show_fem(fimg,1); title('forward model');
0093         subplot(122); show_fem(img,1);  title('reconstruction');
0094    try unit_test_cmp('fwd vs. reconst', fimg.elem_data, img.elem_data, 0.08);
0095    catch me; disp(me.message); pass=0; end
0096 %   pass = pass & inv_solve_abs_core('UNIT_TEST', 'inv_solve_abs_GN');

Generated on Tue 12-May-2015 16:00:42 by m2html © 2005