Changeset 1103 for trunk/psLib/src/math/psMinimize.c
- Timestamp:
- Jun 25, 2004, 2:24:30 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/math/psMinimize.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/math/psMinimize.c
r1093 r1103 37 37 } 38 38 psModelData; 39 39 40 // The first argument to evalModel() and 40 41 // d_evalModel() specifies the data point. … … 77 78 gsl_vector *f) 78 79 { 80 return 0; 79 81 int i; // Loop index variable. 80 82 int j; // Loop index variable. … … 148 150 // have those parameters removed. Here will create a new parameter list 149 151 // with the masked parameters added (we expand initialGuess). 152 153 psMemCheckCorruption(1); 154 printf("Calling psVectorAlloc(%d)\n", initialGuess->n); 155 150 156 inputParameterList = psVectorAlloc(initialGuess->n, PS_TYPE_F32); 157 printf("Called psVectorAlloc(%d)\n", initialGuess->n); 158 151 159 if (mask != NULL) { 152 160 j = 0; … … 208 216 209 217 int numData = domain->numCols; // Number of data points 210 gsl_multifit_fdfsolver *s = NULL; // GSL data structure.211 218 int status; // Return status for the GSL solver. 212 219 int i = 0; // Loop index variable. 213 220 int j = 0; // Loop index variable. 214 221 int iter = 0; // Iteration counter. 215 psModelData *inputData = NULL; // Contains data that the user-supplied216 // function/derivate need.217 222 gsl_multifit_function_fdf f; // GSL structure that contains the 218 223 // functions/derivative to be solved. 219 double *xInit = NULL; // The initial guess at the parameters224 double *xInit = NULL; // The initial guess at the parameters 220 225 // with masked parameters removed. 221 226 const gsl_multifit_fdfsolver_type *T = gsl_multifit_fdfsolver_lmsder; … … 223 228 // Marquardt algorithm for chi2 224 229 // 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; 238 239 if (paramMask != NULL) { 239 240 for (i=0;i<paramMask->n;i++) { 240 241 if (paramMask->data.U8[i] != 0) { 241 inputData ->count++;242 inputData.count++; 242 243 } 243 244 } 244 245 } else { 245 inputData ->count= initialGuess->n;246 inputData.count= initialGuess->n; 246 247 } 247 248 … … 250 251 // parameters are masked out. 251 252 252 xInit = (double *) psAlloc(inputData ->count * sizeof(double));253 xInit = (double *) psAlloc(inputData.count * sizeof(double)); 253 254 if (paramMask != NULL) { 254 255 j = 0; 255 256 for (i=0;i<initialGuess->n;i++) { 256 257 if (paramMask->data.U8[i] == 0) { 257 xInit[j++] = initialGuess->data.F32[i];258 xInit[j++] = (double) initialGuess->data.F32[i]; 258 259 } 259 260 } 260 261 } else { 261 262 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 } 268 266 269 267 const gsl_rng_type *type; … … 283 281 f.fdf = &gsl_my_function_fdf; 284 282 f.n = numData; 285 f.p = inputData ->count;283 f.p = inputData.count; 286 284 f.params = &inputData; 287 285 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 288 291 // 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"); 292 296 // Initialize the GSL minimizer to use function defined by the data 293 297 // structure "f" and x.vector as an initial guess for the parameters. … … 295 299 296 300 301 printf("HERE 05\n"); 297 302 // Each iteration of the following loop will perform one step in an 298 303 // attempt to minimized chi-squared for the function. The loop exits … … 302 307 iter++; 303 308 // Perform an iteration of the GSL solver. 309 printf("HERE 06\n"); 304 310 status = gsl_multifit_fdfsolver_iterate(s); 305 311 printf("HERE 07\n"); 306 312 // If there was a problem, abort. 307 313 if (status) { 314 exit(1); 308 315 psAbort(__func__, "gsl_multifit_fdfsolver_iterate()\n"); 309 316 } 317 printf("HERE 08\n"); 310 318 311 319 // Test if the parameters changed by a small enough amount. 312 320 status = gsl_multifit_test_delta(s->dx, s->x, 1e-4, 1e-4); 321 printf("HERE 09\n"); 313 322 } while (status == GSL_CONTINUE && iter < MAX_LMM_NUM_ITERATIONS); 323 printf("HERE 12\n"); 314 324 315 325 … … 339 349 gsl_multifit_fdfsolver_free(s); 340 350 psFree(xInit); 341 psFree(inputData);342 351 343 352 // Bye bye. … … 621 630 return(NULL); 622 631 } 632 633 634 635 636 637
Note:
See TracChangeset
for help on using the changeset viewer.
