IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 35623


Ignore:
Timestamp:
Jun 3, 2013, 2:05:58 PM (13 years ago)
Author:
eugene
Message:

use Madson option for gain factor; build-time choice of _Old vs _Alt for LMM

Location:
branches/eam_branches/ipp-20130509/psLib
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20130509/psLib/src/math/psMinimizeLMM.c

    r35617 r35623  
    365365
    366366/******************************************************************************
     367psMinimizeLMChi2():  wrapper to call either _Old or _Alt
     368  *****************************************************************************/
     369bool psMinimizeLMChi2(
     370    psMinimization *min,
     371    psImage *covar,
     372    psVector *params,
     373    psMinConstraint *constraint,
     374    const psArray *x,
     375    const psVector *y,
     376    const psVector *yWt,
     377    psMinimizeLMChi2Func func)
     378{
     379    bool status = psMinimizeLMChi2_Alt(
     380        min,
     381        covar,
     382        params,
     383        constraint,
     384        x,
     385        y,
     386        yWt,
     387        func);
     388    return status;
     389}
     390
     391/******************************************************************************
    367392psMinimizeLMChi2():  This routine will take an procedure which calculates an
    368393arbitrary function and it's derivative and minimize the chi-squared match
     
    373398XXX Make an F64 version?
    374399  *****************************************************************************/
    375 bool psMinimizeLMChi2(
     400bool psMinimizeLMChi2_Old(
    376401    psMinimization *min,
    377402    psImage *covar,
     
    510535        psF32 rho = (min->value - Chisq) / dLinear;
    511536
    512         psTrace("psLib.math", 5, "last chisq: %f, new chisq %f, delta: %f, dLinear: %f, rho: %f, lambda: %f, nDOF: %d\n", min->value, Chisq, min->lastDelta, dLinear, rho, lambda, nDOF);
    513 
    514         psTrace("psLib.math.dLinear", 5, "last chisq: %f, new chisq %f, delta: %f, dLinear: %f, rho: %f, lambda: %f\n", min->value, Chisq, min->lastDelta, dLinear, rho, lambda);
     537        psTrace("psLib.math", 5, "last chisq: %f, new chisq %f, delta: %f, dLinear: %f, rho: %f, lambda: %g, nDOF: %d\n", min->value, Chisq, min->lastDelta, dLinear, rho, lambda, nDOF);
     538
     539        psTrace("psLib.math.dLinear", 5, "last chisq: %f, new chisq %f, delta: %f, dLinear: %f, rho: %f, lambda: %g\n", min->value, Chisq, min->lastDelta, dLinear, rho, lambda);
    515540
    516541        // dump some useful info if trace is defined
     
    662687    psF32 Chisq = 0.0;
    663688    psF32 lambda = 0.001;
     689    psF32 nu = 2.0;
    664690    psF32 dLinear = 0.0;
    665691
     
    706732            min->iter ++;
    707733            if (min->iter >=  min->maxIter) break;
    708             lambda *= 10.0;
     734            // lambda *= 10.0;
     735            lambda *= 2.0;
    709736            continue;
    710737        }
     
    732759        // dParDelta = Beta[i]^2   : change (squared) in parameter i
    733760        float rParSigma = 0.0;
    734         for (int j = 0; j < Beta->n; j++) {
    735             rParSigma += PS_SQR(Beta->data.F32[j]) / Alpha->data.F32[j][j];
     761        // for (int j = 0; j < Beta->n; j++) {
     762        //     rParSigma += PS_SQR(Beta->data.F32[j]) / Alpha->data.F32[j][j];
     763        // }
     764        for (int j = 0, J = 0; j < Params->n; j++) {
     765            if (paramMask && (paramMask->data.PS_TYPE_VECTOR_MASK_DATA[j])) {
     766                continue;
     767            }
     768            // fprintf (stderr, "del: %f  - %f  vs %f  : %f\n", Params->data.F32[j], params->data.F32[j], sqrt(Alpha->data.F32[J][J]), PS_SQR(Params->data.F32[j] - params->data.F32[j]) / Alpha->data.F32[J][J]);
     769            rParSigma += PS_SQR(Params->data.F32[j] - params->data.F32[j]) / Alpha->data.F32[J][J];
     770            J++;
    736771        }
    737772        rParSigma = sqrt(rParSigma);
    738773        psTrace("psLib.math", 5, "rParSigma: %f, Niter: %d\n", rParSigma, min->iter);
     774        fprintf (stderr, "rParSigma: %f, Niter: %d\n", rParSigma, min->iter);
    739775
    740776        // calculate Chisq for new guess, update Alpha & Beta
     
    743779            min->iter ++;
    744780            if (min->iter >= min->maxIter) break;
    745             lambda *= 10.0;
     781            // lambda *= 10.0;
     782            lambda *= 2.0;
    746783            continue;
    747784        }
     
    753790        psF32 rho = (min->value - Chisq) / dLinear;
    754791
    755         psTrace("psLib.math", 5, "last chisq: %f, new chisq %f, delta: %f, dLinear: %f, rho: %f, lambda: %f, nDOF: %d\n", min->value, Chisq, min->lastDelta, dLinear, rho, lambda, nDOF);
    756 
    757         psTrace("psLib.math.dLinear", 5, "last chisq: %f, new chisq %f, delta: %f, dLinear: %f, rho: %f, lambda: %f\n", min->value, Chisq, min->lastDelta, dLinear, rho, lambda);
     792        psTrace("psLib.math", 5, "last chisq: %f, new chisq %f, delta: %f, dLinear: %f, rho: %f, lambda: %g, nDOF: %d\n", min->value, Chisq, min->lastDelta, dLinear, rho, lambda, nDOF);
     793
     794        psTrace("psLib.math.dLinear", 5, "last chisq: %f, new chisq %f, delta: %f, dLinear: %f, rho: %f, lambda: %g\n", min->value, Chisq, min->lastDelta, dLinear, rho, lambda);
    758795
    759796        // dump some useful info if trace is defined
     
    767804
    768805        // rho is positive if the new chisq is smaller; allow for some insignificant change (slight negative rho)
     806
     807        // XXX the old version of lambda changes:
    769808        // XXX : Madsen gives suggestion for better use of rho
     809# if (0)
    770810        if (rho >= -1e-6) {
    771811            min->value = Chisq;
     
    777817            lambda *= 10.0;
    778818        }
     819# endif
     820
     821        // rho is positive if the new chisq is smaller
     822        if (rho >= -1e-6) {
     823            min->value = Chisq;
     824            alpha  = psImageCopy(alpha, Alpha, PS_TYPE_F32);
     825            beta   = psVectorCopy(beta, Beta, PS_TYPE_F32);
     826            params = psVectorCopy(params, Params, PS_TYPE_F32);
     827        }
     828
     829# if (0)
     830        // adjust the gain ratio (lambda) based on rho
     831        if (rho < 0.25) {
     832            lambda *= 2.0;
     833        }
     834        if (rho > 0.75) {
     835            lambda *= 0.333;
     836        }
     837# else
     838        if (rho > 0.0) {
     839          lambda *= PS_MAX(0.33, (1.0 - pow(2.0*rho - 1.0, 3.0)));
     840          nu = 2.0;
     841        } else {
     842          lambda *= nu;
     843          nu *= 2.0;
     844        }
     845# endif
    779846        min->iter++;
    780847
     
    831898
    832899    // if the last improvement was at least as good as maxTol, accept the fit:
     900    // XXX : maybe re-work this to use rParSigma & maxTol
    833901    if (min->lastDelta <= min->maxTol) {
    834902        psTrace("psLib.math", 6, "---- end (true) ----\n");
  • branches/eam_branches/ipp-20130509/psLib/src/math/psMinimizeLMM.h

    r35617 r35623  
    134134);
    135135
     136/** Minimizes a specified function based on the Levenberg-Marquardt method.
     137 *
     138 *  @return bool:   True if successful.
     139 */
     140bool psMinimizeLMChi2_Old(
     141    psMinimization *min,               ///< Minimization specification
     142    psImage *covar,                    ///< Covariance matrix
     143    psVector *params,                  ///< "Best Guess" for the parameters that minimize func
     144    psMinConstraint *constraint, ///< Constraints on the parameters
     145    const psArray *x,                  ///< Measurement ordinates of multiple vectors
     146    const psVector *y,                 ///< Measurement coordinates
     147    const psVector *yWt,               ///< Errors in the measurement coordinates
     148    psMinimizeLMChi2Func func          ///< Specified function
     149);
     150
    136151/** Minimizes a specified function based on the Levenberg-Marquardt method
    137152    Uses alternative convergence criterion.
  • branches/eam_branches/ipp-20130509/psLib/test/math/tap_psMinimizeLMM_Trail.c

    r35618 r35623  
    501501
    502502# if (1)       
    503         psTraceSetLevel ("psLib.math.psMinimizeLMChi2_Alt", 5);
     503        // psTraceSetLevel ("psLib.math.psMinimizeLMChi2_Alt", 5);
    504504        bool tmpBool = psMinimizeLMChi2_Alt(min, NULL, params, NULL, ordinates, coordinates, errors, (psMinimizeLMChi2Func)fitFunc);
    505505# else
Note: See TracChangeset for help on using the changeset viewer.