Changeset 2197 for trunk/psLib/test/dataManip
- Timestamp:
- Oct 26, 2004, 11:25:59 AM (22 years ago)
- Location:
- trunk/psLib/test/dataManip
- Files:
-
- 2 edited
-
tst_psMinimize06.c (modified) (5 diffs)
-
tst_psStats07.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/dataManip/tst_psMinimize06.c
r1992 r2197 74 74 } 75 75 76 77 int main() 76 psVector *myFunc2(psImage *myDeriv, 77 psVector *myParams, 78 psArray *myCoords) 79 { 80 psVector *sum = psVectorAlloc(myCoords->n, PS_TYPE_F32); 81 int i; 82 int j; 83 84 85 if (myDeriv == NULL) { 86 myDeriv = psImageAlloc(myParams->n, myCoords->n, PS_TYPE_F32); 87 psError(__func__, "myDeriv is NULL.\n"); 88 } 89 90 for (i=0;i<N;i++) { 91 sum->data.F32[i] = MIN_VALUE; 92 for (j=0;j<NUM_PARAMS;j++) { 93 sum->data.F32[i]+= (myParams->data.F32[j] - expectedParm[j]) * 94 (myParams->data.F32[j] - expectedParm[j]); 95 96 myDeriv->data.F32[i][j] = (2.0 * myParams->data.F32[j]) - 97 (2.0 * expectedParm[j]); 98 } 99 } 100 101 return(sum); 102 } 103 104 int t01() 105 { 106 int currentId = psMemGetId(); 107 int memLeaks = 0; 108 int i = 0; 109 psArray *myCoords; 110 psVector *myParams; 111 psImage *myCovar; 112 psMinimization *min; 113 psVector *y; 114 115 psTraceSetLevel(".psLib", 0); 116 /************************************************************************** 117 *************************************************************************/ 118 min = psMinimizationAlloc(NUM_ITERATIONS, ERR_TOL); 119 myCovar = psImageAlloc(NUM_PARAMS, NUM_PARAMS, PS_TYPE_F32); 120 myParams = psVectorAlloc(NUM_PARAMS, PS_TYPE_F32); 121 myCoords = psArrayAlloc(N); 122 y = psVectorAlloc(N, PS_TYPE_F32); 123 124 for (i=0;i<N;i++) { 125 myCoords->data[i] = (psPTR *) psVectorAlloc(2, PS_TYPE_F32); 126 ((psVector *) (myCoords->data[i]))->data.F32[0] = (float) (i+10); 127 ((psVector *) (myCoords->data[i]))->data.F32[1] = (float) (i+3); 128 y->data.F32[i] = (float) i; 129 } 130 for (i=0;i<NUM_PARAMS;i++) { 131 expectedParm[i] = 2.42 + (float) (2 * i); 132 myParams->data.F32[i] = (float) i; 133 myParams->data.F32[i] = expectedParm[i] * 1.3; 134 myParams->data.F32[i] = (float) (5 + i); 135 myParams->data.F32[i] = 0.0; 136 } 137 138 psMyMinimizeLMChi2(min, 139 myCovar, 140 myParams, 141 NULL, 142 myCoords, 143 y, 144 NULL, 145 (psMyMinimizeLMChi2Func) myFunc2); 146 147 printf("\nThe chi-squared is %f\n", min->value); 148 for (i=0;i<NUM_PARAMS;i++) { 149 printf("Parameter %d at the minimum is %f (expected: %f)\n", i, 150 myParams->data.F32[i], expectedParm[i]); 151 } 152 153 psFree(min); 154 psFree(myCovar); 155 psFree(myParams); 156 psFree(myCoords); 157 psFree(y); 158 159 psMemCheckCorruption(1); 160 memLeaks = psMemCheckLeaks(currentId,NULL,NULL); 161 if (0 != memLeaks) { 162 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks); 163 } 164 return (!testStatus); 165 } 166 167 int t02() 78 168 { 79 169 int currentId = psMemGetId(); … … 85 175 psImage *myCovar; 86 176 psMinimization *min; 87 psVector *x = psVectorAlloc(N, PS_TYPE_F32);88 177 psVector *y = psVectorAlloc(N, PS_TYPE_F32); 89 178 90 179 psTraceSetLevel(".psLib", 0); 180 t02(); 91 181 /************************************************************************** 92 182 *************************************************************************/ … … 101 191 ((psVector *) (myCoords->data[i]))->data.F32[0] = (float) (i+10); 102 192 ((psVector *) (myCoords->data[i]))->data.F32[1] = (float) (i+3); 103 x->data.F32[i] = (float) i;104 193 y->data.F32[i] = (float) i; 105 194 } … … 131 220 psFree(myParamMask); 132 221 psFree(min); 133 psFree(x);134 222 psFree(y); 135 223 psFree(myCovar); … … 142 230 return (!testStatus); 143 231 } 232 233 int main() 234 { 235 t01(); 236 // t02(); 237 } -
trunk/psLib/test/dataManip/tst_psStats07.c
r1900 r2197 10 10 #include <math.h> 11 11 12 #define N 20012 #define N 90 13 13 #define MEAN 32.0 14 14 #define STDEV 2.0 15 15 #define ERROR_TOLERANCE 0.10 16 16 17 int main()17 int t00() 18 18 { 19 19 psStats * myStats = NULL; … … 32 32 float realMedianNoMask = MEAN; 33 33 float realModeNoMask = MEAN; 34 float realStdevNoMask = STDEV * 0. 33;34 float realStdevNoMask = STDEV * 0.20; 35 35 float realLQNoMask = MEAN - ( 0.6 * STDEV ); 36 36 float realUQNoMask = MEAN + ( 0.6 * STDEV ); 37 37 int realN50NoMask = N / 4; 38 38 int realNfitNoMask = N / 4; 39 float realMeanWithMask = MEAN; 40 float realMedianWithMask = MEAN; 41 float realModeWithMask = MEAN; 42 float realStdevWithMask = STDEV; 43 float realLQWithMask = MEAN; 44 float realUQWithMask = MEAN; 45 int realN50WithMask = N / 4; 46 int realNfitWithMask = N / 4; 47 39 40 psTraceSetLevel(".psLib.dataManip.psStats", 10); 48 41 49 42 /*************************************************************************/ … … 232 225 "PS_STAT_ROBUST_STATS: robust Nfit: no vector mask", 233 226 testStatus ); 234 235 236 return ( 0 ); 227 return(testStatus); 228 229 /*************************************************************************/ 230 /* Deallocate data structures */ 231 /*************************************************************************/ 232 printPositiveTestHeader( stdout, 233 "psStats functions", 234 "psStats(): deallocating memory" ); 235 236 psFree( myStats ); 237 psFree( myVector ); 238 psFree( maskVector ); 239 240 psMemCheckCorruption( 1 ); 241 memLeaks = psMemCheckLeaks(currentId,NULL,stderr); 242 if ( 0 != memLeaks ) { 243 psAbort( __func__, "Memory Leaks! (%d leaks)", memLeaks ); 244 } 245 246 printFooter( stdout, 247 "psVector functions", 248 "psStats(): deallocating memory", 249 testStatus ); 250 251 return ( !globalTestStatus ); 252 } 253 254 255 int t01() 256 { 257 psStats * myStats = NULL; 258 int testStatus = true; 259 int globalTestStatus = true; 260 int i = 0; 261 psVector *myVector = NULL; 262 psVector *maskVector = NULL; 263 // NOTE: These values were calculated by running the function on the data. 264 // A: They must be changed if we adjust the number of data points. 265 // B: We don't really know that they are correct. 266 int count = 0; 267 int currentId = psMemGetId(); 268 int memLeaks = 0; 269 float realMeanWithMask = MEAN; 270 float realMedianWithMask = MEAN; 271 float realModeWithMask = MEAN; 272 float realStdevWithMask = STDEV * 0.20; 273 float realLQWithMask = MEAN; 274 float realUQWithMask = MEAN; 275 int realN50WithMask = N / 4; 276 int realNfitWithMask = N / 4; 277 278 psTraceSetLevel(".psLib.dataManip.psStats", 10); 279 280 /*************************************************************************/ 281 /* Allocate and initialize data structures */ 282 /*************************************************************************/ 283 myStats = psStatsAlloc( PS_STAT_ROBUST_MEAN | 284 PS_STAT_ROBUST_MEDIAN | 285 PS_STAT_ROBUST_MODE | 286 PS_STAT_ROBUST_STDEV | 287 PS_STAT_ROBUST_QUARTILE ); 288 289 maskVector = psVectorAlloc( N, PS_TYPE_U8 ); 290 maskVector->n = N; 291 myVector = psGaussianDev( MEAN, STDEV, N ); 292 // Set the mask vector and calculate the expected maximum. 293 for ( i = 0;i < N;i++ ) { 294 if ( i < ( N / 2 ) ) { 295 maskVector->data.U8[ i ] = 0; 296 count++; 297 } else { 298 maskVector->data.U8[ i ] = 1; 299 } 300 } 237 301 238 302 /*************************************************************************/ … … 422 486 return ( !globalTestStatus ); 423 487 } 488 489 int main() 490 { 491 t00(); 492 t01(); 493 }
Note:
See TracChangeset
for help on using the changeset viewer.
