IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 26, 2011, 5:21:42 PM (16 years ago)
Author:
eugene
Message:

report the diff chisq as well as the residual chisq; truncate SVD at dynamic range of 1e10; fix the scaling process

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20101205/psModules/src/imcombine/pmSubtractionEquation.c

    r30333 r30383  
    10721072        // SINGLE solution
    10731073# if (1)
    1074         solution = psMatrixSolveSVD(solution, sumMatrix, sumVector, NAN);
     1074        solution = psMatrixSolveSVD(solution, sumMatrix, sumVector, 1e-10);
    10751075        invMatrix = psMatrixInvert(NULL, sumMatrix, NULL);
    10761076# endif
     
    11761176        // DUAL solution
    11771177# if (1)
    1178         solution = psMatrixSolveSVD(solution, sumMatrix, sumVector, NAN);
     1178        solution = psMatrixSolveSVD(solution, sumMatrix, sumVector, 1e-10);
    11791179        invMatrix = psMatrixInvert(NULL, sumMatrix, NULL);
    11801180# endif
     
    13061306
    13071307// given the convolved image(s) and the residual image, calculate the second moment(s) and the chisq
    1308 bool pmSubtractionChisqStats(psVector *fluxesVector, psVector *chisqVector, psVector *momentVector, psVector *stampMask, psKernel *convolved1, psKernel *convolved2, psKernel *residual, psKernel *weight, psKernel *window) {
     1308bool pmSubtractionChisqStats(psVector *fluxesVector, psVector *chisqDVector, psVector *chisqRVector, psVector *momentVector, psVector *stampMask, psKernel *convolved1, psKernel *convolved2, psKernel *difference, psKernel *residual, psKernel *weight, psKernel *window) {
    13091309
    13101310# ifndef USE_WEIGHT
     
    13161316
    13171317    int npix = 0;
    1318     float chisq = 0;
     1318    float chisqR = 0;
     1319    float chisqD = 0;
    13191320
    13201321    // get the chisq
    13211322    for (int y = residual->yMin; y <= residual->yMax; y++) {
    13221323        for (int x = residual->xMin; x <= residual->xMax; x++) {
    1323             float value = PS_SQR(residual->kernel[y][x]);
     1324            float valueR = PS_SQR(residual->kernel[y][x]);
    13241325            if (weight) {
    1325                 value *= weight->kernel[y][x];
     1326                valueR *= weight->kernel[y][x];
    13261327            }
    1327             // XXX NOTE: do NOT apply the window to the chisq portions of the calculation
    1328             if (false && window) {
    1329                 value *= window->kernel[y][x];
     1328            // XXX NOTE: do NOT apply the window to the chisq portions of the calculation (that would bias the chisq)
     1329            chisqR += valueR;
     1330
     1331            float valueD = PS_SQR(difference->kernel[y][x]);
     1332            if (weight) {
     1333                valueD *= weight->kernel[y][x];
    13301334            }
    1331             chisq += value;
     1335            chisqD += valueD;
    13321336            npix ++;
    13331337        }
    13341338    }
    1335     psVectorAppend(chisqVector, chisq / npix);
     1339    psVectorAppend(chisqRVector, chisqR / npix);
     1340    psVectorAppend(chisqDVector, chisqD / npix);
    13361341
    13371342    float value1 = 0;
     
    14301435    int Nelem = fluxesVector->n - 1;
    14311436    bool valid = true;
    1432     valid &= isfinite(chisqVector->data.F32[Nelem]);
     1437    valid &= isfinite(chisqRVector->data.F32[Nelem]);
    14331438    valid &= isfinite(fluxesVector->data.F32[Nelem]);
    14341439    valid &= isfinite(momentVector->data.F32[Nelem]);
     
    14531458    // XXX need to save these somewhere
    14541459    psVector *fluxes = psVectorAllocEmpty(stamps->num, PS_TYPE_F32);
    1455     psVector *chisq = psVectorAllocEmpty(stamps->num, PS_TYPE_F32);
     1460    psVector *chisqD = psVectorAllocEmpty(stamps->num, PS_TYPE_F32);
     1461    psVector *chisqR = psVectorAllocEmpty(stamps->num, PS_TYPE_F32);
    14561462    psVector *moments = psVectorAllocEmpty(stamps->num, PS_TYPE_F32);
    14571463    psVector *stampMask = psVectorAllocEmpty(stamps->num, PS_TYPE_VECTOR_MASK);
     
    14641470    // storage for the image (convolved2 is not used in SINGLE mode)
    14651471    psKernel *residual = psKernelAlloc(-footprint, footprint, -footprint, footprint); // Residual image
     1472    psKernel *difference = psKernelAlloc(-footprint, footprint, -footprint, footprint); // Residual image
    14661473    psKernel *convolved1 = psKernelAlloc(-footprint, footprint, -footprint, footprint); // Residual image
    14671474    psKernel *convolved2 = psKernelAlloc(-footprint, footprint, -footprint, footprint); // Residual image
     
    14741481            psVectorAppend(moments, NAN);
    14751482            psVectorAppend(fluxes, NAN);
    1476             psVectorAppend(chisq, NAN);
     1483            psVectorAppend(chisqD, NAN);
     1484            psVectorAppend(chisqR, NAN);
    14771485            psVectorAppend(stampMask, 0x01);
    14781486            continue;
     
    14871495        // Calculate residuals
    14881496        psImageInit(residual->image, 0.0);
     1497        psImageInit(difference->image, 0.0);
    14891498
    14901499        psKernel *weight = NULL;
     
    15371546            }
    15381547
    1539             // generate the residual image
     1548            // Generate the difference, residual, and convolved source images.  Note the we
     1549            // accumulate the convolution of (A-B), so we need to replace it to generate the
     1550            // images of the convolved source image.
    15401551            for (int y = - footprint; y <= footprint; y++) {
    15411552                for (int x = - footprint; x <= footprint; x++) {
     1553                    difference->kernel[y][x] = target->kernel[y][x] - source->kernel[y][x] * norm - background;
     1554                    residual->kernel[y][x] = difference->kernel[y][x] - convolved1->kernel[y][x];
    15421555                    convolved1->kernel[y][x] += source->kernel[y][x] * norm;
    1543                     residual->kernel[y][x] = target->kernel[y][x] - convolved1->kernel[y][x] - background;
    15441556                }
    15451557            }
     1558
    15461559            // XXX if we want to have a weight and window, we'll need to pass through to here
    1547             pmSubtractionChisqStats(fluxes, chisq, moments, stampMask, convolved1, NULL, residual, weight, window);
     1560            pmSubtractionChisqStats(fluxes, chisqD, chisqR, moments, stampMask, convolved1, NULL, difference, residual, weight, window);
    15481561
    15491562        } else {
     
    15741587            }
    15751588
     1589            // Generate the difference, residual, and convolved source images.  Note the we
     1590            // accumulate the convolutions of (A-B), so we need to replace (A or B) to generate
     1591            // the images of the convolved source images.
    15761592            for (int y = - footprint; y <= footprint; y++) {
    15771593                for (int x = - footprint; x <= footprint; x++) {
     1594                    difference->kernel[y][x] = image2->kernel[y][x] - image1->kernel[y][x] * norm - background;
     1595                    residual->kernel[y][x] = difference->kernel[y][x] + convolved2->kernel[y][x] - convolved1->kernel[y][x];
    15781596                    convolved1->kernel[y][x] += image1->kernel[y][x] * norm;
    15791597                    convolved2->kernel[y][x] += image2->kernel[y][x];
    1580                     residual->kernel[y][x] = convolved2->kernel[y][x] - convolved1->kernel[y][x] - background;
    15811598                }
    15821599            }
     
    15891606            }
    15901607
    1591             pmSubtractionChisqStats(fluxes, chisq, moments, stampMask, convolved1, convolved2, residual, weight, window);
     1608            pmSubtractionChisqStats(fluxes, chisqD, chisqR, moments, stampMask, convolved1, convolved2, difference, residual, weight, window);
    15921609        }
    15931610    }
     
    15951612    // find the mean chisq and mean moment
    15961613    psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEAN);
    1597     psVectorStats (stats, chisq, NULL, stampMask, 0xff);
    1598     float chisqValue = stats->sampleMean;
     1614    psVectorStats (stats, chisqD, NULL, stampMask, 0xff);
     1615    float chisqDValue = stats->sampleMean;
     1616
     1617    psStatsInit(stats);
     1618    psVectorStats (stats, chisqR, NULL, stampMask, 0xff);
     1619    float chisqRValue = stats->sampleMean;
    15991620
    16001621    psStatsInit(stats);
     
    16371658    // penalized by increasing the score somewhat.  the 0.01 value is not well-chosen.
    16381659    float orderFactor = 0.01 * kernels->spatialOrder;
    1639     float score = 2.0 * chisqValue / (sumKernel1 + sumKernel2) + orderFactor;
    1640     psLogMsg("psModules.imcombine", PS_LOG_INFO, "chisq: %6.3f, moment: %6.3f, sumKernel_1: %6.3f, sumKernel_2, score: %6.3f: %6.3f\n", chisqValue, momentValue, sumKernel1, sumKernel2, score);
     1660    float score = 2.0 * chisqRValue / (sumKernel1 + sumKernel2) + orderFactor;
     1661    psLogMsg("psModules.imcombine", PS_LOG_INFO, "chisq: %6.3f, chisqD: %6.3f, moment: %6.3f, sumKernel_1: %6.3f, sumKernel_2, score: %6.3f: %6.3f\n", chisqRValue, chisqDValue, momentValue, sumKernel1, sumKernel2, score);
    16411662
    16421663    // save this result if it is the first or the best (skip if bestMatch is NULL)
     
    16631684            match->nGood        = nGood;
    16641685            match->fluxes       = psMemIncrRefCounter(fluxes);
    1665             match->chisq        = psMemIncrRefCounter(chisq);
     1686            match->chisq        = psMemIncrRefCounter(chisqR);
    16661687            match->moments      = psMemIncrRefCounter(moments);
    16671688            match->stampMask    = psMemIncrRefCounter(stampMask);
     
    16691690    }
    16701691
    1671     pmSubtractionVisualPlotChisqAndMoments(fluxes, chisq, moments);
     1692    pmSubtractionVisualPlotChisqAndMoments(fluxes, chisqR, moments);
    16721693
    16731694    psFree(stats);
    1674     psFree(chisq);
     1695    psFree(chisqR);
     1696    psFree(chisqD);
    16751697    psFree(fluxes);
    16761698    psFree(moments);
Note: See TracChangeset for help on using the changeset viewer.