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
Public Types | Public Member Functions | Protected Attributes | Static Protected Attributes | List of all members
lsst::ip::diffim::KernelSolution Class Reference

#include <KernelSolution.h>

Inheritance diagram for lsst::ip::diffim::KernelSolution:
lsst::ip::diffim::SpatialKernelSolution lsst::ip::diffim::StaticKernelSolution< InputT > lsst::ip::diffim::MaskedKernelSolution< InputT > lsst::ip::diffim::RegularizedKernelSolution< InputT >

Public Types

enum  KernelSolvedBy {
  NONE = 0, CHOLESKY_LDLT = 1, CHOLESKY_LLT = 2, LU = 3,
  EIGENVECTOR = 4
}
 
enum  ConditionNumberType { EIGENVALUE = 0, SVD = 1 }
 
typedef boost::shared_ptr
< KernelSolution
Ptr
 
typedef
lsst::afw::math::Kernel::Pixel 
PixelT
 
typedef
lsst::afw::image::Image
< lsst::afw::math::Kernel::Pixel
ImageT
 

Public Member Functions

 KernelSolution (boost::shared_ptr< Eigen::MatrixXd > mMat, boost::shared_ptr< Eigen::VectorXd > bVec, bool fitForBackground)
 
 KernelSolution (bool fitForBackground)
 
 KernelSolution ()
 
virtual ~KernelSolution ()
 
virtual void solve ()
 
virtual void solve (Eigen::MatrixXd mMat, Eigen::VectorXd bVec)
 
KernelSolvedBy getSolvedBy ()
 
virtual double getConditionNumber (ConditionNumberType conditionType)
 
virtual double getConditionNumber (Eigen::MatrixXd mMat, ConditionNumberType conditionType)
 
boost::shared_ptr
< Eigen::MatrixXd > 
getM ()
 
boost::shared_ptr
< Eigen::VectorXd > 
getB ()
 
void printM ()
 
void printB ()
 
void printA ()
 
int getId () const
 

Protected Attributes

int _id
 Unique ID for object. More...
 
boost::shared_ptr
< Eigen::MatrixXd > 
_mMat
 Derived least squares M matrix. More...
 
boost::shared_ptr
< Eigen::VectorXd > 
_bVec
 Derived least squares B vector. More...
 
boost::shared_ptr
< Eigen::VectorXd > 
_aVec
 Derived least squares solution matrix. More...
 
KernelSolvedBy _solvedBy
 Type of algorithm used to make solution. More...
 
bool _fitForBackground
 Background terms included in fit. More...
 

Static Protected Attributes

static int _SolutionId = 0
 Unique identifier for solution. More...
 

Detailed Description

Definition at line 30 of file KernelSolution.h.

Member Typedef Documentation

Definition at line 34 of file KernelSolution.h.

Definition at line 33 of file KernelSolution.h.

Definition at line 32 of file KernelSolution.h.

Member Enumeration Documentation

Enumerator
EIGENVALUE 
SVD 

Definition at line 44 of file KernelSolution.h.

Constructor & Destructor Documentation

lsst::ip::diffim::KernelSolution::KernelSolution ( boost::shared_ptr< Eigen::MatrixXd >  mMat,
boost::shared_ptr< Eigen::VectorXd >  bVec,
bool  fitForBackground 
)
explicit

Definition at line 57 of file KernelSolution.cc.

61  :
62  _id(++_SolutionId),
63  _mMat(mMat),
64  _bVec(bVec),
65  _aVec(),
66  _solvedBy(NONE),
67  _fitForBackground(fitForBackground)
68  {};
KernelSolvedBy _solvedBy
Type of algorithm used to make solution.
static int _SolutionId
Unique identifier for solution.
bool _fitForBackground
Background terms included in fit.
int _id
Unique ID for object.
boost::shared_ptr< Eigen::VectorXd > _bVec
Derived least squares B vector.
boost::shared_ptr< Eigen::VectorXd > _aVec
Derived least squares solution matrix.
boost::shared_ptr< Eigen::MatrixXd > _mMat
Derived least squares M matrix.
lsst::ip::diffim::KernelSolution::KernelSolution ( bool  fitForBackground)
explicit

Definition at line 70 of file KernelSolution.cc.

72  :
73  _id(++_SolutionId),
74  _mMat(),
75  _bVec(),
76  _aVec(),
77  _solvedBy(NONE),
78  _fitForBackground(fitForBackground)
79  {};
KernelSolvedBy _solvedBy
Type of algorithm used to make solution.
static int _SolutionId
Unique identifier for solution.
bool _fitForBackground
Background terms included in fit.
int _id
Unique ID for object.
boost::shared_ptr< Eigen::VectorXd > _bVec
Derived least squares B vector.
boost::shared_ptr< Eigen::VectorXd > _aVec
Derived least squares solution matrix.
boost::shared_ptr< Eigen::MatrixXd > _mMat
Derived least squares M matrix.
lsst::ip::diffim::KernelSolution::KernelSolution ( )
explicit

Definition at line 81 of file KernelSolution.cc.

81  :
82  _id(++_SolutionId),
83  _mMat(),
84  _bVec(),
85  _aVec(),
86  _solvedBy(NONE),
87  _fitForBackground(true)
88  {};
KernelSolvedBy _solvedBy
Type of algorithm used to make solution.
static int _SolutionId
Unique identifier for solution.
bool _fitForBackground
Background terms included in fit.
int _id
Unique ID for object.
boost::shared_ptr< Eigen::VectorXd > _bVec
Derived least squares B vector.
boost::shared_ptr< Eigen::VectorXd > _aVec
Derived least squares solution matrix.
boost::shared_ptr< Eigen::MatrixXd > _mMat
Derived least squares M matrix.
virtual lsst::ip::diffim::KernelSolution::~KernelSolution ( )
inlinevirtual

Definition at line 55 of file KernelSolution.h.

55 {};

Member Function Documentation

boost::shared_ptr<Eigen::VectorXd> lsst::ip::diffim::KernelSolution::getB ( )
inline

Definition at line 64 of file KernelSolution.h.

64 {return _bVec;}
boost::shared_ptr< Eigen::VectorXd > _bVec
Derived least squares B vector.
double lsst::ip::diffim::KernelSolution::getConditionNumber ( ConditionNumberType  conditionType)
virtual

Definition at line 94 of file KernelSolution.cc.

94  {
95  return getConditionNumber(*_mMat, conditionType);
96  }
virtual double getConditionNumber(ConditionNumberType conditionType)
boost::shared_ptr< Eigen::MatrixXd > _mMat
Derived least squares M matrix.
double lsst::ip::diffim::KernelSolution::getConditionNumber ( Eigen::MatrixXd  mMat,
ConditionNumberType  conditionType 
)
virtual

Definition at line 98 of file KernelSolution.cc.

99  {
100  switch (conditionType) {
101  case EIGENVALUE:
102  {
103  Eigen::SelfAdjointEigenSolver<Eigen::MatrixXd> eVecValues(mMat);
104  Eigen::VectorXd eValues = eVecValues.eigenvalues();
105  double eMax = eValues.maxCoeff();
106  double eMin = eValues.minCoeff();
107  pexLog::TTrace<5>("lsst.ip.diffim.KernelSolution.getConditionNumber",
108  "EIGENVALUE eMax / eMin = %.3e", eMax / eMin);
109  return (eMax / eMin);
110  break;
111  }
112  case SVD:
113  {
114  Eigen::VectorXd sValues = mMat.jacobiSvd().singularValues();
115  double sMax = sValues.maxCoeff();
116  double sMin = sValues.minCoeff();
117  pexLog::TTrace<5>("lsst.ip.diffim.KernelSolution.getConditionNumber",
118  "SVD eMax / eMin = %.3e", sMax / sMin);
119  return (sMax / sMin);
120  break;
121  }
122  default:
123  {
124  throw LSST_EXCEPT(pexExcept::InvalidParameterError,
125  "Undefined ConditionNumberType : only EIGENVALUE, SVD allowed.");
126  break;
127  }
128  }
129  }
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
int lsst::ip::diffim::KernelSolution::getId ( ) const
inline

Definition at line 68 of file KernelSolution.h.

68 { return _id; }
int _id
Unique ID for object.
boost::shared_ptr<Eigen::MatrixXd> lsst::ip::diffim::KernelSolution::getM ( )
inline

Definition at line 63 of file KernelSolution.h.

63 {return _mMat;}
boost::shared_ptr< Eigen::MatrixXd > _mMat
Derived least squares M matrix.
KernelSolvedBy lsst::ip::diffim::KernelSolution::getSolvedBy ( )
inline

Definition at line 59 of file KernelSolution.h.

59 {return _solvedBy;}
KernelSolvedBy _solvedBy
Type of algorithm used to make solution.
void lsst::ip::diffim::KernelSolution::printA ( )
inline

Definition at line 67 of file KernelSolution.h.

67 {std::cout << *_aVec << std::endl;}
boost::shared_ptr< Eigen::VectorXd > _aVec
Derived least squares solution matrix.
void lsst::ip::diffim::KernelSolution::printB ( )
inline

Definition at line 66 of file KernelSolution.h.

66 {std::cout << *_bVec << std::endl;}
boost::shared_ptr< Eigen::VectorXd > _bVec
Derived least squares B vector.
void lsst::ip::diffim::KernelSolution::printM ( )
inline

Definition at line 65 of file KernelSolution.h.

65 {std::cout << *_mMat << std::endl;}
boost::shared_ptr< Eigen::MatrixXd > _mMat
Derived least squares M matrix.
void lsst::ip::diffim::KernelSolution::solve ( )
virtual

Reimplemented in lsst::ip::diffim::SpatialKernelSolution, lsst::ip::diffim::RegularizedKernelSolution< InputT >, and lsst::ip::diffim::StaticKernelSolution< InputT >.

Definition at line 90 of file KernelSolution.cc.

90  {
91  solve(*_mMat, *_bVec);
92  }
boost::shared_ptr< Eigen::VectorXd > _bVec
Derived least squares B vector.
boost::shared_ptr< Eigen::MatrixXd > _mMat
Derived least squares M matrix.
void lsst::ip::diffim::KernelSolution::solve ( Eigen::MatrixXd  mMat,
Eigen::VectorXd  bVec 
)
virtual

Definition at line 131 of file KernelSolution.cc.

132  {
133 
134  if (DEBUG_MATRIX) {
135  std::cout << "M " << std::endl;
136  std::cout << mMat << std::endl;
137  std::cout << "B " << std::endl;
138  std::cout << bVec << std::endl;
139  }
140 
141  Eigen::VectorXd aVec = Eigen::VectorXd::Zero(bVec.size());
142 
143  boost::timer t;
144  t.restart();
145 
146  pexLog::TTrace<4>("lsst.ip.difim.KernelSolution.solve",
147  "Solving for kernel");
148  _solvedBy = LU;
149  Eigen::FullPivLU<Eigen::MatrixXd> lu(mMat);
150  if (lu.isInvertible()) {
151  aVec = lu.solve(bVec);
152  } else {
153  pexLog::TTrace<5>("lsst.ip.diffim.KernelSolution.solve",
154  "Unable to determine kernel via LU");
155  /* LAST RESORT */
156  try {
157 
158  _solvedBy = EIGENVECTOR;
159  Eigen::SelfAdjointEigenSolver<Eigen::MatrixXd> eVecValues(mMat);
160  Eigen::MatrixXd const& rMat = eVecValues.eigenvectors();
161  Eigen::VectorXd eValues = eVecValues.eigenvalues();
162 
163  for (int i = 0; i != eValues.rows(); ++i) {
164  if (eValues(i) != 0.0) {
165  eValues(i) = 1.0/eValues(i);
166  }
167  }
168 
169  aVec = rMat * eValues.asDiagonal() * rMat.transpose() * bVec;
170  } catch (pexExcept::Exception& e) {
171 
172  _solvedBy = NONE;
173  pexLog::TTrace<5>("lsst.ip.diffim.KernelSolution.solve",
174  "Unable to determine kernel via eigen-values");
175 
176  throw LSST_EXCEPT(pexExcept::Exception, "Unable to determine kernel solution");
177  }
178  }
179 
180  double time = t.elapsed();
181  pexLog::TTrace<5>("lsst.ip.diffim.KernelSolution.solve",
182  "Compute time for matrix math : %.2f s", time);
183 
184  if (DEBUG_MATRIX) {
185  std::cout << "A " << std::endl;
186  std::cout << aVec << std::endl;
187  }
188 
189  _aVec = boost::shared_ptr<Eigen::VectorXd>(new Eigen::VectorXd(aVec));
190  }
KernelSolvedBy _solvedBy
Type of algorithm used to make solution.
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
boost::shared_ptr< Eigen::VectorXd > _aVec
Derived least squares solution matrix.
#define DEBUG_MATRIX

Member Data Documentation

boost::shared_ptr<Eigen::VectorXd> lsst::ip::diffim::KernelSolution::_aVec
protected

Derived least squares solution matrix.

Definition at line 74 of file KernelSolution.h.

boost::shared_ptr<Eigen::VectorXd> lsst::ip::diffim::KernelSolution::_bVec
protected

Derived least squares B vector.

Definition at line 73 of file KernelSolution.h.

bool lsst::ip::diffim::KernelSolution::_fitForBackground
protected

Background terms included in fit.

Definition at line 76 of file KernelSolution.h.

int lsst::ip::diffim::KernelSolution::_id
protected

Unique ID for object.

Definition at line 71 of file KernelSolution.h.

boost::shared_ptr<Eigen::MatrixXd> lsst::ip::diffim::KernelSolution::_mMat
protected

Derived least squares M matrix.

Definition at line 72 of file KernelSolution.h.

int lsst::ip::diffim::KernelSolution::_SolutionId = 0
staticprotected

Unique identifier for solution.

Definition at line 77 of file KernelSolution.h.

KernelSolvedBy lsst::ip::diffim::KernelSolution::_solvedBy
protected

Type of algorithm used to make solution.

Definition at line 75 of file KernelSolution.h.


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