comparison maths/Polyfit.h @ 268:9aedf5ea8c35

* remove exceptions from Polyfit, return bool instead of int from isModeMinor
author Chris Cannam <c.cannam@qmul.ac.uk>
date Thu, 07 Feb 2008 10:01:38 +0000
parents a98dd8ec96f8
children 31f22daeba64
comparison
equal deleted inserted replaced
267:d7b81af99b5e 268:9aedf5ea8c35
38 38
39 /////////////////////////////////////////////////////////////////////////////// 39 ///////////////////////////////////////////////////////////////////////////////
40 // Modified by CLandone for VC6 Aug 2004 40 // Modified by CLandone for VC6 Aug 2004
41 /////////////////////////////////////////////////////////////////////////////// 41 ///////////////////////////////////////////////////////////////////////////////
42 42
43 #include <iostream>
43 44
44 using std::vector; 45 using std::vector;
45
46 46
47 class TPolyFit 47 class TPolyFit
48 { 48 {
49 typedef vector<vector<double> > Matrix; 49 typedef vector<vector<double> > Matrix;
50 public: 50 public:
114 const int nterms(coefs.size()); 114 const int nterms(coefs.size());
115 double correl_coef; 115 double correl_coef;
116 zeroise(g, nterms); 116 zeroise(g, nterms);
117 zeroise(a, nterms, nterms); 117 zeroise(a, nterms, nterms);
118 zeroise(xmatr, npoints, nterms); 118 zeroise(xmatr, npoints, nterms);
119 if(nterms < 1) 119 if (nterms < 1) {
120 throw "PolyFit called with less than one term"; 120 std::cerr << "ERROR: PolyFit called with less than one term" << std::endl;
121 if(npoints < 2) 121 return 0;
122 throw "PolyFit called with less than two points"; 122 }
123 if(npoints != y.size()) 123 if(npoints < 2) {
124 throw "PolyFit called with x and y of unequal size"; 124 std::cerr << "ERROR: PolyFit called with less than two points" << std::endl;
125 return 0;
126 }
127 if(npoints != y.size()) {
128 std::cerr << "ERROR: PolyFit called with x and y of unequal size" << std::endl;
129 return 0;
130 }
125 for(i = 0; i < npoints; ++i) 131 for(i = 0; i < npoints; ++i)
126 { 132 {
127 // { setup x matrix } 133 // { setup x matrix }
128 xi = x[i]; 134 xi = x[i];
129 xmatr[i][0] = 1.0; // { first column } 135 xmatr[i][0] = 1.0; // { first column }
245 251
246 for(int k = 0; k < ncol; ++k) 252 for(int k = 0; k < ncol; ++k)
247 { 253 {
248 if(index [k][2] != 0) 254 if(index [k][2] != 0)
249 { 255 {
250 throw "Error in GaussJordan: matrix is singular"; 256 std::cerr << "ERROR: Error in PolyFit::GaussJordan: matrix is singular" << std::endl;
257 return false;
251 } 258 }
252 } 259 }
253 260
254 for( int i = 0; i < ncol; ++i) 261 for( int i = 0; i < ncol; ++i)
255 coef[i] = w[i][0]; 262 coef[i] = w[i][0];
288 { 295 {
289 if(index[j][2] != 0) 296 if(index[j][2] != 0)
290 { 297 {
291 for(int k = 0; k < ncol; ++k) 298 for(int k = 0; k < ncol; ++k)
292 { 299 {
293 if(index[k][2] > 0) 300 if(index[k][2] > 0) {
294 throw "Error in GaussJordan2: matrix is singular"; 301 std::cerr << "ERROR: Error in PolyFit::GaussJordan2: matrix is singular" << std::endl;
302 return false;
303 }
295 304
296 if(index[k][2] < 0 && fabs(b[j][k]) > big) 305 if(index[k][2] < 0 && fabs(b[j][k]) > big)
297 { 306 {
298 irow = j; 307 irow = j;
299 icol = k; 308 icol = k;