Changeset 1103
- Timestamp:
- Jun 25, 2004, 2:24:30 PM (22 years ago)
- Location:
- trunk/psLib
- Files:
-
- 6 edited
-
src/collections/psVector.c (modified) (2 diffs)
-
src/dataManip/psMinimize.c (modified) (11 diffs)
-
src/dataManip/psMinimize.d (modified) (1 diff)
-
src/math/psMinimize.c (modified) (11 diffs)
-
src/mathtypes/psVector.c (modified) (2 diffs)
-
test/dataManip/tst_psMinimize00.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/collections/psVector.c
r1073 r1103 8 8 * @author Ross Harman, MHPCC 9 9 * 10 * @version $Revision: 1.1 1$ $Name: not supported by cvs2svn $11 * @date $Date: 2004-06-2 3 23:00:15$10 * @version $Revision: 1.12 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2004-06-26 00:24:30 $ 12 12 * 13 13 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 74 74 psVec->type.type = elemType; 75 75 psVec->nalloc = nalloc; 76 psVec->n = 0;76 psVec->n = nalloc; 77 77 78 78 // Create vector data array -
trunk/psLib/src/dataManip/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 -
trunk/psLib/src/dataManip/psMinimize.d
r986 r1103 1 1 psMinimize.o psMinimize.d : psMinimize.c ../sysUtils/psMemory.h \ 2 ../collections/psVector.h ../collections/psType.h ../sysUtils/psTrace.h \ 3 ../sysUtils/psError.h ../sysUtils/psAbort.h psFunctions.h \ 4 ../collections/psSort.h 2 ../collections/psVector.h ../collections/psType.h \ 3 ../collections/psImage.h ../sysUtils/psTrace.h ../sysUtils/psError.h \ 4 ../sysUtils/psAbort.h psFunctions.h ../collections/psSort.h \ 5 psMinimize.h -
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 -
trunk/psLib/src/mathtypes/psVector.c
r1073 r1103 8 8 * @author Ross Harman, MHPCC 9 9 * 10 * @version $Revision: 1.1 1$ $Name: not supported by cvs2svn $11 * @date $Date: 2004-06-2 3 23:00:15$10 * @version $Revision: 1.12 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2004-06-26 00:24:30 $ 12 12 * 13 13 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 74 74 psVec->type.type = elemType; 75 75 psVec->nalloc = nalloc; 76 psVec->n = 0;76 psVec->n = nalloc; 77 77 78 78 // Create vector data array -
trunk/psLib/test/dataManip/tst_psMinimize00.c
r1095 r1103 15 15 #define NUM_PARAMS 4 16 16 17 float *myFunc(psVector *myData,18 psVector *myParams)17 float myFunc(const psVector *restrict myData, 18 const psVector *restrict myParams) 19 19 { 20 20 float x = myData->data.F32[0]; … … 24 24 float C = myParams->data.F32[2]; 25 25 float D = myParams->data.F32[3]; 26 float *tmp = (float *) psAlloc(sizeof(float));27 26 28 *tmp = A + (B*x) + (C*y) + (D*x*y); 29 return(tmp); 27 return(A + (B*x) + (C*y) + (D*x*y)); 30 28 } 31 29 32 float *myFuncDeriv(psVector *myData,33 psVector *myParams,34 int whichParamDeriv)30 float myFuncDeriv(const psVector *restrict myData, 31 const psVector *restrict myParams, 32 int whichParamDeriv) 35 33 { 36 34 float x = myData->data.F32[0]; 37 35 float y = myData->data.F32[1]; 38 float *tmp = (float *) psAlloc(sizeof(float));36 float tmp = 0.0; 39 37 40 38 if (whichParamDeriv == 0) { 41 *tmp = 1.0;39 tmp = 1.0; 42 40 } else if (whichParamDeriv == 1) { 43 *tmp = x;41 tmp = x; 44 42 } else if (whichParamDeriv == 2) { 45 *tmp = y;43 tmp = y; 46 44 } else if (whichParamDeriv == 3) { 47 *tmp = x * y;45 tmp = x * y; 48 46 } 49 47 return(tmp); … … 66 64 int memLeaks = 0; 67 65 68 domain = psImageAlloc( NUM_DATA, DATA_WIDTH, PS_TYPE_F32);66 domain = psImageAlloc(DATA_WIDTH, NUM_DATA, PS_TYPE_F32); 69 67 data = psVectorAlloc(NUM_DATA, PS_TYPE_F32); 70 68 errors = psVectorAlloc(NUM_DATA, PS_TYPE_F32); … … 73 71 tmpVecPtr = psVectorAlloc(DATA_WIDTH, PS_TYPE_F32); 74 72 73 printf("FUCK: initialGuess->n is %d\n", initialGuess->n); 75 74 // Build the data. 76 75 initialGuess->data.F32[0] = 2.0; … … 91 90 tmpVecPtr->data.F32[i] = domain->data.F32[i][j]; 92 91 } 93 data->data.F32[i] = *myFunc(tmpVecPtr, initialGuess);92 data->data.F32[i] = myFunc(tmpVecPtr, initialGuess); 94 93 } 95 94 … … 104 103 errors, 105 104 initialGuess, 106 paramMask,105 NULL, 107 106 &chiSq); 108 107
Note:
See TracChangeset
for help on using the changeset viewer.
