PLearn 0.1
|
The first sentence should be a BRIEF DESCRIPTION of what the class does. More...
#include <KernelDensityEstimator.h>
Public Member Functions | |
KernelDensityEstimator () | |
### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //! | |
virtual real | log_density (const Vec &x) const |
Return log of probability density log(p(y)). | |
virtual real | survival_fn (const Vec &y) const |
Return survival function: P(Y>y). | |
virtual real | cdf (const Vec &y) const |
Return cdf: P(Y<y). | |
virtual void | expectation (Vec &mu) const |
Return E[Y]. | |
virtual void | variance (Mat &cov) const |
Return Var[Y]. | |
virtual void | generate (Vec &y) const |
Return a pseudo-random sample generated from the distribution. | |
virtual void | resetGenerator (long g_seed) |
Reset the random number generator used by generate() using the given seed. | |
virtual void | forget () |
(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!). | |
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 KernelDensityEstimator * | deepCopy (CopiesMap &copies) const |
virtual void | build () |
Simply call 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 | |
PP< Kernel > | kernel |
Kernel type. | |
string | kernel_output_type |
Kernel output type. | |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
Declares the class options. | |
Private Types | |
typedef UnconditionalDistribution | inherited |
Private Member Functions | |
void | build_ () |
This does the actual building. |
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 58 of file KernelDensityEstimator.h.
typedef UnconditionalDistribution PLearn::KernelDensityEstimator::inherited [private] |
Reimplemented from PLearn::UnconditionalDistribution.
Definition at line 60 of file KernelDensityEstimator.h.
PLearn::KernelDensityEstimator::KernelDensityEstimator | ( | ) |
### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //!
Default constructor
Definition at line 54 of file KernelDensityEstimator.cc.
: kernel_output_type("normal") { }
string PLearn::KernelDensityEstimator::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::UnconditionalDistribution.
Definition at line 49 of file KernelDensityEstimator.cc.
OptionList & PLearn::KernelDensityEstimator::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::UnconditionalDistribution.
Definition at line 49 of file KernelDensityEstimator.cc.
RemoteMethodMap & PLearn::KernelDensityEstimator::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::UnconditionalDistribution.
Definition at line 49 of file KernelDensityEstimator.cc.
Reimplemented from PLearn::UnconditionalDistribution.
Definition at line 49 of file KernelDensityEstimator.cc.
Object * PLearn::KernelDensityEstimator::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::UnconditionalDistribution.
Definition at line 49 of file KernelDensityEstimator.cc.
StaticInitializer KernelDensityEstimator::_static_initializer_ & PLearn::KernelDensityEstimator::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::UnconditionalDistribution.
Definition at line 49 of file KernelDensityEstimator.cc.
void PLearn::KernelDensityEstimator::build | ( | ) | [virtual] |
Simply call inherited::build() then build_().
Reimplemented from PLearn::UnconditionalDistribution.
Definition at line 79 of file KernelDensityEstimator.cc.
References PLearn::UnconditionalDistribution::build(), and build_().
{ // ### Nothing to add here, simply calls build_(). inherited::build(); build_(); }
void PLearn::KernelDensityEstimator::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::UnconditionalDistribution.
Definition at line 89 of file KernelDensityEstimator.cc.
Referenced by build().
{ }
Return cdf: P(Y<y).
Reimplemented from PLearn::PDistribution.
Definition at line 96 of file KernelDensityEstimator.cc.
References PLERROR.
{ PLERROR("cdf not implemented for KernelDensityEstimator"); return 0; }
string PLearn::KernelDensityEstimator::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::UnconditionalDistribution.
Definition at line 49 of file KernelDensityEstimator.cc.
void PLearn::KernelDensityEstimator::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares the class options.
Reimplemented from PLearn::UnconditionalDistribution.
Definition at line 62 of file KernelDensityEstimator.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::UnconditionalDistribution::declareOptions(), kernel, and kernel_output_type.
{ declareOption(ol, "kernel", &KernelDensityEstimator::kernel, OptionBase::buildoption, "The kernel used at each point in the training set"); declareOption(ol, "kernel_output_type", &KernelDensityEstimator::kernel_output_type, OptionBase::buildoption, "Specifies whether the output of our kernel is logarithmic in the distance (\"log\") or normal (anything else)"); // Now call the parent class' declareOptions(). inherited::declareOptions(ol); }
static const PPath& PLearn::KernelDensityEstimator::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::UnconditionalDistribution.
Definition at line 141 of file KernelDensityEstimator.h.
:
//##### Protected Options ###############################################
KernelDensityEstimator * PLearn::KernelDensityEstimator::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::UnconditionalDistribution.
Definition at line 49 of file KernelDensityEstimator.cc.
void PLearn::KernelDensityEstimator::expectation | ( | Vec & | mu | ) | const [virtual] |
Return E[Y].
Reimplemented from PLearn::PDistribution.
Definition at line 104 of file KernelDensityEstimator.cc.
References PLERROR.
{ PLERROR("expectation not implemented for KernelDensityEstimator"); }
void PLearn::KernelDensityEstimator::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!).
Reimplemented from PLearn::UnconditionalDistribution.
Definition at line 113 of file KernelDensityEstimator.cc.
References PLearn::UnconditionalDistribution::forget().
{ inherited::forget(); }
void PLearn::KernelDensityEstimator::generate | ( | Vec & | y | ) | const [virtual] |
Return a pseudo-random sample generated from the distribution.
Reimplemented from PLearn::PDistribution.
Definition at line 121 of file KernelDensityEstimator.cc.
References PLERROR.
{ PLERROR("generate not implemented for KernelDensityEstimator"); }
OptionList & PLearn::KernelDensityEstimator::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::UnconditionalDistribution.
Definition at line 49 of file KernelDensityEstimator.cc.
OptionMap & PLearn::KernelDensityEstimator::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::UnconditionalDistribution.
Definition at line 49 of file KernelDensityEstimator.cc.
RemoteMethodMap & PLearn::KernelDensityEstimator::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::UnconditionalDistribution.
Definition at line 49 of file KernelDensityEstimator.cc.
Return log of probability density log(p(y)).
Reimplemented from PLearn::PDistribution.
Definition at line 134 of file KernelDensityEstimator.cc.
References PLearn::VMat::getExample(), i, kernel, kernel_output_type, PLearn::VMat::length(), PLearn::logadd(), pl_log, PLERROR, and PLearn::PLearner::train_set.
{ int numTrain = train_set.length(); Vec input, target; real weight; real result = 0.0; // It can happen that for efficiency/numerical reasons, your kernel outputs // the logarithm of the actual value of the kernel at (input_i,y). if (kernel_output_type=="log") { real logprob = -INFINITY; for(int i=0; i<numTrain; i++) { train_set->getExample(i,input,target,weight); logprob = logadd(logprob,kernel->evaluate(input,y)); } logprob -= pl_log(real(numTrain)); result = logprob; } // Otherwise, it's just a log(\sum_i{k(input_i,y)} / numTrain) else if (kernel_output_type=="normal") { real sprob = 0.0; for(int i=0; i<numTrain; i++) { train_set->getExample(i,input,target,weight); sprob += kernel->evaluate(input,y); } sprob /= real(numTrain); result = pl_log(sprob); } else PLERROR("In KernelDensityEstimator::log_density kernel_output_type must be either \"log\" or \"normal\""); return result; }
void PLearn::KernelDensityEstimator::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::UnconditionalDistribution.
Definition at line 172 of file KernelDensityEstimator.cc.
References PLearn::UnconditionalDistribution::makeDeepCopyFromShallowCopy().
{ inherited::makeDeepCopyFromShallowCopy(copies); }
void PLearn::KernelDensityEstimator::resetGenerator | ( | long | g_seed | ) | [virtual] |
Reset the random number generator used by generate() using the given seed.
Reimplemented from PLearn::PDistribution.
Definition at line 180 of file KernelDensityEstimator.cc.
References PLearn::PDistribution::resetGenerator().
{ inherited::resetGenerator(g_seed); }
Return survival function: P(Y>y).
Reimplemented from PLearn::PDistribution.
Definition at line 188 of file KernelDensityEstimator.cc.
References PLERROR.
{ PLERROR("survival_fn not implemented for KernelDensityEstimator"); return 0; }
void PLearn::KernelDensityEstimator::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 197 of file KernelDensityEstimator.cc.
{
// PLERROR("train method not implemented for KernelDensityEstimator");
}
void PLearn::KernelDensityEstimator::variance | ( | Mat & | cov | ) | const [virtual] |
Reimplemented from PLearn::PDistribution.
Definition at line 205 of file KernelDensityEstimator.cc.
References PLERROR.
{ PLERROR("variance not implemented for KernelDensityEstimator"); }
Reimplemented from PLearn::UnconditionalDistribution.
Definition at line 141 of file KernelDensityEstimator.h.
Kernel type.
Definition at line 78 of file KernelDensityEstimator.h.
Referenced by declareOptions(), and log_density().
Kernel output type.
Definition at line 81 of file KernelDensityEstimator.h.
Referenced by declareOptions(), and log_density().