PLearn 0.1
|
#include <ConcatOfVariable.h>
Public Member Functions | |
ConcatOfVariable () | |
Default constructor for persistence. | |
ConcatOfVariable (VMat the_distr, Func the_f) | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual ConcatOfVariable * | 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 | 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. | |
virtual void | fprop () |
compute output given input | |
virtual void | bprop () |
virtual void | fbprop () |
do both fprop and bprop | |
Static Public Member Functions | |
static string | _classname_ () |
ConcatOfVariable. | |
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) |
Default constructor for persistence. | |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Protected Attributes | |
VMat | distr |
Func | f |
Vec | input_value |
Vec to hold one input sample. | |
Vec | input_gradient |
//!< Vec to hold the gradient for one input sample | |
Private Types | |
typedef NaryVariable | inherited |
Private Member Functions | |
void | build_ () |
Object-specific post-constructor. |
Definition at line 53 of file ConcatOfVariable.h.
typedef NaryVariable PLearn::ConcatOfVariable::inherited [private] |
Reimplemented from PLearn::NaryVariable.
Definition at line 55 of file ConcatOfVariable.h.
PLearn::ConcatOfVariable::ConcatOfVariable | ( | ) | [inline] |
Definition at line 55 of file ConcatOfVariable.cc.
References build_().
: inherited(nonInputParentsOfPath(the_f->inputs, the_f->outputs), the_f->outputs[0]->length() * the_distr->length(), the_f->outputs[0]->width()), distr(the_distr), f(the_f) { build_(); }
string PLearn::ConcatOfVariable::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 53 of file ConcatOfVariable.cc.
OptionList & PLearn::ConcatOfVariable::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 53 of file ConcatOfVariable.cc.
RemoteMethodMap & PLearn::ConcatOfVariable::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 53 of file ConcatOfVariable.cc.
Reimplemented from PLearn::NaryVariable.
Definition at line 53 of file ConcatOfVariable.cc.
Object * PLearn::ConcatOfVariable::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 53 of file ConcatOfVariable.cc.
StaticInitializer ConcatOfVariable::_static_initializer_ & PLearn::ConcatOfVariable::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 53 of file ConcatOfVariable.cc.
void PLearn::ConcatOfVariable::bprop | ( | ) | [virtual] |
Implements PLearn::Variable.
Definition at line 138 of file ConcatOfVariable.cc.
References fbprop().
{ fbprop(); }
void PLearn::ConcatOfVariable::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::NaryVariable.
Definition at line 84 of file ConcatOfVariable.cc.
References PLearn::NaryVariable::build(), and build_().
{ inherited::build(); build_(); }
void PLearn::ConcatOfVariable::build_ | ( | ) | [private] |
Object-specific post-constructor.
This method should be redefined in subclasses and do the actual building of the object according to previously set option fields. Constructors can just set option fields, and then call build_. This method is NOT virtual, and will typically be called only from three places: a constructor, the public virtual build()
method, and possibly the public virtual read method (which calls its parent's read). build_()
can assume that its parent's build_()
has already been called.
Reimplemented from PLearn::NaryVariable.
Definition at line 91 of file ConcatOfVariable.cc.
References distr, f, input_gradient, input_value, PLERROR, PLearn::TVec< T >::resize(), and PLearn::VMat::width().
Referenced by build(), and ConcatOfVariable().
{ if (distr && f) { if(f->outputs.size()!=1) PLERROR("In ConcatOfVariable constructor: function must have a single output variable"); input_value.resize(distr->width()); input_gradient.resize(distr->width()); } }
string PLearn::ConcatOfVariable::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 53 of file ConcatOfVariable.cc.
void PLearn::ConcatOfVariable::declareOptions | ( | OptionList & | ol | ) | [static] |
Default constructor for persistence.
Reimplemented from PLearn::NaryVariable.
Definition at line 76 of file ConcatOfVariable.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::NaryVariable::declareOptions(), distr, and f.
{ declareOption(ol, "distr", &ConcatOfVariable::distr, OptionBase::buildoption, ""); declareOption(ol, "f", &ConcatOfVariable::f, OptionBase::buildoption, ""); inherited::declareOptions(ol); }
static const PPath& PLearn::ConcatOfVariable::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 69 of file ConcatOfVariable.h.
: void build_();
ConcatOfVariable * PLearn::ConcatOfVariable::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::NaryVariable.
Definition at line 53 of file ConcatOfVariable.cc.
void PLearn::ConcatOfVariable::fbprop | ( | ) | [virtual] |
do both fprop and bprop
Reimplemented from PLearn::Variable.
Definition at line 144 of file ConcatOfVariable.cc.
References distr, f, PLearn::Variable::gradient, i, input_gradient, input_value, PLearn::VMat::length(), PLearn::TVec< T >::subVec(), and PLearn::Variable::value.
Referenced by bprop().
{ f->recomputeParents(); int pos = 0; int singleoutputsize = f->outputs[0]->nelems(); for(int i=0; i<distr->length(); i++, pos+=singleoutputsize) { distr->getRow(i, input_value); f->fbprop(input_value, value.subVec(pos,singleoutputsize), input_gradient, gradient.subVec(pos,singleoutputsize)); // We don't use the computed input_gradients, as the input is a dummy variable. // The gradients on other (non-input) variables which we are interested in, // have been accumulated by the call as a side effect. } }
void PLearn::ConcatOfVariable::fprop | ( | ) | [virtual] |
compute output given input
Implements PLearn::Variable.
Definition at line 124 of file ConcatOfVariable.cc.
References distr, f, i, input_value, PLearn::VMat::length(), PLearn::TVec< T >::subVec(), and PLearn::Variable::value.
{ f->recomputeParents(); int pos = 0; int singleoutputsize = f->outputs[0]->nelems(); for(int i=0; i<distr->length(); i++, pos+=singleoutputsize) { distr->getRow(i,input_value); f->fprop(input_value, value.subVec(pos,singleoutputsize)); } }
OptionList & PLearn::ConcatOfVariable::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 53 of file ConcatOfVariable.cc.
OptionMap & PLearn::ConcatOfVariable::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 53 of file ConcatOfVariable.cc.
RemoteMethodMap & PLearn::ConcatOfVariable::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 53 of file ConcatOfVariable.cc.
void PLearn::ConcatOfVariable::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::NaryVariable.
Definition at line 113 of file ConcatOfVariable.cc.
References PLearn::deepCopyField(), distr, f, input_gradient, input_value, and PLearn::NaryVariable::makeDeepCopyFromShallowCopy().
{ inherited::makeDeepCopyFromShallowCopy(copies); deepCopyField(distr, copies); deepCopyField(f, copies); deepCopyField(input_value, copies); deepCopyField(input_gradient, 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 103 of file ConcatOfVariable.cc.
References distr, f, and PLearn::VMat::length().
{ if (f && distr) { l = f->outputs[0]->length() * distr->length(); w = f->outputs[0]->width(); } else l = w = 0; }
Reimplemented from PLearn::NaryVariable.
Definition at line 69 of file ConcatOfVariable.h.
VMat PLearn::ConcatOfVariable::distr [protected] |
Definition at line 58 of file ConcatOfVariable.h.
Referenced by build_(), declareOptions(), fbprop(), fprop(), makeDeepCopyFromShallowCopy(), and recomputeSize().
Func PLearn::ConcatOfVariable::f [protected] |
Definition at line 59 of file ConcatOfVariable.h.
Referenced by build_(), declareOptions(), fbprop(), fprop(), makeDeepCopyFromShallowCopy(), and recomputeSize().
Vec PLearn::ConcatOfVariable::input_gradient [protected] |
//!< Vec to hold the gradient for one input sample
Definition at line 62 of file ConcatOfVariable.h.
Referenced by build_(), fbprop(), and makeDeepCopyFromShallowCopy().
Vec PLearn::ConcatOfVariable::input_value [protected] |
Vec to hold one input sample.
Definition at line 61 of file ConcatOfVariable.h.
Referenced by build_(), fbprop(), fprop(), and makeDeepCopyFromShallowCopy().