PLearn 0.1
|
#include <ReIndexedTargetVariable.h>
Public Member Functions | |
ReIndexedTargetVariable () | |
Default constructor for persistence. | |
ReIndexedTargetVariable (Variable *input1, Variable *input2, VMat the_source, TVec< int > the_target_cols) | |
ReIndexedTargetVariable (Variable *input1, Variable *input2, PP< Dictionary > the_dict, TVec< int > the_target_cols) | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual ReIndexedTargetVariable * | deepCopy (CopiesMap &copies) const |
virtual void | build () |
Post-constructor. | |
virtual void | recomputeSize (int &l, int &w) const |
Recomputes the length l and width w that this variable should have, according to its parent variables. | |
virtual void | fprop () |
compute output given input | |
virtual void | bprop () |
virtual void | symbolicBprop () |
compute a piece of new Var graph that represents the symbolic derivative of this Var | |
virtual void | rfprop () |
virtual void | makeDeepCopyFromShallowCopy (CopiesMap &copies) |
Does the necessary operations to transform a shallow copy (this) into a deep copy by deep-copying all the members that need to be. | |
Static Public Member Functions | |
static string | _classname_ () |
ReIndexedTargetVariable. | |
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 () |
static void | declareOptions (OptionList &ol) |
Declare options (data fields) for the class. | |
Public Attributes | |
VMat | source |
VMatrix that gives the possible values for the target columns. | |
TVec< int > | target_cols |
Target columns. | |
PP< Dictionary > | dict |
Alternatively, the user can give a Dictionary to reindexe If source is not null, then this field is ignored. | |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Protected Member Functions | |
void | build_ () |
This does the actual building. | |
Protected Attributes | |
Vec | row |
Vec | values |
TVec< string > | options |
Private Types | |
typedef BinaryVariable | inherited |
Definition at line 63 of file ReIndexedTargetVariable.h.
typedef BinaryVariable PLearn::ReIndexedTargetVariable::inherited [private] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 65 of file ReIndexedTargetVariable.h.
PLearn::ReIndexedTargetVariable::ReIndexedTargetVariable | ( | ) |
string PLearn::ReIndexedTargetVariable::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 62 of file ReIndexedTargetVariable.cc.
OptionList & PLearn::ReIndexedTargetVariable::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 62 of file ReIndexedTargetVariable.cc.
RemoteMethodMap & PLearn::ReIndexedTargetVariable::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 62 of file ReIndexedTargetVariable.cc.
Reimplemented from PLearn::BinaryVariable.
Definition at line 62 of file ReIndexedTargetVariable.cc.
Object * PLearn::ReIndexedTargetVariable::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 62 of file ReIndexedTargetVariable.cc.
StaticInitializer ReIndexedTargetVariable::_static_initializer_ & PLearn::ReIndexedTargetVariable::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 62 of file ReIndexedTargetVariable.cc.
void PLearn::ReIndexedTargetVariable::bprop | ( | ) | [virtual] |
void PLearn::ReIndexedTargetVariable::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::BinaryVariable.
Definition at line 81 of file ReIndexedTargetVariable.cc.
References PLearn::BinaryVariable::build(), and build_().
{ inherited::build(); build_(); }
void PLearn::ReIndexedTargetVariable::build_ | ( | ) | [protected] |
This does the actual building.
Reimplemented from PLearn::BinaryVariable.
Definition at line 88 of file ReIndexedTargetVariable.cc.
References dict, PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, PLearn::TVec< T >::length(), MISSING_VALUE, options, PLERROR, PLearn::TVec< T >::resize(), row, source, PLearn::TVec< T >::subVec(), target_cols, and PLearn::VMat::width().
Referenced by build(), and ReIndexedTargetVariable().
{ if (input1 && input2 && source) { if(!input1->isVec()) PLERROR("In ReIndexedTargetVariable: input1 must be a vector var"); if(!input2->isVec()) PLERROR("In ReIndexedTargetVariable: input2 must be a vector var"); if(input1->size() != target_cols.length()) PLERROR("In ReIndexedTargetVariable: input1 should be of size target_cols.length()"); if(input2->size() != source->inputsize()) PLERROR("In ReIndexedTargetVariable: input2 should be of size source->inputsize()"); row.resize(source->width()); row.subVec(source->inputsize(),source->width()-source->inputsize()).fill(MISSING_VALUE); } else if (input1 && dict) { if(!input1->isVec()) PLERROR("In ReIndexedTargetVariable: input1 must be a vector var"); if(input1->size() != target_cols.length()) PLERROR("In ReIndexedTargetVariable: input1 should be of size target_cols.length()"); } options.resize(0); }
string PLearn::ReIndexedTargetVariable::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 62 of file ReIndexedTargetVariable.cc.
void PLearn::ReIndexedTargetVariable::declareOptions | ( | OptionList & | ol | ) | [static] |
Declare options (data fields) for the class.
Redefine this in subclasses: call declareOption
(...) for each option, and then call inherited::declareOptions(options)
. Please call the inherited
method AT THE END to get the options listed in a consistent order (from most recently defined to least recently defined).
static void MyDerivedClass::declareOptions(OptionList& ol) { declareOption(ol, "inputsize", &MyObject::inputsize_, OptionBase::buildoption, "The size of the input; it must be provided"); declareOption(ol, "weights", &MyObject::weights, OptionBase::learntoption, "The learned model weights"); inherited::declareOptions(ol); }
ol | List of options that is progressively being constructed for the current class. |
Reimplemented from PLearn::BinaryVariable.
Definition at line 116 of file ReIndexedTargetVariable.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::BinaryVariable::declareOptions(), dict, source, and target_cols.
{ declareOption(ol, "source", &ReIndexedTargetVariable::source, OptionBase::buildoption, ""); declareOption(ol, "dict", &ReIndexedTargetVariable::dict, OptionBase::buildoption, ""); declareOption(ol, "target_cols", &ReIndexedTargetVariable::target_cols, OptionBase::buildoption, ""); inherited::declareOptions(ol); }
static const PPath& PLearn::ReIndexedTargetVariable::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 87 of file ReIndexedTargetVariable.h.
: void build_();
ReIndexedTargetVariable * PLearn::ReIndexedTargetVariable::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 62 of file ReIndexedTargetVariable.cc.
void PLearn::ReIndexedTargetVariable::fprop | ( | ) | [virtual] |
compute output given input
Implements PLearn::Variable.
Definition at line 128 of file ReIndexedTargetVariable.cc.
References dict, PLearn::TVec< T >::find(), for(), PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, j, options, PLERROR, row, source, PLearn::TVec< T >::subVec(), target_cols, PLearn::Variable::valuedata, and values.
{ if(source) row.subVec(0,source->inputsize()) << input2->value; for (int j=0; j<input1->size(); j++) { if(source) { source->getValues(row,target_cols[j],values); valuedata[j] = values.find((int)input1->valuedata[j]); } else { dict->getValues(options,values); valuedata[j] = values.find((int)input1->valuedata[j]); } if(valuedata[j] < 0) PLERROR("In ReIndexedTargetVariable::fprop(): target %d is not among possible values",input1->valuedata[j]); } }
OptionList & PLearn::ReIndexedTargetVariable::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 62 of file ReIndexedTargetVariable.cc.
OptionMap & PLearn::ReIndexedTargetVariable::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 62 of file ReIndexedTargetVariable.cc.
RemoteMethodMap & PLearn::ReIndexedTargetVariable::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 62 of file ReIndexedTargetVariable.cc.
void PLearn::ReIndexedTargetVariable::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Does the necessary operations to transform a shallow copy (this) into a deep copy by deep-copying all the members that need to be.
This needs to be overridden by every class that adds "complex" data members to the class, such as Vec
, Mat
, PP<Something>
, etc. Typical implementation:
void CLASS_OF_THIS::makeDeepCopyFromShallowCopy(CopiesMap& copies) { inherited::makeDeepCopyFromShallowCopy(copies); deepCopyField(complex_data_member1, copies); deepCopyField(complex_data_member2, copies); ... }
copies | A map used by the deep-copy mechanism to keep track of already-copied objects. |
Reimplemented from PLearn::BinaryVariable.
Definition at line 173 of file ReIndexedTargetVariable.cc.
References PLearn::deepCopyField(), dict, PLearn::BinaryVariable::makeDeepCopyFromShallowCopy(), options, row, source, target_cols, and values.
{ inherited::makeDeepCopyFromShallowCopy(copies); deepCopyField(source, copies); deepCopyField(row, copies); deepCopyField(values, copies); deepCopyField(options, copies); deepCopyField(target_cols, copies); deepCopyField(dict, copies); }
Recomputes the length l and width w that this variable should have, according to its parent variables.
This is used for ex. by sizeprop() The default version stupidly returns the current dimensions, so make sure to overload it in subclasses if this is not appropriate.
Reimplemented from PLearn::Variable.
Definition at line 124 of file ReIndexedTargetVariable.cc.
References PLearn::BinaryVariable::input1, PLearn::Var::length(), and PLearn::Var::width().
void PLearn::ReIndexedTargetVariable::rfprop | ( | ) | [virtual] |
Reimplemented from PLearn::Variable.
Definition at line 160 of file ReIndexedTargetVariable.cc.
References PLERROR.
{ PLERROR("In ReIndexedTargetVariable::rfprop(): not implemented."); }
void PLearn::ReIndexedTargetVariable::symbolicBprop | ( | ) | [virtual] |
compute a piece of new Var graph that represents the symbolic derivative of this Var
Reimplemented from PLearn::Variable.
Definition at line 154 of file ReIndexedTargetVariable.cc.
References PLERROR.
{ PLERROR("In ReIndexedTargetVariable::symbolicBprop(): not implemented"); }
Reimplemented from PLearn::BinaryVariable.
Definition at line 87 of file ReIndexedTargetVariable.h.
Alternatively, the user can give a Dictionary to reindexe If source is not null, then this field is ignored.
Definition at line 79 of file ReIndexedTargetVariable.h.
Referenced by build_(), declareOptions(), fprop(), and makeDeepCopyFromShallowCopy().
TVec<string> PLearn::ReIndexedTargetVariable::options [protected] |
Definition at line 70 of file ReIndexedTargetVariable.h.
Referenced by build_(), fprop(), and makeDeepCopyFromShallowCopy().
Vec PLearn::ReIndexedTargetVariable::row [protected] |
Definition at line 68 of file ReIndexedTargetVariable.h.
Referenced by build_(), fprop(), and makeDeepCopyFromShallowCopy().
VMatrix that gives the possible values for the target columns.
Definition at line 74 of file ReIndexedTargetVariable.h.
Referenced by build_(), declareOptions(), fprop(), and makeDeepCopyFromShallowCopy().
Target columns.
Definition at line 76 of file ReIndexedTargetVariable.h.
Referenced by build_(), declareOptions(), fprop(), and makeDeepCopyFromShallowCopy().
Vec PLearn::ReIndexedTargetVariable::values [protected] |
Definition at line 69 of file ReIndexedTargetVariable.h.
Referenced by fprop(), and makeDeepCopyFromShallowCopy().