PLearn 0.1
|
#include <BootstrapSplitter.h>
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 OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual BootstrapSplitter * | deepCopy (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< VMat > | getSplit (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 PPath & | declaringFile () |
Public Attributes | |
real | frac |
int | n_splits |
bool | allow_repetitions |
int | seed |
PP< PRandom > | rgen |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
Declares this class' options. | |
Protected Attributes | |
TMat< VMat > | bootstrapped_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. |
Definition at line 53 of file BootstrapSplitter.h.
typedef Splitter PLearn::BootstrapSplitter::inherited [private] |
Reimplemented from PLearn::Splitter.
Definition at line 55 of file BootstrapSplitter.h.
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()) {}
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.
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().
{ inherited::build(); build_(); }
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); } }
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); }
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.
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); }
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.
{ inherited::makeDeepCopyFromShallowCopy(copies); deepCopyField(bootstrapped_sets, copies); deepCopyField(rgen, copies); }
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. }
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().
TMat<VMat> PLearn::BootstrapSplitter::bootstrapped_sets [protected] |
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().