Home
Install
Use
Develop
Support
News
Credits
hosted by
|
34 template < class T, class U>
36 std::vector<std::vector<U> >& b,
37 int nrow = -1, double singular_threshold = 0.0,
38 std::vector<const char*>* names = 0);
41inline double inv ( double x) { return 1.0/x; }
43template < class T, class U>
45 std::vector<std::vector<U> >& b,
46 int nrow, double singular_threshold,
47 std::vector<const char*>* names)
54 std::cerr << "MEAL::GaussJordan nrow=" << nrow << std::endl;
62 if (b.size() < unsigned(nrow))
63 throw Error (InvalidState, "MEAL::GaussJordan",
64 "b.size()=%d < nrow=%d", b.size(), nrow);
70 std::cerr << "MEAL::GaussJordan nrow=" << nrow << " ncol=" << ncol << std::endl;
73 for ( int i=0; i < nrow; i++)
74 if (a[i].size() < unsigned(nrow))
75 throw Error (InvalidState, "MEAL::GaussJordan",
76 "a[%d].size()=%d < nrow=%d", i, a[i].size(), nrow);
79 std::vector<int> indxc (nrow);
80 std::vector<int> indxr (nrow);
81 std::vector<bool> ipiv (nrow, false);
84 std::cerr << "MEAL::GaussJordan start loop" << std::endl;
87 T log_abs_det_a = 0.0;
89 for ( int i=0; i<nrow; i++)
97 std::cerr << "MEAL::GaussJordan search for pivot" << std::endl;
101 for ( int j=0; j<nrow; j++)
106 for ( int k=0; k<nrow; k++)
111 if (fabs(a[j][k]) >= big)
120 if (big <= singular_threshold)
123 for ( int k=i; k<nrow; k++)
124 std::cerr << "MEAL::GaussJordan singular irow=" << k << " name=" << (*names)[k] << std::endl;
126 throw Error (InvalidState, "MEAL::GaussJordan",
127 "Singular Matrix. icol=%d nrow=%d pivot=%le", i, nrow, big);
130 assert (irow != -1 && icol != -1);
135 std::cerr << "MEAL::GaussJordan pivot found" << std::endl;
140 assert (irow < nrow);
141 assert (icol < nrow);
143 std::cerr << "MEAL::GaussJordan swap a irow=" << irow << " icol=" << icol << std::endl;
146 for ( int j=0; j<nrow; j++)
147 std::swap (a[irow][j], a[icol][j]);
150 std::cerr << "MEAL::GaussJordan swap b" << std::endl;
153 for ( int j=0; j<ncol; j++)
154 std::swap (b[irow][j], b[icol][j]);
157 std::swap ( (*names)[irow], (*names)[icol] );
161 std::cerr << "MEAL::GaussJordan swap done" << std::endl;
167 T pivinv = inv(a[icol][icol]);
168 log_abs_det_a += std::log(std::fabs(a[icol][icol]));
171 std::cerr << "icol=" << icol << " irow=" << irow << " 1/piv=" << pivinv << std::endl;
176 for ( int j=0; j<nrow; j++)
177 a[icol][j] *= pivinv;
179 for ( int j=0; j<ncol; j++)
180 b[icol][j] *= pivinv;
183 for ( int j=0; j<nrow; j++)
191 for ( int k=0; k<nrow; k++)
192 a[j][k] -= a[icol][k]*dum;
194 for ( int k=0; k<ncol; k++)
195 b[j][k] -= b[icol][k]*dum;
201 for ( int i=nrow-1; i>=0; i--)
203 if (indxr[i] != indxc[i])
205 for ( int j=0; j<nrow; j++)
206 std::swap(a[j][indxr[i]],a[j][indxc[i]]);
210 return log_abs_det_a;
Namespace in which all modeling and calibration related code is declared. Definition ExampleComplex2.h:16
T GaussJordan(std::vector< std::vector< T > > &a, std::vector< std::vector< U > > &b, int nrow=-1, double singular_threshold=0.0, std::vector< const char * > *names=0) Definition GaussJordan.h:44
Generated using doxygen 1.14.0
|