LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
LSSTDataManagementBasePackage
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
lsst.afw.math::LeastSquares Class Reference

Solver for linear least-squares problems. More...

#include <LeastSquares.h>

Classes

class  Impl
 

Public Types

enum  Factorization { NORMAL_EIGENSYSTEM, NORMAL_CHOLESKY, DIRECT_SVD }
 Private implementation; forward-declared publicly so we can inherit from it in .cc. More...
 

Public Member Functions

template<typename T1 , typename T2 , int C1, int C2>
void setDesignMatrix (ndarray::Array< T1, 2, C1 > const &design, ndarray::Array< T2, 1, C2 > const &data)
 Reset the design matrix and data vector given as ndarrays; dimension must not change. More...
 
template<typename D1 , typename D2 >
void setDesignMatrix (Eigen::MatrixBase< D1 > const &design, Eigen::MatrixBase< D2 > const &data)
 Reset the design matrix and data vector given as Eigen objects; dimension must not change. More...
 
template<typename T1 , int C1>
void setDesignMatrix (ndarray::Array< T1, 2, C1 > const &design)
 Reset the design matrix given as an ndarray; dimension and data are not changed. More...
 
template<typename D1 , typename D2 >
void setDesignMatrix (Eigen::MatrixBase< D1 > const &design)
 Reset the design matrix given as an Eigen object; dimension and data are not changed. More...
 
template<typename T1 , typename T2 , int C1, int C2>
void setNormalEquations (ndarray::Array< T1, 2, C1 > const &fisher, ndarray::Array< T2, 1, C2 > const &rhs)
 Reset the terms in the normal equations given as ndarrays; dimension must not change. More...
 
template<typename D1 , typename D2 >
void setNormalEquations (Eigen::MatrixBase< D1 > const &fisher, Eigen::MatrixBase< D2 > const &rhs)
 Reset the terms in the normal equations given as Eigen objects; dimension must not change. More...
 
void setThreshold (double threshold)
 Set the threshold used to determine when to truncate Eigenvalues. More...
 
double getThreshold () const
 Get the threshold used to determine when to truncate Eigenvalues. More...
 
ndarray::Array< double const, 1, 1 > getSolution ()
 Return the vector solution to the least squares problem. More...
 
ndarray::Array< double const, 2, 2 > getCovariance ()
 Return the covariance matrix of the least squares problem. More...
 
ndarray::Array< double const, 2, 2 > getFisherMatrix ()
 Return the Fisher matrix (inverse of the covariance) of the parameters. More...
 
ndarray::Array< double const, 1, 1 > getDiagnostic (Factorization factorization)
 Return a factorization-dependent vector that can be used to characterize the stability of the solution. More...
 
int getDimension () const
 Return the number of parameters. More...
 
int getRank () const
 Return the rank of the problem (number of nonzero Eigenvalues). More...
 
Factorization getFactorization () const
 Retun the type of factorization used by the solver. More...
 
 LeastSquares (Factorization factorization, int dimension)
 Construct a least-squares object for the given factorization and dimensionality. More...
 
 ~LeastSquares ()
 

Static Public Member Functions

template<typename T1 , typename T2 , int C1, int C2>
static LeastSquares fromDesignMatrix (ndarray::Array< T1, 2, C1 > const &design, ndarray::Array< T2, 1, C2 > const &data, Factorization factorization=NORMAL_EIGENSYSTEM)
 Initialize from the design matrix and data vector given as ndarrays. More...
 
template<typename D1 , typename D2 >
static LeastSquares fromDesignMatrix (Eigen::MatrixBase< D1 > const &design, Eigen::MatrixBase< D2 > const &data, Factorization factorization=NORMAL_EIGENSYSTEM)
 Initialize from the design matrix and data vector given as an Eigen objects. More...
 
template<typename T1 , typename T2 , int C1, int C2>
static LeastSquares fromNormalEquations (ndarray::Array< T1, 2, C1 > const &fisher, ndarray::Array< T2, 1, C2 > const &rhs, Factorization factorization=NORMAL_EIGENSYSTEM)
 Initialize from the terms in the normal equations, given as ndarrays. More...
 
template<typename D1 , typename D2 >
static LeastSquares fromNormalEquations (Eigen::MatrixBase< D1 > const &fisher, Eigen::MatrixBase< D2 > const &rhs, Factorization factorization=NORMAL_EIGENSYSTEM)
 Initialize from the terms in the normal equations, given as Eigen objects. More...
 

Private Member Functions

Eigen::MatrixXd & _getDesignMatrix ()
 
Eigen::VectorXd & _getDataVector ()
 
Eigen::MatrixXd & _getFisherMatrix ()
 
Eigen::VectorXd & _getRhsVector ()
 
void _factor (bool haveNormalEquations)
 

Private Attributes

boost::shared_ptr< Impl_impl
 

Detailed Description

Solver for linear least-squares problems.

Linear least-squares problems are defined as finding the vector \(x\) that minimizes \(\left|A x - b\right|_2\), with the number of rows of \(A\) generally greater than the number of columns. We call \(A\) the design matrix, \(b\) the data vector, and \(x\) the solution vector. When the rank of \(A\) is equal to the number of columns, we can obtain using the solution using the normal equations:

\[ A^T A x = A^T b \]

If \(A\) is not full-rank, the problem is underconstrained, and we usually wish to solve the minimum-norm least-squares problem, which also minimizes \(|x|_2\). This can be done by computing a pseudo-inverse of \(A\) using an SVD or complete orthogonal factorization of \(A\), or by performing an Eigen decomposition of \(A^T A\).

This class can be constructed from the design matrix and data vector, or from the two terms in the normal equations (below, we call the matrix \(A^TA\) the Fisher matrix, and the vector \(A^T b\) simply the "right-hand side" (RHS) vector). If initialized with the design matrix and data vector, we can still use the normal equations to solve it. The solution via the normal equations is more susceptible to round-off error, but it is also faster, and if the normal equation terms can be computed directly it can be significantly less expensive in terms of memory. The Fisher matrix is a symmetric matrix, and it should be exactly symmetric when provided as input, because which triangle will be used is an implementation detail that is subject to change and may depend on the storage order.

The solver always operates in double precision, and returns all results in double precision. However, it can be initialized from single precision inputs. It isn't usually a good idea to construct the normal equations in single precision, however, even when the data are single precision.

Definition at line 65 of file LeastSquares.h.

Member Enumeration Documentation

Private implementation; forward-declared publicly so we can inherit from it in .cc.

Enumerator
NORMAL_EIGENSYSTEM 

Use the normal equations with a symmetric Eigensystem decomposition.

This method is fully robust and computes the minimum-norm solution when the problem does not have full rank. It is affected slightly more by round-off error than the SVD method, but because it can handle singular matrices this usually isn't a problem.

NORMAL_CHOLESKY 

Use the normal equations with a Cholesky decomposition.

While this method uses a robust LDL^T decomposition that does not require square roots, it is not appropriate for problems that do not have full rank, and cannot be used to determine whether a problem has full rank. It is the fastest decomposition.

DIRECT_SVD 

Use a thin singular value decomposition of the design matrix.

This method is the most robust and computes the minimum-norm solution the problem does not have full rank. However, it is also the slowest and is not available when the solver is initialized with the normal equations.

Definition at line 70 of file LeastSquares.h.

70  {
87  DIRECT_SVD
95  };
Use a thin singular value decomposition of the design matrix.
Definition: LeastSquares.h:87
Use the normal equations with a Cholesky decomposition.
Definition: LeastSquares.h:79
Use the normal equations with a symmetric Eigensystem decomposition.
Definition: LeastSquares.h:71

Constructor & Destructor Documentation

lsst.afw.math::LeastSquares::LeastSquares ( Factorization  factorization,
int  dimension 
)

Construct a least-squares object for the given factorization and dimensionality.

One of the set* member functions must be called before any other operations can be performed on a LeastSquares object initialized this way.

Definition at line 363 of file LeastSquares.cc.

363  {
364  switch (factorization) {
365  case NORMAL_EIGENSYSTEM:
366  _impl = boost::make_shared<EigensystemSolver>(dimension);
367  break;
368  case NORMAL_CHOLESKY:
369  _impl = boost::make_shared<CholeskySolver>(dimension);
370  break;
371  case DIRECT_SVD:
372  _impl = boost::make_shared<SvdSolver>(dimension);
373  break;
374  }
375  _impl->factorization = factorization;
376 }
Use a thin singular value decomposition of the design matrix.
Definition: LeastSquares.h:87
Use the normal equations with a Cholesky decomposition.
Definition: LeastSquares.h:79
Use the normal equations with a symmetric Eigensystem decomposition.
Definition: LeastSquares.h:71
boost::shared_ptr< Impl > _impl
Definition: LeastSquares.h:353
lsst.afw.math::LeastSquares::~LeastSquares ( )

Definition at line 378 of file LeastSquares.cc.

378 {}

Member Function Documentation

void lsst.afw.math::LeastSquares::_factor ( bool  haveNormalEquations)
private

Definition at line 386 of file LeastSquares.cc.

386  {
387  if (haveNormalEquations) {
388  if (_getFisherMatrix().rows() != _impl->dimension) {
389  throw LSST_EXCEPT(
390  pex::exceptions::InvalidParameterError,
391  (boost::format("Number of rows of Fisher matrix (%d) does not match"
392  " dimension of LeastSquares solver.")
393  % _getFisherMatrix().rows() % _impl->dimension).str()
394  );
395  }
396  if (_getFisherMatrix().cols() != _impl->dimension) {
397  throw LSST_EXCEPT(
398  pex::exceptions::InvalidParameterError,
399  (boost::format("Number of columns of Fisher matrix (%d) does not match"
400  " dimension of LeastSquares solver.")
401  % _getFisherMatrix().cols() % _impl->dimension).str()
402  );
403  }
404  if (_getRhsVector().size() != _impl->dimension) {
405  throw LSST_EXCEPT(
406  pex::exceptions::InvalidParameterError,
407  (boost::format("Number of elements in RHS vector (%d) does not match"
408  " dimension of LeastSquares solver.")
409  % _getRhsVector().size() % _impl->dimension).str()
410  );
411  }
413  } else {
414  if (_getDesignMatrix().cols() != _impl->dimension) {
415  throw LSST_EXCEPT(
416  pex::exceptions::InvalidParameterError,
417  "Number of columns of design matrix does not match dimension of LeastSquares solver."
418  );
419  }
420  if (_getDesignMatrix().rows() != _getDataVector().size()) {
421  throw LSST_EXCEPT(
422  pex::exceptions::InvalidParameterError,
423  (boost::format("Number of rows of design matrix (%d) does not match number of "
424  "data points (%d)") % _getDesignMatrix().rows() % _getDataVector().size()
425  ).str()
426  );
427  }
428  if (_getDesignMatrix().cols() > _getDataVector().size()) {
429  throw LSST_EXCEPT(
430  pex::exceptions::InvalidParameterError,
431  (boost::format("Number of columns of design matrix (%d) must be smaller than number of "
432  "data points (%d)") % _getDesignMatrix().cols() % _getDataVector().size()
433  ).str()
434  );
435  }
436  _impl->state = Impl::DESIGN_AND_DATA;
437  }
438  _impl->factor();
439 }
Eigen::VectorXd & _getDataVector()
Eigen::VectorXd & _getRhsVector()
Eigen::MatrixXd & _getDesignMatrix()
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
boost::shared_ptr< Impl > _impl
Definition: LeastSquares.h:353
Eigen::MatrixXd & _getFisherMatrix()
Eigen::VectorXd & lsst.afw.math::LeastSquares::_getDataVector ( )
private

Definition at line 381 of file LeastSquares.cc.

381 { return _impl->data; }
boost::shared_ptr< Impl > _impl
Definition: LeastSquares.h:353
Eigen::MatrixXd & lsst.afw.math::LeastSquares::_getDesignMatrix ( )
private

Definition at line 380 of file LeastSquares.cc.

380 { return _impl->design; }
boost::shared_ptr< Impl > _impl
Definition: LeastSquares.h:353
Eigen::MatrixXd & lsst.afw.math::LeastSquares::_getFisherMatrix ( )
private

Definition at line 383 of file LeastSquares.cc.

383 { return _impl->fisher; }
boost::shared_ptr< Impl > _impl
Definition: LeastSquares.h:353
Eigen::VectorXd & lsst.afw.math::LeastSquares::_getRhsVector ( )
private

Definition at line 384 of file LeastSquares.cc.

384 { return _impl->rhs; }
boost::shared_ptr< Impl > _impl
Definition: LeastSquares.h:353
template<typename T1 , typename T2 , int C1, int C2>
static LeastSquares lsst.afw.math::LeastSquares::fromDesignMatrix ( ndarray::Array< T1, 2, C1 > const &  design,
ndarray::Array< T2, 1, C2 > const &  data,
Factorization  factorization = NORMAL_EIGENSYSTEM 
)
inlinestatic

Initialize from the design matrix and data vector given as ndarrays.

Definition at line 99 of file LeastSquares.h.

103  {
104  LeastSquares r(factorization, design.template getSize<1>());
105  r.setDesignMatrix(design, data);
106  return r;
107  }
LeastSquares(Factorization factorization, int dimension)
Construct a least-squares object for the given factorization and dimensionality.
template<typename D1 , typename D2 >
static LeastSquares lsst.afw.math::LeastSquares::fromDesignMatrix ( Eigen::MatrixBase< D1 > const &  design,
Eigen::MatrixBase< D2 > const &  data,
Factorization  factorization = NORMAL_EIGENSYSTEM 
)
inlinestatic

Initialize from the design matrix and data vector given as an Eigen objects.

Definition at line 111 of file LeastSquares.h.

115  {
116  LeastSquares r(factorization, design.cols());
117  r.setDesignMatrix(design, data);
118  return r;
119  }
LeastSquares(Factorization factorization, int dimension)
Construct a least-squares object for the given factorization and dimensionality.
template<typename T1 , typename T2 , int C1, int C2>
static LeastSquares lsst.afw.math::LeastSquares::fromNormalEquations ( ndarray::Array< T1, 2, C1 > const &  fisher,
ndarray::Array< T2, 1, C2 > const &  rhs,
Factorization  factorization = NORMAL_EIGENSYSTEM 
)
inlinestatic

Initialize from the terms in the normal equations, given as ndarrays.

Definition at line 163 of file LeastSquares.h.

167  {
168  LeastSquares r(factorization, fisher.template getSize<0>());
169  r.setNormalEquations(fisher, rhs);
170  return r;
171  }
LeastSquares(Factorization factorization, int dimension)
Construct a least-squares object for the given factorization and dimensionality.
template<typename D1 , typename D2 >
static LeastSquares lsst.afw.math::LeastSquares::fromNormalEquations ( Eigen::MatrixBase< D1 > const &  fisher,
Eigen::MatrixBase< D2 > const &  rhs,
Factorization  factorization = NORMAL_EIGENSYSTEM 
)
inlinestatic

Initialize from the terms in the normal equations, given as Eigen objects.

Definition at line 175 of file LeastSquares.h.

179  {
180  LeastSquares r(factorization, fisher.rows());
181  r.setNormalEquations(fisher, rhs);
182  return r;
183  }
LeastSquares(Factorization factorization, int dimension)
Construct a least-squares object for the given factorization and dimensionality.
ndarray::Array< double const, 2, 2 > lsst.afw.math::LeastSquares::getCovariance ( )

Return the covariance matrix of the least squares problem.

The returned array is owned by the LeastSquares object and may be modified in-place by future calls to LeastSquares member functions, so it's best to promptly copy the result elsewhere.

If you want an Eigen object instead, just use getCovariance().asEigen().

The covariance is cached the first time this member function is called, and will be reused unless the matrices are reset or the threshold is changed.

Definition at line 331 of file LeastSquares.cc.

331  {
332  _impl->ensure(Impl::COVARIANCE_ARRAY);
333  return _impl->covariance;
334 }
boost::shared_ptr< Impl > _impl
Definition: LeastSquares.h:353
ndarray::Array< double const, 1, 1 > lsst.afw.math::LeastSquares::getDiagnostic ( Factorization  factorization)

Return a factorization-dependent vector that can be used to characterize the stability of the solution.

The returned array's size is always equal to getDimension(). When getRank() is less than getDimension(), some elements of the array were considered effectively zero (see setThreshold).

For the NORMAL_EIGENSYSTEM method, this is the vector of Eigenvalues of the Fisher matrix, including those rejected as being below the threshold, sorted in descending order (all values are nonnegative). This is the square of the singular values of the design matrix, and is only available when the factorization is either NORMAL_EIGENSYSTEM or DIRECT_SVD.

For the DIRECT_SVD method, this is the vector of singular values of the design matrix, including those rejected as being below the threshold, sorted in descending order (all values are nonnegative). This is the square root of the Eigenvalues of the Fisher matrix, and is only available when the factorization is either NORMAL_EIGENSYSTEM or DIRECT_SVD.

For the NORMAL_CHOLESKY method, this is \(D\) in the pivoted Cholesky factorization \(P L D L^T P^T\) of the Fisher matrix. This does not provide a reliable way to test the stability of the problem, but it does provide a way to compute the determinant of the Fisher matrix. It is only available when the factorization is NORMAL_CHOLESKY.

Definition at line 348 of file LeastSquares.cc.

348  {
349  if (_impl->whichDiagnostic != factorization) {
350  _impl->state &= ~Impl::DIAGNOSTIC_ARRAY;
351  _impl->whichDiagnostic = factorization;
352  }
353  _impl->ensure(Impl::DIAGNOSTIC_ARRAY);
354  return _impl->diagnostic;
355 }
boost::shared_ptr< Impl > _impl
Definition: LeastSquares.h:353
int lsst.afw.math::LeastSquares::getDimension ( ) const

Return the number of parameters.

Definition at line 357 of file LeastSquares.cc.

357 { return _impl->dimension; }
boost::shared_ptr< Impl > _impl
Definition: LeastSquares.h:353
LeastSquares::Factorization lsst.afw.math::LeastSquares::getFactorization ( ) const

Retun the type of factorization used by the solver.

Definition at line 361 of file LeastSquares.cc.

361 { return _impl->factorization; }
boost::shared_ptr< Impl > _impl
Definition: LeastSquares.h:353
ndarray::Array< double const, 2, 2 > lsst.afw.math::LeastSquares::getFisherMatrix ( )

Return the Fisher matrix (inverse of the covariance) of the parameters.

Note that the Fisher matrix is exactly the same as the matrix on the lhs of the normal equations.

The returned array is owned by the LeastSquares object and may be modified in-place by future calls to LeastSquares member functions, so it's best to promptly copy the result elsewhere.

If you want an Eigen object instead, just use getFisherMatrix().asEigen().

Definition at line 336 of file LeastSquares.cc.

336  {
338  // Wrap the Eigen::MatrixXd in an ndarray::Array, using _impl as the reference-counted owner.
339  // Doesn't matter if we swap strides, because it's symmetric.
340  return ndarray::external(
341  _impl->fisher.data(),
342  ndarray::makeVector(_impl->dimension, _impl->dimension),
343  ndarray::makeVector(_impl->dimension, 1),
344  _impl
345  );
346 }
detail::ExternalInitializer< T, N, Owner > external(T *data, Vector< int, N > const &shape, Vector< int, N > const &strides, Owner const &owner)
Create an expression that initializes an Array with externally allocated memory.
Vector< T, N > makeVector(T v1, T v2,..., T vN)
Variadic constructor for Vector.
boost::shared_ptr< Impl > _impl
Definition: LeastSquares.h:353
int lsst.afw.math::LeastSquares::getRank ( ) const

Return the rank of the problem (number of nonzero Eigenvalues).

The returned value is always the same as getDimension() when the factorization is NORMAL_CHOLESKY (which may be incorrect, because a Cholesky decomposition is not rank-revealing).

Definition at line 359 of file LeastSquares.cc.

359 { return _impl->rank; }
boost::shared_ptr< Impl > _impl
Definition: LeastSquares.h:353
ndarray::Array< double const, 1, 1 > lsst.afw.math::LeastSquares::getSolution ( )

Return the vector solution to the least squares problem.

The returned array is owned by the LeastSquares object and may be modified in-place by future calls to LeastSquares member functions, so it's best to promptly copy the result elsewhere.

If you want an Eigen object instead, just use getSolution().asEigen().

The solution is cached the first time this member function is called, and will be reused unless the matrices are reset or the threshold is changed.

Definition at line 326 of file LeastSquares.cc.

326  {
327  _impl->ensure(Impl::SOLUTION_ARRAY);
328  return _impl->solution;
329 }
boost::shared_ptr< Impl > _impl
Definition: LeastSquares.h:353
double lsst.afw.math::LeastSquares::getThreshold ( ) const

Get the threshold used to determine when to truncate Eigenvalues.

Definition at line 324 of file LeastSquares.cc.

324 { return _impl->threshold; }
boost::shared_ptr< Impl > _impl
Definition: LeastSquares.h:353
template<typename T1 , typename T2 , int C1, int C2>
void lsst.afw.math::LeastSquares::setDesignMatrix ( ndarray::Array< T1, 2, C1 > const &  design,
ndarray::Array< T2, 1, C2 > const &  data 
)
inline

Reset the design matrix and data vector given as ndarrays; dimension must not change.

Definition at line 123 of file LeastSquares.h.

126  {
127  // n.b. "template cast<T>" below is not a special kind of cast; it's just
128  // the weird C++ syntax required for calling a templated member function
129  // called "cast" in this context; see
130  // http://eigen.tuxfamily.org/dox-devel/TopicTemplateKeyword.html
131  _getDesignMatrix() = design.asEigen().template cast<double>();
132  _getDataVector() = data.asEigen().template cast<double>();
133  _factor(false);
134  }
Eigen::VectorXd & _getDataVector()
EigenView< Element, ND::value, RMC::value, XprKind, Rows, Cols > asEigen() const
Eigen::MatrixXd & _getDesignMatrix()
void _factor(bool haveNormalEquations)
template<typename D1 , typename D2 >
void lsst.afw.math::LeastSquares::setDesignMatrix ( Eigen::MatrixBase< D1 > const &  design,
Eigen::MatrixBase< D2 > const &  data 
)
inline

Reset the design matrix and data vector given as Eigen objects; dimension must not change.

Definition at line 138 of file LeastSquares.h.

141  {
142  _getDesignMatrix() = design.template cast<double>();
143  _getDataVector() = data.template cast<double>();
144  _factor(false);
145  }
Eigen::VectorXd & _getDataVector()
Eigen::MatrixXd & _getDesignMatrix()
void _factor(bool haveNormalEquations)
template<typename T1 , int C1>
void lsst.afw.math::LeastSquares::setDesignMatrix ( ndarray::Array< T1, 2, C1 > const &  design)
inline

Reset the design matrix given as an ndarray; dimension and data are not changed.

Definition at line 149 of file LeastSquares.h.

149  {
150  _getDesignMatrix() = design.asEigen().template cast<double>();
151  _factor(false);
152  }
EigenView< Element, ND::value, RMC::value, XprKind, Rows, Cols > asEigen() const
Eigen::MatrixXd & _getDesignMatrix()
void _factor(bool haveNormalEquations)
template<typename D1 , typename D2 >
void lsst.afw.math::LeastSquares::setDesignMatrix ( Eigen::MatrixBase< D1 > const &  design)
inline

Reset the design matrix given as an Eigen object; dimension and data are not changed.

Definition at line 156 of file LeastSquares.h.

156  {
157  _getDesignMatrix() = design.template cast<double>();
158  _factor(false);
159  }
Eigen::MatrixXd & _getDesignMatrix()
void _factor(bool haveNormalEquations)
template<typename T1 , typename T2 , int C1, int C2>
void lsst.afw.math::LeastSquares::setNormalEquations ( ndarray::Array< T1, 2, C1 > const &  fisher,
ndarray::Array< T2, 1, C2 > const &  rhs 
)
inline

Reset the terms in the normal equations given as ndarrays; dimension must not change.

Definition at line 187 of file LeastSquares.h.

190  {
191  if ((C1 > 0) == bool(Eigen::MatrixXd::IsRowMajor)) {
192  _getFisherMatrix() = fisher.asEigen().template cast<double>();
193  } else {
194  _getFisherMatrix() = fisher.asEigen().transpose().template cast<double>();
195  }
196  _getRhsVector() = rhs.asEigen().template cast<double>();
197  _factor(true);
198  }
Eigen::VectorXd & _getRhsVector()
EigenView< Element, ND::value, RMC::value, XprKind, Rows, Cols > asEigen() const
void _factor(bool haveNormalEquations)
Eigen::MatrixXd & _getFisherMatrix()
template<typename D1 , typename D2 >
void lsst.afw.math::LeastSquares::setNormalEquations ( Eigen::MatrixBase< D1 > const &  fisher,
Eigen::MatrixBase< D2 > const &  rhs 
)
inline

Reset the terms in the normal equations given as Eigen objects; dimension must not change.

Definition at line 202 of file LeastSquares.h.

205  {
206  if (bool(Eigen::MatrixBase<D1>::IsRowMajor) == bool(Eigen::MatrixXd::IsRowMajor)) {
207  _getFisherMatrix() = fisher.template cast<double>();
208  } else {
209  _getFisherMatrix() = fisher.transpose().template cast<double>();
210  }
211  _getRhsVector() = rhs.template cast<double>();
212  _factor(true);
213  }
Eigen::VectorXd & _getRhsVector()
void _factor(bool haveNormalEquations)
Eigen::MatrixXd & _getFisherMatrix()
void lsst.afw.math::LeastSquares::setThreshold ( double  threshold)

Set the threshold used to determine when to truncate Eigenvalues.

The rank of the matrix is determined by comparing the product of this threshold and the first (largest) element of the array returned by getDiagnostic() to all other elements of that array. Elements smaller than this product are ignored and reduce the rank.

In the DIRECT_SVD case, the diagnostic array contains the singular values of the design matrix, while in the NORMAL_EIGENSYSTEM case the diagnostic array holds the Eigenvalues of the Fisher matrix, and the latter are the square of the former. The default threshold is the same (std::numeric_limits<double>::epsilon()) in both cases, reflecting the fact that using the normal equations squares the condition number of the problem.

The NORMAL_CHOLESKY method does not use the threshold and assumes the problem is full-rank.

Definition at line 317 of file LeastSquares.cc.

317  {
318  _impl->threshold = threshold;
319  _impl->state &= ~Impl::SOLUTION_ARRAY;
320  _impl->state &= ~Impl::COVARIANCE_ARRAY;
321  _impl->updateRank();
322 }
boost::shared_ptr< Impl > _impl
Definition: LeastSquares.h:353

Member Data Documentation

boost::shared_ptr< Impl > lsst.afw.math::LeastSquares::_impl
private

Definition at line 353 of file LeastSquares.h.


The documentation for this class was generated from the following files: