lsst.meas.modelfit g8cdf404ddd+3d7f5b43ed
Public Types | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Friends | List of all members
lsst::meas::modelfit::Mixture Class Reference

#include <Mixture.h>

Inheritance diagram for lsst::meas::modelfit::Mixture:
lsst::afw::table::io::PersistableFacade< Mixture > lsst::afw::table::io::Persistable

Public Types

typedef MixtureComponent Component
 
typedef MixtureUpdateRestriction UpdateRestriction
 
typedef std::vector< ComponentComponentList
 
typedef ComponentList::iterator iterator
 
typedef ComponentList::const_iterator const_iterator
 

Public Member Functions

iterator begin ()
 Iterator and indexed access to components. More...
 
iterator end ()
 
const_iterator begin () const
 
const_iterator end () const
 
Componentoperator[] (std::size_t i)
 
Component const & operator[] (std::size_t i) const
 
std::size_t size () const
 Return the number of components. More...
 
virtual int getComponentCount () const
 Return the number of components. More...
 
std::shared_ptr< Mixtureproject (int dim) const
 Project the distribution onto the given dimensions (marginalize over all others) More...
 
std::shared_ptr< Mixtureproject (int dim1, int dim2) const
 Project the distribution onto the given dimensions (marginalize over all others) More...
 
int getDimension () const
 Return the number of dimensions. More...
 
void normalize ()
 Iterate over all components, rescaling their weights so they sum to one. More...
 
void shift (int dim, Scalar offset)
 Shift the mixture in the given dimension, adding the given offset to all mu vectors. More...
 
std::size_t clip (Scalar threshold=0.0)
 Iterate over all components, removing those with weight less than or equal to threshold. More...
 
Scalar getDegreesOfFreedom () const
 Get the number of degrees of freedom in the component Student's T distributions (inf=Gaussian) More...
 
void setDegreesOfFreedom (Scalar df=std::numeric_limits< Scalar >::infinity())
 Set the number of degrees of freedom in the component Student's T distributions (inf=Gaussian) More...
 
template<typename Derived >
Scalar evaluate (Component const &component, Eigen::MatrixBase< Derived > const &x) const
 Evaluate the probability density at the given point for the given component distribution. More...
 
template<typename Derived >
Scalar evaluate (Eigen::MatrixBase< Derived > const &x) const
 Evaluate the mixture distribution probability density function (PDF) at the given points. More...
 
void evaluate (ndarray::Array< Scalar const, 2, 1 > const &x, ndarray::Array< Scalar, 1, 0 > const &p) const
 Evaluate the distribution probability density function (PDF) at the given points. More...
 
void evaluateComponents (ndarray::Array< Scalar const, 2, 1 > const &x, ndarray::Array< Scalar, 2, 1 > const &p) const
 Evaluate the contributions of each component to the full probability at the given points. More...
 
void evaluateDerivatives (ndarray::Array< Scalar const, 1, 1 > const &x, ndarray::Array< Scalar, 1, 1 > const &gradient, ndarray::Array< Scalar, 2, 1 > const &hessian) const
 Evaluate the derivative of the distribution at the given point. More...
 
void evaluateDerivatives (Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > &x, Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > &gradient, Eigen::Matrix< Scalar, Eigen::Dynamic, Eigen::Dynamic > &hessian) const
 Evaluate the derivative of the distribution at the given point. More...
 
void evaluateDerivatives (Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > &x, Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > &gradient) const
 Evaluate the derivative of the distribution at the given point. More...
 
void draw (afw::math::Random &rng, ndarray::Array< Scalar, 2, 1 > const &x) const
 Draw random variates from the distribution. More...
 
void updateEM (ndarray::Array< Scalar const, 2, 1 > const &x, ndarray::Array< Scalar const, 1, 0 > const &w, Scalar tau1=0.0, Scalar tau2=0.5)
 Perform an Expectation-Maximization step, updating the component parameters to match the given weighted samples. More...
 
void updateEM (ndarray::Array< Scalar const, 2, 1 > const &x, ndarray::Array< Scalar const, 1, 0 > const &w, UpdateRestriction const &restriction, Scalar tau1=0.0, Scalar tau2=0.5)
 Perform an Expectation-Maximization step, updating the component parameters to match the given weighted samples. More...
 
void updateEM (ndarray::Array< Scalar const, 2, 1 > const &x, UpdateRestriction const &restriction, Scalar tau1=0.0, Scalar tau2=0.5)
 Perform an Expectation-Maximization step, updating the component parameters to match the given unweighted samples. More...
 
virtual std::shared_ptr< Mixtureclone () const
 Polymorphic deep copy. More...
 
 Mixture (int dim, ComponentList &components, Scalar df=std::numeric_limits< Scalar >::infinity())
 Construct a mixture model. More...
 
virtual bool isPersistable () const noexcept override
 
void writeFits (std::string const &fileName, std::string const &mode="w") const
 
void writeFits (fits::MemFileManager &manager, std::string const &mode="w") const
 
void writeFits (fits::Fits &fitsfile) const
 

Static Public Member Functions

static std::shared_ptr< T > readFits (fits::Fits &fitsfile)
 
static std::shared_ptr< T > readFits (std::string const &fileName, int hdu=fits::DEFAULT_HDU)
 
static std::shared_ptr< T > readFits (fits::MemFileManager &manager, int hdu=fits::DEFAULT_HDU)
 
static std::shared_ptr< T > dynamicCast (std::shared_ptr< Persistable > const &ptr)
 

Protected Types

typedef io::OutputArchiveHandle OutputArchiveHandle
 

Protected Member Functions

std::string getPythonModule () const override
 
std::string getPersistenceName () const override
 
void write (OutputArchiveHandle &handle) const override
 

Friends

std::ostreamoperator<< (std::ostream &os, Mixture const &self)
 

Detailed Description

Definition at line 128 of file Mixture.h.

Member Typedef Documentation

◆ Component

Definition at line 131 of file Mixture.h.

◆ ComponentList

Definition at line 133 of file Mixture.h.

◆ const_iterator

typedef ComponentList::const_iterator lsst::meas::modelfit::Mixture::const_iterator

Definition at line 135 of file Mixture.h.

◆ iterator

typedef ComponentList::iterator lsst::meas::modelfit::Mixture::iterator

Definition at line 134 of file Mixture.h.

◆ UpdateRestriction

Definition at line 132 of file Mixture.h.

Constructor & Destructor Documentation

◆ Mixture()

lsst::meas::modelfit::Mixture::Mixture ( int  dim,
ComponentList components,
Scalar  df = std::numeric_limitsScalar >::infinity() 
)
explicit

Construct a mixture model.

Parameters
[in]dimDimensionality of the distribution
[in]dfNumber of degrees of freedom for component Student's T distributions (inf=Gaussian)
[in]componentsList of components; will be emptied on return.

The components will be automatically normalized after construction.

Member Function Documentation

◆ begin() [1/2]

iterator lsst::meas::modelfit::Mixture::begin ( )
inline

Iterator and indexed access to components.

While mutable iterators and accessors are provided, any modifications to the component weights should be followed by a call to normalize(), as other member functions will not work properly if the mixture is not normalized.

Definition at line 146 of file Mixture.h.

◆ begin() [2/2]

const_iterator lsst::meas::modelfit::Mixture::begin ( ) const
inline

Definition at line 149 of file Mixture.h.

◆ clip()

std::size_t lsst::meas::modelfit::Mixture::clip ( Scalar  threshold = 0.0)

Iterate over all components, removing those with weight less than or equal to threshold.

The weights will be normalized if any are removed.

Returns
the number of components removed.

◆ clone()

virtual std::shared_ptr< Mixture > lsst::meas::modelfit::Mixture::clone ( ) const
virtual

Polymorphic deep copy.

◆ draw()

void lsst::meas::modelfit::Mixture::draw ( afw::math::Random rng,
ndarray::Array< Scalar, 2, 1 > const &  x 
) const

Draw random variates from the distribution.

Parameters
[in,out]rngrandom number generator
[out]xarray of points, shape=(numSamples, dim)

◆ end() [1/2]

iterator lsst::meas::modelfit::Mixture::end ( )
inline

Definition at line 147 of file Mixture.h.

◆ end() [2/2]

const_iterator lsst::meas::modelfit::Mixture::end ( ) const
inline

Definition at line 150 of file Mixture.h.

◆ evaluate() [1/3]

template<typename Derived >
Scalar lsst::meas::modelfit::Mixture::evaluate ( Component const &  component,
Eigen::MatrixBase< Derived > const &  x 
) const
inline

Evaluate the probability density at the given point for the given component distribution.

This evaluates the probability of a single component, including the current weight of that component.

Definition at line 198 of file Mixture.h.

◆ evaluate() [2/3]

template<typename Derived >
Scalar lsst::meas::modelfit::Mixture::evaluate ( Eigen::MatrixBase< Derived > const &  x) const
inline

Evaluate the mixture distribution probability density function (PDF) at the given points.

Parameters
[in]xpoint to evaluate, as an Eigen expression, shape=(dim,)

Definition at line 209 of file Mixture.h.

◆ evaluate() [3/3]

void lsst::meas::modelfit::Mixture::evaluate ( ndarray::Array< Scalar const, 2, 1 > const &  x,
ndarray::Array< Scalar, 1, 0 > const &  p 
) const

Evaluate the distribution probability density function (PDF) at the given points.

Parameters
[in]xarray of points, shape=(numSamples, dim)
[out]parray of probability values, shape=(numSamples,)

◆ evaluateComponents()

void lsst::meas::modelfit::Mixture::evaluateComponents ( ndarray::Array< Scalar const, 2, 1 > const &  x,
ndarray::Array< Scalar, 2, 1 > const &  p 
) const

Evaluate the contributions of each component to the full probability at the given points.

Parameters
[in]xpoints to evaluate at, with number of columns equal to the number of dimensions
[in]parray to fill, with number of columns equal to the number of components

◆ evaluateDerivatives() [1/3]

void lsst::meas::modelfit::Mixture::evaluateDerivatives ( Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > &  x,
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > &  gradient 
) const

Evaluate the derivative of the distribution at the given point.

Parameters
[in]xpoint to evaluate the derivative, with size equal to the number of dimensions
[in]gradient1st derivative array to fill

◆ evaluateDerivatives() [2/3]

void lsst::meas::modelfit::Mixture::evaluateDerivatives ( Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > &  x,
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > &  gradient,
Eigen::Matrix< Scalar, Eigen::Dynamic, Eigen::Dynamic > &  hessian 
) const

Evaluate the derivative of the distribution at the given point.

Parameters
[in]xpoint to evaluate the derivative, with size equal to the number of dimensions
[in]gradient1st derivative array to fill
[in]hessian2nd derivative array to fill

◆ evaluateDerivatives() [3/3]

void lsst::meas::modelfit::Mixture::evaluateDerivatives ( ndarray::Array< Scalar const, 1, 1 > const &  x,
ndarray::Array< Scalar, 1, 1 > const &  gradient,
ndarray::Array< Scalar, 2, 1 > const &  hessian 
) const

Evaluate the derivative of the distribution at the given point.

Parameters
[in]xpoint to evaluate the derivative, with size equal to the number of dimensions
[in]gradient1st derivative array to fill
[in]hessian2nd derivative array to fill

◆ getComponentCount()

virtual int lsst::meas::modelfit::Mixture::getComponentCount ( ) const
inlinevirtual

Return the number of components.

Definition at line 160 of file Mixture.h.

◆ getDegreesOfFreedom()

Scalar lsst::meas::modelfit::Mixture::getDegreesOfFreedom ( ) const
inline

Get the number of degrees of freedom in the component Student's T distributions (inf=Gaussian)

Definition at line 187 of file Mixture.h.

◆ getDimension()

int lsst::meas::modelfit::Mixture::getDimension ( ) const
inline

Return the number of dimensions.

Definition at line 169 of file Mixture.h.

◆ getPersistenceName()

std::string lsst::meas::modelfit::Mixture::getPersistenceName ( ) const
overrideprotectedvirtual

Reimplemented from lsst::afw::table::io::Persistable.

◆ getPythonModule()

std::string lsst::meas::modelfit::Mixture::getPythonModule ( ) const
inlineoverrideprotectedvirtual

Reimplemented from lsst::afw::table::io::Persistable.

Definition at line 368 of file Mixture.h.

◆ isPersistable()

virtual bool lsst::meas::modelfit::Mixture::isPersistable ( ) const
inlineoverridevirtualnoexcept

Reimplemented from lsst::afw::table::io::Persistable.

Definition at line 364 of file Mixture.h.

◆ normalize()

void lsst::meas::modelfit::Mixture::normalize ( )

Iterate over all components, rescaling their weights so they sum to one.

◆ operator[]() [1/2]

Component & lsst::meas::modelfit::Mixture::operator[] ( std::size_t  i)
inline

Definition at line 152 of file Mixture.h.

◆ operator[]() [2/2]

Component const & lsst::meas::modelfit::Mixture::operator[] ( std::size_t  i) const
inline

Definition at line 153 of file Mixture.h.

◆ project() [1/2]

std::shared_ptr< Mixture > lsst::meas::modelfit::Mixture::project ( int  dim) const

Project the distribution onto the given dimensions (marginalize over all others)

◆ project() [2/2]

std::shared_ptr< Mixture > lsst::meas::modelfit::Mixture::project ( int  dim1,
int  dim2 
) const

Project the distribution onto the given dimensions (marginalize over all others)

◆ setDegreesOfFreedom()

void lsst::meas::modelfit::Mixture::setDegreesOfFreedom ( Scalar  df = std::numeric_limitsScalar >::infinity())

Set the number of degrees of freedom in the component Student's T distributions (inf=Gaussian)

◆ shift()

void lsst::meas::modelfit::Mixture::shift ( int  dim,
Scalar  offset 
)

Shift the mixture in the given dimension, adding the given offset to all mu vectors.

◆ size()

std::size_t lsst::meas::modelfit::Mixture::size ( ) const
inline

Return the number of components.

Definition at line 157 of file Mixture.h.

◆ updateEM() [1/3]

void lsst::meas::modelfit::Mixture::updateEM ( ndarray::Array< Scalar const, 2, 1 > const &  x,
ndarray::Array< Scalar const, 1, 0 > const &  w,
Scalar  tau1 = 0.0,
Scalar  tau2 = 0.5 
)

Perform an Expectation-Maximization step, updating the component parameters to match the given weighted samples.

Parameters
[in]xarray of variables, shape=(numSamples, dim)
[in]warray of weights, shape=(numSamples,)
[in]tau1damping parameter (see below)
[in]tau2damping parameter (see below)

The updates to the \(\sigma\) matrices are damped according to:

\[ \sigma_d = \alpha\sigma_1 + (1-\alpha)\sigma_0 \]

Where \(\sigma_0\) is the previous matrix, \(\sigma_1\) is the undamped update, and \(\sigma_d\) is the damped update. The parameter \(\alpha\) is set by the ratio of the determinants:

\[ r \equiv \frac{|\sigma_1|}{|\sigma_0|} \]

When \(r \ge \tau_1\), \(\alpha=1\); when \(r \lt \tau_1\), it is rolled off quadratically to \(\tau_2\).

◆ updateEM() [2/3]

void lsst::meas::modelfit::Mixture::updateEM ( ndarray::Array< Scalar const, 2, 1 > const &  x,
ndarray::Array< Scalar const, 1, 0 > const &  w,
UpdateRestriction const &  restriction,
Scalar  tau1 = 0.0,
Scalar  tau2 = 0.5 
)

Perform an Expectation-Maximization step, updating the component parameters to match the given weighted samples.

Parameters
[in]xarray of variables, shape=(numSamples, dim)
[in]warray of weights, shape=(numSamples,)
[in]restrictionFunctor used to restrict the form of the updated mu and sigma
[in]tau1damping parameter (see Mixture::updateEM)
[in]tau2damping parameter (see Mixture::updateEM)

◆ updateEM() [3/3]

void lsst::meas::modelfit::Mixture::updateEM ( ndarray::Array< Scalar const, 2, 1 > const &  x,
UpdateRestriction const &  restriction,
Scalar  tau1 = 0.0,
Scalar  tau2 = 0.5 
)

Perform an Expectation-Maximization step, updating the component parameters to match the given unweighted samples.

Parameters
[in]xarray of variables, shape=(numSamples, dim)
[in]restrictionFunctor used to restrict the form of the updated mu and sigma
[in]tau1damping parameter (see Mixture::updateEM)
[in]tau2damping parameter (see Mixture::updateEM)

◆ write()

void lsst::meas::modelfit::Mixture::write ( OutputArchiveHandle handle) const
overrideprotectedvirtual

Reimplemented from lsst::afw::table::io::Persistable.

Friends And Related Function Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream os,
Mixture const &  self 
)
friend

Definition at line 359 of file Mixture.h.


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