PLearn 0.1
|
Splitter that separates examples of some classes (test) from the examples of other classes (train). More...
#include <ClassSeparationSplitter.h>
Public Member Functions | |
ClassSeparationSplitter () | |
Default constructor. | |
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. | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual ClassSeparationSplitter * | deepCopy (CopiesMap &copies) const |
virtual void | build () |
Post-constructor. | |
virtual void | makeDeepCopyFromShallowCopy (CopiesMap &copies) |
Transforms a shallow copy into a deep copy. | |
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 PPath & | declaringFile () |
Public Attributes | |
TVec< TVec< int > > | classes |
Classes to isolate from the others. | |
int | numsplits |
Number of splits. If <= 0, then it is set to nclasses. | |
int | nclasses |
Number of classes. Ignored if classes if defined. | |
int | nclasses_test_set |
Number of classes in the test sets. | |
bool | select_classes_randomly |
Indication that the classes should be chosen at random. | |
bool | append_train |
Indication that the training set should be appended to the split sets lists. | |
int32_t | seed |
Seed of random generator. | |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
Declares the class options. | |
Protected Attributes | |
PP< PRandom > | random_gen |
Private Types | |
typedef Splitter | inherited |
Private Member Functions | |
void | build_ () |
This does the actual building. |
Splitter that separates examples of some classes (test) from the examples of other classes (train).
This splitter is intended to measure inductive transfer performance from some tasks to other tasks.
Definition at line 56 of file ClassSeparationSplitter.h.
typedef Splitter PLearn::ClassSeparationSplitter::inherited [private] |
Reimplemented from PLearn::Splitter.
Definition at line 58 of file ClassSeparationSplitter.h.
PLearn::ClassSeparationSplitter::ClassSeparationSplitter | ( | ) |
Default constructor.
Definition at line 55 of file ClassSeparationSplitter.cc.
References random_gen.
:Splitter(), numsplits(-1), nclasses(-1), nclasses_test_set(1), select_classes_randomly(1), append_train(0), seed(-1) { random_gen = new PRandom(); }
string PLearn::ClassSeparationSplitter::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::Splitter.
Definition at line 53 of file ClassSeparationSplitter.cc.
OptionList & PLearn::ClassSeparationSplitter::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::Splitter.
Definition at line 53 of file ClassSeparationSplitter.cc.
RemoteMethodMap & PLearn::ClassSeparationSplitter::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::Splitter.
Definition at line 53 of file ClassSeparationSplitter.cc.
Reimplemented from PLearn::Splitter.
Definition at line 53 of file ClassSeparationSplitter.cc.
Object * PLearn::ClassSeparationSplitter::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 53 of file ClassSeparationSplitter.cc.
StaticInitializer ClassSeparationSplitter::_static_initializer_ & PLearn::ClassSeparationSplitter::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::Splitter.
Definition at line 53 of file ClassSeparationSplitter.cc.
void PLearn::ClassSeparationSplitter::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 123 of file ClassSeparationSplitter.cc.
References PLearn::Object::build(), and build_().
{ inherited::build(); build_(); }
void PLearn::ClassSeparationSplitter::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::Object.
Definition at line 85 of file ClassSeparationSplitter.cc.
References classes, i, j, PLearn::TVec< T >::length(), nclasses, nclasses_test_set, numsplits, PLERROR, random_gen, PLearn::TVec< T >::resize(), seed, and select_classes_randomly.
Referenced by build().
{ if (seed != 0) random_gen->manual_seed(seed); if(classes.length() == 0) { if(nclasses <= 0) PLERROR("In ClassSeparationSplitter::build_(): nclasses should be > 0"); if(nclasses_test_set <= 0) PLERROR("In ClassSeparationSplitter::build_(): nclasses_test_set should be > 0"); if(nclasses_test_set >= nclasses) PLERROR("In ClassSeparationSplitter::build_(): nclasses_test_set should be < nclasses"); if(numsplits <= 0) numsplits = nclasses; classes.resize(numsplits); int it = 0; for(int i=0; i<numsplits; i++) { if(select_classes_randomly) { classes[i].resize(nclasses); for(int j=0; j<nclasses; j++) classes[i][j] = j; random_gen->shuffleElements(classes[i]); classes.resize(nclasses_test_set); } else { classes[i].resize(nclasses_test_set); for(int j=0; j<nclasses_test_set; j++) { classes[i][j] = it%nclasses; it++; } } } } }
string PLearn::ClassSeparationSplitter::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 53 of file ClassSeparationSplitter.cc.
void PLearn::ClassSeparationSplitter::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares the class options.
Reimplemented from PLearn::Splitter.
Definition at line 61 of file ClassSeparationSplitter.cc.
References append_train, PLearn::OptionBase::buildoption, classes, PLearn::declareOption(), PLearn::Splitter::declareOptions(), nclasses, nclasses_test_set, numsplits, seed, and select_classes_randomly.
{ declareOption(ol, "numsplits", &ClassSeparationSplitter::numsplits, OptionBase::buildoption, "Number of splits. If <= 0, then it is set to nclasses."); declareOption(ol, "nclasses", &ClassSeparationSplitter::nclasses, OptionBase::buildoption, "Number of classes."); declareOption(ol, "nclasses_test_set", &ClassSeparationSplitter::nclasses_test_set, OptionBase::buildoption, "Number of classes in the test sets."); declareOption(ol, "classes", &ClassSeparationSplitter::classes, OptionBase::buildoption, "Classes to isolate from the others, for each split. When this field is specified,\n" "then nclasses, nclasses_test_set and nsplit are ignored."); declareOption(ol, "select_classes_randomly", &ClassSeparationSplitter::select_classes_randomly, OptionBase::buildoption, "Indication that the classes should be chosen at random.\n" "Otherwise, the classes are selected by order of their index."); declareOption(ol, "append_train", &ClassSeparationSplitter::append_train, OptionBase::buildoption, "Indication that the training set should be appended to the split sets lists."); declareOption(ol, "seed", &ClassSeparationSplitter::seed, OptionBase::buildoption, "Seed of random generator"); // Now call the parent class' declareOptions inherited::declareOptions(ol); }
static const PPath& PLearn::ClassSeparationSplitter::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::Splitter.
Definition at line 112 of file ClassSeparationSplitter.h.
:
//##### Protected Options ###############################################
ClassSeparationSplitter * PLearn::ClassSeparationSplitter::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::Splitter.
Definition at line 53 of file ClassSeparationSplitter.cc.
OptionList & PLearn::ClassSeparationSplitter::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 53 of file ClassSeparationSplitter.cc.
OptionMap & PLearn::ClassSeparationSplitter::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 53 of file ClassSeparationSplitter.cc.
RemoteMethodMap & PLearn::ClassSeparationSplitter::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 53 of file ClassSeparationSplitter.cc.
Returns split number i.
Implements PLearn::Splitter.
Definition at line 149 of file ClassSeparationSplitter.cc.
References PLearn::TVec< T >::append(), append_train, classes, PLearn::Splitter::dataset, PLearn::TVec< T >::find(), i, PLearn::VMat::length(), nsplits(), PLERROR, PLearn::split(), and PLearn::VMat::width().
{ if (k >= nsplits()) PLERROR("ClassSeparationSplitter::getSplit() - k (%d) cannot be greater than " " the number of splits (%d)", k, nsplits()); TVec<int> classes_k = classes[k]; Vec row(dataset->width()); TVec<int> indices(0); for(int i=0; i<dataset->length(); i++) { dataset->getRow(i,row); if(classes_k.find((int)row[dataset->inputsize()]) >= 0) { indices.push_back(i); } } TVec<VMat> split(2); split[0] = new SelectRowsVMatrix(dataset,indices, true); split[1] = new SelectRowsVMatrix(dataset,indices); if(append_train) split.append(split[0]); return split; }
void PLearn::ClassSeparationSplitter::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::Splitter.
Definition at line 129 of file ClassSeparationSplitter.cc.
References classes, PLearn::deepCopyField(), PLearn::Splitter::makeDeepCopyFromShallowCopy(), and random_gen.
{ inherited::makeDeepCopyFromShallowCopy(copies); deepCopyField(classes, copies); deepCopyField(random_gen, copies); //PLERROR("ClassSeparationSplitter::makeDeepCopyFromShallowCopy not fully (correctly) implemented yet!"); }
int PLearn::ClassSeparationSplitter::nSetsPerSplit | ( | ) | const [virtual] |
Returns the number of sets per split.
Implements PLearn::Splitter.
Definition at line 144 of file ClassSeparationSplitter.cc.
References append_train.
{ return append_train ? 3 : 2; }
int PLearn::ClassSeparationSplitter::nsplits | ( | ) | const [virtual] |
Returns the number of available different "splits".
Implements PLearn::Splitter.
Definition at line 139 of file ClassSeparationSplitter.cc.
References classes, and PLearn::TVec< T >::length().
Referenced by getSplit().
{ return classes.length(); }
Reimplemented from PLearn::Splitter.
Definition at line 112 of file ClassSeparationSplitter.h.
Indication that the training set should be appended to the split sets lists.
Definition at line 81 of file ClassSeparationSplitter.h.
Referenced by declareOptions(), getSplit(), and nSetsPerSplit().
Classes to isolate from the others.
Definition at line 64 of file ClassSeparationSplitter.h.
Referenced by build_(), declareOptions(), getSplit(), makeDeepCopyFromShallowCopy(), and nsplits().
Number of classes. Ignored if classes if defined.
Definition at line 70 of file ClassSeparationSplitter.h.
Referenced by build_(), and declareOptions().
Number of classes in the test sets.
Definition at line 73 of file ClassSeparationSplitter.h.
Referenced by build_(), and declareOptions().
Number of splits. If <= 0, then it is set to nclasses.
Definition at line 67 of file ClassSeparationSplitter.h.
Referenced by build_(), and declareOptions().
PP<PRandom> PLearn::ClassSeparationSplitter::random_gen [protected] |
Definition at line 123 of file ClassSeparationSplitter.h.
Referenced by build_(), ClassSeparationSplitter(), and makeDeepCopyFromShallowCopy().
Seed of random generator.
Definition at line 84 of file ClassSeparationSplitter.h.
Referenced by build_(), and declareOptions().
Indication that the classes should be chosen at random.
Otherwise, the classes are selected by order of their index.
Definition at line 77 of file ClassSeparationSplitter.h.
Referenced by build_(), and declareOptions().