0001 function Reg= prior_covar( inv_model )
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 if ischar(inv_model) && strcmp(inv_model,'UNIT_TEST'); do_unit_test; return; end
0016
0017 params = {inv_model.fwd_model, inv_model.fourD_prior.P_type};
0018 Reg = eidors_cache(@prior_covar_calc, params, 'prior_covar');
0019
0020
0021 function Reg = prior_covar_calc(ff, P_type);
0022
0023 nel = size(ff.elems,1);
0024 eta = .1;
0025
0026 dist = zeros(nel);
0027
0028 z1 = ff.nodes(ff.electrode(1).nodes,3);
0029 z2 = ff.nodes(ff.electrode(end).nodes,3);
0030 zmax = max(z1,z2);
0031 zmin = min(z1,z2);
0032
0033 for dim = 1: size(ff.nodes,2);
0034 coords = reshape(ff.nodes(ff.elems,dim),[size(ff.elems)]);
0035 m_coords = mean( coords,2);
0036 difm = m_coords*ones(1,nel);
0037 difm = difm - difm';
0038 dist= dist + difm.^2;
0039 end
0040 dist = sqrt(dist);
0041
0042 dist = dist/max(dist(:));
0043
0044 Reg = exp(-dist ./ eta);
0045 if dim == 3
0046
0047
0048 above = m_coords>zmax;
0049 below = m_coords<zmin;
0050 switch P_type
0051 case 2
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064 Reg(above,~above) = 0;
0065 Reg(below,~below) = 0;
0066 case 3
0067
0068 temp = find( above | below);
0069 Reg(temp,temp) = 0;
0070 otherwise
0071 error('Prior type (%d) has not yet been defined',P_type);
0072 end
0073 end
0074
0075
0076 function do_unit_test
0077 imdl = mk_common_model('b3cr',[16,3]);
0078 imdl.fourD_prior.P_type = 2;
0079
0080 Reg = prior_covar( imdl );
0081 unit_test_cmp('#1:', diag(Reg), ones(size(Reg,1),1));
0082 unit_test_cmp('#2:', Reg(102:103,100:103), [ ...
0083 0.011818547266014 0.367556336897157 1.000000000000000 0.396442626219240; ...
0084 0.008985742075647 0.160077522568152 0.396442626219240 1.000000000000000], 1e-6);
0085
0086
0087
0088
0089 imdl.fourD_prior.P_type = 3;
0090 Reg = prior_covar( imdl );
0091 test = zeros(size(Reg,1),1); test(769:6912) = 1;
0092 unit_test_cmp('#1:', diag(Reg), test);
0093 unit_test_cmp('#2:', Reg(802:803,800:803), [ ...
0094 0.086725242542203 0.132995997778770 1.000000000000000 0.417609404846561; ...
0095 0.157824974662458 0.293750928546438 0.417609404846561 1.000000000000000], 1e-10);
0096