lsst.meas.modelfit
20.0.0+089c43b26b
|
#include <Mixture.h>
Public Types | |
typedef MixtureComponent | Component |
typedef MixtureUpdateRestriction | UpdateRestriction |
typedef std::vector< Component > | ComponentList |
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 |
Component & | operator[] (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... | |
boost::shared_ptr< Mixture > | project (int dim) const |
Project the distribution onto the given dimensions (marginalize over all others) More... | |
boost::shared_ptr< Mixture > | project (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 boost::shared_ptr< Mixture > | clone () 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::ostream & | operator<< (std::ostream &os, Mixture const &self) |
typedef ComponentList::const_iterator lsst::meas::modelfit::Mixture::const_iterator |
typedef ComponentList::iterator lsst::meas::modelfit::Mixture::iterator |
|
explicit |
Construct a mixture model.
[in] | dim | Dimensionality of the distribution |
[in] | df | Number of degrees of freedom for component Student's T distributions (inf=Gaussian) |
[in] | components | List of components; will be emptied on return. |
The components will be automatically normalized after construction.
|
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.
|
inline |
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.
|
virtual |
Polymorphic deep copy.
void lsst::meas::modelfit::Mixture::draw | ( | afw::math::Random & | rng, |
ndarray::Array< Scalar, 2, 1 > const & | x | ||
) | const |
Draw random variates from the distribution.
[in,out] | rng | random number generator |
[out] | x | array of points, shape=(numSamples, dim) |
|
inline |
|
inline |
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.
[in] | x | array of points, shape=(numSamples, dim) |
[out] | p | array of probability values, shape=(numSamples,) |
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.
[in] | x | points to evaluate at, with number of columns equal to the number of dimensions |
[in] | p | array to fill, with number of columns equal to the number of components |
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.
[in] | x | point to evaluate the derivative, with size equal to the number of dimensions |
[in] | gradient | 1st derivative array to fill |
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.
[in] | x | point to evaluate the derivative, with size equal to the number of dimensions |
[in] | gradient | 1st derivative array to fill |
[in] | hessian | 2nd derivative array to fill |
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.
[in] | x | point to evaluate the derivative, with size equal to the number of dimensions |
[in] | gradient | 1st derivative array to fill |
[in] | hessian | 2nd derivative array to fill |
|
inlinevirtual |
|
inline |
|
inline |
|
overrideprotectedvirtual |
Reimplemented from lsst::afw::table::io::Persistable.
|
inlineoverrideprotectedvirtual |
Reimplemented from lsst::afw::table::io::Persistable.
|
inlineoverridevirtualnoexcept |
Reimplemented from lsst::afw::table::io::Persistable.
void lsst::meas::modelfit::Mixture::normalize | ( | ) |
Iterate over all components, rescaling their weights so they sum to one.
|
inline |
|
inline |
boost::shared_ptr< Mixture > lsst::meas::modelfit::Mixture::project | ( | int | dim | ) | const |
Project the distribution onto the given dimensions (marginalize over all others)
boost::shared_ptr< Mixture > lsst::meas::modelfit::Mixture::project | ( | int | dim1, |
int | dim2 | ||
) | const |
Project the distribution onto the given dimensions (marginalize over all others)
void lsst::meas::modelfit::Mixture::setDegreesOfFreedom | ( | Scalar | df = std::numeric_limits< Scalar >::infinity() | ) |
Set the number of degrees of freedom in the component Student's T distributions (inf=Gaussian)
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.
|
inline |
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.
[in] | x | array of variables, shape=(numSamples, dim) |
[in] | w | array of weights, shape=(numSamples,) |
[in] | tau1 | damping parameter (see below) |
[in] | tau2 | damping 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\).
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.
[in] | x | array of variables, shape=(numSamples, dim) |
[in] | w | array of weights, shape=(numSamples,) |
[in] | restriction | Functor used to restrict the form of the updated mu and sigma |
[in] | tau1 | damping parameter (see Mixture::updateEM) |
[in] | tau2 | damping parameter (see Mixture::updateEM) |
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.
[in] | x | array of variables, shape=(numSamples, dim) |
[in] | restriction | Functor used to restrict the form of the updated mu and sigma |
[in] | tau1 | damping parameter (see Mixture::updateEM) |
[in] | tau2 | damping parameter (see Mixture::updateEM) |
|
overrideprotectedvirtual |
Reimplemented from lsst::afw::table::io::Persistable.
|
friend |