24 #ifndef LSST_MEAS_MODELFIT_Mixture_h_INCLUDED 25 #define LSST_MEAS_MODELFIT_Mixture_h_INCLUDED 29 #include "Eigen/Cholesky" 30 #include "Eigen/StdVector" 41 namespace lsst {
namespace meas {
namespace modelfit {
101 Eigen::LLT<Matrix> _sigmaLLT;
145 iterator
begin() {
return _components.begin(); }
146 iterator
end() {
return _components.end(); }
148 const_iterator
begin()
const {
return _components.begin(); }
149 const_iterator
end()
const {
return _components.end(); }
174 void shift(
int dim,
Scalar offset);
196 template <
typename Derived>
197 Scalar evaluate(Component
const & component, Eigen::MatrixBase<Derived>
const & x)
const {
198 Scalar z = _computeZ(component, x);
199 return component.
weight * _evaluate(z) / component._sqrtDet;
207 template <
typename Derived>
210 for (const_iterator i = begin(); i !=
end(); ++i) {
211 p += evaluate(*i, x);
223 ndarray::Array<Scalar const,2,1>
const &
x,
224 ndarray::Array<Scalar,1,0>
const & p
233 void evaluateComponents(
234 ndarray::Array<Scalar const,2,1>
const & x,
235 ndarray::Array<Scalar,2,1>
const & p
245 void evaluateDerivatives(
246 ndarray::Array<Scalar const,1,1>
const & x,
247 ndarray::Array<Scalar,1,1>
const & gradient,
248 ndarray::Array<Scalar,2,1>
const & hessian
282 ndarray::Array<Scalar const,2,1>
const & x,
283 ndarray::Array<Scalar const,1,0>
const &
w,
298 ndarray::Array<Scalar const,2,1>
const & x,
299 ndarray::Array<Scalar const,1,0>
const & w,
300 UpdateRestriction
const & restriction,
314 ndarray::Array<Scalar const,2,1>
const & x,
315 UpdateRestriction
const & restriction,
351 template <
typename Derived>
352 Scalar _computeZ(Component
const & component, Eigen::MatrixBase<Derived>
const & x)
const {
353 _workspace = x - component._mu;
354 component._sigmaLLT.matrixL().solveInPlace(_workspace);
355 return _workspace.squaredNorm();
359 void updateDampedSigma(
int k,
Matrix const &
sigma,
double tau1,
double tau2);
369 mutable Vector _workspace;
370 ComponentList _components;
375 #endif // !LSST_MEAS_MODELFIT_Mixture_h_INCLUDED table::Key< table::Array< int > > components
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) ...
Component & operator[](std::size_t i)
Iterator and indexed access to components.
std::vector< Component > ComponentList
ComponentList::iterator iterator
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.
virtual bool isPersistable() const
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. ...
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...
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
virtual std::string getPythonModule() const
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.
iterator begin()
Iterator and indexed access to components.
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.