#include <GaussMix.h>
Inheritance diagram for PLearn::GaussMix:
Public Member Functions | |
GaussMix () | |
Default constructor. | |
virtual void | generate (Vec &s) const |
Overridden. | |
virtual void | resetGenerator (long g_seed) const |
Reset the random number generator used by generate() using the given seed. | |
virtual void | forget () |
(Re-)initializes the PLearner in its fresh state (that state may depend on the 'seed' option) And sets 'stage' back to 0 (this is the stage of a fresh learner!) | |
virtual void | build () |
simply calls inherited::build() then build_() | |
virtual void | makeDeepCopyFromShallowCopy (map< const void *, void * > &copies) |
Transforms a shallow copy into a deep copy. | |
PLEARN_DECLARE_OBJECT (GaussMix) | |
Declares name and deepCopy methods. | |
virtual void | train () |
Trains the model. | |
virtual void | setInput (const Vec &input) const |
Set the value for the input part of the conditional probability. | |
virtual void | updateFromConditionalSorting () |
This method updates the internal data given a new sorting of the variables defined by the conditional flags. | |
virtual real | log_density (const Vec &y) const |
return density p(y | x) | |
virtual real | survival_fn (const Vec &y) const |
return survival fn = P(Y>y | x) | |
virtual real | cdf (const Vec &y) const |
return survival fn = P(Y<y | x) | |
virtual void | expectation (Vec &mu) const |
Compute E[Y | x]. | |
virtual void | variance (Mat &cov) const |
Compute Var[Y | x]. | |
int | getNEigenComputed () const |
"Get" methods. | |
Mat | getEigenvectors (int j) const |
Vec | getEigenvals (int j) const |
Public Attributes | |
real | alpha_min |
real | epsilon |
int | kmeans_iterations |
int | L |
int | n_eigen |
real | sigma_min |
string | type |
Vec | alpha |
Mat | mu |
Vec | sigma |
Protected Member Functions | |
virtual void | computeMeansAndCovariances () |
Given the posteriors, fill the centers and covariance of each Gaussian. | |
virtual real | computeLogLikelihood (const Vec &y, int j, bool is_input=false) const |
Compute log p(y | x,j), where j < L is the index of a component of the mixture. | |
virtual void | computePosteriors () |
Compute the posteriors P(j | s_i) for each sample point and each Gaussian. | |
virtual bool | computeWeights () |
Compute the weight of each mixture (the coefficient alpha). | |
virtual void | generateFromGaussian (Vec &s, int given_gaussian) const |
Generate a sample s from the given Gaussian. | |
virtual void | precomputeStuff () |
Precompute stuff specific to each Gaussian, given its current paremeters. | |
virtual void | replaceGaussian (int j) |
Replace the j-th Gaussian with another one (probably because that one is not appropriate). | |
void | resizeStuffBeforeTraining () |
Resize everything before training. | |
void | updateSampleWeights () |
Update the sample weights according to their initial weights and the current posterior probabilities. | |
void | kmeans (VMat samples, int nclust, TVec< int > &clust_idx, Mat &clust, int maxit=9999) |
Perform K-means. | |
Static Protected Member Functions | |
void | declareOptions (OptionList &ol) |
Declares this class' options. | |
Protected Attributes | |
Mat | eigenvalues |
TVec< Mat > | eigenvectors |
int | D |
Mat | diags |
Vec | log_coeff |
Vec | log_p_j_x |
Vec | log_p_x_j_alphaj |
Mat | mu_y_x |
int | n_eigen_computed |
int | nsamples |
Vec | p_j_x |
TVec< Mat > | cov_x |
The covariance of x. | |
TVec< Mat > | cov_y_x |
The covariance of y|x. | |
Mat | eigenvalues_x |
The eigenvalues of the covariance of X. | |
Mat | eigenvalues_y_x |
The eigenvalues of the covariance of Y|x. | |
TVec< Mat > | eigenvectors_x |
The eigenvectors of the covariance of X. | |
TVec< Mat > | eigenvectors_y_x |
The eigenvectors of the covariance of Y|x. | |
TVec< Mat > | full_cov |
The full covariance matrix. | |
TVec< Mat > | y_x_mat |
The product K2 * K1^-1 to compute E[Y|x]. | |
Mat | posteriors |
The posterior probabilities P(j | s_i), where j is the index of a Gaussian and i is the index of a sample. | |
Vec | initial_weights |
The initial weights of the samples s_i in the training set, copied for efficiency concerns. | |
Mat | updated_weights |
A matrix whose j-th line is a Vec with the weights of each sample s_i, multiplied by the posterior P(j | s_i). | |
Private Types | |
typedef PDistribution | inherited |
Private Member Functions | |
void | build_ () |
This does the actual building. | |
Private Attributes | |
Vec | sample_row |
Storage vectors to save memory allocations. | |
Vec | log_likelihood_post |
Storage vectors to save memory allocations. | |
Vec | x_minus_mu_x |
Vec | mu_target |
Vec | log_likelihood_dens |
|
Reimplemented from PLearn::PDistribution. Reimplemented in PLearn::ManifoldParzen2. Definition at line 53 of file GaussMix.h. |
|
Default constructor.
Definition at line 55 of file GaussMix.cc. |
|
simply calls inherited::build() then build_()
Reimplemented from PLearn::PDistribution. Reimplemented in PLearn::ManifoldParzen2. Definition at line 184 of file GaussMix.cc. References build_(). Referenced by train(). |
|
This does the actual building.
Reimplemented from PLearn::PDistribution. Reimplemented in PLearn::ManifoldParzen2. Definition at line 193 of file GaussMix.cc. References alpha, cov_x, cov_y_x, eigenvectors, eigenvectors_x, eigenvectors_y_x, full_cov, L, PLearn::log(), log_coeff, log_p_j_x, log_p_x_j_alphaj, p_j_x, PLERROR, PLearn::TVec< Mat >::resize(), PLearn::TVec< T >::resize(), sigma, type, and y_x_mat. Referenced by build(). |
|
return survival fn = P(Y<y | x)
Reimplemented from PLearn::PDistribution. Definition at line 1025 of file GaussMix.cc. References PLERROR. |
|
Compute log p(y | x,j), where j < L is the index of a component of the mixture. If 'is_input' is set to true, then it will instead compute log p(x | j) (here x = y), the probability of the input part x given j. Definition at line 284 of file GaussMix.cc. References diags, PLearn::dot(), eigenvalues, eigenvalues_x, eigenvalues_y_x, eigenvectors, eigenvectors_x, eigenvectors_y_x, PLearn::gauss_log_density_stddev(), k, log_coeff, PLearn::max(), mu, mu_y_x, n_eigen_computed, PLERROR, PLWARNING, PLearn::pownorm(), PLearn::TVec< T >::resize(), sigma, sigma_min, PLearn::square(), and type. Referenced by computePosteriors(), log_density(), and setInput(). |
|
Given the posteriors, fill the centers and covariance of each Gaussian.
Definition at line 238 of file GaussMix.cc. References PLearn::center(), PLearn::columnmatrix(), PLearn::columnSum(), PLearn::computeInputMeanAndCovar(), PLearn::computeInputMeanAndVariance(), D, diags, eigenvalues, PLearn::eigenVecOfSymmMat(), eigenvectors, epsilon, L, PLearn::mean(), mu, n_eigen_computed, nsamples, PLERROR, PLWARNING, posteriors, sigma, PLearn::sqrt(), type, updated_weights, and PLearn::variance(). Referenced by train(). |
|
Compute the posteriors P(j | s_i) for each sample point and each Gaussian.
Definition at line 390 of file GaussMix.cc. References alpha, computeLogLikelihood(), D, PLearn::exp(), PLearn::VMat::getSubRow(), L, PLearn::log(), log_likelihood_post, PLearn::logadd(), nsamples, PLWARNING, posteriors, PLearn::TVec< T >::resize(), sample_row, and updateSampleWeights(). Referenced by train(). |
|
Compute the weight of each mixture (the coefficient alpha). If a mixture has a too low coefficient, it will be removed, and the method will return 'true' (otherwise it will return 'false'). Definition at line 418 of file GaussMix.cc. References alpha, alpha_min, PLearn::TVec< T >::fill(), L, nsamples, posteriors, and replaceGaussian(). Referenced by train(). |
|
Declares this class' options.
Reimplemented from PLearn::PDistribution. Definition at line 92 of file GaussMix.cc. References PLearn::declareOption(), and PLearn::OptionList. |
|
Compute E[Y | x].
Reimplemented from PLearn::PDistribution. Definition at line 441 of file GaussMix.cc. References PLearn::TVec< T >::clear(), L, mu, mu_y_x, p_j_x, PLERROR, PLearn::TVec< T >::resize(), and type. |
|
(Re-)initializes the PLearner in its fresh state (that state may depend on the 'seed' option) And sets 'stage' back to 0 (this is the stage of a fresh learner!)
Reimplemented from PLearn::PDistribution. Definition at line 473 of file GaussMix.cc. |
|
Overridden.
Reimplemented from PLearn::PDistribution. Definition at line 481 of file GaussMix.cc. References generateFromGaussian(), and x. |
|
Generate a sample s from the given Gaussian. If 'given_gaussian' is equal to -1, then a random Gaussian will be chosen according to the weights alpha. Definition at line 489 of file GaussMix.cc. References alpha, diags, eigenvalues, eigenvalues_y_x, eigenvectors, eigenvectors_y_x, PLearn::TVec< T >::fill(), PLearn::fill_random_normal(), PLearn::gaussian_mu_sigma(), k, PLearn::TVec< T >::length(), PLearn::max(), mu, mu_y_x, PLearn::multinomial_sample(), n_eigen_computed, PLearn::norm(), p_j_x, PLERROR, PLearn::TVec< T >::resize(), sigma, sigma_min, PLearn::sqrt(), and type. Referenced by generate(), and replaceGaussian(). |
|
Definition at line 562 of file GaussMix.cc. References eigenvalues. |
|
Definition at line 555 of file GaussMix.cc. References eigenvectors. |
|
"Get" methods.
Definition at line 548 of file GaussMix.cc. References n_eigen_computed. |
|
Perform K-means.
Definition at line 569 of file GaussMix.cc. References PLearn::TVec< T >::clear(), PLearn::TMat< T >::clear(), PLearn::dist(), PLearn::VMat::getExample(), PLearn::VMat::length(), nsamples, PLearn::pownorm(), PLearn::TVec< T >::resize(), PLearn::TMat< T >::resize(), and val. Referenced by train(). |
|
return density p(y | x)
Reimplemented from PLearn::PDistribution. Definition at line 645 of file GaussMix.cc. References computeLogLikelihood(), L, log_likelihood_dens, log_p_j_x, PLearn::logadd(), PLERROR, PLWARNING, and PLearn::TVec< T >::resize(). |
|
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::PDistribution. Reimplemented in PLearn::ManifoldParzen2. Definition at line 668 of file GaussMix.cc. References alpha, PLearn::deepCopyField(), diags, eigenvalues, eigenvectors, initial_weights, log_coeff, log_likelihood_dens, log_likelihood_post, mu, mu_target, PLERROR, posteriors, sample_row, sigma, updated_weights, and x_minus_mu_x. |
|
Declares name and deepCopy methods.
|
|
Precompute stuff specific to each Gaussian, given its current paremeters.
Definition at line 692 of file GaussMix.cc. References D, eigenvalues, epsilon, k, L, PLearn::log(), log_coeff, PLearn::max(), n_eigen_computed, PLERROR, PLWARNING, sigma_min, and type. Referenced by train(). |
|
Replace the j-th Gaussian with another one (probably because that one is not appropriate). The new one is centered on a random point sampled from the Gaussian with highest weight alpha, and has the same covariance. Definition at line 723 of file GaussMix.cc. References alpha, PLearn::TMat< T >::column(), diags, eigenvalues, eigenvectors, generateFromGaussian(), k, L, log_coeff, mu, PLERROR, sigma, and type. Referenced by computeWeights(). |
|
Reset the random number generator used by generate() using the given seed.
Reimplemented from PLearn::PDistribution. Definition at line 754 of file GaussMix.cc. References PLearn::manual_seed(). |
|
Resize everything before training.
Definition at line 762 of file GaussMix.cc. References D, diags, eigenvalues, eigenvalues_x, eigenvalues_y_x, eigenvectors, initial_weights, L, PLearn::VMat::length(), mu, n_eigen, n_eigen_computed, nsamples, PLERROR, posteriors, PLearn::TVec< Mat >::resize(), PLearn::TMat< T >::resize(), PLearn::TVec< T >::resize(), type, and updated_weights. Referenced by PLearn::ManifoldParzen2::train(), and train(). |
|
Set the value for the input part of the conditional probability.
Reimplemented from PLearn::PDistribution. Definition at line 797 of file GaussMix.cc. References alpha, computeLogLikelihood(), PLearn::exp(), L, PLearn::log(), log_p_j_x, log_p_x_j_alphaj, PLearn::logadd(), mu, mu_target, mu_y_x, p_j_x, PLERROR, PLearn::product(), PLearn::TVec< T >::resize(), PLearn::TVec< T >::subVec(), type, x_minus_mu_x, and y_x_mat. |
|
return survival fn = P(Y>y | x)
Reimplemented from PLearn::PDistribution. Definition at line 1017 of file GaussMix.cc. References PLERROR. |
|
Trains the model.
Reimplemented from PLearn::PDistribution. Reimplemented in PLearn::ManifoldParzen2. Definition at line 837 of file GaussMix.cc. References build(), PLearn::TVec< T >::clear(), computeMeansAndCovariances(), computePosteriors(), computeWeights(), D, PLearn::TMat< T >::fill(), PLearn::TVec< T >::fill(), PLearn::VMat::getExample(), initial_weights, kmeans(), kmeans_iterations, L, log_p_j_x, mu, nsamples, PLERROR, PLWARNING, posteriors, precomputeStuff(), resizeStuffBeforeTraining(), PLearn::sample(), PLearn::ProgressBar::update(), and updateSampleWeights(). |
|
This method updates the internal data given a new sorting of the variables defined by the conditional flags.
Reimplemented from PLearn::PDistribution. Definition at line 920 of file GaussMix.cc. References PLearn::TMat< T >::clear(), PLearn::columnmatrix(), cov_x, cov_y_x, D, diags, eigenvalues, eigenvalues_x, eigenvalues_y_x, PLearn::eigenVecOfSymmMat(), eigenvectors, eigenvectors_x, eigenvectors_y_x, full_cov, k, L, PLearn::max(), mu, mu_y_x, n_eigen_computed, PLERROR, PLearn::product(), PLearn::productTranspose(), PLearn::TVec< Mat >::resize(), PLearn::TMat< T >::resize(), PLearn::rowmatrix(), sigma_min, PLearn::square(), PLearn::TMat< T >::subMat(), type, and y_x_mat. |
|
Update the sample weights according to their initial weights and the current posterior probabilities.
Definition at line 1007 of file GaussMix.cc. References PLearn::TMat< T >::column(), PLearn::columnmatrix(), initial_weights, L, posteriors, and updated_weights. Referenced by computePosteriors(), and train(). |
|
Compute Var[Y | x].
Reimplemented from PLearn::PDistribution. Definition at line 1033 of file GaussMix.cc. References PLERROR. |
|
Definition at line 115 of file GaussMix.h. Referenced by build_(), computePosteriors(), computeWeights(), generateFromGaussian(), makeDeepCopyFromShallowCopy(), replaceGaussian(), and setInput(). |
|
Definition at line 106 of file GaussMix.h. Referenced by computeWeights(). |
|
The covariance of x.
Definition at line 79 of file GaussMix.h. Referenced by build_(), and updateFromConditionalSorting(). |
|
The covariance of y|x.
Definition at line 80 of file GaussMix.h. Referenced by build_(), and updateFromConditionalSorting(). |
|
Definition at line 67 of file GaussMix.h. Referenced by computeMeansAndCovariances(), computePosteriors(), precomputeStuff(), resizeStuffBeforeTraining(), train(), and updateFromConditionalSorting(). |
|
Definition at line 68 of file GaussMix.h. Referenced by computeLogLikelihood(), computeMeansAndCovariances(), generateFromGaussian(), makeDeepCopyFromShallowCopy(), replaceGaussian(), resizeStuffBeforeTraining(), and updateFromConditionalSorting(). |
|
Definition at line 65 of file GaussMix.h. Referenced by computeLogLikelihood(), computeMeansAndCovariances(), generateFromGaussian(), getEigenvals(), makeDeepCopyFromShallowCopy(), precomputeStuff(), replaceGaussian(), resizeStuffBeforeTraining(), and updateFromConditionalSorting(). |
|
The eigenvalues of the covariance of X.
Definition at line 81 of file GaussMix.h. Referenced by computeLogLikelihood(), resizeStuffBeforeTraining(), and updateFromConditionalSorting(). |
|
The eigenvalues of the covariance of Y|x.
Definition at line 82 of file GaussMix.h. Referenced by computeLogLikelihood(), generateFromGaussian(), resizeStuffBeforeTraining(), and updateFromConditionalSorting(). |
|
Definition at line 66 of file GaussMix.h. Referenced by build_(), computeLogLikelihood(), computeMeansAndCovariances(), generateFromGaussian(), getEigenvectors(), makeDeepCopyFromShallowCopy(), replaceGaussian(), resizeStuffBeforeTraining(), and updateFromConditionalSorting(). |
|
The eigenvectors of the covariance of X.
Definition at line 83 of file GaussMix.h. Referenced by build_(), computeLogLikelihood(), and updateFromConditionalSorting(). |
|
The eigenvectors of the covariance of Y|x.
Definition at line 84 of file GaussMix.h. Referenced by build_(), computeLogLikelihood(), generateFromGaussian(), and updateFromConditionalSorting(). |
|
Definition at line 107 of file GaussMix.h. Referenced by computeMeansAndCovariances(), and precomputeStuff(). |
|
The full covariance matrix.
Definition at line 85 of file GaussMix.h. Referenced by build_(), and updateFromConditionalSorting(). |
|
The initial weights of the samples s_i in the training set, copied for efficiency concerns.
Definition at line 94 of file GaussMix.h. Referenced by makeDeepCopyFromShallowCopy(), resizeStuffBeforeTraining(), train(), and updateSampleWeights(). |
|
Definition at line 108 of file GaussMix.h. Referenced by train(). |
|
Definition at line 109 of file GaussMix.h. Referenced by build_(), computeMeansAndCovariances(), computePosteriors(), computeWeights(), expectation(), log_density(), precomputeStuff(), replaceGaussian(), resizeStuffBeforeTraining(), setInput(), train(), updateFromConditionalSorting(), and updateSampleWeights(). |
|
Definition at line 69 of file GaussMix.h. Referenced by build_(), computeLogLikelihood(), makeDeepCopyFromShallowCopy(), precomputeStuff(), and replaceGaussian(). |
|
Definition at line 57 of file GaussMix.h. Referenced by log_density(), and makeDeepCopyFromShallowCopy(). |
|
Storage vectors to save memory allocations.
Definition at line 56 of file GaussMix.h. Referenced by computePosteriors(), and makeDeepCopyFromShallowCopy(). |
|
Definition at line 70 of file GaussMix.h. Referenced by build_(), log_density(), setInput(), and train(). |
|
Definition at line 71 of file GaussMix.h. Referenced by build_(), and setInput(). |
|
Definition at line 116 of file GaussMix.h. Referenced by computeLogLikelihood(), computeMeansAndCovariances(), expectation(), generateFromGaussian(), makeDeepCopyFromShallowCopy(), replaceGaussian(), resizeStuffBeforeTraining(), setInput(), train(), and updateFromConditionalSorting(). |
|
Definition at line 57 of file GaussMix.h. Referenced by makeDeepCopyFromShallowCopy(), and setInput(). |
|
Definition at line 72 of file GaussMix.h. Referenced by computeLogLikelihood(), expectation(), generateFromGaussian(), setInput(), and updateFromConditionalSorting(). |
|
Definition at line 110 of file GaussMix.h. Referenced by resizeStuffBeforeTraining(). |
|
Definition at line 73 of file GaussMix.h. Referenced by computeLogLikelihood(), computeMeansAndCovariances(), generateFromGaussian(), getNEigenComputed(), precomputeStuff(), resizeStuffBeforeTraining(), and updateFromConditionalSorting(). |
|
Definition at line 74 of file GaussMix.h. Referenced by computeMeansAndCovariances(), computePosteriors(), computeWeights(), kmeans(), resizeStuffBeforeTraining(), and train(). |
|
Definition at line 75 of file GaussMix.h. Referenced by build_(), expectation(), generateFromGaussian(), and setInput(). |
|
The posterior probabilities P(j | s_i), where j is the index of a Gaussian and i is the index of a sample.
Definition at line 90 of file GaussMix.h. Referenced by computeMeansAndCovariances(), computePosteriors(), computeWeights(), makeDeepCopyFromShallowCopy(), resizeStuffBeforeTraining(), train(), and updateSampleWeights(). |
|
Storage vectors to save memory allocations.
Definition at line 56 of file GaussMix.h. Referenced by computePosteriors(), and makeDeepCopyFromShallowCopy(). |
|
Definition at line 117 of file GaussMix.h. Referenced by build_(), computeLogLikelihood(), computeMeansAndCovariances(), generateFromGaussian(), makeDeepCopyFromShallowCopy(), and replaceGaussian(). |
|
Definition at line 111 of file GaussMix.h. Referenced by computeLogLikelihood(), generateFromGaussian(), precomputeStuff(), and updateFromConditionalSorting(). |
|
Definition at line 112 of file GaussMix.h. Referenced by build_(), computeLogLikelihood(), computeMeansAndCovariances(), expectation(), generateFromGaussian(), precomputeStuff(), replaceGaussian(), resizeStuffBeforeTraining(), setInput(), and updateFromConditionalSorting(). |
|
A matrix whose j-th line is a Vec with the weights of each sample s_i, multiplied by the posterior P(j | s_i).
Definition at line 98 of file GaussMix.h. Referenced by computeMeansAndCovariances(), makeDeepCopyFromShallowCopy(), resizeStuffBeforeTraining(), and updateSampleWeights(). |
|
Definition at line 57 of file GaussMix.h. Referenced by makeDeepCopyFromShallowCopy(), and setInput(). |
|
The product K2 * K1^-1 to compute E[Y|x].
Definition at line 86 of file GaussMix.h. Referenced by build_(), setInput(), and updateFromConditionalSorting(). |