4 #include "gsl/gsl_linalg.h" 5 #include "gsl/gsl_multifit_nlin.h" 28 const blitz::Array<double, 1>& B,
36 v.transposeSelf(secondDim, firstDim);
38 for(
int i = 0; i < s.rows(); ++i)
39 if(
s(i) <=
s(0) * Rcond)
44 GslVector bgsl(
const_cast<Array<double, 1>&
>(B));
45 Array<double, 1> x(n);
47 int status = gsl_linalg_SV_solve(ugsl.
gsl(), vgsl.
gsl(), sgsl.
gsl(),
67 const blitz::Array<double, 1>& B)
69 GslMatrix Agsl(
const_cast<Array<double, 2>&
>(A));
70 GslVector Bgsl(
const_cast<Array<double, 1>&
>(B));
74 tau.resize(min(A.rows(), A.cols()));
77 int status = gsl_linalg_QR_decomp (Agsl.
gsl(), taugsl.
gsl());
80 Array<double, 1> X(A.cols());
83 Array<double, 1> residual(A.rows());
86 status = gsl_linalg_QR_lssolve (Agsl.
gsl(), taugsl.
gsl(), Bgsl.
gsl(), Xgsl.gsl(), residualgsl.gsl());
89 return Xgsl.blitz_array();
104 blitz::Array<double, 1>& S,
105 blitz::Array<double, 2>& U,
106 blitz::Array<double, 2>& VT)
112 U.reference(Array<double,2>(A.shape()));
114 VT.reference(Array<double,2>(shape(n,n)));
115 Array<double, 1> work(n);
120 int status = gsl_linalg_SV_decomp(ugsl.
gsl(), vtgsl.
gsl(), sgsl.
gsl(),
123 VT.transposeSelf(secondDim, firstDim);
137 blitz::Array<double, 2>&
A,
double Rcond)
139 firstIndex i1; secondIndex i2; thirdIndex i3;
140 blitz::Array<double, 1>
s;
141 blitz::Array<double, 2> u, vt;
143 Array<double, 2> res(vt.cols(), u.rows());
144 res = sum(where(
s(i3) >
s(0) * Rcond, vt(i3, i1) * u(i2, i3) /
s(i3), 0),
165 blitz::Array<double, 2>&
A,
const blitz::Array<bool, 1>& Zero_unused,
168 firstIndex i1; secondIndex i2; thirdIndex i3;
169 if(A.rows() != A.cols())
170 throw Exception(
"This version of generalized_inverse can only be used with square matrix");
171 blitz::Array<double, 1>
s;
172 blitz::Array<double, 2> u, vt;
173 int num_zero = count(Zero_unused);
174 blitz::Array<double, 2> asub(A.rows() - num_zero, A.cols() - num_zero);
176 for(
int i = 0; i < A.rows(); ++i)
177 if(!Zero_unused(i)) {
179 for(
int j = 0; j < A.cols(); ++j)
180 if(!Zero_unused(j)) {
181 asub(isub, jsub) =
A(i, j);
187 Array<double, 2> ressub(vt.cols(), u.rows());
188 ressub = sum(where(
s(i3) >
s(0) * Rcond, vt(i3, i1) * u(i2, i3) /
s(i3), 0),
190 Array<double, 2> res(A.shape());
193 for(
int i = 0; i < A.rows(); ++i)
194 if(!Zero_unused(i)) {
196 for(
int j = 0; j < A.cols(); ++j)
197 if(!Zero_unused(j)) {
198 res(i,j) = ressub(isub, jsub);
214 Array<double, 2> t(A.shape());
216 Array<double, 2> res(rgsl.blitz_array());
218 int status = gsl_linalg_cholesky_decomp(rgsl.gsl());
220 for(
int i = 0; i < res.rows(); ++i)
221 for(
int j = i + 1; j < res.cols(); ++j)
228 Array<double, 2> covar(J.cols(), J.cols());
229 int status = gsl_multifit_covar(
GslMatrix(
const_cast< Array<double, 2>&
>(J)).gsl(), Eps_rel,
GslMatrix(covar).gsl());
236 return gsl_multifit_test_gradient(
GslVector(
const_cast< Array<double, 1>&
>(g)).gsl(), Eps_abs) == GSL_SUCCESS;
240 const blitz::Array<double, 1>& dx,
const blitz::Array<double, 1>& x,
double Eps_abs,
double Eps_rel)
242 return gsl_multifit_test_delta(
GslVector(
const_cast< Array<double, 1>&
>(dx)).gsl(),
243 GslVector(
const_cast< Array<double, 1>&
>(x)).gsl(),
244 Eps_abs, Eps_rel) == GSL_SUCCESS;
const Unit s("s", 1.0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0)
void svd(const blitz::Array< double, 2 > &A, blitz::Array< double, 1 > &S, blitz::Array< double, 2 > &U, blitz::Array< double, 2 > &VT)
Compute the SVD decomposition of a matrix A = U * SIGMA * V^T.
blitz::Array< double, 1 > solve_least_squares(const blitz::Array< double, 2 > &A, const blitz::Array< double, 1 > &B, double Rcond=1e-12)
This solves the least squares system A*x = b, returning the minimum norm solution.
This is the base of the exception hierarchy for Full Physics code.
blitz::Array< double, 2 > cholesky_decomposition(const blitz::Array< double, 2 > &A)
This calculates the Cholesky Decompostion of A so that A = L L^T.
This provides thin wrapper around the GNU Scientific Library gsl_matrix.
Apply value function to a blitz array.
const Unit A("A", 1.0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0)
blitz::Array< double, 1 > solve_least_squares_qr(const blitz::Array< double, 2 > &A, const blitz::Array< double, 1 > &B)
This finds the least squares solution to the overdetermined system A x = b where the matrix A has mor...
blitz::Array< double, 2 > multifit_covar(const blitz::Array< double, 2 > &J, double Eps_rel=std::numeric_limits< double >::epsilon())
bool multifit_test_gradient(const blitz::Array< double, 1 > &g, double Eps_abs=std::numeric_limits< double >::epsilon())
blitz::Array< double, 2 > generalized_inverse(const blitz::Array< double, 2 > &A, double Rcond=std::numeric_limits< double >::epsilon())
This returns the generalized inverse of the given matrix.
#define gsl_check(status)
GSL check.
const Unit m("m", 1.0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
const blitz::Array< double, 1 > & blitz_array() const
Return blitz::Array look at data.
bool multifit_test_delta(const blitz::Array< double, 1 > &dx, const blitz::Array< double, 1 > &x, double Eps_abs=std::numeric_limits< double >::epsilon(), double Eps_rel=std::numeric_limits< double >::epsilon())
const Unit g("g", 1e-3 *kg)
Contains classes to abstract away details in various Spurr Radiative Transfer software.
const gsl_matrix * gsl() const
Return gsl_matrix look at data.
#define range_min_check(V, Min)
Range check.
const gsl_vector * gsl() const
Return gsl_vector look at data.
This provides thin wrapper around the GNU Scientific Library gsl_vector.