0001 function RM= calc_TSVD_RM(mdl,hp)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 if isstr(mdl) && strcmp(mdl, 'UNIT_TEST'), do_unit_test, return,end
0017
0018
0019
0020 switch (mdl.type)
0021 case 'inv_model'
0022 fmdl = mdl.fwd_model;
0023 bkgnd_img = calc_jacobian_bkgnd(mdl);
0024 case 'fwd_model'
0025 fmdl = mdl;
0026 bkgnd_img = mk_image( fmdl,1) ;
0027 otherwise
0028 eidors_msg('calc_TSVD_RM: Object type not supported');
0029 end
0030
0031 if nargin < 2
0032 hp = 1;
0033 end
0034
0035 J= calc_jacobian(fmdl,bkgnd_img);
0036 imdl.solve = @solve_use_matrix;
0037 S = eidors_obj('get-cache',mdl,'TSVD_S');
0038 if isempty(S)
0039 [U,S,V] = svd(J,'econ');
0040 eidors_obj('set-cache',mdl,'TSVD_S',S);
0041 eidors_obj('set-cache',mdl,'TSVD_V',V);
0042 eidors_obj('set-cache',mdl,'TSVD_U',U);
0043 else
0044 U = eidors_obj('get-cache',mdl,'TSVD_U');
0045 V = eidors_obj('get-cache',mdl,'TSVD_V');
0046 end
0047 s = diag(S);
0048 s = s./s(1);
0049 N = find(s >= hp/100,1,'last');
0050 t= 1:N;
0051 RM = eidors_obj('get-cache',mdl,'TSVD_RM',N);
0052 if isempty(RM)
0053 RM = (V(:,t)/S(t,t))*U(:,t)';
0054 eidors_obj('set-cache',mdl,'TSVD_RM',RM,N);
0055 end
0056
0057
0058
0059 function do_unit_test
0060 mdl = mk_common_model('b3t2r',[16,1]);
0061 RM = calc_TSVD_RM(mdl);