Changeset 29004 for trunk/psModules/src/objects/pmSourceFitSet.c
- Timestamp:
- Aug 20, 2010, 1:14:11 PM (16 years ago)
- Location:
- trunk/psModules
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
src/objects/pmSourceFitSet.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules
- Property svn:mergeinfo deleted
-
trunk/psModules/src/objects/pmSourceFitSet.c
r27903 r29004 22 22 #include "pmHDU.h" 23 23 #include "pmFPA.h" 24 25 #include "pmTrend2D.h" 26 #include "pmResiduals.h" 27 #include "pmGrowthCurve.h" 24 28 #include "pmSpan.h" 29 #include "pmFootprintSpans.h" 25 30 #include "pmFootprint.h" 26 31 #include "pmPeaks.h" 27 32 #include "pmMoments.h" 28 #include "pmGrowthCurve.h" 29 #include "pmResiduals.h" 30 #include "pmTrend2D.h" 31 #include "pmPSF.h" 33 #include "pmModelFuncs.h" 32 34 #include "pmModel.h" 35 #include "pmModelUtils.h" 36 #include "pmModelClass.h" 37 #include "pmSourceMasks.h" 38 #include "pmSourceExtendedPars.h" 39 #include "pmSourceDiffStats.h" 33 40 #include "pmSource.h" 34 #include "pmModelClass.h" 41 35 42 #include "pmSourceFitModel.h" 36 43 #include "pmSourceFitSet.h" 37 44 38 45 // save as static values so they may be set externally 39 static psF32 PM_SOURCE_FIT_MODEL_NUM_ITERATIONS = 15;40 static psF32 PM_SOURCE_FIT_MODEL_TOLERANCE = 0.1;41 static psF32 PM_SOURCE_FIT_MODEL_WEIGHT = 1.0;42 static bool PM_SOURCE_FIT_MODEL_PIX_WEIGHTS = true;46 // static psF32 PM_SOURCE_FIT_MODEL_NUM_ITERATIONS = 15; 47 // static psF32 PM_SOURCE_FIT_MODEL_TOLERANCE = 0.1; 48 // static psF32 PM_SOURCE_FIT_MODEL_WEIGHT = 1.0; 49 // static bool PM_SOURCE_FIT_MODEL_PIX_WEIGHTS = true; 43 50 44 51 /********************* Source Model Set Functions ***************************/ … … 429 436 bool pmSourceFitSet (pmSource *source, 430 437 psArray *modelSet, 431 pmSourceFitMode mode,438 pmSourceFitOptions *options, 432 439 psImageMaskType maskVal) 433 440 { … … 478 485 // as variance to avoid the bias from systematic errors here we would just use the 479 486 // source sky variance 480 if ( PM_SOURCE_FIT_MODEL_PIX_WEIGHTS) {481 yErr->data.F32[nPix] = 1.0 / source->variance->data.F32[i][j];482 } else {483 yErr->data.F32[nPix] = 1.0 / PM_SOURCE_FIT_MODEL_WEIGHT;484 }485 nPix++;486 }487 if (options->poissonErrors) { 488 yErr->data.F32[nPix] = 1.0 / source->variance->data.F32[i][j]; 489 } else { 490 yErr->data.F32[nPix] = 1.0 / options->weight; 491 } 492 nPix++; 493 } 487 494 } 488 495 x->n = nPix; … … 490 497 yErr->n = nPix; 491 498 492 // create the FitSet for this thread and set the initial parameter guesses499 // create the FitSet for this thread and set the initial parameter guesses 493 500 pmSourceFitSetData *thisSet = pmSourceFitSetDataSet(modelSet); 494 501 495 // define param and deriv vectors for complete set of parameters502 // define param and deriv vectors for complete set of parameters 496 503 psVector *params = psVectorAlloc (thisSet->nParamSet, PS_TYPE_F32); 497 504 498 // set the param and deriv vectors based on the curent values505 // set the param and deriv vectors based on the curent values 499 506 pmSourceFitSetJoin (NULL, params, thisSet); 500 507 501 // create the minimization constraints508 // create the minimization constraints 502 509 psMinConstraint *constraint = psMinConstraintAlloc(); 503 510 constraint->paramMask = psVectorAlloc (thisSet->nParamSet, PS_TYPE_VECTOR_MASK); 504 511 constraint->checkLimits = pmSourceFitSetCheckLimits; 505 512 506 pmSourceFitSetMasks (constraint, thisSet, mode);507 508 // force the floating parameters to fall within the contraint ranges513 pmSourceFitSetMasks (constraint, thisSet, options->mode); 514 515 // force the floating parameters to fall within the contraint ranges 509 516 for (int i = 0; i < params->n; i++) { 510 pmSourceFitSetCheckLimits (PS_MINIMIZE_PARAM_MIN, i, params->data.F32, NULL);511 pmSourceFitSetCheckLimits (PS_MINIMIZE_PARAM_MAX, i, params->data.F32, NULL);517 pmSourceFitSetCheckLimits (PS_MINIMIZE_PARAM_MIN, i, params->data.F32, NULL); 518 pmSourceFitSetCheckLimits (PS_MINIMIZE_PARAM_MAX, i, params->data.F32, NULL); 512 519 } 513 520 514 521 if (psTraceGetLevel("psModules.objects") >= 5) { 515 for (int i = 0; i < params->n; i++) {516 fprintf (stderr, "%d %f %d\n", i, params->data.F32[i], constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[i]);517 }522 for (int i = 0; i < params->n; i++) { 523 fprintf (stderr, "%d %f %d\n", i, params->data.F32[i], constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[i]); 524 } 518 525 } 519 526 520 527 if (nPix < thisSet->nParamSet + 1) { 521 psTrace (__func__, 4, "insufficient valid pixels\n");522 psTrace("psModules.objects", 10, "---- %s() end : fail pixels ----\n", __func__);523 for (int i = 0; i < modelSet->n; i++) {524 pmModel *model = modelSet->data[i];525 model->flags |= PM_MODEL_STATUS_BADARGS;526 }527 psFree (x);528 psFree (y);529 psFree (yErr);530 psFree (params);531 psFree(constraint);532 pmSourceFitSetDataClear(); // frees thisSet and removes if from the array of fitSets533 return(false);534 } 535 536 psMinimization *myMin = psMinimizationAlloc ( PM_SOURCE_FIT_MODEL_NUM_ITERATIONS, PM_SOURCE_FIT_MODEL_TOLERANCE);528 psTrace (__func__, 4, "insufficient valid pixels\n"); 529 psTrace("psModules.objects", 10, "---- %s() end : fail pixels ----\n", __func__); 530 for (int i = 0; i < modelSet->n; i++) { 531 pmModel *model = modelSet->data[i]; 532 model->flags |= PM_MODEL_STATUS_BADARGS; 533 } 534 psFree (x); 535 psFree (y); 536 psFree (yErr); 537 psFree (params); 538 psFree(constraint); 539 pmSourceFitSetDataClear(); // frees thisSet and removes if from the array of fitSets 540 return(false); 541 } 542 543 psMinimization *myMin = psMinimizationAlloc (options->nIter, options->minTol, options->maxTol); 537 544 538 545 psImage *covar = psImageAlloc (params->n, params->n, PS_TYPE_F32); … … 540 547 fitStatus = psMinimizeLMChi2(myMin, covar, params, constraint, x, y, yErr, pmSourceFitSetFunction); 541 548 if (!fitStatus) { 542 psTrace("psModules.objects", 4, "Failed to fit model (%ld components)\n", modelSet->n);543 } 544 545 // parameter errors from the covariance matrix549 psTrace("psModules.objects", 4, "Failed to fit model (%ld components)\n", modelSet->n); 550 } 551 552 // parameter errors from the covariance matrix 546 553 psVector *dparams = psVectorAlloc (thisSet->nParamSet, PS_TYPE_F32); 547 554 for (int i = 0; i < dparams->n; i++) { 548 if ((constraint->paramMask != NULL) && constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[i])549 continue;550 dparams->data.F32[i] = sqrt(covar->data.F32[i][i]);551 } 552 553 // get the Gauss-Newton distance for fixed model parameters555 if ((constraint->paramMask != NULL) && constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[i]) 556 continue; 557 dparams->data.F32[i] = sqrt(covar->data.F32[i][i]); 558 } 559 560 // get the Gauss-Newton distance for fixed model parameters 554 561 if (constraint->paramMask != NULL) { 555 psVector *delta = psVectorAlloc (params->n, PS_TYPE_F32);556 psVector *altmask = psVectorAlloc (params->n, PS_TYPE_VECTOR_MASK);557 altmask->data.PS_TYPE_VECTOR_MASK_DATA[0] = 1;558 for (int i = 1; i < dparams->n; i++) {559 altmask->data.PS_TYPE_VECTOR_MASK_DATA[i] = (constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[i]) ? 0 : 1;560 }561 psMinimizeGaussNewtonDelta(delta, params, altmask, x, y, yErr, pmSourceFitSetFunction);562 563 for (int i = 0; i < dparams->n; i++) {564 if (!constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[i])565 continue;566 // note that delta is the value *subtracted* from the parameter567 // to get the new guess. for dparams to represent the direction568 // of motion, we need to take -delta569 dparams->data.F32[i] = -delta->data.F32[i];570 }571 psFree (delta);572 psFree (altmask);562 psVector *delta = psVectorAlloc (params->n, PS_TYPE_F32); 563 psVector *altmask = psVectorAlloc (params->n, PS_TYPE_VECTOR_MASK); 564 altmask->data.PS_TYPE_VECTOR_MASK_DATA[0] = 1; 565 for (int i = 1; i < dparams->n; i++) { 566 altmask->data.PS_TYPE_VECTOR_MASK_DATA[i] = (constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[i]) ? 0 : 1; 567 } 568 psMinimizeGaussNewtonDelta(delta, params, altmask, x, y, yErr, pmSourceFitSetFunction); 569 570 for (int i = 0; i < dparams->n; i++) { 571 if (!constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[i]) 572 continue; 573 // note that delta is the value *subtracted* from the parameter 574 // to get the new guess. for dparams to represent the direction 575 // of motion, we need to take -delta 576 dparams->data.F32[i] = -delta->data.F32[i]; 577 } 578 psFree (delta); 579 psFree (altmask); 573 580 } 574 581
Note:
See TracChangeset
for help on using the changeset viewer.
