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
KernelSolution.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
12 #ifndef LSST_IP_DIFFIM_KERNELSOLUTION_H
13 #define LSST_IP_DIFFIM_KERNELSOLUTION_H
14 
15 #include "boost/shared_ptr.hpp"
16 #include "Eigen/Core"
17 
18 #include "lsst/afw/math.h"
19 #include "lsst/afw/geom.h"
20 #include "lsst/afw/image.h"
21 
22 namespace lsst {
23 namespace ip {
24 namespace diffim {
25 
26  /*
27  * @brief Method used to solve for M and B
28  */
29 
31  public:
32  typedef boost::shared_ptr<KernelSolution> Ptr;
35 
37  NONE = 0,
40  LU = 3,
42  };
43 
46  SVD = 1
47  };
48 
49  explicit KernelSolution(boost::shared_ptr<Eigen::MatrixXd> mMat,
50  boost::shared_ptr<Eigen::VectorXd> bVec,
51  bool fitForBackground);
52  explicit KernelSolution(bool fitForBackground);
53  explicit KernelSolution();
54 
55  virtual ~KernelSolution() {};
56  virtual void solve();
57  virtual void solve(Eigen::MatrixXd mMat,
58  Eigen::VectorXd bVec);
60  virtual double getConditionNumber(ConditionNumberType conditionType);
61  virtual double getConditionNumber(Eigen::MatrixXd mMat, ConditionNumberType conditionType);
62 
63  inline boost::shared_ptr<Eigen::MatrixXd> getM() {return _mMat;}
64  inline boost::shared_ptr<Eigen::VectorXd> getB() {return _bVec;}
65  void printM() {std::cout << *_mMat << std::endl;}
66  void printB() {std::cout << *_bVec << std::endl;}
67  void printA() {std::cout << *_aVec << std::endl;}
68  inline int getId() const { return _id; }
69 
70  protected:
71  int _id;
72  boost::shared_ptr<Eigen::MatrixXd> _mMat;
73  boost::shared_ptr<Eigen::VectorXd> _bVec;
74  boost::shared_ptr<Eigen::VectorXd> _aVec;
77  static int _SolutionId;
78 
79  };
80 
81  template <typename InputT>
83  public:
84  typedef boost::shared_ptr<StaticKernelSolution<InputT> > Ptr;
85 
87  bool fitForBackground);
88  virtual ~StaticKernelSolution() {};
89 
90  /* Overrides KernelSolution */
91  void solve();
92 
93  /* Used by RegularizedKernelSolution */
94  virtual void build(lsst::afw::image::Image<InputT> const &templateImage,
95  lsst::afw::image::Image<InputT> const &scienceImage,
99  virtual double getBackground();
100  virtual double getKsum();
101  virtual std::pair<boost::shared_ptr<lsst::afw::math::Kernel>, double> getSolutionPair();
102 
103  protected:
104  boost::shared_ptr<Eigen::MatrixXd> _cMat;
105  boost::shared_ptr<Eigen::VectorXd> _iVec;
106  boost::shared_ptr<Eigen::VectorXd> _ivVec;
107 
109  double _background;
110  double _kSum;
111 
112  void _setKernel();
113  void _setKernelUncertainty();
114  };
115 
116 
117  template <typename InputT>
119  public:
120  typedef boost::shared_ptr<MaskedKernelSolution<InputT> > Ptr;
121 
123  bool fitForBackground);
124  virtual ~MaskedKernelSolution() {};
125  virtual void buildOrig(lsst::afw::image::Image<InputT> const &templateImage,
126  lsst::afw::image::Image<InputT> const &scienceImage,
128  const &varianceEstimate,
130 
131  virtual void buildWithMask(lsst::afw::image::Image<InputT> const &templateImage,
132  lsst::afw::image::Image<InputT> const &scienceImage,
134  const &varianceEstimate,
136 
137  virtual void buildSingleMaskOrig(lsst::afw::image::Image<InputT> const &templateImage,
138  lsst::afw::image::Image<InputT> const &scienceImage,
140  const &varianceEstimate,
141  lsst::afw::geom::Box2I maskBox);
142  };
143 
144 
145 
146  template <typename InputT>
148  public:
149  typedef boost::shared_ptr<RegularizedKernelSolution<InputT> > Ptr;
150 
152  bool fitForBackground,
153  boost::shared_ptr<Eigen::MatrixXd> hMat,
155  );
157  void solve();
158  double getLambda() {return _lambda;}
159  double estimateRisk(double maxCond);
160 
161  /* Include additive term (_lambda * _hMat) in M matrix? */
162  boost::shared_ptr<Eigen::MatrixXd> getM(bool includeHmat = true);
163 
164  private:
165  boost::shared_ptr<Eigen::MatrixXd> _hMat;
166  double _lambda;
168 
169  std::vector<double> _createLambdaSteps();
170  };
171 
172 
174  public:
175  typedef boost::shared_ptr<SpatialKernelSolution> Ptr;
176 
177  /* Creates a polynomial SpatialFunction */
179  lsst::afw::math::Kernel::SpatialFunctionPtr spatialKernelFunction,
182  );
183 
185 
186  void addConstraint(float xCenter, float yCenter,
187  boost::shared_ptr<Eigen::MatrixXd> qMat,
188  boost::shared_ptr<Eigen::VectorXd> wVec);
189 
190  void solve();
194 
195  private:
198 
201  double _kSum;
202 
204  int _nbases;
205  int _nkt;
206  int _nbt;
207  int _nt;
208 
209  void _setKernel();
210  void _setKernelUncertainty();
211  };
212 
213 }}} // end of namespace lsst::ip::diffim
214 
215 #endif
An include file to include the public header files for lsst::afw::math.
boost::shared_ptr< RegularizedKernelSolution< InputT > > Ptr
void _setKernel()
Set kernel after solution.
An include file to include the header files for lsst::afw::geom.
boost::shared_ptr< lsst::afw::math::Function2< double > > SpatialFunctionPtr
Definition: Kernel.h:143
virtual lsst::afw::image::Image< lsst::afw::math::Kernel::Pixel >::Ptr makeKernelImage()
a container for holding hierarchical configuration data in memory.
Definition: Policy.h:169
boost::shared_ptr< KernelSolution > Ptr
SpatialKernelSolution(lsst::afw::math::KernelList const &basisList, lsst::afw::math::Kernel::SpatialFunctionPtr spatialKernelFunction, lsst::afw::math::Kernel::SpatialFunctionPtr background, lsst::pex::policy::Policy policy)
boost::shared_ptr< MaskedKernelSolution< InputT > > Ptr
lsst::afw::math::Kernel::Ptr _kernel
Derived single-object convolution kernel.
virtual lsst::afw::math::Kernel::Ptr getKernel()
KernelSolvedBy _solvedBy
Type of algorithm used to make solution.
StaticKernelSolution(lsst::afw::math::KernelList const &basisList, bool fitForBackground)
double _background
Derived differential background estimate.
boost::shared_ptr< StaticKernelSolution< InputT > > Ptr
lsst::afw::math::Kernel::Pixel PixelT
boost::shared_ptr< Eigen::VectorXd > getB()
boost::shared_ptr< Image< PixelT > > Ptr
Definition: Image.h:418
boost::shared_ptr< Eigen::MatrixXd > getM()
boost::shared_ptr< Kernel > Ptr
Definition: Kernel.h:141
boost::shared_ptr< SpatialKernelSolution > Ptr
An integer coordinate rectangle.
Definition: Box.h:53
void addConstraint(float xCenter, float yCenter, boost::shared_ptr< Eigen::MatrixXd > qMat, boost::shared_ptr< Eigen::VectorXd > wVec)
An include file to include the header files for lsst::afw::image.
virtual void build(lsst::afw::image::Image< InputT > const &templateImage, lsst::afw::image::Image< InputT > const &scienceImage, lsst::afw::image::Image< lsst::afw::image::VariancePixel > const &varianceEstimate)
void _setKernel()
Set kernel after solution.
double _kSum
Derived kernel sum.
static int _SolutionId
Unique identifier for solution.
void _setKernelUncertainty()
Not implemented.
bool _fitForBackground
Background terms included in fit.
lsst::afw::image::Image< lsst::afw::math::Kernel::Pixel > ImageT
virtual double getConditionNumber(ConditionNumberType conditionType)
int _id
Unique ID for object.
boost::shared_ptr< Eigen::VectorXd > _iVec
Vectorized I.
lsst::afw::image::Image< lsst::afw::math::Kernel::Pixel >::Ptr makeKernelImage(lsst::afw::geom::Point2D const &pos)
boost::shared_ptr< Eigen::VectorXd > _bVec
Derived least squares B vector.
virtual void buildOrig(lsst::afw::image::Image< InputT > const &templateImage, lsst::afw::image::Image< InputT > const &scienceImage, lsst::afw::image::Image< lsst::afw::image::VariancePixel > const &varianceEstimate, lsst::afw::image::Mask< lsst::afw::image::MaskPixel > pixelMask)
lsst::afw::math::Kernel::SpatialFunctionPtr _spatialKernelFunction
Spatial function for Kernel.
int _nbt
Number of background terms.
boost::shared_ptr< Eigen::MatrixXd > _hMat
Regularization weights.
bool _constantFirstTerm
Is the first term constant.
lsst::pex::policy::Policy _policy
Policy to control processing.
double _kSum
Derived kernel sum.
lsst::afw::math::LinearCombinationKernel::Ptr _kernel
Spatial convolution kernel.
boost::shared_ptr< Eigen::VectorXd > _aVec
Derived least squares solution matrix.
MaskedKernelSolution(lsst::afw::math::KernelList const &basisList, bool fitForBackground)
lsst::afw::math::Kernel::SpatialFunctionPtr _background
Spatial background model.
RegularizedKernelSolution(lsst::afw::math::KernelList const &basisList, bool fitForBackground, boost::shared_ptr< Eigen::MatrixXd > hMat, lsst::pex::policy::Policy policy)
int _nkt
Number of kernel terms.
boost::shared_ptr< Eigen::MatrixXd > _mMat
Derived least squares M matrix.
std::pair< lsst::afw::math::LinearCombinationKernel::Ptr, lsst::afw::math::Kernel::SpatialFunctionPtr > getSolutionPair()
int _nbases
Number of basis functions.
virtual void buildSingleMaskOrig(lsst::afw::image::Image< InputT > const &templateImage, lsst::afw::image::Image< InputT > const &scienceImage, lsst::afw::image::Image< lsst::afw::image::VariancePixel > const &varianceEstimate, lsst::afw::geom::Box2I maskBox)
virtual std::pair< boost::shared_ptr< lsst::afw::math::Kernel >, double > getSolutionPair()
virtual void buildWithMask(lsst::afw::image::Image< InputT > const &templateImage, lsst::afw::image::Image< InputT > const &scienceImage, lsst::afw::image::Image< lsst::afw::image::VariancePixel > const &varianceEstimate, lsst::afw::image::Mask< lsst::afw::image::MaskPixel > const &pixelMask)
boost::shared_ptr< Eigen::MatrixXd > _cMat
K_i x R.
double _lambda
Overall regularization strength.
std::vector< boost::shared_ptr< Kernel > > KernelList
Definition: Kernel.h:542
boost::shared_ptr< Eigen::VectorXd > _ivVec
Inverse variance.
boost::shared_ptr< LinearCombinationKernel > Ptr
Definition: Kernel.h:818
void _setKernelUncertainty()
Not implemented.