IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 19, 2007, 2:22:24 PM (19 years ago)
Author:
magnier
Message:

dLinear, the linearized change in the chisq, was being calculated
AFTER the parameters were set to their limits. this is inconsistent
with the assumptions, and resulted in impossible negative values for
dLinear, which in turn caused problems for the fitting convergence.

I moved the call to dLinear into GuessABP, and modified the APIs a bit
to deal with this.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/math/psMinimizeLMM.c

    r13981 r14320  
    1010 *  @author EAM, IfA
    1111 *
    12  *  @version $Revision: 1.31 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2007-06-26 19:27:04 $
     12 *  @version $Revision: 1.32 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2007-07-20 00:22:24 $
    1414 *
    1515 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    6363    const psVector *paramMask,
    6464    psMinimizeLMLimitFunc checkLimits,
    65     psF32 lambda)
     65    psF32 lambda,
     66    psF32 *dLinear)
    6667{
    6768    PS_ASSERT_VECTOR_TYPE(Alpha,     PS_TYPE_F32,  false);
     
    135136    # endif
    136137
     138    // measure linear model prediction
     139    // (we must do this before truncating Beta below)
     140    if (dLinear) {
     141        *dLinear = psMinLM_dLinear(Beta, beta, paramMask, lambda);
     142    }
     143
    137144    // apply Beta to get new Params values
    138145    for (int j = 0; j < params->n; j++) {
     
    196203    }
    197204
    198     bool rcBool = psMinLM_GuessABP(Alpha, delta, Params, alpha, beta, params, paramMask, NULL, 0.0);
     205    bool rcBool = psMinLM_GuessABP(Alpha, delta, Params, alpha, beta, params, paramMask, NULL, 0.0, NULL);
    199206    if (rcBool == false) {
    200207        psTrace ("psLib.math", 5, "psMinLM_GuessABP() returned FALSE.\n");
     
    223230    const psVector *Beta,
    224231    const psVector *beta,
     232    const psVector *paramMask,
    225233    psF32 lambda)
    226234{
     
    230238    psF32 *B = Beta->data.F32;
    231239    psF32 *b = beta->data.F32;
     240
     241    float dh = 0.0, sh = 0.0, Sh = 0.0;
    232242    for (int i = 0; i < beta->n; i++) {
     243        if ((paramMask != NULL) && (paramMask->data.U8[i])) continue;
     244        dh = lambda*B[i] + b[i];
     245        sh = 0.5*B[i]*dh;
     246        Sh += sh;
     247        // fprintf (stderr, "%f, %f  * %f %f %f * :  %f : %f + %f\n", B[i], b[i], dh, sh, Sh, lambda*PS_SQR(B[i]) + B[i]*b[i], lambda*PS_SQR(B[i]), B[i]*b[i]);
    233248        dLinear += lambda*PS_SQR(B[i]) + B[i]*b[i];
    234249    }
     
    391406    psF32 Chisq = 0.0;
    392407    psF32 lambda = 0.001;
     408    psF32 dLinear = 0.0;
    393409
    394410    // the user provides the error or NULL.  we need to convert
     
    422438
    423439        // set a new guess for Alpha, Beta, Params
    424         if (!psMinLM_GuessABP(Alpha, Beta, Params, alpha, beta, params, paramMask, checkLimits, lambda)) {
     440        if (!psMinLM_GuessABP(Alpha, Beta, Params, alpha, beta, params, paramMask, checkLimits, lambda, &dLinear)) {
    425441            min->iter ++;
    426442            lambda *= 10.0;
     
    428444        }
    429445
    430         // measure linear model prediction
    431         psF32 dLinear = psMinLM_dLinear(Beta, beta, lambda);
    432 
    433446        // dump some useful info if trace is defined
    434447        if (psTraceGetLevel("psLib.math") >= 6) {
    435             p_psImagePrint(psTraceGetDestination(), Alpha, "alpha guess (1)");
    436             p_psVectorPrint(psTraceGetDestination(), Beta, "beta guess (1)");
     448            p_psImagePrint(psTraceGetDestination(), Alpha, "Alpha guess (1)");
     449            p_psVectorPrint(psTraceGetDestination(), Beta, "Beta guess (1)");
     450            p_psVectorPrint(psTraceGetDestination(), beta, "beta current (1)");
    437451        }
    438452        if (psTraceGetLevel("psLib.math") >= 5) {
     
    454468        psF32 rho = (min->value - Chisq) / dLinear;
    455469
    456         psTrace("psLib.math", 5, "last chisq: %f, new chisq %f, delta: %f, rho: %f\n", min->value,
    457                 Chisq, min->lastDelta, rho);
     470        psTrace("psLib.math", 5, "last chisq: %f, new chisq %f, delta: %f, dLinear: %f, rho: %f, lambda: %f\n", min->value,
     471                Chisq, min->lastDelta, dLinear, rho, lambda);
    458472
    459473        // dump some useful info if trace is defined
     
    470484            beta   = psVectorCopy(beta, Beta, PS_TYPE_F32);
    471485            params = psVectorCopy(params, Params, PS_TYPE_F32);
    472             lambda *= 0.1;
     486            lambda *= 0.25;
    473487        } else {
    474488            lambda *= 10.0;
     
    480494    // construct & return the covariance matrix (if requested)
    481495    if (covar != NULL) {
    482         if (!psMinLM_GuessABP(covar, Beta, Params, alpha, beta, params, paramMask, NULL, 0.0)) {
     496        if (!psMinLM_GuessABP(covar, Beta, Params, alpha, beta, params, paramMask, NULL, 0.0, NULL)) {
    483497            psTrace ("psLib.math", 5, "failure to calculate covariance matrix\n");
    484498        }
Note: See TracChangeset for help on using the changeset viewer.