PLearn 0.1
|
#include <HardSlopeVariable.h>
Public Member Functions | |
HardSlopeVariable () | |
Default constructor for persistence. | |
HardSlopeVariable (Variable *x, Variable *left, Variable *right) | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual HardSlopeVariable * | deepCopy (CopiesMap &copies) const |
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_ () |
HardSlopeVariable. | |
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_ |
Private Types | |
typedef NaryVariable | inherited |
Definition at line 56 of file HardSlopeVariable.h.
typedef NaryVariable PLearn::HardSlopeVariable::inherited [private] |
Reimplemented from PLearn::NaryVariable.
Definition at line 58 of file HardSlopeVariable.h.
PLearn::HardSlopeVariable::HardSlopeVariable | ( | ) | [inline] |
string PLearn::HardSlopeVariable::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 56 of file HardSlopeVariable.cc.
OptionList & PLearn::HardSlopeVariable::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 56 of file HardSlopeVariable.cc.
RemoteMethodMap & PLearn::HardSlopeVariable::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 56 of file HardSlopeVariable.cc.
Reimplemented from PLearn::NaryVariable.
Definition at line 56 of file HardSlopeVariable.cc.
Object * PLearn::HardSlopeVariable::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 56 of file HardSlopeVariable.cc.
StaticInitializer HardSlopeVariable::_static_initializer_ & PLearn::HardSlopeVariable::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 56 of file HardSlopeVariable.cc.
void PLearn::HardSlopeVariable::bprop | ( | ) | [virtual] |
Implements PLearn::Variable.
Definition at line 112 of file HardSlopeVariable.cc.
References PLearn::Variable::gradientdata, i, PLearn::left(), n, PLearn::VarArray::nelems(), PLearn::Variable::nelems(), PLearn::right(), PLearn::NaryVariable::varray, and x.
{ int n=nelems(); int n1=varray[0]->nelems(); int n2=varray[1]->nelems(); int n3=varray[2]->nelems(); int m1= n1==1?0:1; int m2= n2==1?0:1; int m3= n3==1?0:1; real* x = varray[0]->valuedata; real* left = varray[1]->valuedata; real* right = varray[2]->valuedata; real* dx = varray[0]->gradientdata; real* dleft = varray[1]->gradientdata; real* dright = varray[2]->gradientdata; for(int i=0; i<n; i++,x+=m1,left+=m2,right+=m3,dx+=m1,dleft+=m2,dright+=m3) { real tleft = *x - *left; real tright = *x - *right; if (tright<=0 && tleft>=0) { real inv_delta=1.0/(*right - *left); real dll = tright*inv_delta; real drr = -tleft*inv_delta; real dxx = inv_delta; *dx += gradientdata[i] * dxx; *dleft += gradientdata[i] * dll; *dright += gradientdata[i] * drr; } } }
string PLearn::HardSlopeVariable::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 56 of file HardSlopeVariable.cc.
static const PPath& PLearn::HardSlopeVariable::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 65 of file HardSlopeVariable.h.
{ return new HardSlopeVariable(x,left,right); }
HardSlopeVariable * PLearn::HardSlopeVariable::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::NaryVariable.
Definition at line 56 of file HardSlopeVariable.cc.
void PLearn::HardSlopeVariable::fprop | ( | ) | [virtual] |
compute output given input
Implements PLearn::Variable.
Definition at line 85 of file HardSlopeVariable.cc.
References PLearn::hard_slope(), i, PLearn::left(), n, PLearn::VarArray::nelems(), PLearn::Variable::nelems(), PLearn::right(), PLearn::Variable::valuedata, PLearn::NaryVariable::varray, and x.
{ int n=nelems(); int n1=varray[0]->nelems(); int n2=varray[1]->nelems(); int n3=varray[2]->nelems(); real* x = varray[0]->valuedata; real* left = varray[1]->valuedata; real* right = varray[2]->valuedata; if (n1==n && n2==n && n3==n) for(int i=0; i<n; i++) valuedata[i] = hard_slope(x[i], left[i], right[i]); else if (n1==1 && n2==n && n3==n) for(int i=0; i<n; i++) valuedata[i] = hard_slope(*x, left[i], right[i]); else { int m1= n1==1?0:1; int m2= n2==1?0:1; int m3= n3==1?0:1; for(int i=0; i<n; i++,x+=m1,left+=m2,right+=m3) valuedata[i] = hard_slope(*x, *left, *right); } }
OptionList & PLearn::HardSlopeVariable::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 56 of file HardSlopeVariable.cc.
OptionMap & PLearn::HardSlopeVariable::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 56 of file HardSlopeVariable.cc.
RemoteMethodMap & PLearn::HardSlopeVariable::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 56 of file HardSlopeVariable.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 65 of file HardSlopeVariable.cc.
References i, PLearn::Variable::length(), PLERROR, PLearn::TVec< T >::size(), PLearn::NaryVariable::varray, w, and PLearn::Variable::width().
{ l = w = 0; if (varray.size() >= 3) { for (int i = 0;i < 3; i++) { if (varray[i]->length()>l) l = varray[i]->length(); if (varray[i]->width() > w) w = varray[i]->width(); } for (int i = 0;i < 3; i++) { if (varray[i]->length() != l || varray[i]->width() != w) { if (varray[i]->length() != 1 || varray[i]->width() != 1) PLERROR("Each argument of HardSlopeVariable should either have the same length/width as the others or length 1"); } } } }
void PLearn::HardSlopeVariable::symbolicBprop | ( | ) | [virtual] |
compute a piece of new Var graph that represents the symbolic derivative of this Var
Reimplemented from PLearn::Variable.
Definition at line 144 of file HardSlopeVariable.cc.
References PLERROR.
{ PLERROR("HardSlopeVariable::symbolicBprop() not implemented"); }
Reimplemented from PLearn::NaryVariable.
Definition at line 65 of file HardSlopeVariable.h.