IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 13, 2005, 4:06:55 PM (21 years ago)
Author:
eugene
Message:

changed noise to weight, psImageData to eamReadout

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot/src/psMinimize.c

    r5048 r5049  
    33
    44// XXX EAM : this file contains my alternate implementations of psMinimizeLMChi2
    5 
    65// XXX EAM this implementation of MinLM includes limits on params & dparams
     6
    77psBool psMinimizeLMChi2_EAM(psMinimization *min,
    88                            psImage *covar,
     
    1111                            const psArray *x,
    1212                            const psVector *y,
    13                             const psVector *yErr,
     13                            const psVector *yWt,
    1414                            psMinimizeLMChi2Func func)
    1515{
     
    6060    // the user provides the error or NULL.  we need to convert
    6161    // to appropriate weights
    62     dy = psVectorAlloc (y->n, PS_TYPE_F32);
    63     if (yErr != NULL) {
    64         for (int i = 0; i < dy->n; i++) {
    65             if (yErr->data.F32[i] == 0.0) {
    66                 dy->data.F32[i] = 1.0;
    67                 // mask this?  bad pixel, obviously...
    68             } else {
    69                 dy->data.F32[i] = 1.0 / PS_SQR (yErr->data.F32[i]);
    70             }
    71         }
     62    if (yWt != NULL) {
     63        dy = (psVector *) yWt;
    7264    } else {
    73         for (int i = 0; i < dy->n; i++) {
    74             dy->data.F32[i] = 1.0;
    75         }
     65        dy = psVectorAlloc (y->n, PS_TYPE_F32);
     66        psVectorInit (dy, 1.0);
     67//      for (int i = 0; i < dy->n; i++) {
     68//            dy->data.F32[i] = 1.0;
     69//        }
    7670    }
    7771
     
    8276        return (false);
    8377    }
    84     # ifndef PS_NO_TRACE
     78# ifndef PS_NO_TRACE
    8579    // dump some useful info if trace is defined
    8680    if (psTraceGetLevel (".psLib.dataManip.psMinimizeLMChi2") >= 5) {
     
    9286        p_psVectorPrintRow (psTraceGetDestination(), Params, "params guess");
    9387    }
    94     # endif /* PS_NO_TRACE */
     88# endif /* PS_NO_TRACE */
    9589
    9690    // iterate until the tolerance is reached, or give up
     
    10397        psF64 dLinear = p_psMinLM_dLinear (Beta, beta, lambda);
    10498
    105         # ifndef PS_NO_TRACE
     99# ifndef PS_NO_TRACE
    106100        // dump some useful info if trace is defined
    107101        if (psTraceGetLevel (".psLib.dataManip.psMinimizeLMChi2") >= 5) {
     
    113107            p_psVectorPrintRow (psTraceGetDestination(), Params, "params guess");
    114108        }
    115         # endif /* PS_NO_TRACE */
     109# endif /* PS_NO_TRACE */
    116110
    117111        // calculate Chisq for new guess, update Alpha & Beta
     
    125119
    126120        psTrace (".psLib.dataManip.psMinimizeLMChi2", 4, "last chisq: %f, new chisq %f, delta: %f, rho: %f\n", min->value, Chisq, min->lastDelta, rho);
    127         # ifndef PS_NO_TRACE
     121# ifndef PS_NO_TRACE
    128122        // dump some useful info if trace is defined
    129123        if (psTraceGetLevel (".psLib.dataManip.psMinimizeLMChi2") >= 5) {
     
    132126            p_psVectorPrint (psTraceGetDestination(), Params, "params guess");
    133127        }
    134         # endif /* PS_NO_TRACE */
     128# endif /* PS_NO_TRACE */
    135129
    136130        /* if (Chisq < min->value) {  */
     
    151145    // construct & return the covariance matrix (if requested)
    152146    if (covar != NULL) {
    153       p_psMinLM_GuessABP_EAM (covar, Beta, Params, alpha, beta, params, paramMask, beta_lim, param_min, param_max, 0.0);
     147        p_psMinLM_GuessABP_EAM (covar, Beta, Params, alpha, beta, params, paramMask, beta_lim, param_min, param_max, 0.0);
    154148    }     
    155149
     
    160154    psFree (Beta);
    161155    psFree (Params);
    162     psFree (dy);
     156    if (yWt == NULL) {
     157        psFree (dy);
     158    }
    163159
    164160    if (min->iter == min->maxIter) {
    165       return (false);
     161        return (false);
    166162    }
    167163    return (true);
     
    182178{
    183179
    184     # define USE_LU_DECOMP 1
    185     # if (USE_LU_DECOMP)
     180# define USE_LU_DECOMP 1
     181# if (USE_LU_DECOMP)
    186182    psVector *LUv = NULL;
    187183    psImage  *LUm = NULL;
     
    205201    Alpha = psMatrixInvert (Alpha, A, &det);
    206202
    207     # else
     203# else
    208204    // gauss-jordan version
    209205    psTrace (".psLib.dataManip.psMinLM_GuessABP", 5, "using Gauss-J version");
     
    218214
    219215    psGaussJordan (Alpha, Beta);
    220     # endif
     216# endif
    221217
    222218    // apply Beta to get new Params values
     
    241237    }
    242238
    243     # if (USE_LU_DECOMP)
     239# if (USE_LU_DECOMP)
    244240    psFree (A);
    245241    psFree (LUm);
    246242    psFree (LUv);
    247     # endif
     243# endif
    248244
    249245    return true;
    250246}
    251247
     248bool psMinimizeGaussNewtonDelta_EAM (psVector *delta,
     249                                     const psVector *params,
     250                                     const psVector *paramMask,
     251                                     const psArray  *x,
     252                                     const psVector *y,
     253                                     const psVector *yWt,
     254                                     psMinimizeLMChi2Func func)
     255{
     256
     257    // allocate internal arrays (current vs Guess)
     258    psImage  *alpha  = psImageAlloc  (params->n, params->n, PS_TYPE_F64);
     259    psImage  *Alpha  = psImageAlloc  (params->n, params->n, PS_TYPE_F64);
     260    psVector *beta   = psVectorAlloc (params->n, PS_TYPE_F64);
     261    psVector *Params = psVectorAlloc (params->n, PS_TYPE_F64);
     262    psVector *dy     = NULL;
     263
     264    // the user provides the error or NULL.  we need to convert
     265    // to appropriate weights
     266    if (yWt != NULL) {
     267        dy = (psVector *) yWt;
     268    } else {
     269        dy = psVectorAlloc (y->n, PS_TYPE_F32);
     270        psVectorInit (dy, 1.0);
     271//        for (int i = 0; i < dy->n; i++) {
     272//            dy->data.F32[i] = 1.0;
     273//        }
     274    }
     275
     276    p_psMinLM_SetABX (alpha, beta, params, paramMask, x, y, dy, func);
     277    p_psMinLM_GuessABP (Alpha, delta, Params, alpha, beta, params, paramMask, 0.0);
     278
     279    psFree (alpha);
     280    psFree (Alpha);
     281    psFree (beta);
     282    psFree (Params);
     283    if (yWt == NULL) {
     284        psFree (dy);
     285    }
     286    return (true);
     287}
     288
     289
Note: See TracChangeset for help on using the changeset viewer.