- Timestamp:
- Oct 6, 2016, 9:44:08 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/czw_branch/20160809/Ohana/src/relastro/src/FitPMandPar.c
r39612 r39731 25 25 } 26 26 27 fit->useWeight = FALSE; // Ordinary Least Squares 27 28 if (!FitPMandPar_MinChisq (fit, data, points, Npoints)) return FALSE; 28 29 if (!FitPMandPar_SetChisq (fit, data, points, Npoints)) return FALSE; … … 47 48 48 49 // Solve OLS equation: failure here means the chisq matrix is degenerate, give up entirely 50 fit->useWeight = FALSE; // Ordinary Least Squares 49 51 if (!FitPMandPar_MinChisq(fit, data, points, Npoints)) { 50 52 return(FALSE); … … 90 92 91 93 // Solve with the new weights 94 fit->useWeight = TRUE; // Reweighted Least Squares 92 95 if (!FitPMandPar_MinChisq(fit, data, points, Npoints)) { 93 96 … … 157 160 } 158 161 159 // this section calculates the formal error on the weightedfit using the covariance values160 // NOTE EAM: in tests (fitpm.c), they seem to be too large by a factor of ~5.37162 // this section calculates the formal error on the regular (unweighted) fit using the covariance values 163 // NOTE 20160929 : use only the unmasked points to calculate the error 161 164 if (data->getError) { 162 double ax = 0.0, ay = 0.0; 163 double bx = 0.0, by = 0.0; 164 165 for (i = 0; i < Npoints; i++) { 166 ax += dpsi_cauchy(points[i].rx / points[i].dX); 167 ay += dpsi_cauchy(points[i].ry / points[i].dY); 168 169 bx += SQ(points[i].Wx); 170 by += SQ(points[i].Wy); 171 } 172 ax /= 1.0 * Npoints; // mean(psi_dot(r)) 173 ay /= 1.0 * Npoints; 174 bx /= 1.0 * (Npoints - data->Nterms); // mean(psi^2(r)) * (N / (N-p)) 175 by /= 1.0 * (Npoints - data->Nterms); 176 177 double lambda_x = 1.0 + (data->Nterms / Npoints) * (1 - ax) / ax; 178 double lambda_y = 1.0 + (data->Nterms / Npoints) * (1 - ay) / ay; 179 180 double sigma_robust_x = lambda_x * sqrt(bx) * sigma_hat * 2.385 / ax; 181 double sigma_robust_y = lambda_y * sqrt(by) * sigma_hat * 2.385 / ay; 182 183 // This is actually sigma^2, as that's the factor in the covariance (dumouchel 4.1) 184 double sigma_final_x = MAX(SQ(sigma_robust_x), (2 * Npoints * SQ(sigma_robust_x) + SQ(data->Nterms * sigma_ols)) / (2 * Npoints + SQ(data->Nterms))); 185 double sigma_final_y = MAX(SQ(sigma_robust_y), (2 * Npoints * SQ(sigma_robust_y) + SQ(data->Nterms * sigma_ols)) / (2 * Npoints + SQ(data->Nterms))); 186 187 fit[0].dRo = sqrt(data->Cov[0][0]); 188 fit[0].duR = sqrt(data->Cov[1][1]); 189 fit[0].dDo = sqrt(data->Cov[2][2]); 190 fit[0].duD = sqrt(data->Cov[3][3]); 191 fit[0].dp = sqrt(data->Cov[4][4]); 192 193 fit[0].dRo *= sigma_final_x; 194 fit[0].duR *= sigma_final_x; 195 fit[0].dDo *= sigma_final_y; 196 fit[0].duD *= sigma_final_y; 197 fit[0].dp *= sqrt(sigma_final_x * sigma_final_y); 165 FitAstromResult fitErrors; 166 FitAstromResultInit (&fitErrors); 167 fitErrors.useWeight = FALSE; 168 169 FitPMandPar_MinChisq(&fitErrors, data, points, Npoints); 170 171 // we use the errors from a simple OLS, ignoring masked points 172 fit[0].dRo = fitErrors.dRo; 173 fit[0].duR = fitErrors.duR; 174 fit[0].dDo = fitErrors.dDo; 175 fit[0].duD = fitErrors.duD; 176 fit[0].dp = fitErrors.dp; 198 177 } 199 178 … … 219 198 Nfit ++; 220 199 221 wx = points[i].qx; 222 wy = points[i].qy; 200 if (fit->useWeight) { 201 wx = points[i].qx; 202 wy = points[i].qy; 203 } else { 204 wx = points[i].Qx; 205 wy = points[i].Qy; 206 } 223 207 224 208 Wx += wx;
Note:
See TracChangeset
for help on using the changeset viewer.
