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

#include <BootstrapSplitter.h>

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

List of all members.

Public Member Functions

 BootstrapSplitter ()
virtual void build ()
 Post-constructor.
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 BootstrapSplitterdeepCopy (CopiesMap &copies) const
virtual void setDataSet (VMat the_dataset)
 Sets the dataset on which the splits are to be based.
virtual int nsplits () const
 Returns the number of available different "splits".
virtual int nSetsPerSplit () const
 Returns the number of sets per split.
virtual TVec< VMatgetSplit (int i=0)
 Returns split number i.

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

real frac
int n_splits
bool allow_repetitions
int seed
PP< PRandomrgen

Static Public Attributes

static StaticInitializer _static_initializer_

Static Protected Member Functions

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

Protected Attributes

TMat< VMatbootstrapped_sets
 A (n_splits x 1) matrix containing all the splits, constructed at build time.

Private Types

typedef Splitter inherited

Private Member Functions

void build_ ()
 This does the actual building.

Detailed Description

Definition at line 53 of file BootstrapSplitter.h.


Member Typedef Documentation

Reimplemented from PLearn::Splitter.

Definition at line 55 of file BootstrapSplitter.h.


Constructor & Destructor Documentation

PLearn::BootstrapSplitter::BootstrapSplitter ( )

Definition at line 50 of file BootstrapSplitter.cc.

                                    :
    frac(0.6667),
    n_splits(0),
    allow_repetitions(false),
    seed(1827),
    rgen(new PRandom())
{}

Member Function Documentation

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

Declares name and deepCopy methods.

Reimplemented from PLearn::Splitter.

Definition at line 64 of file BootstrapSplitter.cc.

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

Reimplemented from PLearn::Splitter.

Definition at line 64 of file BootstrapSplitter.cc.

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

Reimplemented from PLearn::Splitter.

Definition at line 64 of file BootstrapSplitter.cc.

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

Reimplemented from PLearn::Splitter.

Definition at line 64 of file BootstrapSplitter.cc.

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

Reimplemented from PLearn::Object.

Definition at line 64 of file BootstrapSplitter.cc.

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

Reimplemented from PLearn::Splitter.

Definition at line 64 of file BootstrapSplitter.cc.

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

Post-constructor.

The normal implementation should call simply inherited::build(), then this class's build_(). This method should be callable again at later times, after modifying some option fields to change the "architecture" of the object.

Reimplemented from PLearn::Object.

Definition at line 115 of file BootstrapSplitter.cc.

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

Referenced by setDataSet().

Here is the call graph for this function:

Here is the caller graph for this function:

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

This does the actual building.

Reimplemented from PLearn::Object.

Definition at line 92 of file BootstrapSplitter.cc.

References allow_repetitions, bootstrapped_sets, PLearn::Splitter::dataset, frac, i, n_splits, PLearn::TMat< T >::resize(), rgen, and seed.

Referenced by build().

{
    if (dataset) {
        rgen->manual_seed(seed);
        bootstrapped_sets.resize(0,0); // First clear the current sets.
        bootstrapped_sets.resize(n_splits,1);
        for (int i = 0; i < n_splits; i++) {
            // Construct a new bootstrap sample from the dataset.
            PP<PRandom> vmat_rgen= rgen->split();
            // Note: indices in the bootstrapped sets are sorted, so that
            // access may be faster (e.g. when reading large data from disk).
            bootstrapped_sets(i,0) = 
                new BootstrapVMatrix(dataset,frac,vmat_rgen, 
                                     false, allow_repetitions);
        }
    } else {
        bootstrapped_sets.resize(0,0);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 64 of file BootstrapSplitter.cc.

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

Declares this class' options.

Reimplemented from PLearn::Splitter.

Definition at line 69 of file BootstrapSplitter.cc.

References allow_repetitions, PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::Splitter::declareOptions(), frac, n_splits, and seed.

{
    declareOption(ol, "n_splits", &BootstrapSplitter::n_splits, OptionBase::buildoption,
                  "Number of splits wanted.");

    declareOption(ol, "frac", &BootstrapSplitter::frac, OptionBase::buildoption,
                  "Fraction of elements to take in each bootstrap.");

    declareOption(ol, "allow_repetitions", &BootstrapSplitter::allow_repetitions, 
                  OptionBase::buildoption,
                  "Allows each row to appear more than once per split.");

    declareOption(ol, "seed", &BootstrapSplitter::seed, 
                  OptionBase::buildoption,
                  "Seed for the random number generator.");

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

Here is the call graph for this function:

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

Reimplemented from PLearn::Splitter.

Definition at line 113 of file BootstrapSplitter.h.

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

Reimplemented from PLearn::Splitter.

Definition at line 64 of file BootstrapSplitter.cc.

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

Reimplemented from PLearn::Object.

Definition at line 64 of file BootstrapSplitter.cc.

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

Reimplemented from PLearn::Object.

Definition at line 64 of file BootstrapSplitter.cc.

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

Reimplemented from PLearn::Object.

Definition at line 64 of file BootstrapSplitter.cc.

TVec< VMat > PLearn::BootstrapSplitter::getSplit ( int  i = 0) [virtual]

Returns split number i.

Implements PLearn::Splitter.

Definition at line 148 of file BootstrapSplitter.cc.

References bootstrapped_sets, PLearn::TMat< T >::length(), n_splits, and PLERROR.

{
    // ### Build and return the kth split
    if (k >= n_splits) {
        PLERROR("BootstrapSplitter::getSplit: k is too high");
    } else if (k >= bootstrapped_sets.length()) {
        PLERROR("BootstrapSplitter::getSplit: you asked for a split but they're not ready yet");
    }
    return bootstrapped_sets(k);
}

Here is the call graph for this function:

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

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::Splitter.

Definition at line 124 of file BootstrapSplitter.cc.

References bootstrapped_sets, PLearn::deepCopyField(), PLearn::Splitter::makeDeepCopyFromShallowCopy(), and rgen.

Here is the call graph for this function:

int PLearn::BootstrapSplitter::nSetsPerSplit ( ) const [virtual]

Returns the number of sets per split.

Implements PLearn::Splitter.

Definition at line 142 of file BootstrapSplitter.cc.

{
    // One single set per split.
    return 1;
}
int PLearn::BootstrapSplitter::nsplits ( ) const [virtual]

Returns the number of available different "splits".

Implements PLearn::Splitter.

Definition at line 134 of file BootstrapSplitter.cc.

References n_splits.

{
    return n_splits;
}
void PLearn::BootstrapSplitter::setDataSet ( VMat  the_dataset) [virtual]

Sets the dataset on which the splits are to be based.

Reimplemented from PLearn::Splitter.

Definition at line 162 of file BootstrapSplitter.cc.

References build(), and PLearn::Splitter::setDataSet().

                                                   {
    inherited::setDataSet(the_dataset);
    build(); // necessary to recompute the bootstrap samples.
}

Here is the call graph for this function:


Member Data Documentation

Reimplemented from PLearn::Splitter.

Definition at line 113 of file BootstrapSplitter.h.

Definition at line 78 of file BootstrapSplitter.h.

Referenced by build_(), and declareOptions().

A (n_splits x 1) matrix containing all the splits, constructed at build time.

Definition at line 61 of file BootstrapSplitter.h.

Referenced by build_(), getSplit(), and makeDeepCopyFromShallowCopy().

Definition at line 76 of file BootstrapSplitter.h.

Referenced by build_(), and declareOptions().

Definition at line 77 of file BootstrapSplitter.h.

Referenced by build_(), declareOptions(), getSplit(), and nsplits().

Definition at line 80 of file BootstrapSplitter.h.

Referenced by build_(), and makeDeepCopyFromShallowCopy().

Definition at line 79 of file BootstrapSplitter.h.

Referenced by build_(), and declareOptions().


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