Changeset 6437
- Timestamp:
- Feb 16, 2006, 2:56:48 PM (20 years ago)
- Location:
- trunk/psLib/src/math
- Files:
-
- 6 edited
-
psConstants.h (modified) (5 diffs)
-
psMathUtils.h (modified) (2 diffs)
-
psMinimizeLMM.h (modified) (2 diffs)
-
psPolynomial.c (modified) (6 diffs)
-
psSpline.c (modified) (6 diffs)
-
psStats.c (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/math/psConstants.h
r6204 r6437 6 6 * @author GLG, MHPCC 7 7 * 8 * @version $Revision: 1.8 4$ $Name: not supported by cvs2svn $9 * @date $Date: 2006-0 1-26 21:10:22$8 * @version $Revision: 1.85 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2006-02-17 00:56:48 $ 10 10 * 11 11 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 169 169 } 170 170 171 // Return an error if the arg islies outside the supplied range.171 // Return an error if the arg lies outside the supplied range. 172 172 #define PS_ASSERT_FLOAT_WITHIN_RANGE(NAME, LOWER, UPPER, RVAL) \ 173 173 if ((NAME) < (LOWER) || (NAME) > (UPPER)) { \ … … 186 186 } 187 187 188 // Return an error if the arg lies outside the supplied range189 188 #define PS_ASSERT_LONG_WITHIN_RANGE(NAME, LOWER, UPPER, RVAL) \ 190 189 if ((NAME) < (LOWER) || (NAME) > (UPPER)) { \ … … 519 518 } \ 520 519 521 /* XXX: This is not correct522 #define PS_POLY_2D_DECLARE_ALLOC_STATIC(NAME, ORDER, TYPE) \523 static psPolynomial2D *(NAME) = NULL; \524 if ((NAME) == NULL) { \525 (NAME) = psPolynomial2DAlloc(ORDER, TYPE); \526 p_psMemSetPersistent((NAME), true); \527 } \528 529 #define PS_POLY_3D_DECLARE_ALLOC_STATIC(NAME, ORDER, TYPE) \530 static psPolynomial3D *(NAME) = NULL; \531 if ((NAME) == NULL) { \532 (NAME) = psPolynomial3DAlloc(ORDER, TYPE); \533 p_psMemSetPersistent((NAME), true); \534 } \535 536 #define PS_POLY_4D_DECLARE_ALLOC_STATIC(NAME, ORDER, TYPE) \537 static psPolynomial4D *(NAME) = NULL; \538 if ((NAME) == NULL) { \539 (NAME) = psPolynomial4DAlloc(ORDER, TYPE); \540 p_psMemSetPersistent((NAME), true); \541 } \542 */543 544 520 #define PS_POLY_1D_D_DECLARE_ALLOC_STATIC(NAME, ORDER, TYPE) \ 545 521 static psPolynomial1D *(NAME) = NULL; \ … … 548 524 p_psMemSetPersistent((NAME), true); \ 549 525 } \ 550 551 /* XXX: This is not correct552 #define PS_POLY_2D_D_DECLARE_ALLOC_STATIC(NAME, ORDER, TYPE) \553 static psPolynomial2D *(NAME) = NULL; \554 if ((NAME) == NULL) { \555 (NAME) = psPolynomial2DAlloc(ORDER, TYPE); \556 p_psMemSetPersistent((NAME), true); \557 } \558 559 #define PS_POLY_3D_D_DECLARE_ALLOC_STATIC(NAME, ORDER, TYPE) \560 static psPolynomial3D *(NAME) = NULL; \561 if ((NAME) == NULL) { \562 (NAME) = psPolynomial3DAlloc(ORDER, TYPE); \563 p_psMemSetPersistent((NAME), true); \564 } \565 566 #define PS_POLY_4D_D_DECLARE_ALLOC_STATIC(NAME, ORDER, TYPE) \567 static psPolynomial4D *(NAME) = NULL; \568 if ((NAME) == NULL) { \569 (NAME) = psPolynomial4DAlloc(ORDER, TYPE); \570 p_psMemSetPersistent((NAME), true); \571 } \572 */573 526 574 527 #define PS_POLY_PRINT_1D(NAME) \ -
trunk/psLib/src/math/psMathUtils.h
r6305 r6437 7 7 * @author GLG, MHPCC 8 8 * 9 * @version $Revision: 1. 1$ $Name: not supported by cvs2svn $10 * @date $Date: 2006-02- 02 21:09:07$9 * @version $Revision: 1.2 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2006-02-17 00:56:48 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 51 51 ); 52 52 53 // XXX: Create a single, generic, version of the vector normalize function.54 // XXX: Ask IfA for a public psLib function.55 56 53 psS32 p_psNormalizeVectorRange(psVector* myData, 57 54 psF64 outLow, -
trunk/psLib/src/math/psMinimizeLMM.h
r6226 r6437 8 8 * @author GLG, MHPCC 9 9 * 10 * @version $Revision: 1. 3$ $Name: not supported by cvs2svn $11 * @date $Date: 2006-0 1-27 20:08:58 $10 * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2006-02-17 00:56:48 $ 12 12 * 13 13 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 115 115 const psArray *x, ///< Measurement ordinates of multiple vectors 116 116 const psVector *y, ///< Measurement coordinates 117 const psVector *y Err,///< Errors in the measurement coordinates117 const psVector *yWt, ///< Errors in the measurement coordinates 118 118 psMinimizeLMChi2Func func ///< Specified function 119 119 ); -
trunk/psLib/src/math/psPolynomial.c
r6348 r6437 4 4 * routines. 5 5 * 6 * This file will hold the functions for allocated, freeing, and evaluating6 * This file will hold the routiness for allocating, freeing, and evaluating 7 7 * polynomials. It also contains a Gaussian functions. 8 8 * 9 * @version $Revision: 1.14 2$ $Name: not supported by cvs2svn $10 * @date $Date: 2006-02- 07 23:36:15$9 * @version $Revision: 1.143 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2006-02-17 00:56:48 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 159 159 used frequently and the data structure created here does not contain the 160 160 outer coefficients of the Chebyshev polynomials. 161 162 161 *****************************************************************************/ 163 162 psPolynomial1D **p_psCreateChebyshevPolys(psS32 numPolys) … … 165 164 PS_ASSERT_INT_LARGER_THAN_OR_EQUAL(numPolys, 1, NULL); 166 165 167 if (0) { 168 psPolynomial1D **chebPolys = (psPolynomial1D **) psAlloc(numPolys * sizeof(psPolynomial1D *)); 169 for (psS32 i = 0; i < numPolys; i++) { 170 chebPolys[i] = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, i); 171 chebPolys[i]->coeff[i] = 1; 172 } 173 return (chebPolys); 174 } else { 175 psPolynomial1D **chebPolys = (psPolynomial1D **) psAlloc(numPolys * sizeof(psPolynomial1D *)); 176 for (psS32 i = 0; i < numPolys; i++) { 177 chebPolys[i] = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, i); 178 } 179 180 // Create the Chebyshev polynomials. 181 // Polynomial i has i-th order. 182 chebPolys[0]->coeff[0] = 1.0; 183 if (numPolys >= 2) { 184 chebPolys[1]->coeff[1] = 1.0; 185 186 for (psS32 i = 2; i < numPolys; i++) { 187 for (psS32 j = 0; j < chebPolys[i - 1]->nX+1; j++) { 188 chebPolys[i]->coeff[j + 1] = 2.0 * chebPolys[i - 1]->coeff[j]; 189 } 190 for (psS32 j = 0; j < chebPolys[i - 2]->nX+1; j++) { 191 chebPolys[i]->coeff[j] -= chebPolys[i - 2]->coeff[j]; 192 } 193 } 194 } 195 196 if (psTraceGetLevel(__func__) >= 6) { 197 for (psS32 j = 0; j < numPolys; j++) { 198 PS_POLY_PRINT_1D(chebPolys[j]); 199 } 200 } 201 return (chebPolys); 202 } 166 psPolynomial1D **chebPolys = (psPolynomial1D **) psAlloc(numPolys * sizeof(psPolynomial1D *)); 167 for (psS32 i = 0; i < numPolys; i++) { 168 chebPolys[i] = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, i); 169 } 170 171 // Create the Chebyshev polynomials. 172 // Polynomial i has i-th order. 173 chebPolys[0]->coeff[0] = 1.0; 174 if (numPolys >= 2) { 175 chebPolys[1]->coeff[1] = 1.0; 176 177 for (psS32 i = 2; i < numPolys; i++) { 178 for (psS32 j = 0; j < chebPolys[i - 1]->nX+1; j++) { 179 chebPolys[i]->coeff[j + 1] = 2.0 * chebPolys[i - 1]->coeff[j]; 180 } 181 for (psS32 j = 0; j < chebPolys[i - 2]->nX+1; j++) { 182 chebPolys[i]->coeff[j] -= chebPolys[i - 2]->coeff[j]; 183 } 184 } 185 } 186 187 if (psTraceGetLevel(__func__) >= 6) { 188 for (psS32 j = 0; j < numPolys; j++) { 189 PS_POLY_PRINT_1D(chebPolys[j]); 190 } 191 } 192 return (chebPolys); 203 193 } 204 194 … … 223 213 for (loop_x = 0; loop_x < poly->nX+1; loop_x++) { 224 214 if (poly->mask[loop_x] == 0) { 225 // XXX: If you set the tracelevel to 10 here, and later set the tracelevel to226 // 2 or higher in the test code, you get seg faults.227 215 psTrace(__func__, 8, 228 216 "polysum+= sum*coeff [%lf+= (%lf * %lf)\n", polySum, xSum, poly->coeff[loop_x]); … … 238 226 // XXX: You can do this without having to psAlloc() vector d. 239 227 // XXX: How does the mask vector effect Crenshaw's formula? 240 // XXX: We assume that x is scaled between -1.0 and 1.0;228 // NOTE: We assume that x is scaled between -1.0 and 1.0; 241 229 // XXX: Create a faster version for low-order Chebyshevs. 242 230 static psF64 chebPolynomial1DEval( … … 298 286 psFree(d); 299 287 } else { 300 // This is old code that does not use Clenshaw's formula. Get rid of it.288 // XXX: This is old code that does not use Clenshaw's formula. Get rid of it. 301 289 psPolynomial1D **chebPolys = p_psCreateChebyshevPolys(1 + poly->nX); 302 290 -
trunk/psLib/src/math/psSpline.c
r6305 r6437 6 6 * This file contains the routines that allocate, free, and evaluate splines. 7 7 * 8 * @version $Revision: 1.13 5$ $Name: not supported by cvs2svn $9 * @date $Date: 2006-02- 02 21:09:08 $8 * @version $Revision: 1.136 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2006-02-17 00:56:48 $ 10 10 * 11 11 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 101 101 102 102 The first and second derivatives at the endpoints were previously undefined in 103 the SDR. From bugzilla #???, they are required to be 0.0, imp ementing natural103 the SDR. From bugzilla #???, they are required to be 0.0, implementing natural 104 104 splines. 105 105 … … 228 228 // The following code ensures that xPtr and yPtr points to a psF32 psVector. 229 229 // 230 // XXX: When you debug, use the vector copy and create routines here:230 // XXX: Use the vector copy and create routines here: 231 231 // 232 232 … … 345 345 /***************************************************************************** 346 346 psSpline1DEval(): this routine takes an existing spline of arbitrary order 347 and an independent x value. Eachdetermines which spline that x corresponds347 and an independent x value. It determines which spline that x corresponds 348 348 to by doing a bracket disection on the knots of the spline data structure 349 349 (vectorBinDisectF32()). Then it evaluates the spline at that x location … … 360 360 float x) 361 361 { 362 psTrace(__func__, 3, "---- %s( %f) begin ----\n", __func__, x);362 psTrace(__func__, 3, "---- %s() begin ----\n", __func__); 363 363 PS_ASSERT_PTR_NON_NULL(spline, NAN); 364 364 PS_ASSERT_INT_NONNEGATIVE(spline->n, NAN); … … 366 366 367 367 psS32 n = spline->n; 368 if ((x < spline->knots->data.F32[0]) || (x > spline->knots->data.F32[n-1])) { 369 // If x is outside the range of spline->knots, generate a warning 370 // message, then return the left, or right, endpoint. 371 psLogMsg(__func__, PS_LOG_WARN, 372 "psSpline1DEval(): x ordinate (%f) is outside the spline range (%f - %f) (%d).", 373 x, spline->knots->data.F32[0], spline->knots->data.F32[n-1], n); 374 375 psS32 binNum = (x < spline->knots->data.F32[0]) ? 0 : n-1; 376 psTrace(__func__, 3, "---- %s() end ----\n", __func__); 377 return(psPolynomial1DEval(spline->spline[binNum], x)); 378 } 379 368 380 psScalar tmpScalar; 369 381 tmpScalar.type.type = PS_TYPE_F32; 370 382 tmpScalar.data.F32 = x; 371 383 psS32 binNum = p_psVectorBinDisect(spline->knots, &tmpScalar); 372 373 384 if (binNum < 0) { 374 // 375 // If x is outside the range of spline->knots, generate a warning 376 // message, then return the left, or right, endpoint. 377 // 378 psLogMsg(__func__, PS_LOG_WARN, 379 "psSpline1DEval(): x ordinate (%f) is outside the spline range (%f - %f) (%d).", 380 x, spline->knots->data.F32[0], spline->knots->data.F32[n-1], n); 381 382 if (x < spline->knots->data.F32[0]) { 383 psF32 rcF32 = psPolynomial1DEval(spline->spline[0], x); 384 psTrace(__func__, 3, "---- %s(%f) end ----\n", __func__, rcF32); 385 return(rcF32); 386 } else if (x > spline->knots->data.F32[n-1]) { 387 psF32 rcF32 = psPolynomial1DEval(spline->spline[n-1], x); 388 psTrace(__func__, 3, "---- %s(%f) end ----\n", __func__, rcF32); 389 return(rcF32); 390 } 391 } 392 393 psF32 rcF32 = psPolynomial1DEval(spline->spline[binNum], x); 394 psTrace(__func__, 3, "---- %s(%f) end ----\n", __func__, rcF32); 395 return(rcF32); 385 psError(PS_ERR_UNKNOWN, false, "Could not perform bin dissection on spline->knots.\n"); 386 return(NAN); 387 } 388 389 psTrace(__func__, 3, "---- %s() end ----\n", __func__); 390 return(psPolynomial1DEval(spline->spline[binNum], x)); 396 391 } 397 392 -
trunk/psLib/src/math/psStats.c
r6322 r6437 16 16 * use ->min and ->max (PS_STAT_USE_RANGE) 17 17 * 18 * @version $Revision: 1.16 7$ $Name: not supported by cvs2svn $19 * @date $Date: 2006-02- 03 22:05:22$18 * @version $Revision: 1.168 $ $Name: not supported by cvs2svn $ 19 * @date $Date: 2006-02-17 00:56:48 $ 20 20 * 21 21 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 440 440 unmasked element within the specified min/max range). Otherwise, return 441 441 "false". 442 443 XXX: Can you use psVectorCountPixelMask here?444 442 *****************************************************************************/ 445 bool p_psVectorCheckNonEmpty(const psVector* myVector, 446 const psVector* maskVector, 447 psU32 maskVal, 448 psStats* stats) 443 bool p_psVectorCheckNonEmpty( 444 const psVector* myVector, 445 const psVector* maskVector, 446 psU32 maskVal, 447 psStats* stats) 449 448 { 450 449 psTrace(__func__, 4, "---- %s() begin ----\n", __func__); … … 496 495 number of non-masked pixels in the vector that fall within the min/max 497 496 range, if specified. 498 499 XXX: Can you use psVectorCountPixelMask here?500 497 *****************************************************************************/ 501 498 psS32 p_psVectorNValues(const psVector* myVector, … … 644 641 robustHistogram with a Gaussian of width sigma. It returns a psVector of the 645 642 smoothed data. 646 647 XXX: Only PS_TYPE_F32 is supported.648 649 XXX: Write a general routine which smoothes a psVector. This routine should650 call that. Is that possible?651 643 *****************************************************************************/ 652 644 psVector *p_psVectorSmoothHistGaussian( … … 985 977 -1: error 986 978 -2: warning 987 988 XXX: Use static vectors for tmpMask.989 979 *****************************************************************************/ 990 980 psS32 p_psVectorClippedStats(const psVector* myVector, … … 1224 1214 1225 1215 // 1226 // Ensure that the y values are monotonic. 1227 // 1228 // XXX: This routine should probably be rewritten in a more general fashion 1229 // so that the following checks are not necessary. 1216 // Ensure that the y value lies within range of the y values. 1230 1217 // 1231 1218 if (! (((y->data.F64[0] <= yVal) && (yVal <= y->data.F64[2])) || … … 1236 1223 } 1237 1224 1225 // 1226 // Ensure that the y values are monotonic. 1227 // 1238 1228 if (((y->data.F64[0] < y->data.F64[1]) && !(y->data.F64[1] <= y->data.F64[2])) || 1239 1229 ((y->data.F64[0] > y->data.F64[1]) && !(y->data.F64[1] >= y->data.F64[2]))) { … … 1289 1279 } else if (binNum == (xVec->n - 2)) { 1290 1280 // XXX: Is this right? 1291 tmpFloat = 0.5 * (xVec->data.F32[binNum] + 1292 xVec->data.F32[binNum + 1]); 1281 tmpFloat = 0.5 * (xVec->data.F32[binNum] + xVec->data.F32[binNum + 1]); 1293 1282 } 1294 1283 } … … 1677 1666 tmpScalar.data.F32 = totalDataPoints * 0.25f; 1678 1667 if (tmpScalar.data.F32 <= cumulativeRobustHistogram->nums->data.F32[0]) { 1679 // XXX: Special case where its in first bin. Must code last bin.1668 // Special case where its in first bin. The last bin should be handled automatically. 1680 1669 binLo25 = 0; 1681 1670 } else { … … 1684 1673 tmpScalar.data.F32 = totalDataPoints * 0.75f; 1685 1674 if (tmpScalar.data.F32 <= cumulativeRobustHistogram->nums->data.F32[0]) { 1686 // XXX: Special case where its in first bin. Must code last bin.1675 // Special case where its in first bin. The last bin should be handled automatically. 1687 1676 binHi25 = 0; 1688 1677 } else { … … 1704 1693 // Interpolate to find these two positions exactly: these are the upper 1705 1694 // and lower quartile positions. 1706 // XXX: Check for errors.1707 1695 // 1708 1696 psF32 binLo25F32 = fitQuadraticSearchForYThenReturnX( … … 1711 1699 binLo25, 1712 1700 totalDataPoints * 0.25f); 1701 1713 1702 psF32 binHi25F32 = fitQuadraticSearchForYThenReturnX( 1714 1703 *(psVector* *)&cumulativeRobustHistogram->bounds, … … 1716 1705 binHi25, 1717 1706 totalDataPoints * 0.75f); 1707 1708 if (isnan(binLo25F32) || isnan(binHi25F32)) { 1709 psError(PS_ERR_UNKNOWN, false, "could not determine the robustUQ: fitQuadraticSearchForYThenReturnX() returned a NAN.\n"); 1710 psFree(tmpStatsMinMax); 1711 psFree(robustHistogram); 1712 psFree(cumulativeRobustHistogram); 1713 psFree(tmpMaskVec); 1714 psTrace(__func__, 4, "---- %s(1) end ----\n", __func__); 1715 return(1); 1716 } 1717 1718 1718 stats->robustLQ = binLo25F32; 1719 1719 stats->robustUQ = binHi25F32; 1720 1720 psTrace(__func__, 6, "The 25 and 75 percent data point exact positions are (%f, %f).\n", binLo25F32, binHi25F32); 1721 1722 1721 psS32 N50 = 0; 1723 1722 for (psS32 i = 0 ; i < myVector->n ; i++) { … … 1863 1862 } 1864 1863 1865 // XXX: Use the min/max routines for this 1866 psF32 minY = FLT_MAX; 1867 psF32 maxY = -FLT_MAX; 1868 for (psS32 i = 0 ; i < y->n ; i++) { 1869 if (y->data.F32[i] > maxY) { 1870 maxY = y->data.F32[i]; 1871 } 1872 if (y->data.F32[i] < minY) { 1873 minY = y->data.F32[i]; 1874 } 1875 } 1864 rc = p_psVectorMin(y, NULL, 0, tmpStatsMinMax); 1865 rc|= p_psVectorMax(y, NULL, 0, tmpStatsMinMax); 1866 if ((rc != 0) || isnan(tmpStatsMinMax->min) || isnan(tmpStatsMinMax->max)) { 1867 psError(PS_ERR_UNKNOWN, false, "Failed to calculate the min/max of the input vector.\n"); 1868 psFree(tmpMaskVec); 1869 psFree(robustHistogram); 1870 psFree(cumulativeRobustHistogram); 1871 psFree(tmpStatsMinMax); 1872 psTrace(__func__, 4, "---- %s(1) end ----\n", __func__); 1873 return(1); 1874 } 1875 1876 1876 // 1877 1877 // Normalize y to [0.0:1.0] (since the psMinimizeLMChi2Gauss1D() functions is [0.0:1.0]) … … 1879 1879 // 1880 1880 for (psS32 i = 0 ; i < y->n ; i++) { 1881 y->data.F32[i]= (y->data.F32[i] - minY) / (maxY - minY);1881 y->data.F32[i]= (y->data.F32[i] - tmpStatsMinMax->min) / (tmpStatsMinMax->max - tmpStatsMinMax->min); 1882 1882 } 1883 1883 … … 2295 2295 } 2296 2296 } else { 2297 // XXX:This if-statement really shouldn't be necessary.2297 // This if-statement really shouldn't be necessary. 2298 2298 // However, due to numerical lack of precision, we 2299 2299 // occasionally produce a binNum outside the range. … … 2435 2435 XXX: Should we free stats if the asserts fail? 2436 2436 *****************************************************************************/ 2437 psStats* psVectorStats(psStats* stats, 2438 const psVector* in, 2439 const psVector* errors, 2440 const psVector* mask, 2441 psMaskType maskVal) 2437 psStats* psVectorStats( 2438 psStats* stats, 2439 const psVector* in, 2440 const psVector* errors, 2441 const psVector* mask, 2442 psMaskType maskVal) 2442 2443 { 2443 2444 psTrace(__func__, 3,"---- %s() begin ----\n", __func__);
Note:
See TracChangeset
for help on using the changeset viewer.
