PLearn 0.1
|
The first sentence should be a BRIEF DESCRIPTION of what the class does. More...
#include <SelectRowsMultiInstanceVMatrix.h>
Public Member Functions | |
SelectRowsMultiInstanceVMatrix () | |
Default constructor. | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual SelectRowsMultiInstanceVMatrix * | deepCopy (CopiesMap &copies) const |
virtual void | build () |
Simply calls inherited::build() then build_(). | |
virtual void | makeDeepCopyFromShallowCopy (CopiesMap &copies) |
Transforms a shallow copy into a deep copy. | |
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 | |
int32_t | seed |
### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //! | |
TVec< int > | indices |
TVec< int > | mi_info |
PP< PLearner > | multi_nnet |
VMat | source_select |
double | frac |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Protected Member Functions | |
virtual void | getNewRow (int i, const Vec &v) const |
Fill the vector 'v' with the content of the i-th row. | |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
Declares the class options. | |
Protected Attributes | |
PP< PRandom > | random_generator |
Random number generator. | |
Private Types | |
typedef SourceVMatrix | inherited |
Private Member Functions | |
void | build_ () |
This does the actual building. |
The first sentence should be a BRIEF DESCRIPTION of what the class does.
Place the rest of the class programmer documentation here. Doxygen supports Javadoc-style comments. See http://www.doxygen.org/manual.html
Definition at line 61 of file SelectRowsMultiInstanceVMatrix.h.
typedef SourceVMatrix PLearn::SelectRowsMultiInstanceVMatrix::inherited [private] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 63 of file SelectRowsMultiInstanceVMatrix.h.
PLearn::SelectRowsMultiInstanceVMatrix::SelectRowsMultiInstanceVMatrix | ( | ) |
Default constructor.
Definition at line 64 of file SelectRowsMultiInstanceVMatrix.cc.
: /* ### Initialize all fields to their default value */ seed(-1), frac(0.5), random_generator(new PRandom()) { // ... // ### You may (or not) want to call build_() to finish building the object // ### (doing so assumes the parent classes' build_() have been called too // ### in the parent classes' constructors, something that you must ensure) }
string PLearn::SelectRowsMultiInstanceVMatrix::_classname_ | ( | ) | [static] |
Declares name and deepCopy methods.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 59 of file SelectRowsMultiInstanceVMatrix.cc.
OptionList & PLearn::SelectRowsMultiInstanceVMatrix::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 59 of file SelectRowsMultiInstanceVMatrix.cc.
RemoteMethodMap & PLearn::SelectRowsMultiInstanceVMatrix::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 59 of file SelectRowsMultiInstanceVMatrix.cc.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 59 of file SelectRowsMultiInstanceVMatrix.cc.
Object * PLearn::SelectRowsMultiInstanceVMatrix::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 59 of file SelectRowsMultiInstanceVMatrix.cc.
StaticInitializer SelectRowsMultiInstanceVMatrix::_static_initializer_ & PLearn::SelectRowsMultiInstanceVMatrix::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 59 of file SelectRowsMultiInstanceVMatrix.cc.
void PLearn::SelectRowsMultiInstanceVMatrix::build | ( | ) | [virtual] |
Simply calls inherited::build() then build_().
Reimplemented from PLearn::SourceVMatrix.
Definition at line 99 of file SelectRowsMultiInstanceVMatrix.cc.
References PLearn::SourceVMatrix::build(), and build_().
{ // ### Nothing to add here, simply calls build_ inherited::build(); build_(); }
void PLearn::SelectRowsMultiInstanceVMatrix::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 109 of file SelectRowsMultiInstanceVMatrix.cc.
References PLearn::argmax(), frac, PLearn::VMat::getExample(), i, indices, PLearn::VMatrix::inputsize(), PLearn::VMatrix::inputsize_, PLearn::TVec< T >::length(), PLearn::VMat::length(), PLearn::VMatrix::length_, mi_info, multi_nnet, PLERROR, PLearn::TVec< T >::push_back(), random_generator, PLearn::TVec< T >::resize(), seed, PLearn::SourceVMatrix::setMetaInfoFromSource(), PLearn::SourceVMatrix::source, source_select, PLearn::TVec< T >::subVec(), PLearn::VMatrix::targetsize(), PLearn::VMatrix::targetsize_, PLearn::VMatrix::updateMtime(), PLearn::VMatrix::weightsize(), PLearn::VMatrix::weightsize_, PLearn::VMat::width(), and PLearn::VMatrix::width_.
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. random_generator->manual_seed(seed); if (!source) return; // VMat source_of_indices = source_select ? source_select : source; // if (!source_of_indices) // return; if (source_select && source && source_select->width() >= source->width()) PLERROR("In SelectRowsMultiInstanceVMatrix::build_ - VMats 'source_select'" "should be completely present inside 'source'. Width does not work."); // Generating 'indices' and 'mi_info' vector. int bag_signal_column = source->targetsize() - 1; int first_row = 0; int x_max; indices.resize(0); // This get rid of the user's build option value. mi_info.resize(0); TVec<int> bag_indices; TVec<double> bag_prob; bag_indices.resize(0); bag_prob.resize(0); // Vec prob; Vec input,target,output(1); real weight; int indices_size; for(int row=0; row<source->length(); row++) { source->getExample(row,input,target,weight); if (source_select) { int minnet_inputsize = source->width() - source_select->inputsize() - source_select->targetsize() - source_select->weightsize(); input = input.subVec(minnet_inputsize-1,source_select->inputsize()); } switch(int(target[bag_signal_column])) { case 0: multi_nnet->computeOutput(input,output); bag_prob.push_back(output[0]); break; case 1: first_row = row; multi_nnet->computeOutput(input, output); bag_prob.push_back(output[0]); break; case 2: multi_nnet->computeOutput(input, output); bag_prob.push_back(output[0]); x_max=argmax(bag_prob); bag_indices.resize(0); for(int i=0;i<=row-first_row;i++) { if(i!=x_max) bag_indices.push_back(i); } random_generator->shuffleElements(bag_indices); // Append retained elements to indices indices_size = indices.length(); indices.push_back(first_row+x_max); for(int i=0;i<frac*bag_indices.length();i++) { indices.push_back(first_row+bag_indices[i]); } if(indices.length()-indices_size ==1) mi_info.push_back(3); if(indices.length()-indices_size > 1) { mi_info.push_back(1); for(int i=0;i<indices.length()-indices_size-2;i++) mi_info.push_back(0); mi_info.push_back(2); } bag_prob.resize(0); break; case 3: indices.push_back(row); mi_info.push_back(3); break; }; } // ?? Modify the width, length, (targetsize, inputsize and weight) size attribute. // We suppose that the source and source_select have the same targetsize and weightsize length_ = indices.length(); if(!source_select) { inputsize_ = source->inputsize(); } else { inputsize_ = source->width() - source_select->inputsize()- (2 * source_select->targetsize()) - (2 * source_select->weightsize()); } targetsize_ = source->targetsize(); weightsize_ = source->weightsize(); width_ = inputsize() + targetsize() + weightsize(); // ### In a SourceVMatrix, you will typically end build_() with: setMetaInfoFromSource(); updateMtime(source_select); }
string PLearn::SelectRowsMultiInstanceVMatrix::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 59 of file SelectRowsMultiInstanceVMatrix.cc.
void PLearn::SelectRowsMultiInstanceVMatrix::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares the class options.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 79 of file SelectRowsMultiInstanceVMatrix.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::SourceVMatrix::declareOptions(), frac, multi_nnet, seed, and source_select.
{ // ### 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, "seed", &SelectRowsMultiInstanceVMatrix::seed, OptionBase::buildoption, "Random generator seed (>0) (exceptions : -1 = initialized from clock, 0 = no initialization)."); declareOption(ol, "multi_nnet", &SelectRowsMultiInstanceVMatrix::multi_nnet, OptionBase::buildoption, "MultiNNet from which you select instances"); declareOption(ol, "source_select", &SelectRowsMultiInstanceVMatrix::source_select, OptionBase::buildoption, "The VMat from which we compute the example to be selected."); declareOption(ol, "frac", &SelectRowsMultiInstanceVMatrix::frac, OptionBase::buildoption, "Fraction of the bag to be randomly chosen (Note: this is the fraction of the bag to be randomly chosen in addition of the best instance, which is always added"); // Now call the parent class' declareOptions inherited::declareOptions(ol); }
static const PPath& PLearn::SelectRowsMultiInstanceVMatrix::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 93 of file SelectRowsMultiInstanceVMatrix.h.
:
SelectRowsMultiInstanceVMatrix * PLearn::SelectRowsMultiInstanceVMatrix::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 59 of file SelectRowsMultiInstanceVMatrix.cc.
void PLearn::SelectRowsMultiInstanceVMatrix::getNewRow | ( | int | i, |
const Vec & | v | ||
) | const [protected, virtual] |
Fill the vector 'v' with the content of the i-th row.
v is assumed to be the right size. ### This function must be overridden in your class
Reimplemented from PLearn::SourceVMatrix.
Definition at line 217 of file SelectRowsMultiInstanceVMatrix.cc.
References i, indices, PLearn::VMatrix::inputsize_, mi_info, PLearn::SourceVMatrix::source, and PLearn::VMatrix::targetsize_.
{ int bag_signal_column = inputsize_ + targetsize_ - 1; source->getRow(indices[i], v); v[bag_signal_column]=mi_info[i]; }
OptionList & PLearn::SelectRowsMultiInstanceVMatrix::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 59 of file SelectRowsMultiInstanceVMatrix.cc.
OptionMap & PLearn::SelectRowsMultiInstanceVMatrix::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 59 of file SelectRowsMultiInstanceVMatrix.cc.
RemoteMethodMap & PLearn::SelectRowsMultiInstanceVMatrix::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 59 of file SelectRowsMultiInstanceVMatrix.cc.
void PLearn::SelectRowsMultiInstanceVMatrix::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 227 of file SelectRowsMultiInstanceVMatrix.cc.
References PLearn::deepCopyField(), indices, PLearn::SourceVMatrix::makeDeepCopyFromShallowCopy(), mi_info, multi_nnet, random_generator, and source_select.
{ inherited::makeDeepCopyFromShallowCopy(copies); deepCopyField(indices, copies); deepCopyField(mi_info, copies); deepCopyField(multi_nnet, copies); deepCopyField(source_select, copies); deepCopyField(random_generator, copies); }
Reimplemented from PLearn::SourceVMatrix.
Definition at line 93 of file SelectRowsMultiInstanceVMatrix.h.
Definition at line 77 of file SelectRowsMultiInstanceVMatrix.h.
Referenced by build_(), and declareOptions().
Definition at line 73 of file SelectRowsMultiInstanceVMatrix.h.
Referenced by build_(), getNewRow(), and makeDeepCopyFromShallowCopy().
Definition at line 74 of file SelectRowsMultiInstanceVMatrix.h.
Referenced by build_(), getNewRow(), and makeDeepCopyFromShallowCopy().
Definition at line 75 of file SelectRowsMultiInstanceVMatrix.h.
Referenced by build_(), declareOptions(), and makeDeepCopyFromShallowCopy().
Random number generator.
Definition at line 108 of file SelectRowsMultiInstanceVMatrix.h.
Referenced by build_(), and makeDeepCopyFromShallowCopy().
### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //!
random number generator seed
Definition at line 72 of file SelectRowsMultiInstanceVMatrix.h.
Referenced by build_(), and declareOptions().
Definition at line 76 of file SelectRowsMultiInstanceVMatrix.h.
Referenced by build_(), declareOptions(), and makeDeepCopyFromShallowCopy().