- Timestamp:
- Dec 7, 2015, 7:52:53 PM (11 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/opihi/cmd.astro/fitplx_irls.c (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/cmd.astro/fitplx_irls.c
r39228 r39236 25 25 } 26 26 27 int Noutlier = 0;28 float dPsigMax = FLT_MAX;29 if ((N = get_argument (argc, argv, "-outlier-tests"))) {30 remove_argument (N, &argc, argv);31 Noutlier = atoi(argv[N]);32 remove_argument (N, &argc, argv);33 dPsigMax = atof(argv[N]);34 remove_argument (N, &argc, argv);35 }36 37 27 int Nresample = 0; 38 28 if ((N = get_argument (argc, argv, "-bootstrap-resample"))) { … … 42 32 } 43 33 44 Vector *dPvec = NULL;45 if ((N = get_argument (argc, argv, "-dPsig"))) {46 if (!Noutlier) { gprint (GP_ERR, "-dPsig requires -outlier-tests to be non-zero\n"); return FALSE; }47 remove_argument (N, &argc, argv);48 if (!(dPvec = SelectVector (argv[N], ANYVECTOR, TRUE))) return FALSE;49 remove_argument (N, &argc, argv);50 }51 52 34 int max_iterations = 10; 53 35 if ((N = get_argument (argc, argv, "-max-iterations"))) { … … 57 39 } 58 40 59 Vector *outMask = NULL;60 if ((N = get_argument (argc, argv, "-out-mask"))) {61 remove_argument (N, &argc, argv);62 if (!(outMask = SelectVector(argv[N], ANYVECTOR, TRUE))) return FALSE;63 remove_argument (N, &argc, argv);64 }65 66 41 double outlier_limit = 0.1; 67 42 if ((N = get_argument (argc, argv, "-outlier-limit"))) { … … 74 49 if (argc != 6) { 75 50 gprint (GP_ERR, "USAGE: fitplx (ra) (dR) (dec) (dD) (mjd) [-mask mask] [-v] [-vv]\n"); 76 gprint (GP_ERR, " -outlier-tests Nsamples dPsigMax : run Nsample bootstrap-resamples to define the path deviations and reject based on dPsigMax\n");77 gprint (GP_ERR, " -dPsig vec : save path deviations in vec\n");78 51 gprint (GP_ERR, " -max-iterations : maximum number of IRLS iterations to run (default 10)\n"); 79 gprint (GP_ERR, " -outMask vect : save outlier mask in vec\n");80 52 gprint (GP_ERR, " -outlier-limit : fraction of average weight to reject on (default 0.1)\n"); 81 53 return (FALSE); … … 109 81 // Nsubset : unmasked points 110 82 int Ntotal = tvec->Nelements; // XXX check other lengths 111 if (dPvec) ResetVector (dPvec, OPIHI_FLT, Ntotal);112 if (outMask) ResetVector (outMask, OPIHI_INT, Ntotal);113 83 114 84 double Rmean, Dmean, Tmean; … … 125 95 PlxFitDataAlloc (&fitdata, Ntotal); 126 96 PlxSetEpochPosition (&fitdata, R, D, dR, dD, T, mask, Ntotal, &coords, Tmean); 97 // fitdata only contains the points which are not masked 127 98 128 99 PlxFit fit; memset (&fit, 0, sizeof(PlxFit)); 129 100 130 if (0) {131 // This should be accomplished via the IRLS call132 // determine dPsig for detections based on Noutlier attempts133 if (Noutlier) {134 int clipRetry = TRUE;135 for (i = 0; clipRetry && (i < 3); i++) {136 clipRetry = !PlxOutlierClip (&fitdata, mask, Noutlier, dPsigMax, dPvec, VERBOSE);137 138 // using the new mask values, reset fitdata139 PlxSetMeanEpoch (R, D, T, &Rmean, &Dmean, &Tmean, mask, Ntotal);140 PlxSetEpochPosition (&fitdata, R, D, dR, dD, T, mask, Ntotal, &coords, Tmean);141 if (VERBOSE) fprintf (stderr, "keep %d of %d\n", fitdata.Npts, Ntotal);142 }143 }144 }145 146 101 for (i = 0; (VERBOSE == 2) && (i < fitdata.Npts); i++) { 147 102 int n = fitdata.index[i]; 148 int maskValue = mask ? mask[n] : 0;103 int maskValue = mask ? mask[n] : 1; 149 104 fprintf (stderr, "%f %f : %f %d : %f %f %f\n", R[n], D[n], T[n], maskValue, fitdata.t[i], fitdata.X[i], fitdata.Y[i]); 150 105 } … … 159 114 return FALSE; 160 115 } 161 162 // Set the output mask based on the input mask and the outlier limits. 163 if (outMask) { 164 double Sum_Wx = 0; 165 double Sum_Wy = 0; 166 int *outMask_V = outMask->elements.Int; 167 for (i = 0; i < fitdata.Npts; i++) { 168 Sum_Wx += fitdata.Wx[i]; 169 Sum_Wy += fitdata.Wy[i]; 170 } 171 for (i = 0; i < Ntotal; i++) { 172 outMask_V[i] = mask ? mask[i] : 0; 173 } 174 175 for (i = 0; i < fitdata.Npts; i++) { 176 if ((fitdata.Wx[i] > outlier_limit * Sum_Wx / (1.0 * fitdata.Npts))|| 177 (fitdata.Wy[i] > outlier_limit * Sum_Wy / (1.0 * fitdata.Npts))) { 178 int n = fitdata.index[i]; 179 outMask_V[n] = 1; 180 181 if (VERBOSE == 2) { 182 fprintf (stderr, "%f %f : %f %d : %f %f %f : %f %f %f %f\n", R[n], D[n], T[n], outMask_V[n], fitdata.t[i], fitdata.X[i], fitdata.Y[i], fitdata.Wx[i], fitdata.Wy[i], Sum_Wx, Sum_Wy); 183 } 184 } 185 } 186 } 187 188 116 // FitPMandPar_IRLS sets the values of Wx,Wy based on the fit distance 117 118 // update the mask based on the input mask and the outlier limits. 119 double Sum_Wx = 0; 120 double Sum_Wy = 0; 121 mask = mvec->elements.Int; 122 for (i = 0; i < fitdata.Npts; i++) { 123 Sum_Wx += fitdata.Wx[i]; 124 Sum_Wy += fitdata.Wy[i]; 125 } 126 for (i = 0; i < fitdata.Npts; i++) { 127 // fitdata only includes the previously unmasked points 128 if ((fitdata.Wx[i] < outlier_limit * Sum_Wx / (1.0 * fitdata.Npts))|| 129 (fitdata.Wy[i] < outlier_limit * Sum_Wy / (1.0 * fitdata.Npts))) { 130 int n = fitdata.index[i]; 131 mask[n] = 0; 132 133 if (VERBOSE == 2) { 134 fprintf (stderr, "%f %f : %f %d : %f %f %f : %f %f %f %f\n", R[n], D[n], T[n], mask[n], fitdata.t[i], fitdata.X[i], fitdata.Y[i], fitdata.Wx[i], fitdata.Wy[i], Sum_Wx, Sum_Wy); 135 } 136 } 137 } 138 189 139 if (Nresample){ 140 // now that the mask has been updated, we need to recalculate mean epoch and positions 141 // XXX make this conditional on actually masking unmasked points above 142 PlxSetMeanEpoch (R, D, T, &Rmean, &Dmean, &Tmean, mask, Ntotal); 143 PlxSetEpochPosition (&fitdata, R, D, dR, dD, T, mask, Ntotal, &coords, Tmean); 144 190 145 PlxFitData sample; 191 146 PlxFitDataAlloc (&sample, fitdata.Npts); … … 319 274 } 320 275 276 // XXX EAM : I suggest making these static as well like the A and B matrices 321 277 // Allocate the IRLS specific objects 322 278 ALLOCATE (Cov, double *, 5); … … 327 283 ALLOCATE(Beta, double, 5); 328 284 ALLOCATE(Beta_prev, double, 5); 329 // ALLOCATE(Wx, double, Npts);330 // ALLOCATE(Wy, double, Npts);331 285 ALLOCATE(rx, double, Npts); 332 286 ALLOCATE(ry, double, Npts); … … 348 302 sigma_ols = 0.0; 349 303 for (i = 0; i < Npts; i++) { 304 // double Xf = B[0][0] + B[1][0]*T[i] + B[4][0]*pR[i]; 305 // double Yf = B[2][0] + B[3][0]*T[i] + B[4][0]*pD[i]; 306 350 307 rx[i] = X[i] - (T[i] * B[1][0] + B[0][0] + B[4][0] * pR[i]); 351 308 ry[i] = Y[i] - (T[i] * B[3][0] + B[2][0] + B[4][0] * pD[i]); 309 310 352 311 // u[i] = r[i] / 353 312 sigma_ols += SQ(rx[i]) + SQ(ry[i]); 354 355 313 } 356 314 sigma_ols = sqrt(sigma_ols / (Npts - 5.0)); … … 390 348 391 349 // Solve 392 if (!weighted_LS_PLX(T,p D,pR,X,Wx,Y,Wy,Npts,A,B,VERBOSE)) {350 if (!weighted_LS_PLX(T,pR,pD,X,Wx,Y,Wy,Npts,A,B,VERBOSE)) { 393 351 // Handle fail case 394 352 return(FALSE); … … 478 436 } 479 437 } 480 481 482 438 483 439 // Finish
Note:
See TracChangeset
for help on using the changeset viewer.
