|
PLearn 0.1
|
The first sentence should be a BRIEF DESCRIPTION of what the class does. More...
#include <MixtureDistribution.h>


Public Member Functions | |
| MixtureDistribution () | |
| Default constructor. | |
| virtual real | log_density (const Vec &y) const |
| Return log of probability density log(p(y | x)). | |
| virtual real | survival_fn (const Vec &y) const |
| Return survival function: P(Y>y | x). | |
| virtual real | cdf (const Vec &y) const |
| Return cdf: P(Y<y | x). | |
| virtual void | expectation (Vec &mu) const |
| Return E[Y | x]. | |
| virtual void | variance (Mat &cov) const |
| Return Var[Y | x]. | |
| virtual void | generate (Vec &y) const |
| Return a pseudo-random sample generated from the conditional distribution, of density p(y | x). | |
| virtual void | resetGenerator (long g_seed) |
| Generates a pseudo-random sample x from the reversed conditional distribution, of density p(x | y) (and NOT p(y | x)). | |
| virtual bool | setPredictorPredictedSizes (int the_predictor_size, int the_predicted_size, bool call_parent=true) |
| Set the 'predictor' and 'predicted' sizes for this distribution. | |
| virtual void | setPredictor (const Vec &predictor, bool call_parent=true) const |
| Set the value for the predictor part of a conditional probability. | |
| virtual void | forget () |
| (Re-)initializes the PDistribution in its fresh state (that state may depend on the 'seed' option). | |
| 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 MixtureDistribution * | 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_ () |
| 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 | |
| TVec< PP< PDistribution > > | distributions |
| Vec | weights |
Static Public Attributes | |
| static StaticInitializer | _static_initializer_ |
Protected Member Functions | |
| void | getSizes () const |
| Re-obtain the sizes of the predictor and predicted parts from the first distribution in the 'distributions' vector. | |
Static Protected Member Functions | |
| static void | declareOptions (OptionList &ol) |
| Declares the class options. | |
Private Types | |
| typedef PDistribution | inherited |
Private Member Functions | |
| void | build_ () |
| This does the actual building. | |
Private Attributes | |
| Vec | work |
| Vector to store temporary data. | |
The first sentence should be a BRIEF DESCRIPTION of what the class does.
Place the rest of the class programmer documentation here. Doxygen supports Javadoc-style comments. See http://www.doxygen.org/manual.html
Definition at line 57 of file MixtureDistribution.h.
typedef PDistribution PLearn::MixtureDistribution::inherited [private] |
Reimplemented from PLearn::PDistribution.
Definition at line 59 of file MixtureDistribution.h.
| PLearn::MixtureDistribution::MixtureDistribution | ( | ) |
| string PLearn::MixtureDistribution::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::PDistribution.
Definition at line 50 of file MixtureDistribution.cc.
| OptionList & PLearn::MixtureDistribution::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::PDistribution.
Definition at line 50 of file MixtureDistribution.cc.
| RemoteMethodMap & PLearn::MixtureDistribution::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::PDistribution.
Definition at line 50 of file MixtureDistribution.cc.
Reimplemented from PLearn::PDistribution.
Definition at line 50 of file MixtureDistribution.cc.
| Object * PLearn::MixtureDistribution::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::PDistribution.
Definition at line 50 of file MixtureDistribution.cc.
| StaticInitializer MixtureDistribution::_static_initializer_ & PLearn::MixtureDistribution::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::PDistribution.
Definition at line 50 of file MixtureDistribution.cc.
| void PLearn::MixtureDistribution::build | ( | ) | [virtual] |
Simply calls inherited::build() then build_().
Reimplemented from PLearn::PDistribution.
Definition at line 98 of file MixtureDistribution.cc.
{
inherited::build();
build_();
}
| void PLearn::MixtureDistribution::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::PDistribution.
Definition at line 107 of file MixtureDistribution.cc.
References PLearn::is_equal(), n, PLCHECK_MSG, and PLearn::sum().
{
if (distributions.isEmpty())
return;
if (weights.isEmpty()) {
int n = distributions.length();
weights.resize(n);
weights.fill(1 / real(n));
}
PLCHECK_MSG(weights.length() == distributions.length() &&
is_equal(PLearn::sum(weights), 1),
"There must be one weight for each distribution, and the "
"weights must sum to 1");
getSizes();
}

Return cdf: P(Y<y | x).
Reimplemented from PLearn::PDistribution.
Definition at line 126 of file MixtureDistribution.cc.
References PLERROR.
{
PLERROR("cdf not implemented for MixtureDistribution"); return 0;
}
| string PLearn::MixtureDistribution::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::PDistribution.
Definition at line 50 of file MixtureDistribution.cc.
| void PLearn::MixtureDistribution::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares the class options.
Reimplemented from PLearn::PDistribution.
Definition at line 61 of file MixtureDistribution.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), distributions, PLearn::OptionBase::nosave, PLearn::PDistribution::predicted_size, PLearn::PDistribution::predictor_part, PLearn::PDistribution::predictor_size, PLearn::redeclareOption(), and weights.
{
declareOption(ol, "distributions", &MixtureDistribution::distributions,
OptionBase::buildoption,
"Underlying distributions being mixed.");
declareOption(ol, "weights", &MixtureDistribution::weights,
OptionBase::buildoption,
"Weights of the distributions (must sum to 1). If left empty, then\n"
"each distribution will be given a weight 1/number_of_distributions.");
// Now call the parent class' declareOptions().
inherited::declareOptions(ol);
// Hide unused options.
redeclareOption(ol, "predicted_size",
&MixtureDistribution::predicted_size,
OptionBase::nosave,
"Unused");
redeclareOption(ol, "predictor_part",
&MixtureDistribution::predictor_part,
OptionBase::nosave,
"Unused");
redeclareOption(ol, "predictor_size",
&MixtureDistribution::predictor_size,
OptionBase::nosave,
"Unused");
}

| static const PPath& PLearn::MixtureDistribution::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::PDistribution.
Definition at line 175 of file MixtureDistribution.h.
:
//##### Protected Options ###############################################
| MixtureDistribution * PLearn::MixtureDistribution::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::PDistribution.
Definition at line 50 of file MixtureDistribution.cc.
| void PLearn::MixtureDistribution::expectation | ( | Vec & | mu | ) | const [virtual] |
Return E[Y | x].
Reimplemented from PLearn::PDistribution.
Definition at line 134 of file MixtureDistribution.cc.
References PLearn::TVec< T >::fill(), i, PLearn::multiplyAcc(), PLASSERT, and PLearn::TVec< T >::resize().
{
PLASSERT( !distributions.isEmpty() );
mu.resize(distributions[0]->getNPredicted());
mu.fill(0);
for (int i = 0; i < distributions.length(); i++) {
distributions[i]->expectation(work);
multiplyAcc(mu, work, weights[i]);
}
}

| void PLearn::MixtureDistribution::forget | ( | ) | [virtual] |
(Re-)initializes the PDistribution 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!). ### You may remove this method if your distribution does not ### implement it.
Reimplemented from PLearn::PDistribution.
Definition at line 148 of file MixtureDistribution.cc.
References i.
{
for (int i = 0; i < distributions.length(); i++)
distributions[i]->forget();
inherited::forget();
getSizes();
}
| void PLearn::MixtureDistribution::generate | ( | Vec & | y | ) | const [virtual] |
Return a pseudo-random sample generated from the conditional distribution, of density p(y | x).
Reimplemented from PLearn::PDistribution.
Definition at line 159 of file MixtureDistribution.cc.
References j.
{
int j = random_gen->multinomial_sample(weights);
distributions[j]->generate(y);
}
| OptionList & PLearn::MixtureDistribution::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::PDistribution.
Definition at line 50 of file MixtureDistribution.cc.
| OptionMap & PLearn::MixtureDistribution::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::PDistribution.
Definition at line 50 of file MixtureDistribution.cc.
| RemoteMethodMap & PLearn::MixtureDistribution::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::PDistribution.
Definition at line 50 of file MixtureDistribution.cc.
| void PLearn::MixtureDistribution::getSizes | ( | ) | const [protected] |
Re-obtain the sizes of the predictor and predicted parts from the first distribution in the 'distributions' vector.
This method is used to re-obtain sizes after things may have changed (e.g. after a build(), forget() or train()).
Definition at line 168 of file MixtureDistribution.cc.
References PLASSERT.
{
PLASSERT( !distributions.isEmpty() );
n_predicted = distributions[0]->getNPredicted();
n_predictor = distributions[0]->getNPredictor();
}
Return log of probability density log(p(y | x)).
Reimplemented from PLearn::PDistribution.
Definition at line 177 of file MixtureDistribution.cc.
References i, PLearn::logadd(), n, and pl_log.
{
int n = distributions.length();
work.resize(n);
for (int i = 0; i < n; i++) {
work[i] = distributions[i]->log_density(y) + pl_log(weights[i]);
}
return logadd(work);
}

| void PLearn::MixtureDistribution::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::PDistribution.
Definition at line 190 of file MixtureDistribution.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("MixtureDistribution::makeDeepCopyFromShallowCopy not fully (correctly) implemented yet!");
}
| void PLearn::MixtureDistribution::resetGenerator | ( | long | g_seed | ) | [virtual] |
Generates a pseudo-random sample x from the reversed conditional distribution, of density p(x | y) (and NOT p(y | x)).
i.e., generates a "predictor" part given a "predicted" part, regardless of any previously set predictor. Reset the random number generator used by generate() using the given seed.
Reimplemented from PLearn::PDistribution.
Definition at line 207 of file MixtureDistribution.cc.
References i.
{
for (int i = 0; i < distributions.length(); i++)
distributions[i]->resetGenerator(g_seed);
inherited::resetGenerator(g_seed);
}
| void PLearn::MixtureDistribution::setPredictor | ( | const Vec & | predictor, |
| bool | call_parent = true |
||
| ) | const [virtual] |
Set the value for the predictor part of a conditional probability.
Reimplemented from PLearn::PDistribution.
Definition at line 217 of file MixtureDistribution.cc.
References i.
{
if (call_parent)
inherited::setPredictor(predictor, true);
for (int i = 0; i < distributions.length(); i++)
distributions[i]->setPredictor(predictor, call_parent);
getSizes();
}
| bool PLearn::MixtureDistribution::setPredictorPredictedSizes | ( | int | the_predictor_size, |
| int | the_predicted_size, | ||
| bool | call_parent = true |
||
| ) | [virtual] |
Set the 'predictor' and 'predicted' sizes for this distribution.
Reimplemented from PLearn::PDistribution.
Definition at line 229 of file MixtureDistribution.cc.
References i.
{
bool sizes_have_changed = false;
if (call_parent)
sizes_have_changed = inherited::setPredictorPredictedSizes(
the_predictor_size, the_predicted_size, true);
for (int i = 0; i < distributions.length(); i++)
distributions[i]->setPredictorPredictedSizes(the_predictor_size,
the_predicted_size,
call_parent);
getSizes();
// Returned value.
return sizes_have_changed;
}
Return survival function: P(Y>y | x).
Reimplemented from PLearn::PDistribution.
Definition at line 249 of file MixtureDistribution.cc.
References PLERROR.
{
PLERROR("survival_fn not implemented for MixtureDistribution"); return 0;
}
| void PLearn::MixtureDistribution::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::PDistribution.
Definition at line 257 of file MixtureDistribution.cc.
{
// This generic PLearner method does a number of standard stuff useful for
// (almost) any learner, and return 'false' if no training should take
// place. See PLearner.h for more details.
if (!initTrain())
return;
PLCHECK( nstages == 1 && stage == 0 );
for (int i = 0; i < distributions.length(); i++)
distributions[i]->train();
stage = 1;
getSizes();
}
| void PLearn::MixtureDistribution::variance | ( | Mat & | cov | ) | const [virtual] |
Reimplemented from PLearn::PDistribution.
Definition at line 275 of file MixtureDistribution.cc.
References PLERROR.
{
PLERROR("variance not implemented for MixtureDistribution");
}
Reimplemented from PLearn::PDistribution.
Definition at line 175 of file MixtureDistribution.h.
Definition at line 64 of file MixtureDistribution.h.
Referenced by declareOptions().
Definition at line 65 of file MixtureDistribution.h.
Referenced by declareOptions().
Vec PLearn::MixtureDistribution::work [mutable, private] |
Vector to store temporary data.
Definition at line 211 of file MixtureDistribution.h.
1.7.4