Changeset 1945 for trunk/psLib/test/dataManip/tst_psMinimize04b.c
- Timestamp:
- Oct 3, 2004, 1:35:47 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/dataManip/tst_psMinimize04b.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/dataManip/tst_psMinimize04b.c
r1919 r1945 11 11 #include "psMinimize.h" 12 12 #include <math.h> 13 #define NUM_DATA 1513 #define NUM_DATA 20 14 14 #define POLY_ORDER 10 15 15 #define A 2.0 … … 18 18 #define D 4.0 19 19 #define E 5.0 20 #define ERROR_TOLERANCE 0.10 21 #define IGNORE (ERROR_TOLERANCE * NUM_DATA) 20 22 21 23 double setData(double x) … … 24 26 } 25 27 26 int main()28 int t00() 27 29 { 28 30 psPolynomial1D *myPoly = NULL; … … 31 33 psVector *yErr = NULL; 32 34 int i = 0; 33 // int currentId = psMemGetId(); 34 int testStatus = true; 35 int memLeaks = 0; 36 float sum=0.0; 35 int currentId = psMemGetId(); 36 int testStatus = true; 37 int memLeaks = 0; 37 38 38 39 myPoly = psPolynomial1DAlloc(POLY_ORDER+1, PS_POLYNOMIAL_CHEB); … … 47 48 } 48 49 p_psNormalizeVectorF64(x); 49 for (i=0;i<NUM_DATA;i++) { 50 // printf("Original data %d: (%.1f %.1f)\n", i, x->data.F64[i], y->data.F64[i]); 51 } 52 53 sum=0.0; 54 for (i=0;i<NUM_DATA;i++) 55 sum+=y->data.F64[i]; 56 printf("c0 is %f\n", 2.0 * sum/((float) NUM_DATA)); 57 58 sum=0.0; 59 for (i=0;i<NUM_DATA;i++) 60 sum+=y->data.F64[i] * x->data.F64[i]; 61 printf("c1 is %f\n", 2.0 * sum/((float) NUM_DATA)); 62 sum=0.0; 63 64 for (i=0;i<NUM_DATA;i++) 65 sum+=y->data.F64[i] * ((2.0 * x->data.F64[i] * x->data.F64[i]) - 1.0); 66 printf("c2 is %f\n", 2.0 * sum/((float) NUM_DATA)); 50 51 printPositiveTestHeader(stdout, 52 "psMinimize functions", 53 "psVectorFitPolynomial1D(): CHEB, equal errors in yErr"); 67 54 68 55 psVectorFitPolynomial1D(myPoly, x, y, yErr); … … 72 59 } 73 60 74 for (i=0;i<NUM_DATA;i++) { 75 printf("Fitted data %d: (%.1f %.1f) should be %.1f\n", i, x->data.F64[i], 76 psPolynomial1DEval((float) x->data.F64[i], myPoly), y->data.F64[i]); 77 } 78 79 80 // psMemCheckCorruption(1); 81 printFooter(stdout, 82 "psMinimize functions", 83 "psMinimize(): no masks", 84 testStatus); 85 86 // psMemCheckCorruption(1); 61 // We don't test the first or last few data items. 62 for (i=IGNORE;i<NUM_DATA-IGNORE;i++) { 63 double expectData = y->data.F64[i]; 64 double actualData = psPolynomial1DEval(x->data.F64[i], myPoly); 65 if (fabs(actualData-expectData) > fabs(ERROR_TOLERANCE * expectData)) { 66 printf("ERROR: Fitted data %d: (%.1f %.1f), expected was (%.1f)\n", 67 i, x->data.F64[i], actualData, expectData); 68 testStatus = false; 69 } else { 70 printf("Fitted data %d: (%.1f %.1f), expected was (%.1f)\n", 71 i, x->data.F64[i], actualData, expectData); 72 } 73 } 74 75 psMemCheckCorruption(1); 87 76 psFree(myPoly); 88 77 psFree(x); 89 78 psFree(y); 90 79 psFree(yErr); 91 92 // psMemCheckCorruption(1); 93 // memLeaks = psMemCheckLeaks(currentId,NULL,stderr); 94 if (0 != memLeaks) { 95 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks); 96 } 97 98 return (!testStatus); 99 } 80 psMemCheckCorruption(1); 81 memLeaks = psMemCheckLeaks(currentId,NULL,stderr); 82 if (0 != memLeaks) { 83 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks); 84 } 85 86 printFooter(stdout, 87 "psMinimize functions", 88 "psVectorFitPolynomial1D(): CHEB, equal errors in yErr", 89 testStatus); 90 return (!testStatus); 91 } 92 93 94 int t01() 95 { 96 psPolynomial1D *myPoly = NULL; 97 psVector *x = NULL; 98 psVector *y = NULL; 99 int i = 0; 100 int currentId = psMemGetId(); 101 int testStatus = true; 102 int memLeaks = 0; 103 104 myPoly = psPolynomial1DAlloc(POLY_ORDER+1, PS_POLYNOMIAL_CHEB); 105 x = psVectorAlloc(NUM_DATA, PS_TYPE_F64); 106 y = psVectorAlloc(NUM_DATA, PS_TYPE_F64); 107 108 for (i=0;i<NUM_DATA;i++) { 109 x->data.F64[i] = (double) i; 110 y->data.F64[i] = setData(x->data.F64[i]); 111 } 112 p_psNormalizeVectorF64(x); 113 114 printPositiveTestHeader(stdout, 115 "psMinimize functions", 116 "psVectorFitPolynomial1D(): CHEB, yErr is NULL"); 117 118 psVectorFitPolynomial1D(myPoly, x, y, NULL); 119 120 // We don't test the first or last few data items. 121 for (i=IGNORE;i<NUM_DATA-IGNORE;i++) { 122 double expectData = y->data.F64[i]; 123 double actualData = psPolynomial1DEval(x->data.F64[i], myPoly); 124 if (fabs(actualData-expectData) > fabs(ERROR_TOLERANCE * expectData)) { 125 printf("ERROR: Fitted data %d: (%.1f %.1f), expected was (%.1f)\n", 126 i, x->data.F64[i], actualData, expectData); 127 testStatus = false; 128 } else { 129 printf("Fitted data %d: (%.1f %.1f), expected was (%.1f)\n", 130 i, x->data.F64[i], actualData, expectData); 131 } 132 } 133 134 psMemCheckCorruption(1); 135 psFree(myPoly); 136 psFree(x); 137 psFree(y); 138 psMemCheckCorruption(1); 139 memLeaks = psMemCheckLeaks(currentId,NULL,stderr); 140 if (0 != memLeaks) { 141 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks); 142 } 143 144 printFooter(stdout, 145 "psMinimize functions", 146 "psVectorFitPolynomial1D(): CHEB, yErr is NULL", 147 testStatus); 148 return (!testStatus); 149 } 150 151 152 int t02() 153 { 154 psPolynomial1D *myPoly = NULL; 155 psVector *x = NULL; 156 psVector *y = NULL; 157 int i = 0; 158 int currentId = psMemGetId(); 159 int testStatus = true; 160 int memLeaks = 0; 161 162 myPoly = psPolynomial1DAlloc(POLY_ORDER+1, PS_POLYNOMIAL_CHEB); 163 x = psVectorAlloc(NUM_DATA, PS_TYPE_F64); 164 y = psVectorAlloc(NUM_DATA, PS_TYPE_F64); 165 166 for (i=0;i<NUM_DATA;i++) { 167 x->data.F64[i] = (double) i; 168 y->data.F64[i] = setData(x->data.F64[i]); 169 } 170 p_psNormalizeVectorF64(x); 171 172 printPositiveTestHeader(stdout, 173 "psMinimize functions", 174 "psVectorFitPolynomial1D(): CHEB, x, yErr is NULL"); 175 176 psVectorFitPolynomial1D(myPoly, NULL, y, NULL); 177 178 // We don't test the first or last few data items. 179 for (i=IGNORE;i<NUM_DATA-IGNORE;i++) { 180 double expectData = y->data.F64[i]; 181 double actualData = psPolynomial1DEval(x->data.F64[i], myPoly); 182 if (fabs(actualData-expectData) > fabs(ERROR_TOLERANCE * expectData)) { 183 printf("ERROR: Fitted data %d: (%.1f %.1f), expected was (%.1f)\n", 184 i, x->data.F64[i], actualData, expectData); 185 testStatus = false; 186 } else { 187 printf("Fitted data %d: (%.1f %.1f), expected was (%.1f)\n", 188 i, x->data.F64[i], actualData, expectData); 189 } 190 } 191 192 psMemCheckCorruption(1); 193 psFree(myPoly); 194 psFree(x); 195 psFree(y); 196 psMemCheckCorruption(1); 197 memLeaks = psMemCheckLeaks(currentId,NULL,stderr); 198 if (0 != memLeaks) { 199 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks); 200 } 201 202 printFooter(stdout, 203 "psMinimize functions", 204 "psVectorFitPolynomial1D(): CHEB, x, yErr is NULL", 205 testStatus); 206 return (!testStatus); 207 } 208 209 int t03() 210 { 211 psPolynomial1D *myPoly = NULL; 212 int currentId = psMemGetId(); 213 int testStatus = true; 214 int memLeaks = 0; 215 216 printPositiveTestHeader(stdout, 217 "psMinimize functions", 218 "psVectorFitPolynomial1D(): CHEB, yErr is NULL"); 219 220 myPoly = psVectorFitPolynomial1D(NULL, NULL, NULL, NULL); 221 if (myPoly != NULL) { 222 printf("ERROR: psVectorFitPolynomial1D() returned a non-NULL polynomial.\n"); 223 testStatus = false; 224 } 225 226 psMemCheckCorruption(1); 227 memLeaks = psMemCheckLeaks(currentId,NULL,stderr); 228 if (0 != memLeaks) { 229 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks); 230 } 231 printFooter(stdout, 232 "psMinimize functions", 233 "psVectorFitPolynomial1D(): CHEB, yErr is NULL", 234 testStatus); 235 return (!testStatus); 236 } 237 238 int main() 239 { 240 t00(); 241 t01(); 242 t02(); 243 t03(); 244 }
Note:
See TracChangeset
for help on using the changeset viewer.
