MixturePdf Class Template Reference

Inheritance diagram for MixturePdf:

Inheritance graph
[legend]

List of all members.


Detailed Description

template<class T>
class indii::ml::aux::MixturePdf< T >

Mixture probability density.

Author:
Lawrence Murray <lawrence@indii.org>
Version:
Rev
Date:
Date
Parameters:
T Component type, should be derivative of Pdf.

Serialization

This class supports serialization through the Boost.Serialization library.

Parallelisation

This class supports distributed storage. MixturePdf objects may be instantiated on all nodes of a communicator, each with a different set of mixture components, such that the union of all components defines the full distribution.

"Regular" methods such as getSize(), getTotalWeight() and getExpectation() use only those components stored on the local node. Special "distributed" methods such as getDistributedSize(), getDistributedTotalWeight() and getDistributedExpectation() use all components stored across the nodes.

Definition at line 40 of file MixturePdf.hpp.


Public Member Functions

 MixturePdf ()
 Default constructor.
 MixturePdf (const unsigned int N)
 Constructor.
virtual ~MixturePdf ()
 Destructor.
MixturePdf< T > & operator= (const MixturePdf< T > &o)
 Assignment operator.
virtual void setDimensions (const unsigned int N, const bool preserve=false)
 Set the dimensionality of the distribution.
Local storage methods
Use these methods if:

  • You are not working in a parallel environment,
  • You are working in a parallel environment but are not using the distributed storage features of this class, or
  • You are working in a parallel environment and are using the distributed storage features of this class, but only want to deal with the mixture components stored on the local node.


void add (const T &x, const double w=1.0)
 Add a component to the distribution on the local node.
const T & get (const unsigned int i) const
 Get component on the local node.
T & get (const unsigned int i)
 Get component on the local node.
void set (const unsigned int i, const T &)
 Set component on the local node.
const std::vector< T > & getAll () const
 Get components on the local node.
std::vector< T > & getAll ()
 Get components on the local node.
double getWeight (const unsigned int i) const
 Get component weight on the local node.
void setWeight (const unsigned int i, const double w)
 Set component weight on the local node.
const vectorgetWeights () const
 Get the weights of all components on the local node.
void setWeights (const vector &ws)
 Set the weights of all components on the local node.
void clear ()
 Clear all components from the distribution on the local node.
unsigned int getSize () const
 Get the number of components in the distribution on the local node.
double getTotalWeight () const
 Get the total weight of components on the local node.
void normalise ()
 Normalise weights on the local node to sum to 1.
virtual vector sample ()
 Sample from the distribution on the local node.
virtual double densityAt (const vector &x)
 Calculate the density on the local node at a given point.
virtual const vectorgetExpectation ()
 Get the expected value of the distribution on the local node.
Distributed storage methods
Use these methods if:

  • You are working in a parallel environment and are using the distributed storage features of this class, and want to deal with the mixture components stored across all nodes.
These methods are used for distributed storage of mixtures. They require synchronization and communication between all nodes in the communicator, such that if any of these methods is called on one node, the same method should eventually, and preferably as soon as possible, be called on all other nodes in the same communicator.

unsigned int getDistributedSize () const
 Get the number of components in the distribution across all nodes.
double getDistributedTotalWeight () const
 Get the total weight of components across all nodes.
void distributedNormalise ()
 Normalise weights across all nodes to sum to 1.
virtual vector distributedSample ()
 Sample from the full distribution.
virtual std::vector
< vector
distributedSample (const unsigned int P)
 Draw multiple samples from the full distribution.
virtual double distributedDensityAt (const vector &x)
 Calculate the density of the full distribution at a given point.
virtual vector distributedDensityAt (std::vector< vector > &xs)
 Perform multiple density calculations from the full distribution.
virtual vector getDistributedExpectation ()
 Get the expected value of the full distribution.
void redistributeBySize ()
 Redistribute components across nodes by number.
void redistributeByWeight ()
 Redistribute components across nodes by weight.

Protected Member Functions

virtual void dirty ()
 Called when changes are made to the distribution, such as when a new component is added.

Constructor & Destructor Documentation

MixturePdf (  )  [inline]

Default constructor.

Initialises the mixture with zero dimensions. This should generally only be used when the object is to be restored from a serialization. Indeed, there is no other way to resize the mixture to nonzero dimensionality except by subsequently restoring from a serialization.

Definition at line 484 of file MixturePdf.hpp.

MixturePdf ( const unsigned int  N  )  [inline]

Constructor.

One or more components should be added with add() after construction.

Parameters:
N Dimensionality of the distribution.

Definition at line 490 of file MixturePdf.hpp.

~MixturePdf (  )  [inline, virtual]

Destructor.

Definition at line 496 of file MixturePdf.hpp.


Member Function Documentation

indii::ml::aux::MixturePdf< T > & operator= ( const MixturePdf< T > &  o  )  [inline]

Assignment operator.

Both sides must have the same dimensionality, but may have different number of components.

Definition at line 501 of file MixturePdf.hpp.

void setDimensions ( const unsigned int  N,
const bool  preserve = false 
) [inline, virtual]

Set the dimensionality of the distribution.

Parameters:
N Dimensionality of the distribution.
preserve True to preserve the current sufficient statistics of the distribution in the lower dimensional space, false if these may be discarded.

Implements Pdf.

Reimplemented in DiracMixturePdf, StandardMixturePdf, StandardMixturePdf< indii::ml::aux::GaussianPdf >, and StandardMixturePdf< indii::ml::aux::KernelDensityPdf< NT, KT > >.

Definition at line 670 of file MixturePdf.hpp.

void add ( const T &  x,
const double  w = 1.0 
) [inline]

Add a component to the distribution on the local node.

Parameters:
x The component.
w Unnormalised weight of the component.
The new component is added to the end of the list of components in terms of indices used by get(), getWeight(), etc.

Definition at line 524 of file MixturePdf.hpp.

const T & get ( const unsigned int  i  )  const [inline]

Get component on the local node.

Parameters:
i Index of the component.
Returns:
The i th component.

Definition at line 546 of file MixturePdf.hpp.

T & get ( const unsigned int  i  )  [inline]

Get component on the local node.

Parameters:
i Index of the component.
Returns:
The i th component.
Note:
Modifying any of the components in the mixture may have unintended side effects, especially since Pdf classes rely heavily on precalculations which may consequently become out of date. This method is provided only for those situations where precalculations must be made within the component objects themselves, such as within their getExpectation() methods, such that a non-const context is required. For all other situations, favour the const version of this method.

Definition at line 552 of file MixturePdf.hpp.

void set ( const unsigned int  i,
const T &  x 
) [inline]

Set component on the local node.

Parameters:
i Index of the component.
x Value of the component.

Definition at line 557 of file MixturePdf.hpp.

const std::vector< T > & getAll (  )  const [inline]

Get components on the local node.

Returns:
$\{(\mathbf{x}^{(i)},w^{(i)})\}$; set of weighted components defining the distribution, as a vector.

Definition at line 563 of file MixturePdf.hpp.

std::vector< T > & getAll (  )  [inline]

Get components on the local node.

Returns:
$\{(\mathbf{x}^{(i)},w^{(i)})\}$; set of weighted components defining the distribution, as a vector.
Note:
Modifying any of the components in the mixture may have unintended side effects, especially since Pdf classes rely heavily on precalculations which may consequently become out of date. This method is provided only for those situations where precalculations must be made within the component objects themselves, such as within their getExpectation() methods, such that a non-const context is required. For all other situations, favour the const version of this method.

Definition at line 568 of file MixturePdf.hpp.

double getWeight ( const unsigned int  i  )  const [inline]

Get component weight on the local node.

Parameters:
i Index of the component.
Returns:
Weight of the i th component.

Definition at line 573 of file MixturePdf.hpp.

void setWeight ( const unsigned int  i,
const double  w 
) [inline]

Set component weight on the local node.

Parameters:
i Index of the component.
w Weight of the i th component.

Definition at line 579 of file MixturePdf.hpp.

const indii::ml::aux::vector & getWeights (  )  const [inline]

Get the weights of all components on the local node.

Returns:
Vector of the weights of all components.

Definition at line 601 of file MixturePdf.hpp.

void setWeights ( const vector ws  )  [inline]

Set the weights of all components on the local node.

Parameters:
ws Vector of the weights of all components.

Definition at line 606 of file MixturePdf.hpp.

void clear (  )  [inline]

Clear all components from the distribution on the local node.

Definition at line 656 of file MixturePdf.hpp.

unsigned int getSize (  )  const [inline]

Get the number of components in the distribution on the local node.

Returns:
$K$; the number of components in the distribution.

Definition at line 626 of file MixturePdf.hpp.

double getTotalWeight (  )  const [inline]

Get the total weight of components on the local node.

Returns:
$W$; the total weight of components.

Definition at line 665 of file MixturePdf.hpp.

void normalise (  )  [inline]

Normalise weights on the local node to sum to 1.

Warning:
If in a distributed storage situation this is probably not what you want. Consider distributedNormalise() instead. Normalising the weights only on the local node will skew the weighting of mixture components across all nodes.

Definition at line 631 of file MixturePdf.hpp.

indii::ml::aux::vector sample (  )  [inline, virtual]

Sample from the distribution on the local node.

Returns:
A sample from the distribution.

Implements Pdf.

Definition at line 699 of file MixturePdf.hpp.

double densityAt ( const vector x  )  [inline, virtual]

Calculate the density on the local node at a given point.

\[p(\mathbf{x}) = \frac{1}{W}\sum_{i=1}^{K}w^{(i)}p^{(i)}(\mathbf{x})\]

Parameters:
x $\mathbf{x}$; the point at which to calculate the density.
Returns:
$p(\mathbf{x})$; the density at $\mathbf{x}$.

Implements Pdf.

Definition at line 711 of file MixturePdf.hpp.

const indii::ml::aux::vector & getExpectation (  )  [inline, virtual]

Get the expected value of the distribution on the local node.

Returns:
$\mathbf{\mu}$; expected value of the distribution.

Implements Pdf.

Definition at line 691 of file MixturePdf.hpp.

unsigned int getDistributedSize (  )  const [inline]

Get the number of components in the distribution across all nodes.

Returns:
$\sum_i K_i$; the number of components in the distribution.

Definition at line 728 of file MixturePdf.hpp.

double getDistributedTotalWeight (  )  const [inline]

Get the total weight of components across all nodes.

Returns:
$\sum_i W_i$; the total weight of components across all nodes.

Definition at line 736 of file MixturePdf.hpp.

void distributedNormalise (  )  [inline]

Normalise weights across all nodes to sum to 1.

Definition at line 743 of file MixturePdf.hpp.

indii::ml::aux::vector distributedSample (  )  [inline, virtual]

Sample from the full distribution.

Returns:
A sample from the full distribution.

Definition at line 766 of file MixturePdf.hpp.

std::vector< indii::ml::aux::vector > distributedSample ( const unsigned int  P  )  [inline, virtual]

Draw multiple samples from the full distribution.

This is significantly more efficient than multiple calls to distributedSample(), as it involves less message passing.

Parameters:
P $P$; number of samples to draw.
Returns:
Vector of samples drawn on the local node. The number of samples drawn across all nodes will total $P$.

Definition at line 817 of file MixturePdf.hpp.

double distributedDensityAt ( const vector x  )  [inline, virtual]

Calculate the density of the full distribution at a given point.

Parameters:
x $\mathbf{x}$; the point at which to calculate the density.
Returns:
$p(\mathbf{x})$; the density at $\mathbf{x}$.

Definition at line 856 of file MixturePdf.hpp.

indii::ml::aux::vector distributedDensityAt ( std::vector< vector > &  xs  )  [inline, virtual]

Perform multiple density calculations from the full distribution.

This is significantly more efficient than multiple calls to distributedDensityAt(const vector&), as it involves less message passing.

Parameters:
xs The points on this node at which to calculate densities.
Returns:
The densities at the given points on this node.
Note that while each node is passed only its set of points and returns only the density calculations for its set of points, all nodes participate in the calculation for all points.

See also:
distributedDensityAt(const vector&);

Definition at line 867 of file MixturePdf.hpp.

indii::ml::aux::vector getDistributedExpectation (  )  [inline, virtual]

Get the expected value of the full distribution.

Returns:
$\mathbf{\mu}$; expected value of the full distribution.

Definition at line 890 of file MixturePdf.hpp.

void redistributeBySize (  )  [inline]

Redistribute components across nodes by number.

This attempts to redistribute the components of the full distribution across nodes, so that each node stores as close to an equal number of components as possible.

Definition at line 915 of file MixturePdf.hpp.

void redistributeByWeight (  )  [inline]

Redistribute components across nodes by weight.

This attempts to redistribute the components of the full distribution across nodes, so that the total weight of components at each node is as close to an equal number as possible.

Definition at line 1013 of file MixturePdf.hpp.

void dirty (  )  [inline, protected, virtual]

Called when changes are made to the distribution, such as when a new component is added.

This allows pre-calculations to be refreshed.

Reimplemented in DiracMixturePdf, StandardMixturePdf, StandardMixturePdf< indii::ml::aux::GaussianPdf >, and StandardMixturePdf< indii::ml::aux::KernelDensityPdf< NT, KT > >.

Definition at line 1115 of file MixturePdf.hpp.


Generated on Wed Dec 17 15:11:58 2008 for dysii Dynamical Systems Library by  doxygen 1.5.3