LSSTApplications  18.1.0
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 std::shared_ptr< KernelSolutionPtr
 
typedef lsst::afw::math::Kernel::Pixel PixelT
 
typedef lsst::afw::image::Image< lsst::afw::math::Kernel::PixelImageT
 

Public Member Functions

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

Protected Attributes

int _id
 Unique ID for object. More...
 
Eigen::MatrixXd _mMat
 Derived least squares M matrix. More...
 
Eigen::VectorXd _bVec
 Derived least squares B vector. More...
 
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 31 of file KernelSolution.h.

Member Typedef Documentation

◆ ImageT

Definition at line 35 of file KernelSolution.h.

◆ PixelT

Definition at line 34 of file KernelSolution.h.

◆ Ptr

Definition at line 33 of file KernelSolution.h.

Member Enumeration Documentation

◆ ConditionNumberType

Enumerator
EIGENVALUE 
SVD 

Definition at line 45 of file KernelSolution.h.

◆ KernelSolvedBy

Constructor & Destructor Documentation

◆ KernelSolution() [1/3]

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

Definition at line 55 of file KernelSolution.cc.

59  :
60  _id(++_SolutionId),
61  _mMat(mMat),
62  _bVec(bVec),
63  _aVec(),
64  _solvedBy(NONE),
65  _fitForBackground(fitForBackground)
66  {};
Eigen::VectorXd _bVec
Derived least squares B vector.
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.
Eigen::MatrixXd _mMat
Derived least squares M matrix.
Eigen::VectorXd _aVec
Derived least squares solution matrix.

◆ KernelSolution() [2/3]

lsst::ip::diffim::KernelSolution::KernelSolution ( bool  fitForBackground)
explicit

Definition at line 68 of file KernelSolution.cc.

70  :
71  _id(++_SolutionId),
72  _mMat(),
73  _bVec(),
74  _aVec(),
75  _solvedBy(NONE),
76  _fitForBackground(fitForBackground)
77  {};
Eigen::VectorXd _bVec
Derived least squares B vector.
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.
Eigen::MatrixXd _mMat
Derived least squares M matrix.
Eigen::VectorXd _aVec
Derived least squares solution matrix.

◆ KernelSolution() [3/3]

lsst::ip::diffim::KernelSolution::KernelSolution ( )
explicit

Definition at line 79 of file KernelSolution.cc.

79  :
80  _id(++_SolutionId),
81  _mMat(),
82  _bVec(),
83  _aVec(),
84  _solvedBy(NONE),
85  _fitForBackground(true)
86  {};
Eigen::VectorXd _bVec
Derived least squares B vector.
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.
Eigen::MatrixXd _mMat
Derived least squares M matrix.
Eigen::VectorXd _aVec
Derived least squares solution matrix.

◆ ~KernelSolution()

virtual lsst::ip::diffim::KernelSolution::~KernelSolution ( )
inlinevirtual

Definition at line 56 of file KernelSolution.h.

56 {};

Member Function Documentation

◆ getB()

Eigen::VectorXd const& lsst::ip::diffim::KernelSolution::getB ( )
inline

Definition at line 65 of file KernelSolution.h.

65 {return _bVec;}
Eigen::VectorXd _bVec
Derived least squares B vector.

◆ getConditionNumber() [1/2]

double lsst::ip::diffim::KernelSolution::getConditionNumber ( ConditionNumberType  conditionType)
virtual

Definition at line 92 of file KernelSolution.cc.

92  {
93  return getConditionNumber(_mMat, conditionType);
94  }
virtual double getConditionNumber(ConditionNumberType conditionType)
Eigen::MatrixXd _mMat
Derived least squares M matrix.

◆ getConditionNumber() [2/2]

double lsst::ip::diffim::KernelSolution::getConditionNumber ( Eigen::MatrixXd const &  mMat,
ConditionNumberType  conditionType 
)
virtual

Definition at line 96 of file KernelSolution.cc.

97  {
98  switch (conditionType) {
99  case EIGENVALUE:
100  {
101  Eigen::SelfAdjointEigenSolver<Eigen::MatrixXd> eVecValues(mMat);
102  Eigen::VectorXd eValues = eVecValues.eigenvalues();
103  double eMax = eValues.maxCoeff();
104  double eMin = eValues.minCoeff();
105  LOGL_DEBUG("TRACE3.ip.diffim.KernelSolution.getConditionNumber",
106  "EIGENVALUE eMax / eMin = %.3e", eMax / eMin);
107  return (eMax / eMin);
108  break;
109  }
110  case SVD:
111  {
112  Eigen::VectorXd sValues = mMat.jacobiSvd().singularValues();
113  double sMax = sValues.maxCoeff();
114  double sMin = sValues.minCoeff();
115  LOGL_DEBUG("TRACE3.ip.diffim.KernelSolution.getConditionNumber",
116  "SVD eMax / eMin = %.3e", sMax / sMin);
117  return (sMax / sMin);
118  break;
119  }
120  default:
121  {
123  "Undefined ConditionNumberType : only EIGENVALUE, SVD allowed.");
124  break;
125  }
126  }
127  }
#define LOGL_DEBUG(logger, message...)
Log a debug-level message using a varargs/printf style interface.
Definition: Log.h:489
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
Reports invalid arguments.
Definition: Runtime.h:66

◆ getId()

int lsst::ip::diffim::KernelSolution::getId ( ) const
inline

Definition at line 69 of file KernelSolution.h.

69 { return _id; }
int _id
Unique ID for object.

◆ getM()

Eigen::MatrixXd const& lsst::ip::diffim::KernelSolution::getM ( )
inline

Definition at line 64 of file KernelSolution.h.

64 {return _mMat;}
Eigen::MatrixXd _mMat
Derived least squares M matrix.

◆ getSolvedBy()

KernelSolvedBy lsst::ip::diffim::KernelSolution::getSolvedBy ( )
inline

Definition at line 60 of file KernelSolution.h.

60 {return _solvedBy;}
KernelSolvedBy _solvedBy
Type of algorithm used to make solution.

◆ printA()

void lsst::ip::diffim::KernelSolution::printA ( )
inline

Definition at line 68 of file KernelSolution.h.

68 {std::cout << _aVec << std::endl;}
T endl(T... args)
Eigen::VectorXd _aVec
Derived least squares solution matrix.

◆ printB()

void lsst::ip::diffim::KernelSolution::printB ( )
inline

Definition at line 67 of file KernelSolution.h.

67 {std::cout << _bVec << std::endl;}
Eigen::VectorXd _bVec
Derived least squares B vector.
T endl(T... args)

◆ printM()

void lsst::ip::diffim::KernelSolution::printM ( )
inline

Definition at line 66 of file KernelSolution.h.

66 {std::cout << _mMat << std::endl;}
T endl(T... args)
Eigen::MatrixXd _mMat
Derived least squares M matrix.

◆ solve() [1/2]

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 88 of file KernelSolution.cc.

88  {
89  solve(_mMat, _bVec);
90  }
Eigen::VectorXd _bVec
Derived least squares B vector.
Eigen::MatrixXd _mMat
Derived least squares M matrix.

◆ solve() [2/2]

void lsst::ip::diffim::KernelSolution::solve ( Eigen::MatrixXd const &  mMat,
Eigen::VectorXd const &  bVec 
)
virtual

Definition at line 129 of file KernelSolution.cc.

130  {
131 
132  if (DEBUG_MATRIX) {
133  std::cout << "M " << std::endl;
134  std::cout << mMat << std::endl;
135  std::cout << "B " << std::endl;
136  std::cout << bVec << std::endl;
137  }
138 
139  Eigen::VectorXd aVec = Eigen::VectorXd::Zero(bVec.size());
140 
141  boost::timer t;
142  t.restart();
143 
144  LOGL_DEBUG("TRACE2.ip.diffim.KernelSolution.solve",
145  "Solving for kernel");
146  _solvedBy = LU;
147  Eigen::FullPivLU<Eigen::MatrixXd> lu(mMat);
148  if (lu.isInvertible()) {
149  aVec = lu.solve(bVec);
150  } else {
151  LOGL_DEBUG("TRACE3.ip.diffim.KernelSolution.solve",
152  "Unable to determine kernel via LU");
153  /* LAST RESORT */
154  try {
155 
157  Eigen::SelfAdjointEigenSolver<Eigen::MatrixXd> eVecValues(mMat);
158  Eigen::MatrixXd const& rMat = eVecValues.eigenvectors();
159  Eigen::VectorXd eValues = eVecValues.eigenvalues();
160 
161  for (int i = 0; i != eValues.rows(); ++i) {
162  if (eValues(i) != 0.0) {
163  eValues(i) = 1.0/eValues(i);
164  }
165  }
166 
167  aVec = rMat * eValues.asDiagonal() * rMat.transpose() * bVec;
168  } catch (pexExcept::Exception& e) {
169 
170  _solvedBy = NONE;
171  LOGL_DEBUG("TRACE3.ip.diffim.KernelSolution.solve",
172  "Unable to determine kernel via eigen-values");
173 
174  throw LSST_EXCEPT(pexExcept::Exception, "Unable to determine kernel solution");
175  }
176  }
177 
178  double time = t.elapsed();
179  LOGL_DEBUG("TRACE3.ip.diffim.KernelSolution.solve",
180  "Compute time for matrix math : %.2f s", time);
181 
182  if (DEBUG_MATRIX) {
183  std::cout << "A " << std::endl;
184  std::cout << aVec << std::endl;
185  }
186 
187  _aVec = aVec;
188  }
T endl(T... args)
KernelSolvedBy _solvedBy
Type of algorithm used to make solution.
Provides consistent interface for LSST exceptions.
Definition: Exception.h:107
#define LOGL_DEBUG(logger, message...)
Log a debug-level message using a varargs/printf style interface.
Definition: Log.h:489
T time(T... args)
#define DEBUG_MATRIX
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
Eigen::VectorXd _aVec
Derived least squares solution matrix.

Member Data Documentation

◆ _aVec

Eigen::VectorXd lsst::ip::diffim::KernelSolution::_aVec
protected

Derived least squares solution matrix.

Definition at line 75 of file KernelSolution.h.

◆ _bVec

Eigen::VectorXd lsst::ip::diffim::KernelSolution::_bVec
protected

Derived least squares B vector.

Definition at line 74 of file KernelSolution.h.

◆ _fitForBackground

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

Background terms included in fit.

Definition at line 77 of file KernelSolution.h.

◆ _id

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

Unique ID for object.

Definition at line 72 of file KernelSolution.h.

◆ _mMat

Eigen::MatrixXd lsst::ip::diffim::KernelSolution::_mMat
protected

Derived least squares M matrix.

Definition at line 73 of file KernelSolution.h.

◆ _SolutionId

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

Unique identifier for solution.

Definition at line 78 of file KernelSolution.h.

◆ _solvedBy

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

Type of algorithm used to make solution.

Definition at line 76 of file KernelSolution.h.


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