PLearn 0.1
|
#include <RandomGaussMix.h>
Public Member Functions | |
RandomGaussMix () | |
Default constructor. | |
virtual void | train () |
The role of the train method is to bring the learner up to stage == nstages, updating the train_stats collector with training costs measured on-line in the process. | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual RandomGaussMix * | deepCopy (CopiesMap &copies) const |
virtual void | build () |
Simply calls inherited::build() then build_(). | |
virtual void | makeDeepCopyFromShallowCopy (CopiesMap &copies) |
Transforms a shallow copy into a deep copy. | |
Static Public Member Functions | |
static string | _classname_ () |
Declares name and deepCopy methods. | |
static OptionList & | _getOptionList_ () |
static RemoteMethodMap & | _getRemoteMethodMap_ () |
static Object * | _new_instance_for_typemap_ () |
static bool | _isa_ (const Object *o) |
static void | _static_initialize_ () |
static const PPath & | declaringFile () |
Public Attributes | |
PP< PDistribution > | mean_distribution |
PP< PDistribution > | variance_distribution |
PP< PDistribution > | weight_distribution |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
Declares the class options. | |
Private Types | |
typedef GaussMix | inherited |
Private Member Functions | |
void | build_ () |
This does the actual building. |
Definition at line 50 of file RandomGaussMix.h.
typedef GaussMix PLearn::RandomGaussMix::inherited [private] |
Reimplemented from PLearn::GaussMix.
Definition at line 52 of file RandomGaussMix.h.
PLearn::RandomGaussMix::RandomGaussMix | ( | ) |
string PLearn::RandomGaussMix::_classname_ | ( | ) | [static] |
Declares name and deepCopy methods.
Reimplemented from PLearn::GaussMix.
Definition at line 56 of file RandomGaussMix.cc.
OptionList & PLearn::RandomGaussMix::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::GaussMix.
Definition at line 56 of file RandomGaussMix.cc.
RemoteMethodMap & PLearn::RandomGaussMix::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::GaussMix.
Definition at line 56 of file RandomGaussMix.cc.
Reimplemented from PLearn::GaussMix.
Definition at line 56 of file RandomGaussMix.cc.
Object * PLearn::RandomGaussMix::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::GaussMix.
Definition at line 56 of file RandomGaussMix.cc.
StaticInitializer RandomGaussMix::_static_initializer_ & PLearn::RandomGaussMix::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::GaussMix.
Definition at line 56 of file RandomGaussMix.cc.
void PLearn::RandomGaussMix::build | ( | ) | [virtual] |
Simply calls inherited::build() then build_().
Reimplemented from PLearn::GaussMix.
Definition at line 192 of file RandomGaussMix.cc.
{ inherited::build(); build_(); }
void PLearn::RandomGaussMix::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::GaussMix.
Definition at line 201 of file RandomGaussMix.cc.
References PLearn::center(), PLearn::GramSchmidtOrthogonalization(), j, PLearn::TVec< T >::length(), PLearn::min(), PLASSERT, PLERROR, PLearn::TMat< T >::resize(), PLearn::sortElements(), PLearn::TVec< T >::subVec(), PLearn::sum(), and PLearn::TVec< T >::swap().
{ if (!variance_distribution || !mean_distribution || !weight_distribution) return; // Need to reset the underlying distributions' seeds so that the generated // values are always the same at each build. mean_distribution->resetGenerator(mean_distribution->seed_); variance_distribution->resetGenerator(variance_distribution->seed_); weight_distribution->resetGenerator(weight_distribution->seed_); D = mean_distribution->getNPredicted(); // Generate random Gaussian parameters. eigenvalues.resize(L, D); center.resize(L, D); alpha.resize(L); eigenvectors.resize(L); for (int j = 0; j < L; j++) { // Generate random matrix and perform Gram-Schmidt orthonormalization. Mat& eigenvecs = eigenvectors[j]; eigenvecs.resize(D, D); int n_basis = -1; // It might happen that the rows of the random matrix are not // sufficiently independent, in which case we just try again. while (n_basis != D) { random_gen->fill_random_uniform(eigenvecs, -1, 1); n_basis = GramSchmidtOrthogonalization(eigenvecs); } // Generate random eigenvalues. Vec eigenvals = eigenvalues(j); variance_distribution->generate(eigenvals); PLASSERT( eigenvals.length() == D ); // Note that eigenvalues must be sorted in decreasing order. sortElements(eigenvals); eigenvals.swap(); // Generate random mean. Vec mean_j = center(j); mean_distribution->generate(mean_j); PLASSERT( mean_j.length() == D ); // Generate random weight. Vec alpha_j = alpha.subVec(j, 1); weight_distribution->generate(alpha_j); PLASSERT( alpha_j.length() == 1 ); } // Normalize 'alpha' so that it sums to 1. real sum = 0; for (int j = 0; j < L; j++) { real alpha_j = alpha[j]; if (alpha_j < 0) PLERROR("In RandomGaussMix::build_ - The weight of a Gaussian " "cannot be negative"); sum += alpha_j; } PLASSERT( sum > 0 ); alpha /= sum; // Set a few parameters that are needed. alpha_min = min(alpha); sigma_min = 1e-10; inputsize_ = D; n_eigen_computed = D; stage = 1; // Rebuild the mixture. inherited::build(); }
string PLearn::RandomGaussMix::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::GaussMix.
Definition at line 56 of file RandomGaussMix.cc.
void PLearn::RandomGaussMix::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares the class options.
Reimplemented from PLearn::GaussMix.
Definition at line 69 of file RandomGaussMix.cc.
References PLearn::GaussMix::alpha_min, PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::GaussMix::efficient_k_median, PLearn::GaussMix::efficient_k_median_iter, PLearn::GaussMix::efficient_missing, PLearn::GaussMix::epsilon, PLearn::PLearner::expdir, PLearn::PLearner::forget_when_training_set_changes, PLearn::GaussMix::impute_missing, PLearn::GaussMix::kmeans_iterations, mean_distribution, PLearn::GaussMix::n_eigen, PLearn::PDistribution::n_predictor, PLearn::OptionBase::nosave, PLearn::PLearner::nservers, PLearn::PLearner::nstages, PLearn::PDistribution::predicted_size, PLearn::PDistribution::predictor_part, PLearn::PDistribution::predictor_size, PLearn::redeclareOption(), PLearn::PLearner::save_trainingset_prefix, PLearn::GaussMix::sigma_min, PLearn::GaussMix::type, variance_distribution, and weight_distribution.
{ // ### Declare all of this object's options here // ### For the "flags" of each option, you should typically specify // ### one of OptionBase::buildoption, OptionBase::learntoption or // ### OptionBase::tuningoption. Another possible flag to be combined with // ### is OptionBase::nosave declareOption(ol, "mean_distribution", &RandomGaussMix::mean_distribution, OptionBase::buildoption, "The distribution from which means are sampled. A sample from this\n" "distribution should be a D-dimensional vector, representing the mean\n" "of a Gaussian in the input space."); declareOption(ol, "variance_distribution", &RandomGaussMix::variance_distribution, OptionBase::buildoption, "The distribution from which variances are sampled. A sample from\n" "this distribution should be a D-dimensional vector, representing\n" "the variance in each of the D principal directions of the Gaussian."); declareOption(ol, "weight_distribution", &RandomGaussMix::weight_distribution, OptionBase::buildoption, "The distribution from which the weight of each Gaussian is sampled.\n" "It should output a single non-negative scalar (the weights will be\n" "normalized afterwards so that they sum to 1)."); // Now call the parent class' declareOptions(). inherited::declareOptions(ol); // Hide unused options. redeclareOption(ol, "type", &RandomGaussMix::type, OptionBase::nosave, "Not used in RandomGaussMix."); redeclareOption(ol, "n_eigen", &RandomGaussMix::n_eigen, OptionBase::nosave, "Not used in RandomGaussMix."); redeclareOption(ol, "efficient_missing", &RandomGaussMix::efficient_missing, OptionBase::nosave, "Not used in RandomGaussMix."); redeclareOption(ol, "efficient_k_median", &RandomGaussMix::efficient_k_median, OptionBase::nosave, "Not used in RandomGaussMix."); redeclareOption(ol, "efficient_k_median_iter", &RandomGaussMix::efficient_k_median_iter, OptionBase::nosave, "Not used in RandomGaussMix."); redeclareOption(ol, "impute_missing", &RandomGaussMix::impute_missing, OptionBase::nosave, "Not used in RandomGaussMix."); redeclareOption(ol, "kmeans_iterations", &RandomGaussMix::kmeans_iterations, OptionBase::nosave, "Not used in RandomGaussMix."); redeclareOption(ol, "alpha_min", &RandomGaussMix::alpha_min, OptionBase::nosave, "Not used in RandomGaussMix."); redeclareOption(ol,"sigma_min", &RandomGaussMix::sigma_min, OptionBase::nosave, "Not used in RandomGaussMix."); redeclareOption(ol, "epsilon", &RandomGaussMix::epsilon, OptionBase::nosave, "Not used in RandomGaussMix."); redeclareOption(ol, "predictor_size", &RandomGaussMix::predictor_size, OptionBase::nosave, "Not used in RandomGaussMix."); redeclareOption(ol, "predicted_size", &RandomGaussMix::predicted_size, OptionBase::nosave, "Not used in RandomGaussMix."); redeclareOption(ol, "predictor_part", &RandomGaussMix::predictor_part, OptionBase::nosave, "Not used in RandomGaussMix."); redeclareOption(ol, "n_predictor", &RandomGaussMix::n_predictor, OptionBase::nosave, "Not used in RandomGaussMix."); redeclareOption(ol, "expdir", &RandomGaussMix::expdir, OptionBase::nosave, "Not used in RandomGaussMix."); redeclareOption(ol, "forget_when_training_set_changes", &RandomGaussMix::forget_when_training_set_changes, OptionBase::nosave, "Not used in RandomGaussMix."); redeclareOption(ol, "nstages", &RandomGaussMix::nstages, OptionBase::nosave, "Not used in RandomGaussMix."); redeclareOption(ol, "nservers", &RandomGaussMix::nservers, OptionBase::nosave, "Not used in RandomGaussMix."); redeclareOption(ol, "save_trainingset_prefix", &RandomGaussMix::save_trainingset_prefix, OptionBase::nosave, "Not used in RandomGaussMix."); }
static const PPath& PLearn::RandomGaussMix::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::GaussMix.
Definition at line 77 of file RandomGaussMix.h.
:
//##### Protected Options ###############################################
RandomGaussMix * PLearn::RandomGaussMix::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::GaussMix.
Definition at line 56 of file RandomGaussMix.cc.
OptionList & PLearn::RandomGaussMix::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::GaussMix.
Definition at line 56 of file RandomGaussMix.cc.
OptionMap & PLearn::RandomGaussMix::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::GaussMix.
Definition at line 56 of file RandomGaussMix.cc.
RemoteMethodMap & PLearn::RandomGaussMix::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::GaussMix.
Definition at line 56 of file RandomGaussMix.cc.
void PLearn::RandomGaussMix::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::GaussMix.
Definition at line 270 of file RandomGaussMix.cc.
References PLERROR.
{ inherited::makeDeepCopyFromShallowCopy(copies); // ### Call deepCopyField on all "pointer-like" fields // ### that you wish to be deepCopied rather than // ### shallow-copied. // ### ex: // deepCopyField(trainvec, copies); // ### Remove this line when you have fully implemented this method. PLERROR("RandomGaussMix::makeDeepCopyFromShallowCopy not fully (correctly) implemented yet!"); }
void PLearn::RandomGaussMix::train | ( | ) | [virtual] |
The role of the train method is to bring the learner up to stage == nstages, updating the train_stats collector with training costs measured on-line in the process.
Reimplemented from PLearn::GaussMix.
Definition at line 287 of file RandomGaussMix.cc.
{ // This class does not need to be trained. return; }
Reimplemented from PLearn::GaussMix.
Definition at line 77 of file RandomGaussMix.h.
Definition at line 57 of file RandomGaussMix.h.
Referenced by declareOptions().
Definition at line 58 of file RandomGaussMix.h.
Referenced by declareOptions().
Definition at line 59 of file RandomGaussMix.h.
Referenced by declareOptions().