PLearn 0.1
|
#include <Max2Variable.h>
Public Member Functions | |
Max2Variable () | |
Default constructor for persistence. | |
Max2Variable (Variable *input, Variable *power) | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual Max2Variable * | 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 | |
Static Public Member Functions | |
static string | _classname_ () |
Max2Variable. | |
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 Public Attributes | |
static StaticInitializer | _static_initializer_ |
Protected Member Functions | |
void | build_ () |
This does the actual building. | |
Private Types | |
typedef BinaryVariable | inherited |
elementwise max over 2 elements: max(v1,v2)[i] = max(v1[i],v2[i]) with same dimensions as the input vectors (both must have same length())
Definition at line 56 of file Max2Variable.h.
typedef BinaryVariable PLearn::Max2Variable::inherited [private] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 58 of file Max2Variable.h.
PLearn::Max2Variable::Max2Variable | ( | ) | [inline] |
string PLearn::Max2Variable::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 62 of file Max2Variable.cc.
OptionList & PLearn::Max2Variable::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 62 of file Max2Variable.cc.
RemoteMethodMap & PLearn::Max2Variable::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 62 of file Max2Variable.cc.
Reimplemented from PLearn::BinaryVariable.
Definition at line 62 of file Max2Variable.cc.
Object * PLearn::Max2Variable::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 62 of file Max2Variable.cc.
StaticInitializer Max2Variable::_static_initializer_ & PLearn::Max2Variable::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 62 of file Max2Variable.cc.
void PLearn::Max2Variable::bprop | ( | ) | [virtual] |
Implements PLearn::Variable.
Definition at line 109 of file Max2Variable.cc.
References PLearn::TVec< T >::data(), grad, PLearn::Variable::gradient, i, PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, PLearn::Var::length(), n, and PLASSERT.
{ PLASSERT( input1 && input2 ); int n=input1->value.length(); real* v1=input1->value.data(); real* v2=input2->value.data(); real* grad1=input1->gradient.data(); real* grad2=input2->gradient.data(); real* grad=gradient.data(); for (int i=0;i<n;i++) { if (v2[i]<v1[i]) grad1[i] += grad[i]; if (v1[i]<v2[i]) grad2[i] += grad[i]; } }
void PLearn::Max2Variable::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 72 of file Max2Variable.cc.
References PLearn::BinaryVariable::build(), and build_().
{ inherited::build(); build_(); }
void PLearn::Max2Variable::build_ | ( | ) | [protected] |
This does the actual building.
Reimplemented from PLearn::BinaryVariable.
Definition at line 79 of file Max2Variable.cc.
References PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, PLearn::Var::length(), PLERROR, and PLearn::Var::width().
Referenced by build(), and Max2Variable().
{ if (input1 && input2) { if (input1->length() != input2->length() || input1->width() != input2->width()) PLERROR("IN Max2Variable input1 and input2 must have the same size"); } }
string PLearn::Max2Variable::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 62 of file Max2Variable.cc.
static const PPath& PLearn::Max2Variable::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 65 of file Max2Variable.h.
: void build_();
Max2Variable * PLearn::Max2Variable::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 62 of file Max2Variable.cc.
void PLearn::Max2Variable::fprop | ( | ) | [virtual] |
compute output given input
Implements PLearn::Variable.
Definition at line 97 of file Max2Variable.cc.
References PLearn::TVec< T >::data(), i, PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, PLearn::Var::length(), max, n, PLASSERT, and PLearn::Variable::value.
{ PLASSERT( input1 && input2 ); int n=input1->value.length(); real* v1=input1->value.data(); real* v2=input2->value.data(); real* v=value.data(); for (int i=0;i<n;i++) v[i] = std::max(v1[i],v2[i]); }
OptionList & PLearn::Max2Variable::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 62 of file Max2Variable.cc.
OptionMap & PLearn::Max2Variable::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 62 of file Max2Variable.cc.
RemoteMethodMap & PLearn::Max2Variable::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 62 of file Max2Variable.cc.
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 88 of file Max2Variable.cc.
References PLearn::BinaryVariable::input1, PLearn::Var::length(), and PLearn::Var::width().
void PLearn::Max2Variable::symbolicBprop | ( | ) | [virtual] |
compute a piece of new Var graph that represents the symbolic derivative of this Var
Reimplemented from PLearn::Variable.
Definition at line 128 of file Max2Variable.cc.
References PLearn::Variable::g, PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, and PLASSERT.
Reimplemented from PLearn::BinaryVariable.
Definition at line 65 of file Max2Variable.h.