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

#include <EmpiricalDistribution.h>

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

List of all members.

Public Member Functions

 EmpiricalDistribution ()
 EmpiricalDistribution (int inputsize, bool random_sample_=true)
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual EmpiricalDistributiondeepCopy (CopiesMap &copies) const
void makeDeepCopyFromShallowCopy (CopiesMap &copies)
 Transforms a shallow copy into a deep copy.
virtual void train (VMat training_set)
 trains the model
virtual double log_density (const Vec &x) const
 return log of probability density log(p(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 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

bool random_sample
int length
int current_sample_x
int current_sample_y
bool flip

Static Public Attributes

static StaticInitializer _static_initializer_

Protected Types

typedef Distribution inherited

Static Protected Member Functions

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

Protected Attributes

VMat data

Detailed Description

Definition at line 42 of file EmpiricalDistribution.h.


Member Typedef Documentation

Reimplemented from PLearn::Distribution.

Definition at line 48 of file EmpiricalDistribution.h.


Constructor & Destructor Documentation

PLearn::EmpiricalDistribution::EmpiricalDistribution ( )

Definition at line 54 of file EmpiricalDistribution.cc.

References PLearn::seed().

    :inherited()
{
    seed();
}

Here is the call graph for this function:

PLearn::EmpiricalDistribution::EmpiricalDistribution ( int  inputsize,
bool  random_sample_ = true 
)

Definition at line 61 of file EmpiricalDistribution.cc.

References current_sample_x, current_sample_y, flip, PLearn::Learner::inputsize(), PLearn::Learner::inputsize_, and PLearn::seed().

    :inherited(), random_sample(random_sample_)
{
    inputsize_ = inputsize;
    current_sample_x = 0;
    current_sample_y = 0;
    flip = false;
    seed();
}

Here is the call graph for this function:


Member Function Documentation

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

Declares name and deepCopy methods.

Reimplemented from PLearn::Distribution.

Definition at line 45 of file EmpiricalDistribution.cc.

OptionList & PLearn::EmpiricalDistribution::_getOptionList_ ( ) [static]

Reimplemented from PLearn::Distribution.

Definition at line 45 of file EmpiricalDistribution.cc.

RemoteMethodMap & PLearn::EmpiricalDistribution::_getRemoteMethodMap_ ( ) [static]

Reimplemented from PLearn::Distribution.

Definition at line 45 of file EmpiricalDistribution.cc.

bool PLearn::EmpiricalDistribution::_isa_ ( const Object o) [static]

Reimplemented from PLearn::Distribution.

Definition at line 45 of file EmpiricalDistribution.cc.

Object * PLearn::EmpiricalDistribution::_new_instance_for_typemap_ ( ) [static]

Reimplemented from PLearn::Distribution.

Definition at line 45 of file EmpiricalDistribution.cc.

StaticInitializer EmpiricalDistribution::_static_initializer_ & PLearn::EmpiricalDistribution::_static_initialize_ ( ) [static]

Reimplemented from PLearn::Distribution.

Definition at line 45 of file EmpiricalDistribution.cc.

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

return survival fn = P(X<x)

Reimplemented from PLearn::Distribution.

Definition at line 111 of file EmpiricalDistribution.cc.

References data, i, j, PLearn::VMat::length(), and PLearn::VMat::width().

{
    double nbLower = 0;
    bool addOne;
    for(int i = 0; i<data.length(); i++){
        addOne = true;
        for(int j = 0;j<data.width(); j++){
            if(data(i,j) >= x[j])
                addOne = false;
        }
        if(addOne)
            nbLower++;
    }
    return nbLower / ((double) data.length());
}

Here is the call graph for this function:

string PLearn::EmpiricalDistribution::classname ( ) const [virtual]

Reimplemented from PLearn::Distribution.

Definition at line 45 of file EmpiricalDistribution.cc.

void PLearn::EmpiricalDistribution::declareOptions ( OptionList ol) [static, protected]

Declares this class' options.

Reimplemented from PLearn::Distribution.

Definition at line 73 of file EmpiricalDistribution.cc.

References PLearn::Distribution::declareOptions().

Here is the call graph for this function:

static const PPath& PLearn::EmpiricalDistribution::declaringFile ( ) [inline, static]

Reimplemented from PLearn::Distribution.

Definition at line 56 of file EmpiricalDistribution.h.

:
    static void declareOptions(OptionList& ol);
EmpiricalDistribution * PLearn::EmpiricalDistribution::deepCopy ( CopiesMap copies) const [virtual]

Reimplemented from PLearn::Distribution.

Definition at line 45 of file EmpiricalDistribution.cc.

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

return E[X]

Reimplemented from PLearn::Distribution.

Definition at line 128 of file EmpiricalDistribution.cc.

References PLearn::computeMean(), data, PLearn::Learner::inputsize_, and PLearn::mean().

Here is the call graph for this function:

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

return a sample generated from the distribution.

Reimplemented from PLearn::Distribution.

Definition at line 145 of file EmpiricalDistribution.cc.

References current_sample_x, current_sample_y, data, flip, length, random_sample, PLearn::TVec< T >::resize(), PLearn::uniform_multinomial_sample(), and PLearn::VMat::width().

{
    if(random_sample){
        x.resize(data.width());
        x << data(uniform_multinomial_sample(length));
    }
    //Hack for generating all the possible combinations of two
    //examples.
    else{
        if(!flip){
            x.resize(data.width());
            x << data(current_sample_x);
            flip = true;
        }
        else{
            x.resize(data.width());
            x << data(current_sample_y);
            current_sample_y++;
            flip = false;
        }
        if(current_sample_y == length){
            current_sample_y = 0;
            current_sample_x++;
        }
        if(current_sample_x == length)
            current_sample_x = 0;
    }
}

Here is the call graph for this function:

OptionList & PLearn::EmpiricalDistribution::getOptionList ( ) const [virtual]

Reimplemented from PLearn::Distribution.

Definition at line 45 of file EmpiricalDistribution.cc.

OptionMap & PLearn::EmpiricalDistribution::getOptionMap ( ) const [virtual]

Reimplemented from PLearn::Distribution.

Definition at line 45 of file EmpiricalDistribution.cc.

RemoteMethodMap & PLearn::EmpiricalDistribution::getRemoteMethodMap ( ) const [virtual]

Reimplemented from PLearn::Distribution.

Definition at line 45 of file EmpiricalDistribution.cc.

double PLearn::EmpiricalDistribution::log_density ( const Vec x) const [virtual]

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

Reimplemented from PLearn::Distribution.

Definition at line 88 of file EmpiricalDistribution.cc.

References PLERROR.

{
    PLERROR("Density not implemented for EmpiricalDistribution");
    return 0;
}
void PLearn::EmpiricalDistribution::makeDeepCopyFromShallowCopy ( CopiesMap copies) [virtual]

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::Distribution.

Definition at line 47 of file EmpiricalDistribution.cc.

References PLearn::deepCopyField().

Here is the call graph for this function:

double PLearn::EmpiricalDistribution::survival_fn ( const Vec x) const [virtual]

return survival fn = P(X>x)

Reimplemented from PLearn::Distribution.

Definition at line 95 of file EmpiricalDistribution.cc.

References data, i, j, PLearn::VMat::length(), and PLearn::VMat::width().

{
    double nbHigher = 0;
    bool addOne;
    for(int i = 0; i<data.length(); i++){
        addOne = true;
        for(int j = 0;j<data.width(); j++){
            if(data(i,j) <= x[j])
                addOne = false;
        }
        if(addOne)
            nbHigher++;
    }
    return nbHigher / ((double) data.length());
}

Here is the call graph for this function:

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

trains the model

Reimplemented from PLearn::Distribution.

Definition at line 79 of file EmpiricalDistribution.cc.

References data, PLearn::Learner::inputsize_, PLearn::VMat::length(), length, PLERROR, PLearn::VMat::subMatColumns(), PLearn::Learner::targetsize_, and PLearn::VMat::width().

{
    if(inputsize_ == 0)
        PLERROR("inputsize_ must be specified before training");
    data = training_set.subMatColumns(0, inputsize_);
    targetsize_ = data.width()-inputsize_;
    length = training_set.length();
}

Here is the call graph for this function:

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

return Var[X]

Reimplemented from PLearn::Distribution.

Definition at line 135 of file EmpiricalDistribution.cc.

References PLearn::computeMeanAndCovar(), data, PLearn::Learner::inputsize_, and PLearn::mean().

{

    Vec mean(inputsize_);
    Mat covar(inputsize_,inputsize_);
    computeMeanAndCovar(data, mean, covar);
    return covar;
}

Here is the call graph for this function:


Member Data Documentation

Reimplemented from PLearn::Distribution.

Definition at line 56 of file EmpiricalDistribution.h.

Definition at line 92 of file EmpiricalDistribution.h.

Referenced by EmpiricalDistribution(), and generate().

Definition at line 93 of file EmpiricalDistribution.h.

Referenced by EmpiricalDistribution(), and generate().

Definition at line 46 of file EmpiricalDistribution.h.

Referenced by cdf(), expectation(), generate(), survival_fn(), train(), and variance().

Definition at line 94 of file EmpiricalDistribution.h.

Referenced by EmpiricalDistribution(), and generate().

Definition at line 89 of file EmpiricalDistribution.h.

Referenced by generate(), and train().

Definition at line 86 of file EmpiricalDistribution.h.

Referenced by generate().


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