24 #ifndef LSST_MEAS_MODELFIT_Mixture_h_INCLUDED 25 #define LSST_MEAS_MODELFIT_Mixture_h_INCLUDED 29 #include "Eigen/Cholesky" 30 #include "Eigen/StdVector" 31 #include "Eigen/Dense" 42 namespace lsst {
namespace meas {
namespace modelfit {
102 Eigen::LLT<Matrix> _sigmaLLT;
146 iterator
begin() {
return _components.begin(); }
147 iterator
end() {
return _components.end(); }
149 const_iterator
begin()
const {
return _components.begin(); }
150 const_iterator
end()
const {
return _components.end(); }
175 void shift(
int dim,
Scalar offset);
197 template <
typename Derived>
198 Scalar evaluate(Component
const & component, Eigen::MatrixBase<Derived>
const &
x)
const {
199 Scalar z = _computeZ(component, x);
200 return component.
weight * _evaluate(z) / component._sqrtDet;
208 template <
typename Derived>
211 for (const_iterator i = begin(); i !=
end(); ++i) {
212 p += evaluate(*i, x);
224 ndarray::Array<Scalar const,2,1>
const &
x,
225 ndarray::Array<Scalar,1,0>
const & p
234 void evaluateComponents(
235 ndarray::Array<Scalar const,2,1>
const & x,
236 ndarray::Array<Scalar,2,1>
const & p
246 void evaluateDerivatives(
247 ndarray::Array<Scalar const,1,1>
const & x,
248 ndarray::Array<Scalar,1,1>
const & gradient,
249 ndarray::Array<Scalar,2,1>
const & hessian
259 void evaluateDerivatives(
260 Eigen::Matrix<Scalar, Eigen::Dynamic, 1> & x,
261 Eigen::Matrix<Scalar, Eigen::Dynamic, 1> & gradient,
262 Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> & hessian
271 void evaluateDerivatives(
272 Eigen::Matrix<Scalar, Eigen::Dynamic, 1> & x,
273 Eigen::Matrix<Scalar, Eigen::Dynamic, 1> & gradient
307 ndarray::Array<Scalar const,2,1>
const & x,
308 ndarray::Array<Scalar const,1,0>
const &
w,
323 ndarray::Array<Scalar const,2,1>
const & x,
324 ndarray::Array<Scalar const,1,0>
const & w,
325 UpdateRestriction
const & restriction,
339 ndarray::Array<Scalar const,2,1>
const & x,
340 UpdateRestriction
const & restriction,
375 template <
typename A,
typename B,
typename C>
376 void _evaluateDerivativesImpl(A
const & x,
379 bool computeHessian =
true)
const;
381 template <
typename Derived>
382 Scalar _computeZ(Component
const & component, Eigen::MatrixBase<Derived>
const & x)
const {
383 _workspace = x - component._mu;
384 component._sigmaLLT.matrixL().solveInPlace(_workspace);
385 return _workspace.squaredNorm();
389 void updateDampedSigma(
int k,
Matrix const &
sigma,
double tau1,
double tau2);
399 mutable Vector _workspace;
400 ComponentList _components;
405 #endif // !LSST_MEAS_MODELFIT_Mixture_h_INCLUDED table::Key< table::Array< int > > components
def write(self, patchRef, catalog)
Write the output.
Component const & operator[](std::size_t i) const
Iterator and indexed access to components.
Scalar getDegreesOfFreedom() const
Get the number of degrees of freedom in the component Student's T distributions (inf=Gaussian) ...
virtual bool isPersistable() const noexcept override
Return true if this particular object can be persisted using afw::table::io.
Component & operator[](std::size_t i)
Iterator and indexed access to components.
std::vector< Component > ComponentList
ComponentList::iterator iterator
An object passed to Persistable::write to allow it to persist itself.
MixtureComponent(int dim)
Default-construct a mixture component with weight=1, mu=0, sigma=identity.
MixtureUpdateRestriction UpdateRestriction
MixtureComponent Component
std::size_t size() const
Return the number of components.
double Scalar
Typedefs to be used for probability and parameter values.
virtual ~MixtureUpdateRestriction()
MixtureComponent & operator=(MixtureComponent const &other)
ItemVariant const * other
int getDimension() const
Return the number of dimensions.
Vector getMu() const
Get/set the location parameter (mean/median/mode) of this component.
afw::table::Key< double > sigma
A weighted Student's T or Gaussian distribution used as a component in a Mixture. ...
A base class for objects that can be persisted via afw::table::io Archive classes.
Helper class used to define restrictions to the form of the component parameters in Mixture::updateEM...
Scalar evaluate(Component const &component, Eigen::MatrixBase< Derived > const &x) const
Evaluate the probability density at the given point for the given component distribution.
Scalar evaluate(Eigen::MatrixBase< Derived > const &x) const
Evaluate the mixture distribution probability density function (PDF) at the given points...
A base class for image defects.
MixtureUpdateRestriction(int dim)
Eigen::Matrix< Scalar, Eigen::Dynamic, Eigen::Dynamic > Matrix
Typedefs to be used for probability and parameter values.
int getDimension() const
Return the number of dimensions.
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > Vector
Typedefs to be used for probability and parameter values.
MixtureComponent project(int dim) const
Project the distribution onto the given dimension (marginalize over all others)
const_iterator begin() const
Iterator and indexed access to components.
virtual int getComponentCount() const
Return the number of components.
ComponentList::const_iterator const_iterator
Scalar weight
Weight of this distribution in the mixture.
friend std::ostream & operator<<(std::ostream &os, Mixture const &self)
virtual void restrictSigma(Matrix &sigma) const
std::string getPythonModule() const override
Return the fully-qualified Python module that should be imported to guarantee that its factory is reg...
void setSigma(Matrix const &sigma)
Get/set the shape/size parameter.
const_iterator end() const
Iterator and indexed access to components.
iterator end()
Iterator and indexed access to components.
Matrix getSigma() const
Get/set the shape/size parameter.
A CRTP facade class for subclasses of Persistable.
iterator begin()
Iterator and indexed access to components.
A class that can be used to generate sequences of random numbers according to a number of different a...
friend std::ostream & operator<<(std::ostream &os, MixtureComponent const &self)
virtual void restrictMu(Vector &mu) const
void setMu(Vector const &mu)
Get/set the location parameter (mean/median/mode) of this component.