Changeset 8245 for trunk/psLib/src/math/psMinimizePowell.c
- Timestamp:
- Aug 8, 2006, 4:26:44 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/math/psMinimizePowell.c (modified) (32 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/math/psMinimizePowell.c
r7766 r8245 11 11 * NOTE: XXX: The SDR is silent about data types. F32 is implemented here. 12 12 * 13 * @version $Revision: 1. 9$ $Name: not supported by cvs2svn $14 * @date $Date: 2006-0 6-30 02:20:06$13 * @version $Revision: 1.10 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2006-08-09 02:26:44 $ 15 15 * 16 16 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 117 117 psBool boolLineIsNull = true; 118 118 119 psTrace( __func__, 4, "---- p_psDetermineBracket() begin ----\n");119 psTrace("psLib.math", 4, "---- p_psDetermineBracket() begin ----\n"); 120 120 121 121 // If the line vector is zero, then return NULL. 122 122 PS_VECTOR_WITH_MASK_F32_CHECK_ZERO_VECTOR(params, paramMask, boolLineIsNull); 123 123 if (boolLineIsNull == true) { 124 psTrace( __func__, 2, "p_psDetermineBracket() called with zero line vector.\n");125 psTrace( __func__, 4, "---- p_psDetermineBracket() end (NULL) ----\n");124 psTrace("psLib.math", 2, "p_psDetermineBracket() called with zero line vector.\n"); 125 psTrace("psLib.math", 4, "---- p_psDetermineBracket() end (NULL) ----\n"); 126 126 psFree(bracket); 127 127 return(NULL); … … 155 155 } 156 156 157 psTrace( __func__, 6, "(a, b, c) is (%f %f %f) (fa, fb, fc) is (%f %f %f)\n", a, b, c, fa, fb, fc);157 psTrace("psLib.math", 6, "(a, b, c) is (%f %f %f) (fa, fb, fc) is (%f %f %f)\n", a, b, c, fa, fb, fc); 158 158 159 159 while (iter > 0) { 160 psTrace( __func__, 6, "psDetermineBracket(): iteration %d\n", iter);160 psTrace("psLib.math", 6, "psDetermineBracket(): iteration %d\n", iter); 161 161 if ((fb < fa) && (fb < fc)) { 162 162 bracket->data.F32[0] = a; … … 164 164 bracket->data.F32[2] = c; 165 165 psFree(tmp); 166 psTrace( __func__, 6, "---- p_psDetermineBracket() end ----\n");166 psTrace("psLib.math", 6, "---- p_psDetermineBracket() end ----\n"); 167 167 return(bracket); 168 168 } … … 177 177 fc = func(tmp, coords); 178 178 179 psTrace( __func__, 6, "Iter(%d): (a, b, c) is (%f %f %f) (fa, fb, fc) is (%f %f %f)\n", iter, a, b, c, fa, fb, fc);179 psTrace("psLib.math", 6, "Iter(%d): (a, b, c) is (%f %f %f) (fa, fb, fc) is (%f %f %f)\n", iter, a, b, c, fa, fb, fc); 180 180 181 181 if (fa < fb) { … … 195 195 bracket->data.F32[2] = c; 196 196 psFree(tmp); 197 psTrace( __func__, 4, "---- p_psDetermineBracket() end ----\n");197 psTrace("psLib.math", 4, "---- p_psDetermineBracket() end ----\n"); 198 198 return(bracket); 199 199 } … … 204 204 bracket->data.F32[2] = c; 205 205 psFree(tmp); 206 psTrace( __func__, 4, "---- p_psDetermineBracket() end ----\n");206 psTrace("psLib.math", 4, "---- p_psDetermineBracket() end ----\n"); 207 207 return(bracket); 208 208 } … … 213 213 psFree(tmp); 214 214 psFree(bracket); 215 psTrace( __func__, 4, "---- p_psDetermineBracket() end (NULL) ----\n");215 psTrace("psLib.math", 4, "---- p_psDetermineBracket() end (NULL) ----\n"); 216 216 return(NULL); 217 217 } … … 228 228 bracket->data.F32[2] = a; \ 229 229 } \ 230 psTrace( __func__, 4, "Final bracket (a, b, c) is (%f %f %f) (fa, fb, fc) is (%f %f %f)\n", a, b, c, fa, fb, fc); \231 psTrace( __func__, 4, "---- p_psDetermineBracket() end ----\n"); \230 psTrace("psLib.math", 4, "Final bracket (a, b, c) is (%f %f %f) (fa, fb, fc) is (%f %f %f)\n", a, b, c, fa, fb, fc); \ 231 psTrace("psLib.math", 4, "---- p_psDetermineBracket() end ----\n"); \ 232 232 psFree(tmp); \ 233 233 return(bracket); \ … … 253 253 psS32 countMin = 0; 254 254 255 psTrace( __func__, 4, "---- p_psDetermineBracket() begin ----\n");255 psTrace("psLib.math", 4, "---- p_psDetermineBracket() begin ----\n"); 256 256 257 257 // If the line vector is zero, then return NULL. 258 258 PS_VECTOR_WITH_MASK_F32_CHECK_ZERO_VECTOR(params, paramMask, boolLineIsNull); 259 259 if (boolLineIsNull == true) { 260 psTrace( __func__, 2, "p_psDetermineBracket() called with zero line vector.\n");261 psTrace( __func__, 4, "---- p_psDetermineBracket() end (NULL) ----\n");260 psTrace("psLib.math", 2, "p_psDetermineBracket() called with zero line vector.\n"); 261 psTrace("psLib.math", 4, "---- p_psDetermineBracket() end (NULL) ----\n"); 262 262 psFree(tmp); 263 263 return(NULL); … … 289 289 iter = 0; 290 290 while (iter < PS_DETERMINE_BRACKET_MAX_ITERATIONS) { 291 psTrace( __func__, 6, "psDetermineBracket(): iterationA %d\n", iter);291 psTrace("psLib.math", 6, "psDetermineBracket(): iterationA %d\n", iter); 292 292 c+= (1.0 + PS_DETERMINE_BRACKET_STEP_SIZE) * (c - a); 293 293 … … 295 295 fc = func(tmp, coords); 296 296 297 psTrace( __func__, 6, "Iteration(%d) (bracket): (a, b, c) is (%f %f %f) (fa, fb, fc) is (%f %f %f)\n", iter, a, b, c, fa, fb, fc);297 psTrace("psLib.math", 6, "Iteration(%d) (bracket): (a, b, c) is (%f %f %f) (fa, fb, fc) is (%f %f %f)\n", iter, a, b, c, fa, fb, fc); 298 298 299 299 if ((fb < fa) && (fb < fc)) { … … 320 320 321 321 psFree(bracket); 322 psTrace( __func__, 4, "---- p_psDetermineBracket() end (NULL) (BAD) ----\n");322 psTrace("psLib.math", 4, "---- p_psDetermineBracket() end (NULL) (BAD) ----\n"); 323 323 return(NULL); 324 324 } … … 371 371 psS32 numIterations = 0; 372 372 373 psTrace( __func__, 4, "---- LineMin() begin ----\n");373 psTrace("psLib.math", 4, "---- LineMin() begin ----\n"); 374 374 PS_VECTOR_F32_CHECK_ZERO_VECTOR(line, boolLineIsNull); 375 375 376 376 if (boolLineIsNull == true) { 377 377 min->value = func(params, coords); 378 psTrace( __func__, 2, "LineMin() called with zero line vector. Return 0.0. Function value is %f\n", min->value);378 psTrace("psLib.math", 2, "LineMin() called with zero line vector. Return 0.0. Function value is %f\n", min->value); 379 379 return(0.0); 380 380 } … … 382 382 if (6 <= psTraceGetLevel(__func__)) { 383 383 for (i=0;i<params->n;i++) { 384 psTrace( __func__, 6, "(params, paramMask, line)[%d] is (%f %d %f)\n", i,384 psTrace("psLib.math", 6, "(params, paramMask, line)[%d] is (%f %d %f)\n", i, 385 385 params->data.F32[i], paramMask->data.U8[i], line->data.F32[i]); 386 386 } … … 402 402 while (numIterations < PS_LINEMIN_MAX_ITERATIONS) { 403 403 numIterations++; 404 psTrace( __func__, 6, "LineMin(): iteration %d\n", numIterations);404 psTrace("psLib.math", 6, "LineMin(): iteration %d\n", numIterations); 405 405 406 406 a = bracket->data.F32[0]; … … 413 413 fb = func(tmpb, coords); 414 414 fc = func(tmpc, coords); 415 psTrace( __func__, 6, "LineMin: f(%f %f %f) is (%f %f %f)\n", a, b, c, fa, fb, fc);415 psTrace("psLib.math", 6, "LineMin: f(%f %f %f) is (%f %f %f)\n", a, b, c, fa, fb, fc); 416 416 417 417 // We determine which is the biggest segment in [a,b,c] then split … … 449 449 } 450 450 } 451 psTrace( __func__, 6, "LineMin: new bracket is (%f %f %f)\n", bracket->data.F32[0], bracket->data.F32[1], bracket->data.F32[2]);451 psTrace("psLib.math", 6, "LineMin: new bracket is (%f %f %f)\n", bracket->data.F32[0], bracket->data.F32[1], bracket->data.F32[2]); 452 452 453 453 mul = bracket->data.F32[1]; … … 456 456 min->value = func(params, coords); 457 457 psFree(bracket); 458 psTrace( __func__, 4, "---- LineMin() end.a (%f) (%f) ----\n", mul, min->value);458 psTrace("psLib.math", 4, "---- LineMin() end.a (%f) (%f) ----\n", mul, min->value); 459 459 psFree(tmpa); 460 460 psFree(tmpb); … … 468 468 PS_VECTOR_ADD_MULTIPLE(params, paramMask, line, params, mul); 469 469 min->value = func(params, coords); 470 psTrace( __func__, 4, "---- LineMin() end.b (%f) %f ----\n", mul, min->value);470 psTrace("psLib.math", 4, "---- LineMin() end.b (%f) %f ----\n", mul, min->value); 471 471 472 472 psFree(bracket); … … 517 517 psS32 iterationNumber = 0; 518 518 519 psTrace( __func__, 4, "---- psMinimizePowell() begin ----\n");520 psTrace( __func__, 6, "min->maxIter is %d\n", min->maxIter);521 psTrace( __func__, 6, "min->tol is %f\n", min->tol);519 psTrace("psLib.math", 4, "---- psMinimizePowell() begin ----\n"); 520 psTrace("psLib.math", 6, "min->maxIter is %d\n", min->maxIter); 521 psTrace("psLib.math", 6, "min->tol is %f\n", min->tol); 522 522 523 523 if (paramMask == NULL) { … … 562 562 while (iterationNumber < min->maxIter) { 563 563 iterationNumber++; 564 psTrace( __func__, 6, "psMinimizePowell() iteration %d\n", iterationNumber);564 psTrace("psLib.math", 6, "psMinimizePowell() iteration %d\n", iterationNumber); 565 565 566 566 // 3: For each dimension in params, move Q only in the vector v[i] to … … 569 569 baseFuncVal = func(Q, coords); 570 570 currFuncVal = baseFuncVal; 571 psTrace( __func__, 6, "Current function value is %f\n", currFuncVal);571 psTrace("psLib.math", 6, "Current function value is %f\n", currFuncVal); 572 572 573 573 biggestDiff = 0; … … 588 588 return(false); 589 589 } 590 psTrace( __func__, 6, "LineMin along dimension %d has multiple %f\n", i, mul);590 psTrace("psLib.math", 6, "LineMin along dimension %d has multiple %f\n", i, mul); 591 591 592 592 if (fabs(dummyMin.value - currFuncVal) > biggestDiff) { … … 598 598 // XXX: how can it be that we are not saving mul anywhere? 599 599 } 600 psTrace( __func__, 6, "New function value is %f\n", currFuncVal);600 psTrace("psLib.math", 6, "New function value is %f\n", currFuncVal); 601 601 // XXX: There must be a bug here. How can currFuncVal be the current function value? 602 602 // It is simply the minimum along one of the parameter dimensions. … … 608 608 u->n++; 609 609 610 psTrace( __func__, 6, "u[i]=Q[i]-P[i] (%f = %f - %f)\n", u->data.F32[i],610 psTrace("psLib.math", 6, "u[i]=Q[i]-P[i] (%f = %f - %f)\n", u->data.F32[i], 611 611 Q->data.F32[i], 612 612 params->data.F32[i]); … … 620 620 // 5: Move Q only in the direction u, and minimize the function. 621 621 for (i=0;i<numDims;i++) { 622 psTrace( __func__, 6, "u[i] is %f\n", u->data.F32[i]);622 psTrace("psLib.math", 6, "u[i] is %f\n", u->data.F32[i]); 623 623 } 624 624 … … 643 643 min->value = currFuncVal; 644 644 min->lastDelta = 0.0; 645 psTrace( __func__, 4, "---- psMinimizePowell() end (1)(true) ----\n");645 psTrace("psLib.math", 4, "---- psMinimizePowell() end (1)(true) ----\n"); 646 646 return(true); 647 647 } … … 685 685 min->iter = iterationNumber; 686 686 min->lastDelta = currFuncVal - baseFuncVal; 687 psTrace( __func__, 4, "---- psMinimizePowell() end (2) (true) ----\n");687 psTrace("psLib.math", 4, "---- psMinimizePowell() end (2) (true) ----\n"); 688 688 return(true); 689 689 } … … 695 695 psFree(Q); 696 696 min->iter = iterationNumber; 697 psTrace( __func__, 4, "---- psMinimizePowell() end (0) (false) ----\n");697 psTrace("psLib.math", 4, "---- psMinimizePowell() end (0) (false) ----\n"); 698 698 return(false); 699 699 } … … 712 712 const psArray *coords) 713 713 { 714 psTrace( __func__, 4, "---- myPowellChi2Func() begin ----\n");714 psTrace("psLib.math", 4, "---- myPowellChi2Func() begin ----\n"); 715 715 PS_ASSERT_VECTOR_NON_NULL(params, NAN); 716 716 PS_ASSERT_VECTOR_NON_EMPTY(params, NAN); … … 750 750 } 751 751 psFree(tmp); 752 psTrace( __func__, 4, "---- myPowellChi2Func() end (chi2 is %f) ----\n", chi2);752 psTrace("psLib.math", 4, "---- myPowellChi2Func() end (chi2 is %f) ----\n", chi2); 753 753 return(chi2); 754 754 }
Note:
See TracChangeset
for help on using the changeset viewer.
