PLearn 0.1
|
#include <TestInTrainSplitter.h>
Public Member Functions | |
TestInTrainSplitter () | |
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 TestInTrainSplitter * | deepCopy (CopiesMap &copies) const |
virtual void | setDataSet (VMat the_dataset) |
Overridden to forward to underlying splitter and reset 'first_source_split'. | |
virtual int | nsplits () const |
Returns the number of available different "splits". | |
virtual int | nSetsPerSplit () const |
Returns the number of sets per split. | |
virtual void | getFirstSplit () const |
Compute the first split of source_splitter and store it in 'first_source_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 | percentage_added |
PP< Splitter > | source_splitter |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
Declares this class' options. | |
Protected Attributes | |
TVec< VMat > | first_source_split |
Store the first split provided by the source_splitter. | |
int | n_left |
The number of samples in the test set that would be left if we didn't make sure they were all added once. | |
int | n_splits_per_source_split |
The number of splits to make for each split given by the source_splitter. | |
int | n_train |
The number of samples in the train and test parts, as given by the source_splitter. | |
int | n_test |
int | n_to_add |
The number of sample to add each time in the train set. | |
Private Types | |
typedef Splitter | inherited |
Private Member Functions | |
void | build_ () |
This does the actual building. |
Definition at line 52 of file TestInTrainSplitter.h.
typedef Splitter PLearn::TestInTrainSplitter::inherited [private] |
Reimplemented from PLearn::Splitter.
Definition at line 57 of file TestInTrainSplitter.h.
PLearn::TestInTrainSplitter::TestInTrainSplitter | ( | ) |
Definition at line 51 of file TestInTrainSplitter.cc.
: percentage_added(0.1) /* ### Initialize all fields to their default value */ { // ... // ### You may or may not want to call build_() to finish building the object // build_(); }
string PLearn::TestInTrainSplitter::_classname_ | ( | ) | [static] |
Declares name and deepCopy methods.
Reimplemented from PLearn::Splitter.
Definition at line 73 of file TestInTrainSplitter.cc.
OptionList & PLearn::TestInTrainSplitter::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::Splitter.
Definition at line 73 of file TestInTrainSplitter.cc.
RemoteMethodMap & PLearn::TestInTrainSplitter::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::Splitter.
Definition at line 73 of file TestInTrainSplitter.cc.
Reimplemented from PLearn::Splitter.
Definition at line 73 of file TestInTrainSplitter.cc.
Object * PLearn::TestInTrainSplitter::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 73 of file TestInTrainSplitter.cc.
StaticInitializer TestInTrainSplitter::_static_initializer_ & PLearn::TestInTrainSplitter::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::Splitter.
Definition at line 73 of file TestInTrainSplitter.cc.
void PLearn::TestInTrainSplitter::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 105 of file TestInTrainSplitter.cc.
References PLearn::Object::build(), and build_().
{ inherited::build(); build_(); }
void PLearn::TestInTrainSplitter::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::Object.
Definition at line 94 of file TestInTrainSplitter.cc.
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. }
string PLearn::TestInTrainSplitter::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 73 of file TestInTrainSplitter.cc.
void PLearn::TestInTrainSplitter::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares this class' options.
Reimplemented from PLearn::Splitter.
Definition at line 75 of file TestInTrainSplitter.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::Splitter::declareOptions(), percentage_added, and source_splitter.
{ // ### 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, "percentage_added", &TestInTrainSplitter::percentage_added, OptionBase::buildoption, "The ratio between the number of examples in the test set added to the train set and the\n" "number of examples in the train set."); declareOption(ol, "source_splitter", &TestInTrainSplitter::source_splitter, OptionBase::buildoption, "The underlying splitter."); // Now call the parent class' declareOptions inherited::declareOptions(ol); }
static const PPath& PLearn::TestInTrainSplitter::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::Splitter.
Definition at line 128 of file TestInTrainSplitter.h.
TestInTrainSplitter * PLearn::TestInTrainSplitter::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::Splitter.
Definition at line 73 of file TestInTrainSplitter.cc.
void PLearn::TestInTrainSplitter::getFirstSplit | ( | ) | const [virtual] |
Compute the first split of source_splitter and store it in 'first_source_split'.
Definition at line 162 of file TestInTrainSplitter.cc.
References first_source_split, PLearn::TVec< T >::length(), n_test, n_train, and source_splitter.
Referenced by getSplit(), and nsplits().
{ first_source_split = source_splitter->getSplit(0); n_train = first_source_split[0]->length(); n_test = first_source_split[1]->length(); }
OptionList & PLearn::TestInTrainSplitter::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 73 of file TestInTrainSplitter.cc.
OptionMap & PLearn::TestInTrainSplitter::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 73 of file TestInTrainSplitter.cc.
RemoteMethodMap & PLearn::TestInTrainSplitter::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 73 of file TestInTrainSplitter.cc.
Returns split number i.
Implements PLearn::Splitter.
Definition at line 171 of file TestInTrainSplitter.cc.
References first_source_split, getFirstSplit(), i, PLearn::TVec< T >::isEmpty(), PLearn::TVec< T >::length(), PLearn::VMat::length(), n_left, n_splits_per_source_split, n_test, n_to_add, n_train, PLERROR, source_splitter, PLearn::vconcat(), and PLearn::VMat::width().
{ TVec<VMat> source_split; if (first_source_split.isEmpty()) { getFirstSplit(); } if (k == 0) { source_split = first_source_split; } else { source_split = source_splitter->getSplit(k / n_splits_per_source_split); } int n_test_part = k % n_splits_per_source_split; int i_test_start = n_test_part * n_to_add; VMat train_set = source_split[0]; VMat test_set = source_split[1]; if (train_set->length() != n_train || test_set->length() != n_test) { PLERROR("In TestInTrainSplitter::getSplit - The train / test sizes have changed!"); } TVec<VMat> result(source_split.length()); if (n_to_add == 0) { // Do not change the split. result[0] = train_set; result[1] = test_set; } else if (n_left == 0 || n_test_part != n_splits_per_source_split - 1) { // Easy case: we add the same subset in train that the one for test. VMat added_to_train = new SubVMatrix(test_set, i_test_start, 0, n_to_add, test_set->width()); result[0] = vconcat(train_set, added_to_train); result[1] = added_to_train; } else { // We also take the beginning of the test to fill added_to_train, // so that we add the correct number of points in the training set. VMat new_test = new SubVMatrix(test_set, i_test_start, 0, n_left, test_set->width()); result[1] = new_test; VMat compl_for_train = new SubVMatrix(test_set, 0, 0, n_to_add - n_left, test_set->width()); VMat added_to_train = vconcat(new_test, compl_for_train); result[0] = vconcat(train_set, added_to_train); } for (int i = 2; i < result.length(); i++) { result[i] = source_split[i]; } return result; }
void PLearn::TestInTrainSplitter::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::Splitter.
Definition at line 111 of file TestInTrainSplitter.cc.
References PLearn::Splitter::makeDeepCopyFromShallowCopy(), and PLERROR.
{ inherited::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("TestInTrainSplitter::makeDeepCopyFromShallowCopy not fully (correctly) implemented yet!"); }
int PLearn::TestInTrainSplitter::nSetsPerSplit | ( | ) | const [virtual] |
Returns the number of sets per split.
Implements PLearn::Splitter.
Definition at line 154 of file TestInTrainSplitter.cc.
References source_splitter.
{ return source_splitter->nSetsPerSplit(); }
int PLearn::TestInTrainSplitter::nsplits | ( | ) | const [virtual] |
Returns the number of available different "splits".
Implements PLearn::Splitter.
Definition at line 128 of file TestInTrainSplitter.cc.
References first_source_split, getFirstSplit(), PLearn::TVec< T >::isEmpty(), n_left, n_splits_per_source_split, n_test, n_to_add, n_train, percentage_added, PLERROR, and source_splitter.
{ if (first_source_split.isEmpty()) { getFirstSplit(); // This is just to initialize n_train and n_test. } n_to_add = int(n_train * percentage_added + 0.5); if (n_to_add == 0) { // Do NOT add points in the train set. n_splits_per_source_split = 1; n_left = 0; } else { n_splits_per_source_split = n_test / n_to_add; n_left = n_test % n_to_add; } if (n_splits_per_source_split == 0) { PLERROR("In TestInTrainSplitter::nsplits - Asked to add more test samples than available"); } if (n_left > 0) n_splits_per_source_split++; int n_total = n_splits_per_source_split * source_splitter->nsplits(); return n_total; }
void PLearn::TestInTrainSplitter::setDataSet | ( | VMat | the_dataset | ) | [virtual] |
Overridden to forward to underlying splitter and reset 'first_source_split'.
Reimplemented from PLearn::Splitter.
Definition at line 217 of file TestInTrainSplitter.cc.
References first_source_split, PLearn::TVec< T >::resize(), PLearn::Splitter::setDataSet(), and source_splitter.
{ first_source_split.resize(0); inherited::setDataSet(the_dataset); source_splitter->setDataSet(the_dataset); }
Reimplemented from PLearn::Splitter.
Definition at line 128 of file TestInTrainSplitter.h.
TVec<VMat> PLearn::TestInTrainSplitter::first_source_split [mutable, protected] |
Store the first split provided by the source_splitter.
This is because we need it the number of points in the train and test parts in the nsplits() method.
Definition at line 72 of file TestInTrainSplitter.h.
Referenced by getFirstSplit(), getSplit(), nsplits(), and setDataSet().
int PLearn::TestInTrainSplitter::n_left [mutable, protected] |
The number of samples in the test set that would be left if we didn't make sure they were all added once.
Definition at line 76 of file TestInTrainSplitter.h.
Referenced by getSplit(), and nsplits().
int PLearn::TestInTrainSplitter::n_splits_per_source_split [mutable, protected] |
The number of splits to make for each split given by the source_splitter.
Definition at line 79 of file TestInTrainSplitter.h.
Referenced by getSplit(), and nsplits().
int PLearn::TestInTrainSplitter::n_test [mutable, protected] |
Definition at line 83 of file TestInTrainSplitter.h.
Referenced by getFirstSplit(), getSplit(), and nsplits().
int PLearn::TestInTrainSplitter::n_to_add [mutable, protected] |
The number of sample to add each time in the train set.
Definition at line 86 of file TestInTrainSplitter.h.
Referenced by getSplit(), and nsplits().
int PLearn::TestInTrainSplitter::n_train [mutable, protected] |
The number of samples in the train and test parts, as given by the source_splitter.
Definition at line 83 of file TestInTrainSplitter.h.
Referenced by getFirstSplit(), getSplit(), and nsplits().
Definition at line 94 of file TestInTrainSplitter.h.
Referenced by declareOptions(), and nsplits().
Definition at line 95 of file TestInTrainSplitter.h.
Referenced by declareOptions(), getFirstSplit(), getSplit(), nSetsPerSplit(), nsplits(), and setDataSet().