IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 25, 2004, 2:24:30 PM (22 years ago)
Author:
gusciora
Message:

...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/dataManip/psMinimize.c

    r1093 r1103  
    3737}
    3838psModelData;
     39
    3940// The first argument to evalModel() and
    4041// d_evalModel() specifies the data point.
     
    7778                   gsl_vector *f)
    7879{
     80    return 0;
    7981    int i;    // Loop index variable.
    8082    int j;    // Loop index variable.
     
    148150    // have those parameters removed.  Here will create a new parameter list
    149151    // with the masked parameters added (we expand initialGuess).
     152
     153    psMemCheckCorruption(1);
     154    printf("Calling psVectorAlloc(%d)\n", initialGuess->n);
     155
    150156    inputParameterList = psVectorAlloc(initialGuess->n, PS_TYPE_F32);
     157    printf("Called psVectorAlloc(%d)\n", initialGuess->n);
     158
    151159    if (mask != NULL) {
    152160        j = 0;
     
    208216
    209217    int numData = domain->numCols; // Number of data points
    210     gsl_multifit_fdfsolver *s = NULL; // GSL data structure.
    211218    int status;    // Return status for the GSL solver.
    212219    int i = 0;    // Loop index variable.
    213220    int j = 0;    // Loop index variable.
    214221    int iter = 0;   // Iteration counter.
    215     psModelData *inputData = NULL; // Contains data that the user-supplied
    216     // function/derivate need.
    217222    gsl_multifit_function_fdf f; // GSL structure that contains the
    218223    // functions/derivative to be solved.
    219     double *xInit = NULL;  // The initial guess at the parameters
     224    double *xInit = NULL;     // The initial guess at the parameters
    220225    // with masked parameters removed.
    221226    const gsl_multifit_fdfsolver_type *T = gsl_multifit_fdfsolver_lmsder;
     
    223228    // Marquardt algorithm for chi2
    224229    // minimization.
    225 
    226     inputData = (psModelData *) psAlloc(sizeof(psModelData));
    227     inputData->n = numData;
    228     inputData->count = 0;
    229     inputData->initialGuess = initialGuess;
    230     inputData->domain = domain;
    231     //    inputData->data = data;
    232     //    inputData->errors = errors;
    233     //    inputData->paramMask = paramMask;
    234     //    inputData->evalModel = evalModel;
    235     //    inputData->d_evalModel = DevalModel;
    236 
    237     inputData->count = 0;
     230    gsl_multifit_fdfsolver *s; // GSL data structure.
     231
     232    //    inputData = (psModelData *) psAlloc(sizeof(psModelData));
     233    psModelData inputData;
     234    inputData.n = numData;
     235    inputData.count = 0;
     236    inputData.initialGuess = initialGuess;
     237    inputData.domain = domain;
     238    inputData.count = 0;
    238239    if (paramMask != NULL) {
    239240        for (i=0;i<paramMask->n;i++) {
    240241            if (paramMask->data.U8[i] != 0) {
    241                 inputData->count++;
     242                inputData.count++;
    242243            }
    243244        }
    244245    } else {
    245         inputData->count= initialGuess->n;
     246        inputData.count= initialGuess->n;
    246247    }
    247248
     
    250251    // parameters are masked out.
    251252
    252     xInit = (double *) psAlloc(inputData->count * sizeof(double));
     253    xInit = (double *) psAlloc(inputData.count * sizeof(double));
    253254    if (paramMask != NULL) {
    254255        j = 0;
    255256        for (i=0;i<initialGuess->n;i++) {
    256257            if (paramMask->data.U8[i] == 0) {
    257                 xInit[j++] = initialGuess->data.F32[i];
     258                xInit[j++] = (double) initialGuess->data.F32[i];
    258259            }
    259260        }
    260261    } else {
    261262        for (i=0;i<initialGuess->n;i++) {
    262             xInit[i] = initialGuess->data.F32[i];
    263         }
    264     }
    265 
    266     // Creates the vector for x which GSL uses.  Must deallocate.
    267     gsl_vector_view x = gsl_vector_view_array(xInit, inputData->count);
     263            xInit[i] = (double) initialGuess->data.F32[i];
     264        }
     265    }
    268266
    269267    const gsl_rng_type *type;
     
    283281    f.fdf = &gsl_my_function_fdf;
    284282    f.n = numData;
    285     f.p = inputData->count;
     283    f.p = inputData.count;
    286284    f.params = &inputData;
    287285
     286    printf("inputData.count is %d\n", inputData.count);
     287    printf("numData is %d\n", numData);
     288    // Creates the vector for x which GSL uses.  Must deallocate.
     289    gsl_vector_view x = gsl_vector_view_array(xInit, inputData.count);
     290
    288291    // Create an instance of the GSL solver that we will be iterating on.
    289     // It will have numData data points and inputData->count parameters.
    290     s = gsl_multifit_fdfsolver_alloc(T, numData, inputData->count);
    291 
     292    // It will have numData data points and inputData.count parameters.
     293    s = gsl_multifit_fdfsolver_alloc(T, numData, inputData.count);
     294
     295    printf("HERE 04\n");
    292296    // Initialize the GSL minimizer to use function defined by the data
    293297    // structure "f" and x.vector as an initial guess for the parameters.
     
    295299
    296300
     301    printf("HERE 05\n");
    297302    // Each iteration of the following loop will perform one step in an
    298303    // attempt to minimized chi-squared for the function.  The loop exits
     
    302307        iter++;
    303308        // Perform an iteration of the GSL solver.
     309        printf("HERE 06\n");
    304310        status = gsl_multifit_fdfsolver_iterate(s);
    305 
     311        printf("HERE 07\n");
    306312        // If there was a problem, abort.
    307313        if (status) {
     314            exit(1);
    308315            psAbort(__func__, "gsl_multifit_fdfsolver_iterate()\n");
    309316        }
     317        printf("HERE 08\n");
    310318
    311319        // Test if the parameters changed by a small enough amount.
    312320        status = gsl_multifit_test_delta(s->dx, s->x, 1e-4, 1e-4);
     321        printf("HERE 09\n");
    313322    } while (status == GSL_CONTINUE && iter < MAX_LMM_NUM_ITERATIONS);
     323    printf("HERE 12\n");
    314324
    315325
     
    339349    gsl_multifit_fdfsolver_free(s);
    340350    psFree(xInit);
    341     psFree(inputData);
    342351
    343352    // Bye bye.
     
    621630    return(NULL);
    622631}
     632
     633
     634
     635
     636
     637
Note: See TracChangeset for help on using the changeset viewer.