PLearn 0.1
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Static Protected Member Functions | Private Member Functions
PLearn::Distribution Class Reference

#include <Distribution.h>

Inheritance diagram for PLearn::Distribution:
Inheritance graph
[legend]
Collaboration diagram for PLearn::Distribution:
Collaboration graph
[legend]

List of all members.

Public Types

typedef Learner inherited

Public Member Functions

 Distribution ()
virtual void build ()
 **** SUBCLASS WRITING: **** This method should be redefined in subclasses, to just call inherited::build() and then build_()
virtual void makeDeepCopyFromShallowCopy (CopiesMap &copies)
 Transforms a shallow copy into a deep copy.
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual DistributiondeepCopy (CopiesMap &copies) const
virtual void train (VMat training_set)
 trains the model
virtual void use (const Vec &input, Vec &output)
 computes the ouptu of a trained model
virtual double log_density (const Vec &x) const
 return log of probability density log(p(x))
virtual double density (const Vec &x) const
 return probability density p(x) [ default version returns exp(log_density(x)) ]
virtual double survival_fn (const Vec &x) const
 return survival fn = P(X>x)
virtual double cdf (const Vec &x) const
 return survival fn = P(X<x)
virtual Vec expectation () const
 return E[X]
virtual Mat variance () const
 return Var[X]
virtual void generate (Vec &x) const
 return a pseudo-random sample generated from the distribution.

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 PPathdeclaringFile ()

Public Attributes

string use_returns_what
 A string where the characters have the following meaning: 'l'->log_density, 'd' -> density, 'c' -> cdf, 's' -> survival_fn, 'e' -> expectation, 'v' -> variance.

Static Public Attributes

static StaticInitializer _static_initializer_

Static Protected Member Functions

static void declareOptions (OptionList &ol)
 Declares this class' options.

Private Member Functions

void build_ ()
 This does the actual building.

Detailed Description

Definition at line 56 of file Distribution.h.


Member Typedef Documentation


Constructor & Destructor Documentation

PLearn::Distribution::Distribution ( )

Definition at line 50 of file Distribution.cc.

References PLearn::neg_output_costfunc(), and PLearn::Learner::setTestCostFunctions().

    :Learner(0,1,1), use_returns_what("l")
{
    // cost function is -log_density
    setTestCostFunctions(neg_output_costfunc());
}

Here is the call graph for this function:


Member Function Documentation

string PLearn::Distribution::_classname_ ( ) [static]

Declares name and deepCopy methods.

Reimplemented from PLearn::Learner.

Reimplemented in PLearn::ConditionalDistribution, PLearn::ConditionalGaussianDistribution, PLearn::EmpiricalDistribution, and PLearn::LocallyWeightedDistribution.

Definition at line 59 of file Distribution.cc.

OptionList & PLearn::Distribution::_getOptionList_ ( ) [static]
RemoteMethodMap & PLearn::Distribution::_getRemoteMethodMap_ ( ) [static]
bool PLearn::Distribution::_isa_ ( const Object o) [static]
Object * PLearn::Distribution::_new_instance_for_typemap_ ( ) [static]
StaticInitializer Distribution::_static_initializer_ & PLearn::Distribution::_static_initialize_ ( ) [static]
void PLearn::Distribution::build ( ) [virtual]

**** SUBCLASS WRITING: **** This method should be redefined in subclasses, to just call inherited::build() and then build_()

Reimplemented from PLearn::Learner.

Reimplemented in PLearn::ConditionalGaussianDistribution, and PLearn::LocallyWeightedDistribution.

Definition at line 91 of file Distribution.cc.

References PLearn::Learner::build(), and build_().

Referenced by PLearn::ConditionalGaussianDistribution::build().

Here is the call graph for this function:

Here is the caller graph for this function:

void PLearn::Distribution::build_ ( ) [private]

This does the actual building.

Reimplemented from PLearn::Learner.

Reimplemented in PLearn::LocallyWeightedDistribution.

Definition at line 77 of file Distribution.cc.

References PLearn::Learner::outputsize_, and use_returns_what.

Referenced by build().

{
    // ### This method should do the real building of the object,
    // ### according to set 'options', in *any* situation. 
    // ### Typical situations include:
    // ###  - Initial building of an object from a few user-specified options
    // ###  - Building of a "reloaded" object: i.e. from the complete set of all serialised options.
    // ###  - Updating or "re-building" of an object after a few "tuning" options have been modified.
    // ### You should assume that the parent class' build_() has already been called.

    outputsize_ = use_returns_what.length();
}

Here is the caller graph for this function:

double PLearn::Distribution::cdf ( const Vec x) const [virtual]

return survival fn = P(X<x)

Reimplemented in PLearn::ConditionalGaussianDistribution, and PLearn::EmpiricalDistribution.

Definition at line 154 of file Distribution.cc.

References PLERROR.

Referenced by use(), and PLearn::ConditionalDistribution::use().

{ PLERROR("cdf not implemented for this Distribution"); return 0; }

Here is the caller graph for this function:

string PLearn::Distribution::classname ( ) const [virtual]
void PLearn::Distribution::declareOptions ( OptionList ol) [static, protected]

Declares this class' options.

Reimplemented from PLearn::Learner.

Reimplemented in PLearn::ConditionalGaussianDistribution, PLearn::EmpiricalDistribution, and PLearn::LocallyWeightedDistribution.

Definition at line 61 of file Distribution.cc.

References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::Learner::declareOptions(), and use_returns_what.

Referenced by PLearn::EmpiricalDistribution::declareOptions(), and PLearn::ConditionalGaussianDistribution::declareOptions().

{
    // ### 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, "use_returns_what", &Distribution::use_returns_what, OptionBase::buildoption,
                  "A string where the characters have the following meaning: \n"
                  "'l'-> log_density, 'd' -> density, 'c' -> cdf, 's' -> survival_fn, 'e' -> expectation, 'v' -> variance");
  
    // Now call the parent class' declareOptions
    inherited::declareOptions(ol);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static const PPath& PLearn::Distribution::declaringFile ( ) [inline, static]
Distribution * PLearn::Distribution::deepCopy ( CopiesMap copies) const [virtual]
double PLearn::Distribution::density ( const Vec x) const [virtual]

return probability density p(x) [ default version returns exp(log_density(x)) ]

Reimplemented in PLearn::ConditionalGaussianDistribution.

Definition at line 148 of file Distribution.cc.

References PLearn::exp(), and log_density().

Referenced by use(), and PLearn::ConditionalDistribution::use().

{ return exp(log_density(x)); }

Here is the call graph for this function:

Here is the caller graph for this function:

Vec PLearn::Distribution::expectation ( ) const [virtual]

return E[X]

Reimplemented in PLearn::ConditionalGaussianDistribution, and PLearn::EmpiricalDistribution.

Definition at line 157 of file Distribution.cc.

References PLERROR.

Referenced by PLearn::ConditionalDistribution::use().

{ PLERROR("expectation not implemented for this Distribution"); return Vec(); }

Here is the caller graph for this function:

void PLearn::Distribution::generate ( Vec x) const [virtual]

return a pseudo-random sample generated from the distribution.

Reimplemented in PLearn::ConditionalGaussianDistribution, and PLearn::EmpiricalDistribution.

Definition at line 163 of file Distribution.cc.

References PLERROR.

{ PLERROR("generate not implemented for this Distribution"); }
OptionList & PLearn::Distribution::getOptionList ( ) const [virtual]
OptionMap & PLearn::Distribution::getOptionMap ( ) const [virtual]
RemoteMethodMap & PLearn::Distribution::getRemoteMethodMap ( ) const [virtual]
double PLearn::Distribution::log_density ( const Vec x) const [virtual]

return log of probability density log(p(x))

Reimplemented in PLearn::ConditionalGaussianDistribution, PLearn::EmpiricalDistribution, and PLearn::LocallyWeightedDistribution.

Definition at line 145 of file Distribution.cc.

References PLERROR.

Referenced by density(), use(), and PLearn::ConditionalDistribution::use().

{ PLERROR("density not implemented for this Distribution"); return 0; }

Here is the caller graph for this function:

void PLearn::Distribution::makeDeepCopyFromShallowCopy ( CopiesMap copies) [virtual]
double PLearn::Distribution::survival_fn ( const Vec x) const [virtual]

return survival fn = P(X>x)

Reimplemented in PLearn::ConditionalGaussianDistribution, and PLearn::EmpiricalDistribution.

Definition at line 151 of file Distribution.cc.

References PLERROR.

Referenced by use(), and PLearn::ConditionalDistribution::use().

{ PLERROR("survival_fn not implemented for this Distribution"); return 0; }

Here is the caller graph for this function:

void PLearn::Distribution::train ( VMat  training_set) [virtual]

trains the model

Implements PLearn::Learner.

Reimplemented in PLearn::ConditionalGaussianDistribution, PLearn::EmpiricalDistribution, and PLearn::LocallyWeightedDistribution.

Definition at line 98 of file Distribution.cc.

References PLearn::Learner::inputsize(), PLERROR, PLearn::Learner::setTrainingSet(), PLearn::Learner::targetsize(), and PLearn::VMat::width().

{ 
    if(training_set->width() != inputsize()+targetsize())
        PLERROR("In Distribution::train(VMat training_set) training_set->width() != inputsize()+targetsize()");
  
    setTrainingSet(training_set);
  
    // ### Please implement the actual training of the model.
    // ### For models with incremental training, to benefit 
    // ### from the "testing during training" and early-stopping 
    // ### mechanisms, you should make sure to call measure at 
    // ### every "epoch" (whatever epoch means for your algorithm).
    // ### ex:
    // if(measure(epoch,costvec)) 
    //     break; // exit training loop because early-stopping contditions were met
}

Here is the call graph for this function:

void PLearn::Distribution::use ( const Vec input,
Vec output 
) [virtual]

computes the ouptu of a trained model

Reimplemented in PLearn::ConditionalDistribution.

Definition at line 115 of file Distribution.cc.

References cdf(), density(), i, log_density(), PLERROR, survival_fn(), and use_returns_what.

{
    int l = (int)use_returns_what.length();
    for(int i=0; i<l; i++)
    {
        switch(use_returns_what[i])
        {
        case 'l':
            output[i] = (real) log_density(input);
            break;
        case 'd':
            output[i] = (real) density(input);
            break;
        case 'c':
            output[i] = (real) cdf(input);
            break;
        case 's':
            output[i] = (real) survival_fn(input);
            break;
        default:
            PLERROR("In Distribution::use unknown use_returns_what character");
        }
    }
}

Here is the call graph for this function:

Mat PLearn::Distribution::variance ( ) const [virtual]

return Var[X]

Reimplemented in PLearn::ConditionalGaussianDistribution, and PLearn::EmpiricalDistribution.

Definition at line 160 of file Distribution.cc.

References PLERROR.

Referenced by PLearn::ConditionalDistribution::use().

{ PLERROR("variance not implemented for this Distribution"); return Mat(); }

Here is the caller graph for this function:


Member Data Documentation

A string where the characters have the following meaning: 'l'->log_density, 'd' -> density, 'c' -> cdf, 's' -> survival_fn, 'e' -> expectation, 'v' -> variance.

Definition at line 76 of file Distribution.h.

Referenced by build_(), declareOptions(), use(), and PLearn::ConditionalDistribution::use().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines