0001 function Reg= prior_gaussian_HPF( fwd_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
0028
0029
0030
0031
0032
0033
0034 if ischar(fwd_model) && strcmp(fwd_model,'UNIT_TEST'); do_unit_test; return; end
0035
0036 if ~strcmp(fwd_model.type, 'fwd_model')
0037 fwd_model= fwd_model.fwd_model;
0038 end
0039 try
0040 diam_frac= fwd_model.prior_gaussian_HPF.diam_frac;
0041 catch
0042 diam_frac= 0.1;
0043 end
0044 try
0045 diam_frac= fwd_model.prior_gaussian_HPF.zero_thresh;
0046 catch
0047 zero_thresh = .0001;
0048 end
0049
0050 copt.cache_obj= {fwd_model.nodes, fwd_model.elems, diam_frac};
0051 copt.fstr = 'prior_gaussian_HPF';
0052 Reg = eidors_cache(@calc_Gaussian_HPF, {fwd_model, diam_frac, zero_thresh}, copt );
0053
0054 function filt= calc_Gaussian_HPF( fmdl, diam_frac, zero_thresh)
0055 pts = interp_mesh(fmdl,3);
0056 fmdl.interp_mesh.n_interp = 0;
0057 ptc = interp_mesh(fmdl,0);
0058
0059
0060 mdl_dim = max(fmdl.nodes) - min(fmdl.nodes);
0061 mdl_dim = mean(mdl_dim(1:2));
0062
0063 beta=2.769/(diam_frac * mdl_dim)^2;
0064 dim = elem_dim(fmdl);
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074 Abeta_pi = get_elem_volume(fmdl,'no_c2f') ...
0075 *(beta/pi)^(dim/2);
0076 for j= 1:num_elems(fmdl)
0077 dif = bsxfun(@minus, pts, ptc(j,:));
0078 r2 = sum(dif.^2, 2);
0079 mean_elem = mean( exp(-beta*r2 ),3);
0080 flt(:,j)=Abeta_pi.*mean_elem;
0081 end
0082
0083 flt = flt./sum(flt);
0084
0085 flt=eye(num_elems(fmdl)) - flt;
0086 flt= ( flt+flt' )/ 2;
0087 filt= sparse(flt.*(abs(flt)>zero_thresh));
0088
0089
0090
0091 function filt= calc_Gaussian_HPF_old( fmdl, diam_frac)
0092 ELEM= fmdl.elems';
0093 NODE= fmdl.nodes';
0094
0095
0096 e= size(ELEM, 2);
0097 np= 128;
0098 [x,xc,y,yc] = interp_points(NODE,ELEM,np);
0099
0100 v_yx= [-y,x];
0101 o= ones(np*np,1);
0102 filt= zeros(e);
0103 tourne= [0 -1 1;1 0 -1;-1 1 0];
0104
0105 for j= 1:e
0106
0107 xy= NODE(:,ELEM(:,j))';
0108 a= xy([2;3;1],1).*xy([3;1;2],2) ...
0109 -xy([3;1;2],1).*xy([2;3;1],2);
0110 aire=abs(sum(a));
0111 mx_xy = max(xy);
0112 mn_xy = min(xy);
0113 endr=find(y<=mx_xy(2) & y>=mn_xy(2) ...
0114 & x<=mx_xy(1) & x>=mn_xy(1) )';
0115 aa= sum(abs(ones(length(endr),1)*a' ...
0116 +v_yx(endr,:)*xy'*tourne)');
0117 endr( find( abs(1 - aa / aire) > 1e-8 ) )=[];
0118 ll=length(endr); endr=endr-1;
0119
0120 yp= rem(endr,np)/(np-1) - .5;
0121 ym= ones(e,1)*yp -yc*ones(1,ll);
0122 xp= floor(endr/np)/(np-1) - .5;
0123 xm= ones(e,1)*xp -xc*ones(1,ll);
0124
0125 beta=2.769/diam_frac.^2;
0126
0127 filt(:,j)=-beta/pi*sum( exp(-beta*(ym.^2+xm.^2))')';
0128 end
0129
0130 filt=filt/np^2+eye(e);
0131 filt= ( filt+filt' )/ 2;
0132 filt= sparse(filt.*(abs(filt)>.003));
0133
0134 function [x,xc,y,yc] = interp_points(NODE,ELEM,np);
0135 taille=max(NODE')-min(NODE');
0136 e= size(ELEM, 2);
0137
0138
0139 xt= reshape(NODE(1,ELEM(:)),3,e)';
0140 yt= reshape(NODE(2,ELEM(:)),3,e)';
0141
0142
0143 pts= [2,2,2;4,1,1;1,4,1;1,1,4]'/6;
0144 xp= xt*pts;
0145 yp= yt*pts;
0146
0147 [x y]=meshgrid( ...
0148 linspace( min(NODE(1,:)), max(NODE(1,:)) ,np ), ...
0149 linspace( min(NODE(2,:)), max(NODE(2,:)) ,np ) );
0150
0151
0152 x= [x(:);xp(:)];
0153 y= [y(:);yp(:)];
0154
0155
0156
0157 xc= mean(xt,2)/taille(1);
0158 yc= mean(yt,2)/taille(2);
0159
0160 function do_unit_test
0161 imdl = mk_common_model('a2c0',16);
0162 RtR = prior_gaussian_HPF(imdl);
0163 tt=[0.557367798877852, -0.124016055611277, -0.029231532288002, -0.124016055611277];
0164 unit_test_cmp('a2c2 :1', RtR(1,1:4),tt,1e-10);
0165
0166
0167 RtR= calc_Gaussian_HPF_old( imdl.fwd_model, 0.1);
0168 tt=[0.562239752317943, -0.117068756722254, -0.025875127622824, -0.117068756722254];
0169 unit_test_cmp('a2c2 _old :1', RtR(1,1:4),tt,1e-10);
0170
0171 imdl = mk_common_model('a3cr',16);
0172 RtR = prior_gaussian_HPF(imdl);
0173 tt=[0.793660877689329,-0.096517734290331;
0174 -0.096517734290331, 0.793660877689329;
0175 -0.004236643618993,-0.011516904603663;
0176 -0.011516904603663,-0.004236643618993];
0177 unit_test_cmp('a3cr :1', RtR(1:4,1:2),tt,1e-10);
0178
0179 ls = -1:.1:1;
0180 fmdl = mk_grid_model([], ls, ls);
0181 fmdl = rmfield(fmdl,'coarse2fine');
0182 RtR = prior_gaussian_HPF(fmdl);
0183
0184
0185 ll= 2*(length(ls)-1);
0186 unit_test_cmp('2D space indep', ...
0187 RtR(10*ll+(1:4),10*ll+(1:4)), ...
0188 RtR(12*ll+(1:4),12*ll+(1:4)), 1e-14);
0189
0190
0191 ls = -1:.2:1;
0192 fmdl = mk_grid_model([],ls,ls,(-4:2:4)/10);
0193 fmdl = rmfield(fmdl,'coarse2fine');
0194 RtR = prior_gaussian_HPF(fmdl);
0195
0196
0197 ll= 6*(length(ls)-1);
0198 lv= 6*(length(ls)-1)^2;
0199 unit_test_cmp('3D space indep', ...
0200 RtR(lv+3*ll+(1:4),lv+3*ll+(1:4)), ...
0201 RtR(lv+5*ll+(1:4),lv+5*ll+(1:4)), 1e-14);
0202