IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 24, 2016, 5:07:24 PM (10 years ago)
Author:
eugene
Message:

modify irls fitting to apply the multiply the modified weight by the error-based weight

Location:
trunk/Ohana/src/opihi
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/cmd.astro/astrom_ops.c

    r39228 r39610  
    5454  ALLOCATE (data->Wx, double, N);
    5555  ALLOCATE (data->Wy, double, N);
     56  ALLOCATE (data->Qx, double, N);
     57  ALLOCATE (data->Qy, double, N);
     58  ALLOCATE (data->qx, double, N);
     59  ALLOCATE (data->qy, double, N);
    5660  ALLOCATE (data->index, int, N);
    5761  return TRUE;
     
    6872  FREE (data->Wx);
    6973  FREE (data->Wy);
     74  FREE (data->Qx);
     75  FREE (data->Qy);
     76  FREE (data->qx);
     77  FREE (data->qy);
    7078  FREE (data->index);
    7179}
  • trunk/Ohana/src/opihi/cmd.astro/fitplx.c

    r39234 r39610  
    597597  dsort (values, Npts);
    598598
    599   if (Npts % 2) {
    600     int Ncenter = Npts / 2;
    601     *median = values[Ncenter];
    602   } else {
    603     int Ncenter = Npts / 2 - 1;
    604     *median = 0.5*(values[Ncenter] + values[Ncenter + 1]);
    605   }
    606 
    607   double Slo = VectorFractionInterpolate (values, 0.158655, Npts);
    608   double Shi = VectorFractionInterpolate (values, 0.841345, Npts);
    609 
    610   *sigma = (Shi - Slo) / 2.0;
    611 
     599  if (median) {
     600    if (Npts % 2) {
     601      int Ncenter = Npts / 2;
     602      *median = values[Ncenter];
     603    } else {
     604      int Ncenter = Npts / 2 - 1;
     605      *median = 0.5*(values[Ncenter] + values[Ncenter + 1]);
     606    }
     607  }
     608   
     609  if (sigma) {
     610    double Slo = VectorFractionInterpolate (values, 0.158655, Npts);
     611    double Shi = VectorFractionInterpolate (values, 0.841345, Npts);
     612    *sigma = (Shi - Slo) / 2.0;
     613  }
     614 
    612615  return TRUE;
    613616}
  • trunk/Ohana/src/opihi/cmd.astro/fitplx_irls.c

    r39596 r39610  
    119119                         fitdata.t, fitdata.pX, fitdata.pY,
    120120                         fitdata.Wx, fitdata.Wy,
     121                         fitdata.Qx, fitdata.Qy,
     122                         fitdata.qx, fitdata.qy,
    121123                         fitdata.Npts, max_iterations, outlier_limit, binning_step, VERBOSE)) {
    122124    return FALSE;
     
    204206    }
    205207
    206     // now calculate median and sigma for each vector
    207     VectorRobustStats (pvec,  &fit.p,  &fit.dp);
    208     VectorRobustStats (uRvec, &fit.uR, &fit.duR);
    209     VectorRobustStats (uDvec, &fit.uD, &fit.duD);
    210     VectorRobustStats (Rvec,  &fit.Ro, &fit.dRo);
    211     VectorRobustStats (Dvec,  &fit.Do, &fit.dDo);
     208    // now calculate robust sigma for each vector
     209    VectorRobustStats (pvec,  NULL, &fit.dp);
     210    VectorRobustStats (uRvec, NULL, &fit.duR);
     211    VectorRobustStats (uDvec, NULL, &fit.duD);
     212    VectorRobustStats (Rvec,  NULL, &fit.dRo);
     213    VectorRobustStats (Dvec,  NULL, &fit.dDo);
     214
     215    PlxFitDataFree (&sample);   
    212216  }
    213217
     
    250254  set_variable ("Nfit",  fit.Nfit);
    251255
    252 
     256  PlxFitDataFree (&fitdata);
    253257 
    254258  return (TRUE);
     
    257261/* do we want an init function which does the alloc and a clear function to free? */
    258262int FitPMandPar_IRLS (PlxFit *fit, double *X, double *dX, double *Y, double *dY, double *T, double *pR, double *pD,
    259                       double *Wx, double *Wy,
     263                      double *Wx, double *Wy, double *Qx, double *Qy, double *qx, double *qy,
    260264                      int Npts, int max_iterations, double outlier_limit, double binning_step, int VERBOSE) {
    261265
     
    270274
    271275  double sigma_ols, sigma_hat; // Sigma estimates.
    272   //  double *Wx, *Wy;             // Weight vectors.  Not errors.
    273276  double *rx, *ry;             // Deviation from model
    274277  double *u;                   // Deviation magnitude
     
    305308  // Convert the measurement errors into the initial weights.
    306309  for (i = 0; i < Npts; i++) {
    307     Wx[i] = (fabs(dX[i]) < 0.0001) ? 1.0 : 1.0 / SQ(dX[i]);
    308     Wy[i] = (fabs(dY[i]) < 0.0001) ? 1.0 : 1.0 / SQ(dY[i]);
     310    Qx[i] = (fabs(dX[i]) < 0.0001) ? 1.0 : 1.0 / SQ(dX[i]);
     311    Qy[i] = (fabs(dY[i]) < 0.0001) ? 1.0 : 1.0 / SQ(dY[i]);
    309312  }
    310313 
     
    313316  // Solve OLS equation
    314317  if (binning_step == 0.0) {
    315     if (!weighted_LS_PLX(T,pR,pD,X,Wx,Y,Wy,Npts,
    316                          A,B,VERBOSE)) {
     318    if (!weighted_LS_PLX(T,pR,pD,X,Qx,Y,Qy,Npts,A,B,VERBOSE)) {
    317319      // Handle fail case
    318320      return(FALSE);
     
    329331    double *WYbin = NULL;
    330332
    331     if (!bin_points_PLX(T, pR, pD, X, Wx, Y, Wy, Npts,
     333    if (!bin_points_PLX(T, pR, pD, X, Qx, Y, Qy, Npts,
    332334                        &Tbin, &pRbin, &pDbin, &Xbin, &WXbin, &Ybin, &WYbin, &Nbins,  binning_step) ) {
    333335      return(FALSE);
     
    396398      Wx[i] = weight_cauchy(rx[i] / dX[i]);
    397399      Wy[i] = weight_cauchy(ry[i] / dY[i]);
     400      qx[i] = Qx[i] * Wx[i];
     401      qy[i] = Qy[i] * Wy[i];
    398402    }
    399403
    400404    // Solve
    401     if (!weighted_LS_PLX(T,pR,pD,X,Wx,Y,Wy,Npts,A,B,VERBOSE)) {
     405    if (!weighted_LS_PLX(T,pR,pD,X,qx,Y,qy,Npts,A,B,VERBOSE)) {
    402406      // Handle fail case
    403407      return(FALSE);
  • trunk/Ohana/src/opihi/include/astro.h

    r39585 r39610  
    2020  double *dX;
    2121  double *dY;
    22   double *Wx;
    23   double *Wy;
     22  double *Wx; // modified weight based on distance from fit
     23  double *Wy; // modified weight based on distance from fit
     24  double *Qx; // raw error-based weight (1/dX^2)
     25  double *Qy;
     26  double *qx; // modified error-based weight (1/dX^2) * Wx
     27  double *qy;
    2428  int *index;
    2529  int Npts;
     
    5963
    6064int FitPMonly_IRLS (PlxFit *fit, double *X, double *dX, double *Y, double *dY, double *T, int Npts, double binning_step, int VERBOSE);
    61 int FitPMandPar_IRLS (PlxFit *fit, double *X, double *dX, double *Y, double *dY, double *T, double *pR, double *pD, double *Wx, double *Wy, int Npts, int max_iterations, double outlier_limit, double binning_step, int VERBOSE);
     65int FitPMandPar_IRLS (PlxFit *fit, double *X, double *dX, double *Y, double *dY, double *T, double *pR, double *pD, double *Wx, double *Wy, double *Qx, double *Qy, double *qx, double *qy, int Npts, int max_iterations, double outlier_limit, double binning_step, int VERBOSE);
    6266
    6367int weighted_LS_PLX (double *T, double *pR, double *pD, double *X, double *WX, double *Y, double *WY, int Npts, double **A, double **B, int VERBOSE);
Note: See TracChangeset for help on using the changeset viewer.