Changeset 4731
- Timestamp:
- Aug 8, 2005, 11:44:09 AM (21 years ago)
- Location:
- trunk/psLib/test/math
- Files:
-
- 11 edited
-
tst_psFunc00.c (modified) (2 diffs)
-
tst_psFunc01.c (modified) (1 diff)
-
tst_psFunc02.c (modified) (2 diffs)
-
tst_psFunc03.c (modified) (1 diff)
-
tst_psFunc04.c (modified) (1 diff)
-
tst_psFunc05.c (modified) (1 diff)
-
tst_psFunc08.c (modified) (2 diffs)
-
tst_psFunc09.c (modified) (2 diffs)
-
tst_psFunc10.c (modified) (2 diffs)
-
tst_psFunc11.c (modified) (2 diffs)
-
tst_psMinimize06.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/math/tst_psFunc00.c
r4581 r4731 13 13 * XXX: Modify these tests so that polynomials with a variety of different 14 14 * orders are created. 15 * 16 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $17 * @date $Date: 2005-0 7-20 01:21:13$15 * 16 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 17 * @date $Date: 2005-08-08 21:44:09 $ 18 18 * 19 19 * Copyright 2004-2005 Maui High Performance Computing Center, Univ. of Hawaii … … 43 43 psS32 main(psS32 argc, char* argv[]) 44 44 { 45 psLogSetFormat("HLNM"); 45 46 psLogSetLevel(PS_LOG_INFO); 46 47 -
trunk/psLib/test/math/tst_psFunc01.c
r4547 r4731 15 15 psS32 main() 16 16 { 17 psLogSetFormat("HLNM"); 17 18 psS32 testStatus = true; 18 19 float x = 0.0; -
trunk/psLib/test/math/tst_psFunc02.c
r4547 r4731 16 16 psS32 main() 17 17 { 18 psLogSetFormat("HLNM"); 18 19 psS32 testStatus = true; 19 20 psS32 memLeaks=0; … … 388 389 "psSpline1DAllocGeneric(): negative order", 389 390 testStatus); 391 // XXX: Currently, if you free a psStructure twice, it seg faults. Why? 392 psFree(bounds); 390 393 */ 391 psFree(bounds);392 393 394 /****************************************************************************/ 394 395 /****************************************************************************/ -
trunk/psLib/test/math/tst_psFunc03.c
r4547 r4731 17 17 psS32 main() 18 18 { 19 psLogSetFormat("HLNM"); 19 20 psS32 testStatus = true; 20 21 psS32 memLeaks=0; -
trunk/psLib/test/math/tst_psFunc04.c
r4547 r4731 129 129 psS32 main() 130 130 { 131 psLogSetFormat("HLNM"); 131 132 t00(); 133 // XXX: Why is this commented? 132 134 // t01(); 133 135 } -
trunk/psLib/test/math/tst_psFunc05.c
r4547 r4731 20 20 psS32 main() 21 21 { 22 psLogSetFormat("HLNM"); 22 23 psS32 testStatus = true; 23 24 psS32 memLeaks=0; -
trunk/psLib/test/math/tst_psFunc08.c
r4581 r4731 4 4 * ORD and CHEB type polynomials. 5 5 * 6 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $7 * @date $Date: 2005-0 7-20 01:21:13$6 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 7 * @date $Date: 2005-08-08 21:44:09 $ 8 8 * 9 9 * XXX: Probably should test single- and multi-dimensional polynomials in … … 46 46 psS32 main(psS32 argc, char* argv[]) 47 47 { 48 psLogSetFormat("HLNM"); 48 49 psLogSetLevel(PS_LOG_INFO); 49 50 -
trunk/psLib/test/math/tst_psFunc09.c
r4581 r4731 4 4 * ORD and CHEB type polynomials. 5 5 * 6 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $7 * @date $Date: 2005-0 7-20 01:21:13$6 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 7 * @date $Date: 2005-08-08 21:44:09 $ 8 8 * 9 9 * Copyright 2004-2005 Maui High Performance Computing Center, Univ. of Hawaii … … 75 75 psS32 main(psS32 argc, char* argv[]) 76 76 { 77 psLogSetFormat("HLNM"); 77 78 psLogSetLevel(PS_LOG_INFO); 78 79 -
trunk/psLib/test/math/tst_psFunc10.c
r4581 r4731 4 4 * ORD and CHEB type polynomials. 5 5 * 6 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $7 * @date $Date: 2005-0 7-20 01:21:13$6 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 7 * @date $Date: 2005-08-08 21:44:09 $ 8 8 * 9 9 * Copyright 2004-2005 Maui High Performance Computing Center, Univ. of Hawaii … … 126 126 psS32 main(psS32 argc, char* argv[]) 127 127 { 128 psLogSetFormat("HLNM"); 128 129 psLogSetLevel(PS_LOG_INFO); 129 130 -
trunk/psLib/test/math/tst_psFunc11.c
r4581 r4731 4 4 * ORD and CHEB type polynomials. 5 5 * 6 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $7 * @date $Date: 2005-0 7-20 01:21:13$6 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 7 * @date $Date: 2005-08-08 21:44:09 $ 8 8 * 9 9 * Copyright 2004-2005 Maui High Performance Computing Center, Univ. of Hawaii … … 368 368 psS32 main(psS32 argc, char* argv[]) 369 369 { 370 psLogSetFormat("HLNM"); 370 371 psLogSetLevel(PS_LOG_INFO); 371 372 -
trunk/psLib/test/math/tst_psMinimize06.c
r4547 r4731 6 6 #include "psTest.h" 7 7 #include <math.h> 8 #define NUM_ITERATIONS 100 008 #define NUM_ITERATIONS 100 9 9 #define ERR_TOL 0.0 10 #define N 20 11 #define MIN_VALUE 5.0 12 #define NUM_PARAMS 3 10 #define NUM_DATA_POINTS 20 11 #define NUM_PARAMS 5 13 12 float expectedParm[NUM_PARAMS]; 14 13 psS32 testStatus = true; … … 16 15 /***************************************************************************** 17 16 myFunc(): 18 sum = (param[0] * x[0]) + 19 (param[1] * x[1]) + 20 ... 17 sum = param[0] + x[0] * x[1] + 18 param[1] * x[0] + 19 param[2] * x[0]^2 + 20 param[3] * x[1] + 21 param[4] * x[1]^2 22 21 23 *****************************************************************************/ 22 psF 64myFunc(psVector *deriv,24 psF32 myFunc(psVector *deriv, 23 25 psVector *params, 24 26 psVector *x) 25 27 { 26 if ((deriv == NULL) || 27 (params == NULL)) { 28 if ((deriv == NULL) || (params == NULL)) { 28 29 psError(PS_ERR_UNKNOWN, true, "deriv or params is NULL.\n"); 29 30 } 30 31 31 psF64 sum = 0.0; 32 for (psS32 i=0 ; i < params->n ; i++) { 33 sum += (params->data.F32[i] * x->data.F32[i]); 34 deriv->data.F32[i] = params->data.F32[i]; 35 } 32 psF32 sum = (params->data.F32[0] * x->data.F32[0] * x->data.F32[1]) + 33 (params->data.F32[1] * x->data.F32[0]) + 34 (params->data.F32[2] * PS_SQR(x->data.F32[0])) + 35 (params->data.F32[3] * x->data.F32[1]) + 36 (params->data.F32[4] * PS_SQR(x->data.F32[1])); 37 38 deriv->data.F32[0] = x->data.F32[0] * x->data.F32[1]; 39 deriv->data.F32[1] = x->data.F32[0]; 40 deriv->data.F32[2] = PS_SQR(x->data.F32[0]); 41 deriv->data.F32[3] = x->data.F32[1]; 42 deriv->data.F32[4] = PS_SQR(x->data.F32[1]); 36 43 37 44 return(sum); … … 42 49 { 43 50 psS32 currentId = psMemGetId(); 44 psS32 memLeaks = 0;45 psS32 i = 0;46 psArray *myCoords;47 psVector *myParams;48 psImage *myCovar;49 psMinimization *min;50 psVector *y;51 52 51 psTraceSetLevel(".psLib", 0); 53 52 /************************************************************************** 54 53 *************************************************************************/ 55 min = psMinimizationAlloc(NUM_ITERATIONS, ERR_TOL); 56 myCovar = psImageAlloc(NUM_PARAMS, NUM_PARAMS, PS_TYPE_F32); 57 myParams = psVectorAlloc(NUM_PARAMS, PS_TYPE_F32); 58 myCoords = psArrayAlloc(N); 59 y = psVectorAlloc(N, PS_TYPE_F32); 54 psMinimization *min = psMinimizationAlloc(NUM_ITERATIONS, ERR_TOL); 55 psImage *myCovar = psImageAlloc(NUM_PARAMS, NUM_PARAMS, PS_TYPE_F32); 56 psVector *myParams = psVectorAlloc(NUM_PARAMS, PS_TYPE_F32); 57 psVector *myDerivs = psVectorAlloc(NUM_PARAMS, PS_TYPE_F32); 58 psArray *myCoords = psArrayAlloc(NUM_DATA_POINTS); 59 psVector *y = psVectorAlloc(NUM_DATA_POINTS, PS_TYPE_F32); 60 60 61 for ( i=0;i<N;i++) {61 for (psS32 i=0;i<NUM_DATA_POINTS;i++) { 62 62 myCoords->data[i] = (psPtr *) psVectorAlloc(2, PS_TYPE_F32); 63 63 ((psVector *) (myCoords->data[i]))->data.F32[0] = (float) (i+10); 64 64 ((psVector *) (myCoords->data[i]))->data.F32[1] = (float) (i+3); 65 /* 66 printf("x[%d] is vector (%f, %f)\n", i, ((psVector *) (myCoords->data[i]))->data.F32[0], 67 ((psVector *) (myCoords->data[i]))->data.F32[1]); 68 */ 65 69 y->data.F32[i] = (float) i; 66 70 } 67 for ( i=0;i<NUM_PARAMS;i++) {71 for (psS32 i=0;i<NUM_PARAMS;i++) { 68 72 expectedParm[i] = 2.42 + (float) (2 * i); 69 myParams->data.F32[i] = (float) i; 70 myParams->data.F32[i] = expectedParm[i] * 1.3; 71 myParams->data.F32[i] = 0.0; 72 myParams->data.F32[i] = (float) (5 + i); 73 myParams->data.F32[i] = (float) (2 * i); 73 74 } 74 75 … … 82 83 (psMinimizeLMChi2Func) myFunc); 83 84 84 printf("\nThe chi-squared is %f\n", min->value); 85 for (i=0;i<NUM_PARAMS;i++) { 85 printf("\nThe value of the function at the minimum is %f\n", min->value); 86 for (psS32 i=0;i<NUM_DATA_POINTS;i++) { 87 printf("The minimum for data point %d: %f\n", i, myFunc(myDerivs, myParams, (psVector *) myCoords->data[i])); 88 } 89 90 for (psS32 i=0;i<NUM_PARAMS;i++) { 86 91 printf("Parameter %d at the minimum is %f (expected: %f)\n", i, 87 92 myParams->data.F32[i], expectedParm[i]); … … 91 96 psFree(myCovar); 92 97 psFree(myParams); 98 psFree(myDerivs); 93 99 psFree(myCoords); 94 100 psFree(y); 95 101 96 102 psMemCheckCorruption(1); 97 memLeaks = psMemCheckLeaks(currentId,NULL,NULL,false);103 psS32 memLeaks = psMemCheckLeaks(currentId,NULL,NULL,false); 98 104 if (0 != memLeaks) { 99 105 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
Note:
See TracChangeset
for help on using the changeset viewer.
