IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 27, 2007, 2:39:47 PM (19 years ago)
Author:
eugene
Message:

was failing to set parameters on start, update on cycles; added print utility functions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/objects/pmSourceFitSet.c

    r14938 r15055  
    66 *  @author GLG, MHPCC
    77 *
    8  *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2007-09-21 00:09:05 $
     8 *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2007-09-28 00:39:41 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    6969        int nParams = pmModelClassParameterCount (model->type);
    7070
    71         set->paramSet->data[i] = psVectorAlloc (nParams, PS_DATA_F32);
     71        set->paramSet->data[i] = psVectorCopy (NULL, model->params, PS_DATA_F32);
    7272        set->derivSet->data[i] = psVectorAlloc (nParams, PS_DATA_F32);
     73        psVectorInit (set->derivSet->data[i], 0.0);
    7374
    7475        set->nParamSet += nParams;
     
    107108}
    108109
     110// merge parameters from FitSet models into single param and deriv vectors
    109111bool pmSourceFitSetJoin (psVector *deriv, psVector *param, pmSourceFitSetData *set) {
    110112
     
    117119        psVector *paramOne = set->paramSet->data[i];
    118120        psVector *derivOne = set->derivSet->data[i];
    119         assert ((deriv == NULL) || (paramOne->n == derivOne->n));
    120 
     121
     122        // one or the other (param or deriv) must be set
     123        assert ((deriv != NULL) || (param != NULL));
     124        assert ((deriv == NULL) || (param == NULL) || (paramOne->n == derivOne->n));
     125       
    121126        for (int j = 0; j < paramOne->n; j++, n++) {
    122             param->data.F32[n] = paramOne->data.F32[j];
     127            if (param) {
     128                param->data.F32[n] = paramOne->data.F32[j];
     129            }
    123130            if (deriv) {
    124131                deriv->data.F32[n] = derivOne->data.F32[j];
     
    129136}
    130137
     138// distribute parameters from single param and deriv vectors into FitSet models
    131139bool pmSourceFitSetSplit (pmSourceFitSetData *set, const psVector *deriv, const psVector *param) {
    132140
     
    191199}
    192200
     201// generic psMinLMM-style function for fitting: split the parameters across the models, call
     202// each model function one-at-a-time, the join the derivatives for on-going evaluation
    193203psF32 pmSourceFitSetFunction(psVector *deriv, const psVector *param, const psVector *x)
    194204{
     
    209219        chisqSum += chisqOne;
    210220    }
     221    pmSourceFitSetJoin (deriv, NULL, thisSet);
    211222
    212223    return (chisqSum);
     
    248259        }
    249260        n += paramOne->n;
     261    }
     262    return true;
     263}
     264
     265bool pmSourcePrintModelSet (FILE *file, psArray *modelSet) {
     266
     267    for (int i = 0; i < modelSet->n; i++) {
     268        pmModel *model = modelSet->data[i];
     269        int nParams = pmModelClassParameterCount (model->type);
     270        for (int j = 0; j < nParams; j++) {
     271            fprintf (file, "%d %d  : %f %f\n", i, j, model->params->data.F32[j], model->dparams->data.F32[j]);
     272        }
     273    }
     274    return true;
     275}
     276
     277bool pmSourceFitSetPrint (FILE *file, pmSourceFitSetData *set) {
     278
     279    for (int i = 0; i < set->paramSet->n; i++) {
     280        psVector *paramOne = set->paramSet->data[i];
     281        psVector *derivOne = set->derivSet->data[i];
     282        for (int j = 0; j < paramOne->n; j++) {
     283            fprintf (file, "%d %d  : %f %f\n", i, j, paramOne->data.F32[j], derivOne->data.F32[j]);
     284        }
    250285    }
    251286    return true;
     
    314349    yErr->n = nPix;
    315350
     351    // create the FitSet and set the initial parameter guesses
    316352    thisSet = pmSourceFitSetDataAlloc (modelSet);
    317353
     
    383419            altmask->data.U8[i] = (constraint->paramMask->data.U8[i]) ? 0 : 1;
    384420        }
    385         if (!psMinimizeGaussNewtonDelta(delta, params, altmask, x, y, yErr, pmSourceFitSetFunction)) {
    386             // Can we really do anything about it?
    387             // It will happily continue on, but the presence of an error upsets the psphot cleanup
    388             psErrorClear();
    389         }
     421        psMinimizeGaussNewtonDelta(delta, params, altmask, x, y, yErr, pmSourceFitSetFunction);
     422
    390423        for (int i = 0; i < dparams->n; i++) {
    391424            if (!constraint->paramMask->data.U8[i])
Note: See TracChangeset for help on using the changeset viewer.