Changeset 12338
- Timestamp:
- Mar 8, 2007, 1:23:00 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/rel-1_0/psLib/src/math/psMinimizePolyFit.c
r10999 r12338 10 10 * @author EAM, IfA 11 11 * 12 * @version $Revision: 1.29 $ $Name: not supported by cvs2svn $13 * @date $Date: 2007-0 1-09 22:38:53$12 * @version $Revision: 1.29.2.1 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2007-03-08 23:23:00 $ 14 14 * 15 15 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 879 879 double stdevValue = psStatsGetValue (stats, stdevOption); 880 880 881 // correct for the number of degrees of freedom absorbed by the fit 882 const int nterm = psPolynomial1DNterm(poly); 883 if (Nkeep <= nterm) { // we can't estimate the standard deviation 884 psError(PS_ERR_UNKNOWN, true, "Number of data points %d is <= number of degrees of freedom %d", 885 Nkeep, nterm); 886 psFree(resid); 887 psFree(fit); 888 889 return false; 890 } 891 stdevValue *= (Nkeep - 1)/(Nkeep - nterm - 1); 892 881 893 psTrace("psLib.math", 5, "Mean is %f\n", meanValue); 882 894 psTrace("psLib.math", 5, "Stdev is %f\n", stdevValue); … … 1045 1057 } 1046 1058 psFree(xySums); 1047 1059 #if 0 1060 /* 1061 * psMatrixGJSolve doesn't detect singular matrices very well. I'll do an SVN decomp 1062 * to test for this -- but this is quite expensive, and a better solver would be wise. RHL. 1063 * 1064 * Don't run this test for now as I made the Gauss-Jordan solver require that |pivot| > FLT_EPSILON 1065 * 1066 * We could use lambda/evectors to solve the system without proceeding to a Gauss-Jordan 1067 * solver, but I'm too lazy for now 1068 */ 1069 psVector *lambda = psVectorAlloc(A->numCols, A->type.type); // eigenvalues 1070 psImage *evectors = psMatrixSVD(NULL, lambda, A); // eigenvectors 1071 1072 for (int i = 0; i < lambda->n; i++) { 1073 const double l = psVectorGet(lambda, i); 1074 1075 if (l > -FLT_EPSILON && l < FLT_EPSILON) { 1076 psError(PS_ERR_UNKNOWN, true, "Found almost zero eigenvalue %g. Returning NULL.\n", l); 1077 psFree(lambda); psFree(evectors); 1078 psFree(A); 1079 psFree(B); 1080 return false; 1081 } 1082 } 1083 1084 psFree(lambda); 1085 psFree(evectors); 1086 #endif 1048 1087 if (!psMatrixGJSolve(A, B)) { 1049 1088 psError(PS_ERR_UNKNOWN, false, "Could not solve linear equations. Returning NULL.\n"); … … 1116 1155 result = VectorFitPolynomial2DOrd(poly, mask, maskValue, f64, fErr64, x64, y64); 1117 1156 if (!result) { 1118 psError(PS_ERR_UNKNOWN, true, "Could not fit polynomial. Returning NULL.\n");1157 psError(PS_ERR_UNKNOWN, false, "Could not fit polynomial. Returning NULL.\n"); 1119 1158 } 1120 1159 break; … … 1253 1292 if (!psVectorStats(stats, resid, NULL, mask, maskValue)) { 1254 1293 psError(PS_ERR_UNKNOWN, false, "Could not compute statistics on the resid vector. Returning NULL.\n"); 1255 psFree(resid) 1256 psFree(fit) 1294 psFree(resid); 1295 psFree(fit); 1257 1296 return false; 1258 1297 } … … 1260 1299 double meanValue = psStatsGetValue (stats, meanOption); 1261 1300 double stdevValue = psStatsGetValue (stats, stdevOption); 1301 1302 // correct for the number of degrees of freedom absorbed by the fit 1303 const int nterm = psPolynomial2DNterm(poly); 1304 if (Nkeep <= nterm) { // we can't estimate the standard deviation 1305 psError(PS_ERR_UNKNOWN, true, "Number of data points %d is <= number of degrees of freedom %d", 1306 Nkeep, nterm); 1307 psFree(resid); 1308 psFree(fit); 1309 1310 return false; 1311 } 1312 stdevValue *= (Nkeep - 1)/(Nkeep - nterm - 1); 1262 1313 1263 1314 psTrace("psLib.math", 5, "Mean is %f\n", meanValue);
Note:
See TracChangeset
for help on using the changeset viewer.
