PLearn 0.1
|
#include <PowVariableVariable.h>
Public Member Functions | |
PowVariableVariable () | |
Default constructor for persistence. | |
PowVariableVariable (Variable *input, Variable *power) | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual PowVariableVariable * | 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_ () |
PowVariableVariable. | |
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 pow: power may be a scalar or a var with same dimensions as the input (returns 0 wherever input is negative)
Definition at line 66 of file PowVariableVariable.h.
typedef BinaryVariable PLearn::PowVariableVariable::inherited [private] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 68 of file PowVariableVariable.h.
PLearn::PowVariableVariable::PowVariableVariable | ( | ) | [inline] |
string PLearn::PowVariableVariable::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 62 of file PowVariableVariable.cc.
OptionList & PLearn::PowVariableVariable::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 62 of file PowVariableVariable.cc.
RemoteMethodMap & PLearn::PowVariableVariable::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 62 of file PowVariableVariable.cc.
Reimplemented from PLearn::BinaryVariable.
Definition at line 62 of file PowVariableVariable.cc.
Object * PLearn::PowVariableVariable::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 62 of file PowVariableVariable.cc.
StaticInitializer PowVariableVariable::_static_initializer_ & PLearn::PowVariableVariable::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 62 of file PowVariableVariable.cc.
void PLearn::PowVariableVariable::bprop | ( | ) | [virtual] |
Implements PLearn::Variable.
Definition at line 116 of file PowVariableVariable.cc.
References PLearn::Variable::gradientdata, i, PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, PLearn::Variable::nelems(), PLearn::safeflog(), and PLearn::Variable::valuedata.
{ if (input2->isScalar()) { real p = input2->valuedata[0]; real& dp = input2->gradientdata[0]; for(int i=0; i<nelems(); i++) { if (input1->valuedata[i]>0) { input1->gradientdata[i] += gradientdata[i] * valuedata[i] * p / input1->valuedata[i]; dp += gradientdata[i] * valuedata[i] * safeflog(input1->valuedata[i]); } } } else { for(int i=0; i<nelems(); i++) { if (input1->valuedata[i]>0) { input1->gradientdata[i] += gradientdata[i] * valuedata[i] * input2->valuedata[i] / input1->valuedata[i]; input2->gradientdata[i] += gradientdata[i] * valuedata[i] * safeflog(input1->valuedata[i]); } } } }
void PLearn::PowVariableVariable::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 71 of file PowVariableVariable.cc.
References PLearn::BinaryVariable::build(), and build_().
{ inherited::build(); build_(); }
void PLearn::PowVariableVariable::build_ | ( | ) | [protected] |
This does the actual building.
Reimplemented from PLearn::BinaryVariable.
Definition at line 78 of file PowVariableVariable.cc.
References PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, PLearn::Var::length(), PLERROR, and PLearn::Var::width().
Referenced by build(), and PowVariableVariable().
{ if (input1 && input2) { if(!input2->isScalar() && (input1->length()!=input2->length() || input1->width()!=input2->width())) PLERROR("IN FunctionPowVariableVariable(Variable* input1, Variable* input2) input1 and input2 must have the same size or input2 must be scalar"); } }
string PLearn::PowVariableVariable::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 62 of file PowVariableVariable.cc.
static const PPath& PLearn::PowVariableVariable::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 75 of file PowVariableVariable.h.
: void build_();
PowVariableVariable * PLearn::PowVariableVariable::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 62 of file PowVariableVariable.cc.
void PLearn::PowVariableVariable::fprop | ( | ) | [virtual] |
compute output given input
Implements PLearn::Variable.
Definition at line 96 of file PowVariableVariable.cc.
References i, PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, PLearn::Variable::nelems(), PLearn::pow(), and PLearn::Variable::valuedata.
{ if (input2->isScalar()) { real p = input2->valuedata[0]; for(int i=0; i<nelems(); i++) if (input1->valuedata[i]>0) valuedata[i] = pow(input1->valuedata[i],p); else valuedata[i] = 0; } else for(int i=0; i<nelems(); i++) if (input1->valuedata[i]>0) valuedata[i] = pow(input1->valuedata[i],input2->valuedata[i]); else valuedata[i] = 0; }
OptionList & PLearn::PowVariableVariable::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 62 of file PowVariableVariable.cc.
OptionMap & PLearn::PowVariableVariable::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 62 of file PowVariableVariable.cc.
RemoteMethodMap & PLearn::PowVariableVariable::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 62 of file PowVariableVariable.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 86 of file PowVariableVariable.cc.
References PLearn::BinaryVariable::input1, PLearn::Var::length(), and PLearn::Var::width().
void PLearn::PowVariableVariable::symbolicBprop | ( | ) | [virtual] |
compute a piece of new Var graph that represents the symbolic derivative of this Var
Reimplemented from PLearn::Variable.
Definition at line 149 of file PowVariableVariable.cc.
References PLearn::dot(), PLearn::Variable::g, PLearn::ifThenElse(), PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, PLearn::Variable::length(), PLearn::log(), PLearn::Variable::Var, PLearn::Variable::width(), and zero.
{ Var gv = g * Var(this); Var input1zero = (input1<=0.0); Var zero(length(), width()); input1->accg(ifThenElse(input1zero, zero, gv * input2 / input1)); if (input2->isScalar()) input2->accg(dot(gv,ifThenElse(input1zero, zero, log(input1)))); else input2->accg(ifThenElse(input1zero, zero, gv * log(input1))); }
Reimplemented from PLearn::BinaryVariable.
Definition at line 75 of file PowVariableVariable.h.