0001 function Reg= prior_laplace_old( inv_model );
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027 if ischar(inv_model) && strcmp(inv_model,'UNIT_TEST'); do_unit_test; return; end
0028
0029 switch inv_model.type
0030 case 'inv_model'; fwd_model = inv_model.fwd_model;
0031 case 'fwd_model'; fwd_model = inv_model;
0032 otherwise; error('PRIOR_LAPLACE requires input type of inv_model or fwd_model');
0033 end
0034
0035 Reg = eidors_cache(@build_laplace, fwd_model, 'prior_laplace');
0036
0037 function Reg = build_laplace(fwd_model)
0038
0039 pp= fwd_model_parameters( fwd_model );
0040 Reg = speye( pp.n_elem );
0041
0042 Iidx= [];
0043 Jidx= [];
0044 Vidx= [];
0045 for ii=1:pp.n_elem
0046 el_adj = find_adjoin( ii, pp.ELEM );
0047 for jj=el_adj(:)'
0048 Iidx= [Iidx, ii, ii, jj, jj];
0049 Jidx= [Jidx, ii, jj, ii, jj];
0050 Vidx= [Vidx, 1, -1, -1, 1];
0051 end
0052 end
0053
0054 Reg = sparse(Iidx,Jidx, Vidx, pp.n_elem, pp.n_elem );
0055
0056
0057
0058 function elems= find_adjoin(ee, ELEM)
0059 nn= ELEM(:,ee);
0060 [d,e]= size(ELEM);
0061 ss = false(size(ELEM));
0062 for i=1:d
0063 ss= ss | ELEM==nn(i);
0064 end
0065 elems= find(sum(ss,1)==d-1);
0066
0067 function do_unit_test
0068
0069 imdl = mk_common_model('a2c2',16);
0070 RtR = prior_laplace_old( imdl );
0071 subplot(221); spy(RtR);
0072 unit_test_cmp('a2c2', nnz(RtR), 240);
0073
0074 fmdl = mk_circ_tank(2,[],4);
0075 RtR = prior_laplace_old( fmdl );
0076 subplot(222); spy(RtR);
0077 unit_test_cmp('2-4',RtR(1:4,1:8), [ ...
0078 6, -2, 0, -2, -2, 0, 0, 0; -2, 6, -2, 0, 0, -2, 0, 0;
0079 0, -2, 6, -2, 0, 0, -2, 0; -2, 0, -2, 6, 0, 0, 0, -2]);