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

#include <LocallyWeightedDistribution.h>

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

List of all members.

Public Member Functions

 LocallyWeightedDistribution ()
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
LocallyWeightedDistribution
deepCopy (CopiesMap &copies) const
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))

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

Ker weighting_kernel
 The kernel that will be used to locally weigh the samples.
PP< Distributionlocaldistr
 The distribution that will be trained with local weights.

Static Public Attributes

static StaticInitializer _static_initializer_

Static Protected Member Functions

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

Private Types

typedef Distribution inherited

Private Member Functions

void build_ ()
 This does the actual building.

Private Attributes

Vec trainsample
 Global storage to save memory allocations.
Vec weights

Detailed Description

Definition at line 52 of file LocallyWeightedDistribution.h.


Member Typedef Documentation

Reimplemented from PLearn::Distribution.

Definition at line 57 of file LocallyWeightedDistribution.h.


Constructor & Destructor Documentation

PLearn::LocallyWeightedDistribution::LocallyWeightedDistribution ( )

Definition at line 47 of file LocallyWeightedDistribution.cc.

{}

Member Function Documentation

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

Declares name and deepCopy methods.

Reimplemented from PLearn::Distribution.

Definition at line 51 of file LocallyWeightedDistribution.cc.

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

Reimplemented from PLearn::Distribution.

Definition at line 51 of file LocallyWeightedDistribution.cc.

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

Reimplemented from PLearn::Distribution.

Definition at line 51 of file LocallyWeightedDistribution.cc.

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

Reimplemented from PLearn::Distribution.

Definition at line 51 of file LocallyWeightedDistribution.cc.

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

Reimplemented from PLearn::Distribution.

Definition at line 51 of file LocallyWeightedDistribution.cc.

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

Reimplemented from PLearn::Distribution.

Definition at line 51 of file LocallyWeightedDistribution.cc.

void PLearn::LocallyWeightedDistribution::build ( ) [virtual]

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

Reimplemented from PLearn::Distribution.

Definition at line 84 of file LocallyWeightedDistribution.cc.

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

This does the actual building.

Reimplemented from PLearn::Distribution.

Definition at line 65 of file LocallyWeightedDistribution.cc.

References PLERROR.

{
    // ### 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.

    if(weightsize()!=0 && weightsize()!=1)
        PLERROR("In LocallyWeightedDistribution::build_, weightsize must be 0 or 1");

    localdistr->inputsize_ = inputsize_;
    localdistr->weightsize_ = 1;
    localdistr->build();
}
string PLearn::LocallyWeightedDistribution::classname ( ) const [virtual]

Reimplemented from PLearn::Distribution.

Definition at line 51 of file LocallyWeightedDistribution.cc.

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

Declares this class' options.

Reimplemented from PLearn::Distribution.

Definition at line 53 of file LocallyWeightedDistribution.cc.

References PLearn::OptionBase::buildoption, PLearn::declareOption(), localdistr, and weighting_kernel.

{
    declareOption(ol, "weighting_kernel", &LocallyWeightedDistribution::weighting_kernel, OptionBase::buildoption,
                  "The kernel that will be used to locally weigh the samples");

    declareOption(ol, "localdistr", &LocallyWeightedDistribution::localdistr, OptionBase::buildoption,
                  "The distribution that will be trianed with local weights");

    // Now call the parent class' declareOptions
    inherited::declareOptions(ol);
}

Here is the call graph for this function:

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

Reimplemented from PLearn::Distribution.

Definition at line 106 of file LocallyWeightedDistribution.h.

:654)
LocallyWeightedDistribution * PLearn::LocallyWeightedDistribution::deepCopy ( CopiesMap copies) const [virtual]

Reimplemented from PLearn::Distribution.

Definition at line 51 of file LocallyWeightedDistribution.cc.

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

Reimplemented from PLearn::Distribution.

Definition at line 51 of file LocallyWeightedDistribution.cc.

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

Reimplemented from PLearn::Distribution.

Definition at line 51 of file LocallyWeightedDistribution.cc.

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

Reimplemented from PLearn::Distribution.

Definition at line 51 of file LocallyWeightedDistribution.cc.

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

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

Reimplemented from PLearn::Distribution.

Definition at line 114 of file LocallyWeightedDistribution.cc.

References PLearn::columnmatrix(), PLearn::hconcat(), i, PLearn::TVec< T >::subVec(), and w.

{
    int l = train_set.length();
    int w = inputsize();
    weights.resize(l);
    // 'weights' will contain the "localization" weights for the current test point.
    trainsample.resize(w+weightsize());
    Vec input = trainsample.subVec(0,w);

    for(int i=0; i<l; i++)
    {
        train_set->getRow(i,trainsample);
        real weight = weighting_kernel(x,input);
        if(weightsize()==1)
            weight *= trainsample[w];
        weights[i] = weight;
    }
  
    VMat weight_column(columnmatrix(weights));

    VMat weighted_trainset;
    if(weightsize()==0) // append weight column    
        weighted_trainset = hconcat(train_set, weight_column);
    else // replace last column by weight column
        weighted_trainset = hconcat(train_set.subMatColumns(0,inputsize()), weight_column);

    localdistr->forget();
    localdistr->train(weighted_trainset);
    return localdistr->log_density(x);
}

Here is the call graph for this function:

void PLearn::LocallyWeightedDistribution::makeDeepCopyFromShallowCopy ( CopiesMap copies) [virtual]

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::Distribution.

Definition at line 99 of file LocallyWeightedDistribution.cc.

References PLearn::Distribution::makeDeepCopyFromShallowCopy(), and PLERROR.

{
    Distribution::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("LocallyWeightedDistribution::makeDeepCopyFromShallowCopy not fully (correctly) implemented yet!");
}

Here is the call graph for this function:

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

trains the model

Reimplemented from PLearn::Distribution.

Definition at line 91 of file LocallyWeightedDistribution.cc.

References PLERROR, and PLearn::VMat::width().

{ 
    if(training_set.width() != inputsize()+weightsize())
        PLERROR("In LocallyWeightedDistribution::train width of training set is different from inputsize()+weightsize()");
    setTrainingSet(training_set);
}

Here is the call graph for this function:


Member Data Documentation

Reimplemented from PLearn::Distribution.

Definition at line 106 of file LocallyWeightedDistribution.h.

The distribution that will be trained with local weights.

Definition at line 73 of file LocallyWeightedDistribution.h.

Referenced by declareOptions().

Global storage to save memory allocations.

Definition at line 60 of file LocallyWeightedDistribution.h.

The kernel that will be used to locally weigh the samples.

Definition at line 70 of file LocallyWeightedDistribution.h.

Referenced by declareOptions().

Definition at line 60 of file LocallyWeightedDistribution.h.


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