LSSTApplications  16.0-10-g0ee56ad+5,16.0-11-ga33d1f2+5,16.0-12-g3ef5c14+3,16.0-12-g71e5ef5+18,16.0-12-gbdf3636+3,16.0-13-g118c103+3,16.0-13-g8f68b0a+3,16.0-15-gbf5c1cb+4,16.0-16-gfd17674+3,16.0-17-g7c01f5c+3,16.0-18-g0a50484+1,16.0-20-ga20f992+8,16.0-21-g0e05fd4+6,16.0-21-g15e2d33+4,16.0-22-g62d8060+4,16.0-22-g847a80f+4,16.0-25-gf00d9b8+1,16.0-28-g3990c221+4,16.0-3-gf928089+3,16.0-32-g88a4f23+5,16.0-34-gd7987ad+3,16.0-37-gc7333cb+2,16.0-4-g10fc685+2,16.0-4-g18f3627+26,16.0-4-g5f3a788+26,16.0-5-gaf5c3d7+4,16.0-5-gcc1f4bb+1,16.0-6-g3b92700+4,16.0-6-g4412fcd+3,16.0-6-g7235603+4,16.0-69-g2562ce1b+2,16.0-8-g14ebd58+4,16.0-8-g2df868b+1,16.0-8-g4cec79c+6,16.0-8-gadf6c7a+1,16.0-8-gfc7ad86,16.0-82-g59ec2a54a+1,16.0-9-g5400cdc+2,16.0-9-ge6233d7+5,master-g2880f2d8cf+3,v17.0.rc1
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 <memory>
16 #include "Eigen/Core"
17 
18 #include "lsst/afw/math.h"
19 #include "lsst/afw/geom.h"
20 #include "lsst/afw/image.h"
21 #include "lsst/pex/policy.h"
22 
23 namespace lsst {
24 namespace ip {
25 namespace diffim {
26 
27  /*
28  * @brief Method used to solve for M and B
29  */
30 
32  public:
36 
38  NONE = 0,
41  LU = 3,
43  };
44 
47  SVD = 1
48  };
49 
50  explicit KernelSolution(Eigen::MatrixXd mMat,
51  Eigen::VectorXd bVec,
52  bool fitForBackground);
53  explicit KernelSolution(bool fitForBackground);
54  explicit KernelSolution();
55 
56  virtual ~KernelSolution() {};
57  virtual void solve();
58  virtual void solve(Eigen::MatrixXd const& mMat,
59  Eigen::VectorXd const& bVec);
61  virtual double getConditionNumber(ConditionNumberType conditionType);
62  virtual double getConditionNumber(Eigen::MatrixXd const& mMat, ConditionNumberType conditionType);
63 
64  inline Eigen::MatrixXd const& getM() {return _mMat;}
65  inline Eigen::VectorXd const& getB() {return _bVec;}
66  void printM() {std::cout << _mMat << std::endl;}
67  void printB() {std::cout << _bVec << std::endl;}
68  void printA() {std::cout << _aVec << std::endl;}
69  inline int getId() const { return _id; }
70 
71  protected:
72  int _id;
73  Eigen::MatrixXd _mMat;
74  Eigen::VectorXd _bVec;
75  Eigen::VectorXd _aVec;
78  static int _SolutionId;
79 
80  };
81 
82  template <typename InputT>
84  public:
86 
88  bool fitForBackground);
89  virtual ~StaticKernelSolution() {};
90 
91  /* Overrides KernelSolution */
92  void solve();
93 
94  /* Used by RegularizedKernelSolution */
95  virtual void build(lsst::afw::image::Image<InputT> const &templateImage,
96  lsst::afw::image::Image<InputT> const &scienceImage,
98  virtual std::shared_ptr<lsst::afw::math::Kernel> getKernel();
100  virtual double getBackground();
101  virtual double getKsum();
102  virtual std::pair<std::shared_ptr<lsst::afw::math::Kernel>, double> getSolutionPair();
103 
104  protected:
105  Eigen::MatrixXd _cMat;
106  Eigen::VectorXd _iVec;
107  Eigen::VectorXd _ivVec;
108 
110  double _background;
111  double _kSum;
112 
113  void _setKernel();
114  void _setKernelUncertainty();
115  };
116 
117 
118  template <typename InputT>
120  public:
122 
124  bool fitForBackground);
125  virtual ~MaskedKernelSolution() {};
126  virtual void buildOrig(lsst::afw::image::Image<InputT> const &templateImage,
127  lsst::afw::image::Image<InputT> const &scienceImage,
129  const &varianceEstimate,
131 
132  virtual void buildWithMask(lsst::afw::image::Image<InputT> const &templateImage,
133  lsst::afw::image::Image<InputT> const &scienceImage,
135  const &varianceEstimate,
137 
138  virtual void buildSingleMaskOrig(lsst::afw::image::Image<InputT> const &templateImage,
139  lsst::afw::image::Image<InputT> const &scienceImage,
141  const &varianceEstimate,
142  lsst::afw::geom::Box2I maskBox);
143  };
144 
145 
146 
147  template <typename InputT>
149  public:
151 
153  bool fitForBackground,
154  Eigen::MatrixXd const& hMat,
156  );
158  void solve();
159  double getLambda() {return _lambda;}
160  double estimateRisk(double maxCond);
161 
162  /* Include additive term (_lambda * _hMat) in M matrix? */
163  Eigen::MatrixXd getM(bool includeHmat = true);
164 
165  private:
166  Eigen::MatrixXd const _hMat;
167  double _lambda;
169 
170  std::vector<double> _createLambdaSteps();
171  };
172 
173 
175  public:
177 
178  /* Creates a polynomial SpatialFunction */
180  lsst::afw::math::Kernel::SpatialFunctionPtr spatialKernelFunction,
183  );
184 
186 
187  void addConstraint(float xCenter, float yCenter,
188  Eigen::MatrixXd const& qMat,
189  Eigen::VectorXd const& wVec);
190 
191  void solve();
195 
196  private:
197  lsst::afw::math::Kernel::SpatialFunctionPtr _spatialKernelFunction;
198  bool _constantFirstTerm;
199 
202  double _kSum;
203 
204  lsst::pex::policy::Policy _policy;
205  int _nbases;
206  int _nkt;
207  int _nbt;
208  int _nt;
209 
210  void _setKernel();
211  void _setKernelUncertainty();
212  };
213 
214 }}} // end of namespace lsst::ip::diffim
215 
216 #endif
std::shared_ptr< SpatialKernelSolution > Ptr
std::shared_ptr< RegularizedKernelSolution< InputT > > Ptr
a container for holding hierarchical configuration data in memory.
Definition: Policy.h:169
Eigen::VectorXd _bVec
Derived least squares B vector.
T endl(T... args)
KernelSolvedBy _solvedBy
Type of algorithm used to make solution.
double _background
Derived differential background estimate.
Eigen::VectorXd _iVec
Vectorized I.
lsst::afw::math::Kernel::Pixel PixelT
Eigen::VectorXd _ivVec
Inverse variance.
Eigen::VectorXd const & getB()
std::shared_ptr< StaticKernelSolution< InputT > > Ptr
A base class for image defects.
static int _SolutionId
Unique identifier for solution.
bool _fitForBackground
Background terms included in fit.
Represent a 2-dimensional array of bitmask pixels.
Definition: Mask.h:78
lsst::afw::image::Image< lsst::afw::math::Kernel::Pixel > ImageT
virtual double getConditionNumber(ConditionNumberType conditionType)
int _id
Unique ID for object.
std::shared_ptr< KernelSolution > Ptr
Eigen::MatrixXd _mMat
Derived least squares M matrix.
double _kSum
Derived kernel sum.
Eigen::MatrixXd const & getM()
Eigen::VectorXd _aVec
Derived least squares solution matrix.
std::shared_ptr< lsst::afw::math::Kernel > _kernel
Derived single-object convolution kernel.
std::shared_ptr< MaskedKernelSolution< InputT > > Ptr
An integer coordinate rectangle.
Definition: Box.h:54