Changeset 41470 for trunk/Ohana/src/opihi/cmd.data/fit1d_irls.c
- Timestamp:
- Jan 12, 2021, 4:16:47 PM (6 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/opihi/cmd.data/fit1d_irls.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/cmd.data/fit1d_irls.c
r39640 r41470 10 10 double weight_cauchy (double x); 11 11 double VectorFractionInterpolate (double *values, float fraction, int Npts); 12 13 // using file-globals to carry values into 'fit_least_squares' 14 double *priorValue = NULL; 15 double *priorStdev = NULL; 12 16 13 17 int fit1d_irls (int argc, char **argv) { … … 73 77 UseMean = FALSE; 74 78 } 79 int UsePriors = FALSE; 80 if ((N = get_argument (argc, argv, "-use-priors"))) { 81 remove_argument (N, &argc, argv); 82 UsePriors = TRUE; 83 } 75 84 76 85 if ((argc != 4) || !dyvec) { 77 86 // require a y error value 78 gprint (GP_ERR, "USAGE: fit1d x y order -dy wt [-quiet/-q] [-wt wtOut] [-yfit yfit] [-mask maskOut]\n"); 87 gprint (GP_ERR, "USAGE: fit1d_irls x y order [-dy wt] [-quiet/-q] [-wt wtOut] [-yfit yfit] [-mask maskOut] [-Nboot N] [-max-iterations N] [-weight-threshold f] [-use-median] [-use-priors]\n"); 88 gprint (GP_ERR, " [-dy wt] : optional error vector (use value of 1 by default)\n"); 89 gprint (GP_ERR, " [-quiet/-q] : reduce verbosity\n"); 90 gprint (GP_ERR, " [-wt wtOut] : save the weights in supplied vector\n"); 91 gprint (GP_ERR, " [-yfit yfit] : save the fitted values in supplied vector\n"); 92 gprint (GP_ERR, " [-mask maskOut] : save the masked / unmasked state (weight below threshold\n"); 93 gprint (GP_ERR, " [-Nboot N] : number of bootstrap samples\n"); 94 gprint (GP_ERR, " [-max-iterations N] : max number of iterations\n"); 95 gprint (GP_ERR, " [-weight-threshold f] : limit for masked values\n"); 96 gprint (GP_ERR, " [-use-median] : use median (as opposed to mean) to calculate weight threshold\n"); 97 gprint (GP_ERR, " [-use-priors] : include priors for parameters (specified as prior value $P0v and stdev $dP0, $P1v, $dP1, etc). Unspecified or NAN values are ignored.\n"); 79 98 return (FALSE); 80 99 } … … 100 119 order = atof (argv[3]); 101 120 nterm = order + 1; 102 mterm = 2* nterm;121 mterm = 2*order + 1; 103 122 104 123 ALLOCATE_PTR (yoff, opihi_flt, xvec[0].Nelements); … … 119 138 } 120 139 140 if (UsePriors) { 141 ALLOCATE (priorValue, double, nterm); 142 ALLOCATE (priorStdev, double, nterm); 143 for (i = 0; i < nterm; i++) { 144 int isFound; 145 double tmpValue; 146 snprintf (name, 64, "P%dv", i); 147 tmpValue = get_double_variable (name, &isFound); 148 priorValue[i] = isFound ? tmpValue : NAN; 149 snprintf (name, 64, "dP%d", i); 150 tmpValue = get_double_variable (name, &isFound); 151 priorStdev[i] = isFound ? tmpValue : NAN; 152 if (!isFound) priorValue[i] = NAN; // need both Pnv and dPn 153 } 154 } 155 121 156 // define initial weights as 1.0 122 157 for (i = 0; i < xvec[0].Nelements; i++) { … … 137 172 } 138 173 174 // save this solution 175 for (i = 0; i < nterm; i++) { 176 b_old[i][0] = b[i][0]; 177 } 178 139 179 if (!fit_least_squares (s, b, c, nterm, mterm, xvec[0].elements.Flt, yvec[0].elements.Flt, dyvec[0].elements.Flt, wt, NULL, xvec[0].Nelements)) { 140 // restore 180 // restore the saved solution 141 181 for (i = 0; i < nterm; i++) { 142 182 b[i][0] = b_old[i][0]; 143 183 } 144 184 break; 145 }146 147 // save this solution148 for (i = 0; i < nterm; i++) {149 b_old[i][0] = b[i][0];150 185 } 151 186 … … 172 207 return TRUE; */ 173 208 209 // save the solution. we re-use b[][] below in the bootstrap resampling 174 210 for (i = 0; i < nterm; i++) { 175 211 b_old[i][0] = b[i][0]; 176 212 } 177 178 213 179 214 // calculate the weight thresholds to mask the bad points: … … 307 342 free (dysample); 308 343 344 if (priorValue) { 345 free (priorValue); priorValue = NULL; 346 free (priorStdev); priorStdev = NULL; 347 } 348 309 349 return (TRUE); 310 350 … … 356 396 for (j = 0; j < nterm; j++) { 357 397 c[i][j] = s[i + j]; 398 if (priorValue && (i == j)) { 399 if (!isnan(priorValue[i])) { 400 c[i][i] += 1.0 / SQ(priorStdev[i]); 401 b[i][0] += priorValue[i] / SQ(priorStdev[i]); 402 } 403 } 358 404 } 359 405 }
Note:
See TracChangeset
for help on using the changeset viewer.
