LSST Applications
21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
|
#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... | |
std::shared_ptr< Mixture > | project (int dim) const |
Project the distribution onto the given dimensions (marginalize over all others) More... | |
std::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 std::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 |
Return true if this particular object can be persisted using afw::table::io. More... | |
void | writeFits (std::string const &fileName, std::string const &mode="w") const |
Write the object to a regular FITS file. More... | |
void | writeFits (fits::MemFileManager &manager, std::string const &mode="w") const |
Write the object to a FITS image in memory. More... | |
void | writeFits (fits::Fits &fitsfile) const |
Write the object to an already-open FITS object. More... | |
Static Public Member Functions | |
static std::shared_ptr< Mixture > | readFits (fits::Fits &fitsfile) |
Read an object from an already open FITS object. More... | |
static std::shared_ptr< Mixture > | readFits (std::string const &fileName, int hdu=fits::DEFAULT_HDU) |
Read an object from a regular FITS file. More... | |
static std::shared_ptr< Mixture > | readFits (fits::MemFileManager &manager, int hdu=fits::DEFAULT_HDU) |
Read an object from a FITS file in memory. More... | |
static std::shared_ptr< Mixture > | dynamicCast (std::shared_ptr< Persistable > const &ptr) |
Dynamically cast a shared_ptr. More... | |
Protected Types | |
using | OutputArchiveHandle = io::OutputArchiveHandle |
Protected Member Functions | |
std::string | getPythonModule () const override |
Return the fully-qualified Python module that should be imported to guarantee that its factory is registered. More... | |
std::string | getPersistenceName () const override |
Return the unique name used to persist this object and look up its factory. More... | |
void | write (OutputArchiveHandle &handle) const override |
Write the object to one or more catalogs. More... | |
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 |
|
protectedinherited |
Definition at line 108 of file Persistable.h.
|
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.
Definition at line 146 of file Mixture.h.
|
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) |
|
staticinherited |
Dynamically cast a shared_ptr.
Dynamically cast a shared pointer and raise on failure.
You must provide an explicit template instantiation in the .cc file for each class that inherits from PersistableFacade. Designed to work around RTTI issues on macOS with hidden symbols;
lsst::pex::exceptions::LogicError | if the cast fails |
param[in] ptr The pointer to be cast.
lsst::pex::exceptions::TypeError | If the dynamic cast fails. |
Definition at line 218 of file Persistable.cc.
|
inline |
|
inline |
|
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.
|
inline |
Evaluate the mixture distribution probability density function (PDF) at the given points.
[in] | x | point to evaluate, as an Eigen expression, shape=(dim,) |
Definition at line 209 of file Mixture.h.
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 |
Return the number of components.
Definition at line 160 of file Mixture.h.
|
inline |
|
inline |
|
overrideprotectedvirtual |
Return the unique name used to persist this object and look up its factory.
Must be less than ArchiveIndexSchema::MAX_NAME_LENGTH characters.
Reimplemented from lsst::afw::table::io::Persistable.
|
inlineoverrideprotectedvirtual |
Return the fully-qualified Python module that should be imported to guarantee that its factory is registered.
Must be less than ArchiveIndexSchema::MAX_MODULE_LENGTH characters.
Will be ignored if empty.
Reimplemented from lsst::afw::table::io::Persistable.
|
inlineoverridevirtualnoexcept |
Return true if this particular object can be persisted using afw::table::io.
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 |
std::shared_ptr<Mixture> lsst::meas::modelfit::Mixture::project | ( | int | dim | ) | const |
Project the distribution onto the given dimensions (marginalize over all others)
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)
|
inlinestaticinherited |
Read an object from an already open FITS object.
[in] | fitsfile | FITS object to read from, already positioned at the desired HDU. |
Definition at line 183 of file Persistable.h.
|
inlinestaticinherited |
Read an object from a FITS file in memory.
[in] | manager | Manager for the memory to read from. |
[in] | hdu | HDU to read, where 0 is the primary. The special value of afw::fits::DEFAULT_HDU skips the primary HDU if it is empty. |
Definition at line 205 of file Persistable.h.
|
inlinestaticinherited |
Read an object from a regular FITS file.
[in] | fileName | Name of the file to read. |
[in] | hdu | HDU to read, where 0 is the primary. The special value of afw::fits::DEFAULT_HDU skips the primary HDU if it is empty. |
Definition at line 194 of file Persistable.h.
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 |
Write the object to one or more catalogs.
The handle object passed to this function provides an interface for adding new catalogs and adding nested objects to the same archive (while checking for duplicates). See OutputArchiveHandle for more information.
Reimplemented from lsst::afw::table::io::Persistable.
|
inherited |
Write the object to an already-open FITS object.
[in] | fitsfile | Open FITS object to write to. |
Definition at line 18 of file Persistable.cc.
|
inherited |
Write the object to a FITS image in memory.
[in] | manager | Name of the file to write to. |
[in] | mode | If "w", any existing file with the given name will be overwritten. If "a", new HDUs will be appended to an existing file. |
Definition at line 29 of file Persistable.cc.
|
inherited |
Write the object to a regular FITS file.
[in] | fileName | Name of the file to write to. |
[in] | mode | If "w", any existing file with the given name will be overwritten. If "a", new HDUs will be appended to an existing file. |
Definition at line 24 of file Persistable.cc.
|
friend |