Changeset 6527 for trunk/psLib/src/math/psMinimizePolyFit.c
- Timestamp:
- Mar 6, 2006, 10:57:42 AM (20 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/math/psMinimizePolyFit.c (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/math/psMinimizePolyFit.c
r6484 r6527 10 10 * @author EAM, IfA 11 11 * 12 * @version $Revision: 1. 8$ $Name: not supported by cvs2svn $13 * @date $Date: 2006-0 2-24 23:43:15$12 * @version $Revision: 1.9 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2006-03-06 20:57:42 $ 14 14 * 15 15 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 41 41 #define PS_VECTOR_GEN_CHEBY_INDEX(VEC, SIZE, TYPE) \ 42 42 VEC = psVectorAlloc(SIZE, TYPE); \ 43 VEC->n = VEC->nalloc; \ 43 44 if (TYPE == PS_TYPE_F64) { \ 44 45 for (psS32 i = 0 ; i < SIZE ; i++) { \ 45 46 VEC->data.F64[i] = ((2.0 / ((psF64) (SIZE - 1))) * ((psF64) i)) - 1.0; \ 46 VEC->n++; \47 47 }\ 48 48 } else if (TYPE == PS_TYPE_F32){ \ 49 49 for (psS32 i = 0 ; i < SIZE ; i++) { \ 50 50 VEC->data.F32[i] = ((2.0 / ((psF32) (SIZE - 1))) * ((psF32) i)) - 1.0; \ 51 VEC->n++; \52 51 }\ 53 52 }\ … … 309 308 linear equations which can be easily solved. The resulting vector is the 310 309 coefficients of the Chebyshev polys. 311 310 312 311 This method is significantly slower than the standard NR algorithm. It 313 312 was explicitly requested that we not use the NR algorithm. … … 370 369 psImage *A = psImageAlloc(numPoly, numPoly, PS_TYPE_F64); 371 370 psVector *B = psVectorAlloc(numPoly, PS_TYPE_F64); 371 B->n = B->nalloc; 372 372 for (psS32 i = 0 ; i < numPoly ; i++) { 373 373 for (psS32 j = 0 ; j < numPoly ; j++) { … … 375 375 } 376 376 B->data.F64[i] = ordPoly->coeff[i]; 377 B->n++;378 377 } 379 378 … … 817 816 } 818 817 for (psS32 i = 0; i < nTerm; i++) { 818 if (myPoly->mask[i]) 819 continue; 819 820 B->data.F64[i] += f->data.F64[k] * xSums->data.F64[i] * wt; 820 821 } … … 823 824 // we must handle masked orders 824 825 for (psS32 i = 0; i < nTerm; i++) { 826 if (myPoly->mask[i]) 827 continue; 825 828 for (psS32 j = 0; j < nTerm; j++) { 829 if (myPoly->mask[j]) 830 continue; 826 831 A->data.F64[i][j] += xSums->data.F64[i + j] * wt; 827 832 } … … 829 834 } 830 835 836 // set masked elements in A,B appropriately 837 for (int i = 0; i < nTerm; i++) { 838 if (!myPoly->mask[i]) 839 continue; 840 B->data.F64[i] = 0; 841 for (int j = 0; j < nTerm; j++) { 842 A->data.F64[i][j] = (i == j) ? 1 : 0; 843 } 844 } 845 846 847 // XXX: rel10_ifa used psGaussJordan(). However, this failed tests. So, I'm using psMatrixLUD(). 831 848 if (0) { 832 849 // GaussJordan version … … 840 857 for (psS32 k = 0; k < nTerm; k++) { 841 858 myPoly->coeff[k] = B->data.F64[k]; 859 myPoly->coeffErr[k] = sqrt(A->data.F64[k][k]); 842 860 } 843 861 } … … 864 882 for (psS32 k = 0; k < nTerm; k++) { 865 883 myPoly->coeff[k] = coeffs->data.F64[k]; 884 // XXX LUD does not give inverse of A 866 885 } 867 886 } … … 1245 1264 for (psS32 n = 0; n < nXterm; n++) { 1246 1265 for (psS32 m = 0; m < nYterm; m++) { 1266 if (myPoly->mask[n][m]) 1267 continue; 1247 1268 B->data.F64[n+m*nXterm] += f->data.F64[k] * Sums->data.F64[n][m] * wt; 1248 1269 } … … 1251 1272 for (psS32 i = 0; i < nXterm; i++) { 1252 1273 for (psS32 j = 0; j < nYterm; j++) { 1274 if (myPoly->mask[i][j]) 1275 continue; 1253 1276 for (psS32 n = 0; n < nXterm; n++) { 1254 1277 for (psS32 m = 0; m < nYterm; m++) { 1278 if (myPoly->mask[n][m]) 1279 continue; 1255 1280 A->data.F64[i+j*nXterm][n+m*nXterm] += Sums->data.F64[i+n][j+m] * wt; 1256 1281 } 1282 } 1283 } 1284 } 1285 } 1286 1287 // set masked elements appropriately 1288 for (int i = 0; i < nXterm; i++) { 1289 for (int j = 0; j < nYterm; j++) { 1290 if (!myPoly->mask[i][j]) 1291 continue; 1292 int nx = i+j*nXterm; 1293 B->data.F64[nx] = 0; 1294 for (int n = 0; n < nXterm; n++) { 1295 for (int m = 0; m < nYterm; m++) { 1296 int ny = n+m*nXterm; 1297 A->data.F64[nx][ny] = (nx == ny) ? 1 : 0; 1257 1298 } 1258 1299 } … … 1269 1310 for (psS32 m = 0; m < nYterm; m++) { 1270 1311 myPoly->coeff[n][m] = B->data.F64[n+m*nXterm]; 1312 myPoly->coeffErr[n][m] = sqrt(A->data.F64[n+m*nXterm][n+m*nXterm]); 1271 1313 } 1272 1314 } … … 1723 1765 } 1724 1766 1767 // XXX: rel10_ifa used psGaussJordan(). However, this failed tests. So, I'm using psMatrixLUD(). 1725 1768 if (0) { 1726 1769 // does the solution in place … … 1775 1818 psS32 nx = ix+iy*nXterm+iz*nXterm*nYterm; 1776 1819 myPoly->coeff[ix][iy][iz] = coeffs->data.F64[nx]; 1777 myPoly->coeffErr[ix][iy][iz] = sqrt(A->data.F64[nx][nx]); 1820 // XXX myPoly->coeffErr[ix][iy][iz] = sqrt(A->data.F64[nx][nx]); 1821 // XXX this is wrong: A is not replaced with inverse(A), as for GaussJordan 1778 1822 } 1779 1823 } … … 2278 2322 2279 2323 2324 // XXX: rel10_ifa used psGaussJordan(). However, this failed tests. So, I'm using psMatrixLUD(). 2280 2325 if (0) { 2281 2326 // does the solution in place … … 2336 2381 psS32 nx = ix+iy*nXterm+iz*nXterm*nYterm+it*nXterm*nYterm*nZterm; 2337 2382 myPoly->coeff[ix][iy][iz][it] = coeffs->data.F64[nx]; 2338 myPoly->coeffErr[ix][iy][iz][it] = sqrt(A->data.F64[nx][nx]); 2383 // myPoly->coeffErr[ix][iy][iz][it] = sqrt(A->data.F64[nx][nx]); 2384 // XXX this is wrong: LUD does not supply inverse(A) 2339 2385 } 2340 2386 }
Note:
See TracChangeset
for help on using the changeset viewer.
