Changeset 42089 for trunk/psLib
- Timestamp:
- Feb 28, 2022, 2:43:25 PM (4 years ago)
- Location:
- trunk/psLib/src
- Files:
-
- 7 edited
-
fits/psFits.h (modified) (1 diff)
-
fits/psFitsImage.c (modified) (1 diff)
-
fits/psFitsScale.c (modified) (1 diff)
-
fits/psFitsTableNew.c (modified) (3 diffs)
-
math/psMinimizeLMM.c (modified) (11 diffs)
-
math/psMinimizeLMM.h (modified) (2 diffs)
-
math/psRandom.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/fits/psFits.h
r31633 r42089 60 60 PS_FITS_SCALE_ASINH_STDEV_NEGATIVE, ///< Do asinh scaling, auto-scale to sample stdev, place mean at upper limit 61 61 PS_FITS_SCALE_ASINH_STDEV_BOTH, ///< Do asinh scaling, auto-scale to sample stdev, place mean at middle 62 PS_FITS_SCALE_ASINH_MANUAL ///< Manual scaling after doing asinh scaling. 62 PS_FITS_SCALE_ASINH_MANUAL ///< Manual scaling after doing asinh scaling.(use specified BSCALE, BZERO, BOFFSET, BSOFTEN) 63 63 } psFitsScaling; 64 64 -
trunk/psLib/src/fits/psFitsImage.c
r41521 r42089 744 744 } 745 745 } 746 // Remove any BSOFTEN values that exist in the header if we are not using that scaling anymore746 // Remove any BSOFTEN values that exist in the header if we are not using that scaling anymore 747 747 if (options && (!((options->scaling == PS_FITS_SCALE_ASINH_RANGE)|| 748 748 (options->scaling == PS_FITS_SCALE_ASINH_MANUAL)|| -
trunk/psLib/src/fits/psFitsScale.c
r41521 r42089 963 963 *bzero = options->bzero; 964 964 *boffset = options->boffset; 965 break; 966 case PS_FITS_SCALE_ASINH_MANUAL: 967 *bscale = options->bscale; 968 *bzero = options->bzero; 969 *boffset = options->boffset; 970 *bsoften = options->bsoften; 965 971 break; 966 972 default: -
trunk/psLib/src/fits/psFitsTableNew.c
r41896 r42089 97 97 freeTable(psFitsTable *table) 98 98 { 99 if (!table) return; 99 100 for (int col = 0; col < table->numCols; col++) { 100 101 psFitsTableColumn *column = &table->columns[col]; … … 176 177 { 177 178 // add any element frees here 179 if (!column) return; 180 181 psFree (column->name); 178 182 return; 179 183 } … … 195 199 psFitsTableColumn *column = psFitsTableColumnAlloc (name, type); 196 200 psArrayAdd (tableColumns, 10, column); 201 psFree (column); 197 202 return true; 198 203 } -
trunk/psLib/src/math/psMinimizeLMM.c
r36082 r42089 220 220 221 221 // XXX should we give up if chisq is nan? 222 psF32 chisq = psMinLM_SetABX(alpha, Beta, params, paramMask, x, y, dy, func); 222 // do not apply reweighting 223 psF32 chisq = psMinLM_SetABX(alpha, Beta, params, paramMask, x, y, dy, false, func); 223 224 if (isnan(chisq)) { 224 225 psTrace ("psLib.math", 5, "psMinLM_SetABX() returned a NAN chisq.\n"); … … 282 283 return(0.5*dLinear); 283 284 } 285 286 // NOTE : reweight is true, the implementation below calculates the alpha,beta terms 287 // including a modified weight, but the chi-square value is calculated usig standard 288 // weights. 284 289 285 290 // alpha, beta, params are already allocated … … 292 297 const psVector *y, 293 298 const psVector *dy, 299 bool reweight, // if true, we calculate the reweighting for each point based on distance from model 294 300 psMinimizeLMChi2Func func) 295 301 { … … 306 312 } 307 313 308 psF32 chisq;309 psF32 delta;310 psF32 weight;311 psF32 ymodel;312 314 psVector *deriv = psVectorAlloc(params->n, PS_TYPE_F32); 313 315 … … 315 317 psImageInit (alpha, 0.0); 316 318 psVectorInit (beta, 0.0); 317 chisq = 0.0;319 psF32 chisq = 0.0; 318 320 319 321 // calculate chisq, alpha, beta. alpha & beta only represent unmasked parameters; skip 320 322 // masked ones 321 323 for (psS32 i = 0; i < y->n; i++) { 322 ymodel = func(deriv, params, (psVector *) x->data[i]); 323 324 delta = ymodel - y->data.F32[i]; 325 chisq += PS_SQR(delta) * dy->data.F32[i]; 324 psF32 ymodel = func(deriv, params, (psVector *) x->data[i]); 325 psF32 delta = ymodel - y->data.F32[i]; 326 psF32 dChi2 = PS_SQR(delta) * dy->data.F32[i]; 327 psF32 wtmod = reweight ? 1.0 / (1.0 + 5.69*dChi2) : 1.0; // see fit1d_irls.c:weight_cauchy 328 chisq += dChi2; 329 330 // if we are doing an IRLS-style fit, we downweight points based on the dChisq 331 // value above: this means setting an additional weight term 326 332 327 333 // XXX remove this later: … … 337 343 if (paramMask && (paramMask->data.PS_TYPE_VECTOR_MASK_DATA[j])) continue; 338 344 339 weight = deriv->data.F32[j] * dy->data.F32[i];345 psF32 weight = deriv->data.F32[j] * dy->data.F32[i] * wtmod; 340 346 341 347 for (int k = 0, K = 0; k <= j; k++) { … … 477 483 478 484 // calculate initial alpha and beta, set chisq (min->value) 479 min->value = psMinLM_SetABX(alpha, beta, params, paramMask, x, y, dy, func); 485 // do not apply IRLS reweighting yet, even if requested 486 min->value = psMinLM_SetABX(alpha, beta, params, paramMask, x, y, dy, false, func); 480 487 if (isnan(min->value)) { 481 488 min->iter = min->maxIter; … … 529 536 530 537 // calculate Chisq for new guess, update Alpha & Beta 531 Chisq = psMinLM_SetABX(Alpha, Beta, Params, paramMask, x, y, dy, func);538 Chisq = psMinLM_SetABX(Alpha, Beta, Params, paramMask, x, y, dy, min->useReweighting, func); 532 539 if (isnan(Chisq)) { 533 540 min->iter ++; … … 716 723 717 724 // calculate initial alpha and beta, set chisq (min->value) 718 min->value = psMinLM_SetABX(alpha, beta, params, paramMask, x, y, dy, func); 725 // do not apply IRLS reweighting yet, even if requested 726 min->value = psMinLM_SetABX(alpha, beta, params, paramMask, x, y, dy, false, func); 719 727 if (isnan(min->value)) { 720 728 min->iter = min->maxIter; … … 788 796 789 797 // calculate Chisq for new guess, update Alpha & Beta 790 Chisq = psMinLM_SetABX(Alpha, Beta, Params, paramMask, x, y, dy, func); 798 // if requested, modify the weights IRLS-style 799 Chisq = psMinLM_SetABX(Alpha, Beta, Params, paramMask, x, y, dy, min->useReweighting, func); 791 800 if (isnan(Chisq)) { 792 801 min->iter ++; … … 985 994 min->gainFactorMode = 0; 986 995 min->isInteractive = false; 996 min->useReweighting = false; 987 997 988 998 return(min); -
trunk/psLib/src/math/psMinimizeLMM.h
r36082 r42089 90 90 bool chisqConvergence; 91 91 bool isInteractive; 92 bool useReweighting; 92 93 } 93 94 psMinimization; … … 194 195 const psVector *y, ///< Measurement coordinates 195 196 const psVector *dy, ///< Weights calculated from y-errors 197 bool reweight, ///< if true, we calculate the reweighting for each point based on distance from model 196 198 psMinimizeLMChi2Func func ///< Specified function 197 199 ); -
trunk/psLib/src/math/psRandom.c
r23269 r42089 38 38 #include "psAssert.h" 39 39 40 41 unsigned long seed = 0; // Seed for RNG 42 40 // XXX set to non-zero for a test 41 # define HARDWIRED_SEED 0 42 unsigned long seed = HARDWIRED_SEED; // Seed for RNG 43 43 44 44 psU64 p_psRandomGetSystemSeed(bool log) … … 71 71 psU64 psRandomSeed(psU64 value) 72 72 { 73 if (HARDWIRED_SEED) { 74 seed = HARDWIRED_SEED; 75 return seed; 76 } 77 73 78 while (value == 0) { 74 79 value = p_psRandomGetSystemSeed(false);
Note:
See TracChangeset
for help on using the changeset viewer.
