0001 function Reg= exponential_covar_prior( inv_model );
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 fwd_model= inv_model.fwd_model;
0021
0022 try
0023 gamma= inv_model.exponential_covar_prior.gamma;
0024 catch
0025 xy_diam = max( max(fwd_model.nodes(:,1:2)) - ...
0026 min(fwd_model.nodes(:,1:2)));
0027 gamma= 0.05*xy_diam;
0028 end
0029
0030 Reg = calc_exponential_covar_prior( fwd_model, gamma);
0031 Reg= 0.5*(Reg+Reg');
0032
0033 Reg= inv(Reg);
0034
0035 try
0036 noser_exp= inv_model.exponential_covar_prior.noser_exp;
0037 catch
0038 noser_exp= 0;
0039 end
0040
0041 if noser_exp>0
0042
0043 J = calc_jacobian( mk_image( inv_model ));
0044
0045
0046 n_elem = size(inv_model.fwd_model.elems,1);
0047 if size(J,2) > n_elem; J = J(:,1:n_elem); end
0048 l_prior= size(J,2);
0049
0050
0051 diag_col= sum(J.^2,1)';
0052 RegN = spdiags( diag_col.^noser_exp/2, 0, l_prior, l_prior);
0053
0054 Reg= RegN * Reg * RegN;
0055 end
0056
0057
0058
0059 function Reg= calc_exponential_covar_prior( fwd_model, gamma)
0060 [rad,ctr]= get_elem_rad_ctr( fwd_model );
0061
0062 n_elem= size(ctr,1);
0063 oo= ones(n_elem,1);
0064 radh = rad/2;
0065 Reg=zeros(n_elem,n_elem);
0066 for i=1:size(ctr,1)
0067 ctr_i = sqrt( sum( (ctr - oo*ctr(i,:)).^2 , 2));
0068 Reg_i= integ_fn(-radh,radh,ctr_i-radh(i),ctr_i+radh(i), gamma);
0069 Reg(:,i)= Reg_i .*(Reg_i>1e-4);
0070 end
0071 Reg=sparse(Reg);
0072
0073 function [rad,elem_ctr]= get_elem_rad_ctr( fwd_model );
0074 pp= aa_fwd_parameters( fwd_model);
0075 if pp.n_dims==2
0076 rad= sqrt(pp.VOLUME/pi);
0077 elseif pp.n_dims ==3
0078 rad= (pp.VOLUME*3/4/pi).^(1/3);
0079 elseif pp.n_dims ==1
0080 rad= pp.VOLUME/2;
0081 else
0082 error('dont know what to do with n_dims ==%d',pp.n_dims);
0083 end
0084
0085
0086 node_map = fwd_model.nodes(pp.ELEM,:);
0087 elem_ctr = mean( reshape( node_map, pp.n_dims+1, [], pp.n_dims), 1);
0088 elem_ctr = squeeze( elem_ctr);
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100 function fi= integ_fn(x1i,x2i,y1i,y2i, gamma)
0101 i_gam = 1/gamma;
0102
0103 x1= min(x1i,x2i); x2= max(x1i,x2i);
0104 y1= min(y1i,y2i); y2= max(y1i,y2i);
0105
0106 Dx= abs(x1-x2); Dy= abs(y1-y2);
0107
0108 xa1= x1;
0109 xa2= max(x1,min(x2,y1)); xb1= xa2;
0110 xb2= max(x1,min(x2,y2)); xc1= xb2;
0111 xc2= x2;
0112
0113 RA= exp(-i_gam*y1).*(1-exp(-i_gam*Dy));
0114 RC= exp( i_gam*y2).*(1-exp(-i_gam*Dy));
0115 fi = 1./Dx./Dy/i_gam^2 .* ( ...
0116 RA.*(exp( i_gam*xa2) - exp( i_gam*xa1)) - ...
0117 RC.*(exp(-i_gam*xc2) - exp(-i_gam*xc1)) + ...
0118 2*i_gam*(xb2-xb1) - ...
0119 exp(-i_gam*y2).*(exp( i_gam*xb2) - exp( i_gam*xb1)) + ...
0120 exp( i_gam*y1).*(exp(-i_gam*xb2) - exp(-i_gam*xb1))...
0121 );
0122
0123