PLearn 0.1
|
#include <FractionSplitter.h>
Public Member Functions | |
FractionSplitter () | |
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 FractionSplitter * | deepCopy (CopiesMap &copies) const |
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 | |
bool | one_is_absolute |
bool | round_to_closest |
TMat< pair< real, real > > | splits |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
Declares this class' options. | |
Private Types | |
typedef Splitter | inherited |
Private Member Functions | |
void | build_ () |
This does the actual building. |
Definition at line 48 of file FractionSplitter.h.
typedef Splitter PLearn::FractionSplitter::inherited [private] |
Reimplemented from PLearn::Splitter.
Definition at line 53 of file FractionSplitter.h.
PLearn::FractionSplitter::FractionSplitter | ( | ) |
Definition at line 48 of file FractionSplitter.cc.
: one_is_absolute(false), round_to_closest(0) {}
string PLearn::FractionSplitter::_classname_ | ( | ) | [static] |
Declares name and deepCopy methods.
Reimplemented from PLearn::Splitter.
Definition at line 56 of file FractionSplitter.cc.
OptionList & PLearn::FractionSplitter::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::Splitter.
Definition at line 56 of file FractionSplitter.cc.
RemoteMethodMap & PLearn::FractionSplitter::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::Splitter.
Definition at line 56 of file FractionSplitter.cc.
Reimplemented from PLearn::Splitter.
Definition at line 56 of file FractionSplitter.cc.
Object * PLearn::FractionSplitter::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 56 of file FractionSplitter.cc.
StaticInitializer FractionSplitter::_static_initializer_ & PLearn::FractionSplitter::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::Splitter.
Definition at line 56 of file FractionSplitter.cc.
void PLearn::FractionSplitter::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 101 of file FractionSplitter.cc.
References PLearn::Object::build(), and build_().
{ inherited::build(); build_(); }
void PLearn::FractionSplitter::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::Object.
Definition at line 94 of file FractionSplitter.cc.
Referenced by build().
{ }
string PLearn::FractionSplitter::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 56 of file FractionSplitter.cc.
void PLearn::FractionSplitter::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares this class' options.
Reimplemented from PLearn::Splitter.
Definition at line 61 of file FractionSplitter.cc.
References PLearn::OptionBase::advanced_level, PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::Splitter::declareOptions(), one_is_absolute, round_to_closest, and splits.
{ declareOption(ol, "round_to_closest", &FractionSplitter::round_to_closest, OptionBase::buildoption, "If set to 1, then the integer value found when using fractions will\n" "be the closest integer, instead of the integer part."); declareOption(ol, "splits", &FractionSplitter::splits, OptionBase::buildoption, "A matrix of start:end pairs. Each row represents a split. \n" "Each start:end element represents a range of samples in the dataset to be splitted. \n" "start and end, which are positions in the datataset, can be specified as either \n" "a fraction of the dataset length (if <=1), or an absolute number of elements (if >1).\n" "The range includes all samples from start to end, but excluding the end sample \n" "(so that, for ex., the same value can be used as the start of the next range \n" "without having the two ranges ovelap). \n" "The value 1 is a bit special as it always means \"until last element inclusive\".\n" "Ex: 1 2 [ 0:0.80, 0.80:1 ] yields a single split with the first part being the first 80% \n" "of the data, and the second the next 20% \n"); declareOption(ol, "one_is_absolute", &FractionSplitter::one_is_absolute, OptionBase::buildoption, "If true, then 1 is always considered as an absolute index, not as a\n" "fraction giving the end of the dataset. This can be useful if you\n" "actually want a split with a single element in it.", OptionBase::advanced_level); // Now call the parent class' declareOptions inherited::declareOptions(ol); }
static const PPath& PLearn::FractionSplitter::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::Splitter.
Definition at line 106 of file FractionSplitter.h.
FractionSplitter * PLearn::FractionSplitter::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::Splitter.
Definition at line 56 of file FractionSplitter.cc.
OptionList & PLearn::FractionSplitter::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 56 of file FractionSplitter.cc.
OptionMap & PLearn::FractionSplitter::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 56 of file FractionSplitter.cc.
RemoteMethodMap & PLearn::FractionSplitter::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 56 of file FractionSplitter.cc.
Returns split number i.
Implements PLearn::Splitter.
Definition at line 124 of file FractionSplitter.cc.
References PLearn::Splitter::dataset, PLearn::TVec< T >::first(), i, PLearn::is_equal(), PLearn::TVec< T >::length(), PLearn::VMat::length(), n, one_is_absolute, round_to_closest, splits, and PLearn::VMat::subMatRows().
{ TVec< pair<real,real> > frac_k = splits(k); int n = frac_k.length(); TVec<VMat> vms(n); int l = dataset.length(); int start = 0; int end = 0; for(int i=0; i<n; i++) { real fstart = frac_k[i].first; real fend = frac_k[i].second; if(fstart>1 || (one_is_absolute && is_equal(fstart, 1))) // absolute position start = int(round(fstart)); else {// relative position if (round_to_closest) { start = int(fstart*l + 0.5); } else { start = int(fstart*l); } } if(fend>1 || (one_is_absolute && is_equal(fend, 1))) // absolute end position end = int(round(fend)); else if(is_equal(fend,1)) // until last element inclusive end = l; else {// relative end position if (round_to_closest) { end = int(fend*l + 0.5); } else { end = int(fend*l); } } vms[i] = dataset.subMatRows(start, end-start); } return vms; }
void PLearn::FractionSplitter::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::Splitter.
Definition at line 107 of file FractionSplitter.cc.
References PLearn::deepCopyField(), PLearn::Splitter::makeDeepCopyFromShallowCopy(), and splits.
{ inherited::makeDeepCopyFromShallowCopy(copies); deepCopyField(splits, copies); }
int PLearn::FractionSplitter::nSetsPerSplit | ( | ) | const [virtual] |
Returns the number of sets per split.
Implements PLearn::Splitter.
Definition at line 118 of file FractionSplitter.cc.
References splits, and PLearn::TMat< T >::width().
{ return splits.width(); }
int PLearn::FractionSplitter::nsplits | ( | ) | const [virtual] |
Returns the number of available different "splits".
Implements PLearn::Splitter.
Definition at line 113 of file FractionSplitter.cc.
References PLearn::TMat< T >::length(), and splits.
{ return splits.length(); }
Reimplemented from PLearn::Splitter.
Definition at line 106 of file FractionSplitter.h.
Definition at line 70 of file FractionSplitter.h.
Referenced by declareOptions(), and getSplit().
Definition at line 71 of file FractionSplitter.h.
Referenced by declareOptions(), and getSplit().
TMat< pair<real, real> > PLearn::FractionSplitter::splits |
Definition at line 72 of file FractionSplitter.h.
Referenced by declareOptions(), getSplit(), makeDeepCopyFromShallowCopy(), nSetsPerSplit(), and nsplits().