0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025 function [xest,A,v,weights,Cov] = estimate_profile_robust...
0026 (N,ts,ys,sigma_e,sigma_n,Niter,type_out,type_r,...
0027 print_type,plot_type)
0028
0029
0030 k = 2;
0031
0032 type_robust = type_r(1);
0033 g_factor = type_r(2);
0034 w_factor = type_r(3);
0035 rob_p_d = type_r(4);
0036
0037
0038 M = length(ts);
0039 A = zeros(M+N-2,N);
0040
0041
0042 xa = zeros(N,1);
0043 weights = ones(M+N-2,1);
0044 Cov = 0;
0045 sigma_e0 = sigma_e;
0046 gain = 1;
0047
0048
0049 for iter = 1:Niter+1
0050 if plot_type> 0
0051 figure
0052 end
0053
0054 sigma_e = sigma_e0*gain^(Niter-iter);
0055
0056 if print_type > 0
0057 iter__sigmae_sigma_n_ratio = [iter,sigma_e,sigma_n,sigma_e/sigma_n]
0058 weight_before_iteration = weights(1:20)'
0059 end
0060
0061 b=zeros(M+N-2,1);
0062
0063 for m = 1:M
0064 w = 1/sigma_n*sqrt(weights(m));
0065 A(m,ts(m)) = w;
0066 dl = ys(m)-xa(ts(m));
0067 b(m) = dl*w;
0068 end
0069
0070 kk = M;
0071
0072 for n = 2:N-1
0073 kk = kk+1;
0074 w = 1/sigma_e*sqrt(weights(kk));
0075 A(kk,n-1:n+1)= [1 -2 1]*w;
0076 dl = -(xa(n+1)-2*xa(n)+xa(n-1));
0077 b(kk) = dl*w;
0078 end
0079
0080
0081 Nmatrix = A'*A;
0082 nvector = A'*b;
0083 if N <= 1000
0084 Cov = inv(Nmatrix);
0085 end
0086
0087
0088 dx = Nmatrix\nvector;
0089
0090 xa = xa+dx;
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103 if iter == Niter+1 && print_type > 0
0104 xa_dx = [xa';dx']
0105 end
0106 v = A*dx-b;
0107
0108
0109 eso_robust = median(abs(v()))*1.48;
0110
0111 vori=v;
0112 vori(1:M) = v(1:M)*sigma_n./sqrt(weights(1:M));
0113 vori(M+1:end) = v(M+1:end)*sigma_e./sqrt(weights(M+1:end));
0114 vs = vori;
0115
0116
0117 eso_n = median(abs(vs(1:M)))*1.48;
0118
0119
0120 eso_e = median(abs(vs(M+1:end)))*1.48;
0121
0122 if print_type > 0
0123 estimated_s0_s0p_s0k=[eso,eso_p,eso_k]
0124 end
0125
0126
0127 kn = k*eso_n;
0128 ke = k*eso_e;
0129
0130
0131 if iter < Niter
0132 if type_out == 0
0133 if print_type > 0
0134 disp('rob_p_d')
0135 end
0136 if iter < 4
0137 if rob_p_d == 1 || rob_p_d == 3
0138 weights(M+1:M+N-2) = ...
0139 min(1,1./(abs(vs(M+1:M+N-2))/ke+0.0001));
0140
0141
0142
0143 if print_type > 1
0144 iter_ke_max_v_min_w = ...
0145 [iter,ke,max(abs(vs(M+1:M+N-2))),...
0146 min(weights(M+1:M+N-2))];
0147 disp('iter_ke_max_v_min_w')
0148 disp('modify dem weights')
0149 residuals_new_weights_of_dem=...
0150 [vs(M+1:M+N-2)';weights(M+1:M+N-2)'];
0151 disp('residuals_new_weights_of_dem')
0152 end
0153 if plot_type > 0
0154 subplot(3,1,1)
0155 plot(2:N-1,xa(2:N-1),'-b')
0156 title(num2str(sigma_e/sigma_n));
0157 subplot(3,1,2);
0158 hold on
0159 plot(2:N-1,vs(M+1:M+N-2),'-b')
0160 plot(2:N-1,vori(M+1:M+N-2),'-r')
0161 plot(2:N-1,ones(N-2,1)*ke,'-b')
0162 plot(2:N-1,-ones(N-2,1)*ke,'-b')
0163 title(num2str(ke))
0164 subplot(3,1,3);
0165 plot(2:N-1,weights(M+1:M+N-2),'-b')
0166 title(num2str(iter))
0167 end
0168 end
0169 if rob_p_d == 2 || rob_p_d == 3
0170 weights(1:M) = min(1,1./(abs(vs(1:M))/kn+0.0001));
0171
0172
0173
0174 if print_type > 1
0175 residuals_new_weights_of_points_L1 = ...
0176 [(1:20);v(1:20)';vs(1:20)';weights(1:20)']
0177 end
0178 end
0179 else
0180 if rob_p_d == 1 || rob_p_d == 3
0181 weights(M+1:M+N-2) = exp(-abs(vs(M+1:M+N-2)).^2./ke^2/2)+0.0001;
0182
0183
0184
0185 if print_type > 1
0186 iter_kk_max_v_min_w = ...
0187 [iter,ke,max(abs(vs(M+1:M+N-2))),min(weights(M+1:M+N-2))]
0188 disp('modify dem weights')
0189 residuals_new_weights_of_dem = ...
0190 [vs(M+1:M+N-2)';weights(M+1:M+N-2)']
0191 end
0192
0193 if plot_type > 0
0194 subplot(3,1,1)
0195 plot(2:N-1,xa(2:N-1),'-b')
0196 title(num2str(sigma_e/sigma_n));
0197 subplot(3,1,2);
0198 hold on
0199 plot(2:N-1,vs(M+1:M+N-2),'-b')
0200 plot(2:N-1,vori(M+1:M+N-2),'-r')
0201 plot(2:N-1,ones(N-2,1)*ke,'-b')
0202 plot(2:N-1,-ones(N-2,1)*ke,'-b')
0203 title(num2str(ke))
0204 subplot(3,1,3);
0205 plot(2:N-1,weights(M+1:M+N-2),'-b')
0206 title(num2str(iter))
0207 end
0208 end
0209 if rob_p_d == 2 || rob_p_d == 3
0210 weights(1:M) = exp(-abs(vs(1:M)).^2/kn^2/2)+0.0001;
0211
0212
0213
0214 if print_type > 1
0215 residuals_new_weights_of_points_exp = ...
0216 [(1:20);v(1:20)';vs(1:20)'/kn;weights(1:20)']
0217 end
0218 end
0219 end
0220 else
0221 k = 1;
0222 g = g_factor*k;
0223 w = w_factor*k;
0224 if type_robust==0
0225 weights(1:M) = max(min(1,1./abs(vs(1:M))/k+0.0001),((sign(vs(1:M))/k)+1)/2);
0226 else
0227 for m=1:M
0228 if vs(m) < g-w
0229 weights(m) = 0;
0230 elseif vs(m) > g
0231 weights(m)=1;
0232 else
0233 weights(m)=1/(1+(vs(m)-g)^4);
0234 end
0235 end
0236 end
0237 end
0238 else
0239
0240 weights = 0.9999*ceil(weights-0.5)+0.0001;
0241
0242 if iter == Niter
0243 xa = zeros(N,1);
0244 end
0245 end
0246 end
0247
0248 xest = xa;
0249
0250
0251