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

#include <NeighborhoodBoxVolumeDensityEstimator.h>

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

List of all members.

Public Member Functions

 NeighborhoodBoxVolumeDensityEstimator ()
 Default constructor.
virtual void build ()
 Simply call inherited::build() then build_().
virtual void makeDeepCopyFromShallowCopy (CopiesMap &copies)
 Transform a shallow copy into a deep copy.
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual
NeighborhoodBoxVolumeDensityEstimator
deepCopy (CopiesMap &copies) const
virtual real log_density (const Vec &x) const
 Return log of probability density log(p(y | x)).
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 void forget ()
 Resets the distribution.

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

Public Attributes

int nneighbors
real min_radius

Static Public Attributes

static StaticInitializer _static_initializer_

Protected Member Functions

bool box_contains (const Vec &center, const Vec &radius, const Vec &input) const
 Returns true if input is contained in the box specified by center and radius.

Static Protected Member Functions

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

Protected Attributes

PP< GenericNearestNeighborsNN
Vec NN_outputs

Private Types

typedef UnconditionalDistribution inherited

Private Member Functions

void build_ ()
 This does the actual building.

Private Attributes

Vec trainsample
 Global storage to save memory allocations.

Detailed Description

Definition at line 53 of file NeighborhoodBoxVolumeDensityEstimator.h.


Member Typedef Documentation

Reimplemented from PLearn::UnconditionalDistribution.

Definition at line 58 of file NeighborhoodBoxVolumeDensityEstimator.h.


Constructor & Destructor Documentation

PLearn::NeighborhoodBoxVolumeDensityEstimator::NeighborhoodBoxVolumeDensityEstimator ( )

Default constructor.

Definition at line 56 of file NeighborhoodBoxVolumeDensityEstimator.cc.

References NN.

    :nneighbors(1),
     min_radius(1e-6)
{
    // for default use Exhaustive search and default Euclidean distance
    NN = new ExhaustiveNearestNeighbors(); 
}

Member Function Documentation

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

Reimplemented from PLearn::UnconditionalDistribution.

Definition at line 68 of file NeighborhoodBoxVolumeDensityEstimator.cc.

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

Reimplemented from PLearn::UnconditionalDistribution.

Definition at line 68 of file NeighborhoodBoxVolumeDensityEstimator.cc.

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

Reimplemented from PLearn::UnconditionalDistribution.

Definition at line 68 of file NeighborhoodBoxVolumeDensityEstimator.cc.

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

Reimplemented from PLearn::UnconditionalDistribution.

Definition at line 68 of file NeighborhoodBoxVolumeDensityEstimator.cc.

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

Reimplemented from PLearn::UnconditionalDistribution.

Definition at line 68 of file NeighborhoodBoxVolumeDensityEstimator.cc.

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

Reimplemented from PLearn::UnconditionalDistribution.

Definition at line 68 of file NeighborhoodBoxVolumeDensityEstimator.cc.

bool PLearn::NeighborhoodBoxVolumeDensityEstimator::box_contains ( const Vec center,
const Vec radius,
const Vec input 
) const [protected]

Returns true if input is contained in the box specified by center and radius.

Definition at line 140 of file NeighborhoodBoxVolumeDensityEstimator.cc.

References j, PLearn::TVec< T >::length(), and w.

Referenced by log_density().

{
    int w = center.length();
    for(int j=0; j<w; j++)
        if(fabs(input[j]-center[j])>radius[j])
            return false;
    return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Simply call inherited::build() then build_().

Reimplemented from PLearn::UnconditionalDistribution.

Definition at line 100 of file NeighborhoodBoxVolumeDensityEstimator.cc.

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

{
    // ### Nothing to add here, simply calls build_().
    inherited::build();
    build_();
}

Here is the call graph for this function:

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

This does the actual building.

Reimplemented from PLearn::UnconditionalDistribution.

Definition at line 110 of file NeighborhoodBoxVolumeDensityEstimator.cc.

References PLearn::PP< T >::isNull(), NN, NN_outputs, nneighbors, PLearn::TVec< T >::resize(), and PLearn::PLearner::train_set.

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.

    // ### If the distribution is conditional, you should finish build_() by:
    // PDistribution::finishConditionalBuild();

    NN->num_neighbors = nneighbors;
    NN->copy_input = false;
    NN->copy_target = false;
    NN->copy_weight = false;
    NN->copy_index = true;
    NN->build();
    if(!train_set.isNull())
    {
        NN->setTrainingSet(train_set);
        NN->train();
    }
    NN_outputs.resize(nneighbors);
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Reimplemented from PLearn::UnconditionalDistribution.

Definition at line 68 of file NeighborhoodBoxVolumeDensityEstimator.cc.

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

Declare this class' options.

Reimplemented from PLearn::UnconditionalDistribution.

Definition at line 73 of file NeighborhoodBoxVolumeDensityEstimator.cc.

References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::UnconditionalDistribution::declareOptions(), PLearn::OptionBase::learntoption, min_radius, NN, nneighbors, and PLearn::PLearner::train_set.

{
    // ### 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, "nneighbors", &NeighborhoodBoxVolumeDensityEstimator::nneighbors, OptionBase::buildoption,
                  "Number of neighbors to consider to determine the boxed region centered on the test point");

    declareOption(ol, "min_radius", &NeighborhoodBoxVolumeDensityEstimator::min_radius, OptionBase::buildoption,
                  "This is added to each dimension of the found box (as some dimensions may be initially 0)");

    declareOption(ol, "train_set", &NeighborhoodBoxVolumeDensityEstimator::train_set, OptionBase::learntoption,
                  "We need to store the training set, as this learner is memory-based...");

    declareOption(ol, "NN", &NeighborhoodBoxVolumeDensityEstimator::NN, OptionBase::buildoption,
                  "The nearest neighbor search method to use (default uses ehaustive search with Euclidean distance)");

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

Here is the call graph for this function:

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

Reimplemented from PLearn::UnconditionalDistribution.

Definition at line 124 of file NeighborhoodBoxVolumeDensityEstimator.h.

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

Reimplemented from PLearn::UnconditionalDistribution.

Definition at line 68 of file NeighborhoodBoxVolumeDensityEstimator.cc.

void PLearn::NeighborhoodBoxVolumeDensityEstimator::forget ( ) [virtual]

Resets the distribution.

Reimplemented from PLearn::UnconditionalDistribution.

Definition at line 215 of file NeighborhoodBoxVolumeDensityEstimator.cc.

References NN.

{
    NN->forget();
}
OptionList & PLearn::NeighborhoodBoxVolumeDensityEstimator::getOptionList ( ) const [virtual]

Reimplemented from PLearn::UnconditionalDistribution.

Definition at line 68 of file NeighborhoodBoxVolumeDensityEstimator.cc.

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

Reimplemented from PLearn::UnconditionalDistribution.

Definition at line 68 of file NeighborhoodBoxVolumeDensityEstimator.cc.

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

Reimplemented from PLearn::UnconditionalDistribution.

Definition at line 68 of file NeighborhoodBoxVolumeDensityEstimator.cc.

real PLearn::NeighborhoodBoxVolumeDensityEstimator::log_density ( const Vec x) const [virtual]

Return log of probability density log(p(y | x)).

Reimplemented from PLearn::PDistribution.

Definition at line 150 of file NeighborhoodBoxVolumeDensityEstimator.cc.

References box_contains(), d, i, PLearn::PLearner::inputsize(), j, PLearn::TVec< T >::length(), PLearn::VMat::length(), PLearn::max(), min_radius, NN, NN_outputs, pl_log, PLearn::TVec< T >::resize(), PLearn::TVec< T >::subVec(), PLearn::PLearner::train_set, trainsample, w, and PLearn::ws().

{
    int l = train_set.length();
    int w = inputsize();
    int ws = train_set->weightsize();
    trainsample.resize(w+ws);
    Vec input = trainsample.subVec(0,w);

    // Find distance d to width_neighbor neighbour
    NN->computeOutput(y, NN_outputs);

    Vec radius(w);
    for(int k=0; k<NN_outputs.length(); k++)
    {
        train_set->getRow((int)NN_outputs[k],trainsample);
        for(int j=0; j<w; j++)
        {
            real d = fabs(y[j]-input[j]);
            radius[j] = max(radius[j],d);
        }
    }
    radius += min_radius;
    
    int region_count = 0;
    for(int i=0; i<l; i++)
    {
        train_set->getRow(i,trainsample);
        if(box_contains(y,radius,input))
            region_count++;
    }
    
    double log_region_volume = 0;
    for(int j=0; j<w; j++)
        log_region_volume += pl_log(radius[j]);

    return pl_log(double(region_count))-log_region_volume-pl_log(double(l));
}

Here is the call graph for this function:

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

Transform a shallow copy into a deep copy.

Reimplemented from PLearn::UnconditionalDistribution.

Definition at line 191 of file NeighborhoodBoxVolumeDensityEstimator.cc.

References PLearn::deepCopyField(), PLearn::UnconditionalDistribution::makeDeepCopyFromShallowCopy(), and NN.

{
    inherited::makeDeepCopyFromShallowCopy(copies);

    // ### Call deepCopyField on all "pointer-like" fields
    // ### that you wish to be deepCopied rather than
    // ### shallow-copied.
    // ### ex:
    // deepCopyField(trainvec, copies);
    deepCopyField(NN, copies);
}

Here is the call graph for this function:

void PLearn::NeighborhoodBoxVolumeDensityEstimator::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 208 of file NeighborhoodBoxVolumeDensityEstimator.cc.

References NN, and PLearn::PLearner::train_set.

{
    NN->setTrainingSet(train_set);
    NN->train();
}

Member Data Documentation

Reimplemented from PLearn::UnconditionalDistribution.

Definition at line 124 of file NeighborhoodBoxVolumeDensityEstimator.h.

Definition at line 80 of file NeighborhoodBoxVolumeDensityEstimator.h.

Referenced by declareOptions(), and log_density().

Definition at line 70 of file NeighborhoodBoxVolumeDensityEstimator.h.

Referenced by build_(), and log_density().

Definition at line 79 of file NeighborhoodBoxVolumeDensityEstimator.h.

Referenced by build_(), and declareOptions().

Global storage to save memory allocations.

Definition at line 61 of file NeighborhoodBoxVolumeDensityEstimator.h.

Referenced by log_density().


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