LSST Applications g0f08755f38+9c285cab97,g1635faa6d4+13f3999e92,g1653933729+a8ce1bb630,g1a0ca8cf93+bf6eb00ceb,g28da252d5a+0829b12dee,g29321ee8c0+5700dc9eac,g2bbee38e9b+9634bc57db,g2bc492864f+9634bc57db,g2cdde0e794+c2c89b37c4,g3156d2b45e+41e33cbcdc,g347aa1857d+9634bc57db,g35bb328faa+a8ce1bb630,g3a166c0a6a+9634bc57db,g3e281a1b8c+9f2c4e2fc3,g414038480c+077ccc18e7,g41af890bb2+fde0dd39b6,g5fbc88fb19+17cd334064,g781aacb6e4+a8ce1bb630,g80478fca09+55a9465950,g82479be7b0+d730eedb7d,g858d7b2824+9c285cab97,g9125e01d80+a8ce1bb630,g9726552aa6+10f999ec6a,ga5288a1d22+2a84bb7594,gacf8899fa4+c69c5206e8,gae0086650b+a8ce1bb630,gb58c049af0+d64f4d3760,gc28159a63d+9634bc57db,gcf0d15dbbd+4b7d09cae4,gda3e153d99+9c285cab97,gda6a2b7d83+4b7d09cae4,gdaeeff99f8+1711a396fd,ge2409df99d+5e831397f4,ge79ae78c31+9634bc57db,gf0baf85859+147a0692ba,gf3967379c6+41c94011de,gf3fb38a9a8+8f07a9901b,gfb92a5be7c+9c285cab97,w.2024.46
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. | |
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. | |
virtual int | getComponentCount () const |
Return the number of components. | |
std::shared_ptr< Mixture > | project (int dim) const |
Project the distribution onto the given dimensions (marginalize over all others) | |
std::shared_ptr< Mixture > | project (int dim1, int dim2) const |
Project the distribution onto the given dimensions (marginalize over all others) | |
int | getDimension () const |
Return the number of dimensions. | |
void | normalize () |
Iterate over all components, rescaling their weights so they sum to one. | |
void | shift (int dim, Scalar offset) |
Shift the mixture in the given dimension, adding the given offset to all mu vectors. | |
std::size_t | clip (Scalar threshold=0.0) |
Iterate over all components, removing those with weight less than or equal to threshold. | |
Scalar | getDegreesOfFreedom () const |
Get the number of degrees of freedom in the component Student's T distributions (inf=Gaussian) | |
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) | |
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. | |
template<typename Derived > | |
Scalar | evaluate (Eigen::MatrixBase< Derived > const &x) const |
Evaluate the mixture distribution probability density function (PDF) at the given points. | |
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. | |
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. | |
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. | |
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. | |
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. | |
void | draw (afw::math::Random &rng, ndarray::Array< Scalar, 2, 1 > const &x) const |
Draw random variates from the distribution. | |
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. | |
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. | |
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. | |
virtual std::shared_ptr< Mixture > | clone () const |
Polymorphic deep copy. | |
Mixture (int dim, ComponentList &components, Scalar df=std::numeric_limits< Scalar >::infinity()) | |
Construct a mixture model. | |
virtual bool | isPersistable () const noexcept override |
Return true if this particular object can be persisted using afw::table::io. | |
void | writeFits (std::string const &fileName, std::string const &mode="w") const |
Write the object to a regular FITS file. | |
void | writeFits (fits::MemFileManager &manager, std::string const &mode="w") const |
Write the object to a FITS image in memory. | |
void | writeFits (fits::Fits &fitsfile) const |
Write the object to an already-open FITS object. | |
Static Public Member Functions | |
static std::shared_ptr< Mixture > | readFits (fits::Fits &fitsfile) |
Read an object from an already open FITS object. | |
static std::shared_ptr< Mixture > | readFits (std::string const &fileName, int hdu=fits::DEFAULT_HDU) |
Read an object from a regular FITS file. | |
static std::shared_ptr< Mixture > | readFits (fits::MemFileManager &manager, int hdu=fits::DEFAULT_HDU) |
Read an object from a FITS file in memory. | |
static std::shared_ptr< Mixture > | dynamicCast (std::shared_ptr< Persistable > const &ptr) |
Dynamically cast a shared_ptr. | |
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. | |
std::string | getPersistenceName () const override |
Return the unique name used to persist this object and look up its factory. | |
void | write (OutputArchiveHandle &handle) const override |
Write the object to one or more catalogs. | |
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.
Definition at line 368 of file Mixture.h.
|
inlineoverridevirtualnoexcept |
Return true if this particular object can be persisted using afw::table::io.
Reimplemented from lsst::afw::table::io::Persistable.
Definition at line 364 of file Mixture.h.
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 |