PLearn 0.1
|
#include <SoftSlopeVariable.h>
Public Member Functions | |
SoftSlopeVariable () | |
Default constructor for persistence. | |
SoftSlopeVariable (Variable *x, Variable *smoothness, Variable *left, Variable *right, bool tabulated=true) | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual SoftSlopeVariable * | 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_ () |
SoftSlopeVariable. | |
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 | |
bool | tabulated |
Private Types | |
typedef NaryVariable | inherited |
Definition at line 58 of file SoftSlopeVariable.h.
typedef NaryVariable PLearn::SoftSlopeVariable::inherited [private] |
Reimplemented from PLearn::NaryVariable.
Definition at line 60 of file SoftSlopeVariable.h.
PLearn::SoftSlopeVariable::SoftSlopeVariable | ( | ) | [inline] |
string PLearn::SoftSlopeVariable::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 59 of file SoftSlopeVariable.cc.
OptionList & PLearn::SoftSlopeVariable::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 59 of file SoftSlopeVariable.cc.
RemoteMethodMap & PLearn::SoftSlopeVariable::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 59 of file SoftSlopeVariable.cc.
Reimplemented from PLearn::NaryVariable.
Definition at line 59 of file SoftSlopeVariable.cc.
Object * PLearn::SoftSlopeVariable::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 59 of file SoftSlopeVariable.cc.
StaticInitializer SoftSlopeVariable::_static_initializer_ & PLearn::SoftSlopeVariable::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 59 of file SoftSlopeVariable.cc.
void PLearn::SoftSlopeVariable::bprop | ( | ) | [virtual] |
Implements PLearn::Variable.
Definition at line 125 of file SoftSlopeVariable.cc.
References PLearn::fast_exact_is_equal(), PLearn::Variable::gradientdata, i, PLearn::left(), n, PLearn::VarArray::nelems(), PLearn::Variable::nelems(), PLearn::right(), PLearn::sigmoid(), PLearn::soft_slope(), tabulated, PLearn::tabulated_soft_slope(), PLearn::NaryVariable::varray, and x.
{ int n=nelems(); int n1=varray[0]->nelems(); int n2=varray[1]->nelems(); int n3=varray[2]->nelems(); int n4=varray[3]->nelems(); int m1= n1==1?0:1; int m2= n2==1?0:1; int m3= n3==1?0:1; int m4= n4==1?0:1; real* x = varray[0]->valuedata; real* smoothness = varray[1]->valuedata; real* left = varray[2]->valuedata; real* right = varray[3]->valuedata; real* dx = varray[0]->gradientdata; real* dsmoothness = varray[1]->gradientdata; real* dleft = varray[2]->gradientdata; real* dright = varray[3]->gradientdata; for(int i=0; i<n; i++,x+=m1,smoothness+=m2,left+=m3,right+=m4,dx+=m1,dsmoothness+=m2,dleft+=m3,dright+=m4) { if (fast_exact_is_equal(*smoothness, 0)) continue; real inv_smoothness = 1.0 / *smoothness; real t1 = sigmoid(- *smoothness*(*x-*left)); real t2 = sigmoid(- *smoothness*(*x-*right)); real inv_delta=1.0/(*right-*left); real rat = (tabulated?tabulated_soft_slope(*x, *smoothness, *left, *right):soft_slope(*x, *smoothness, *left, *right)) -1; real move = rat * inv_delta; real dss = (-t1*(*x-*left) + t2*(*x-*right))*inv_smoothness*inv_delta - rat * inv_smoothness; real dll = t1*inv_delta*inv_smoothness + move; real drr = -t2*inv_delta*inv_smoothness - move; real dxx = (-t1+t2)*inv_delta; *dx += gradientdata[i] * dxx; *dsmoothness += gradientdata[i] * dss; *dleft += gradientdata[i] * dll; *dright += gradientdata[i] * drr; } }
string PLearn::SoftSlopeVariable::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 59 of file SoftSlopeVariable.cc.
void PLearn::SoftSlopeVariable::declareOptions | ( | OptionList & | ol | ) | [static] |
Default constructor for persistence.
Reimplemented from PLearn::NaryVariable.
Definition at line 68 of file SoftSlopeVariable.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::NaryVariable::declareOptions(), and tabulated.
{ declareOption(ol, "tabulated", &SoftSlopeVariable::tabulated, OptionBase::buildoption, ""); inherited::declareOptions(ol); }
static const PPath& PLearn::SoftSlopeVariable::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 70 of file SoftSlopeVariable.h.
{ return new SoftSlopeVariable(x,smoothness,left,right); }
SoftSlopeVariable * PLearn::SoftSlopeVariable::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::NaryVariable.
Definition at line 59 of file SoftSlopeVariable.cc.
void PLearn::SoftSlopeVariable::fprop | ( | ) | [virtual] |
compute output given input
Implements PLearn::Variable.
Definition at line 95 of file SoftSlopeVariable.cc.
References i, PLearn::left(), n, PLearn::VarArray::nelems(), PLearn::Variable::nelems(), PLearn::right(), PLearn::soft_slope(), tabulated, PLearn::tabulated_soft_slope(), 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(); int n4=varray[3]->nelems(); real* x = varray[0]->valuedata; real* smoothness = varray[1]->valuedata; real* left = varray[2]->valuedata; real* right = varray[3]->valuedata; if (n1==n && n2==n && n3==n && n4==n) for(int i=0; i<n; i++) valuedata[i] = tabulated?tabulated_soft_slope(x[i], smoothness[i], left[i], right[i]):soft_slope(x[i], smoothness[i], left[i], right[i]); else if (n1==1 && n2==n && n3==n && n4==n) for(int i=0; i<n; i++) valuedata[i] = tabulated?tabulated_soft_slope(*x, smoothness[i], left[i], right[i]):soft_slope(*x, smoothness[i], left[i], right[i]); else { int m1= n1==1?0:1; int m2= n2==1?0:1; int m3= n3==1?0:1; int m4= n4==1?0:1; for(int i=0; i<n; i++,x+=m1,smoothness+=m2,left+=m3,right+=m4) valuedata[i] = tabulated?tabulated_soft_slope(*x, *smoothness, *left, *right):soft_slope(*x, *smoothness, *left, *right); } }
OptionList & PLearn::SoftSlopeVariable::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 59 of file SoftSlopeVariable.cc.
OptionMap & PLearn::SoftSlopeVariable::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 59 of file SoftSlopeVariable.cc.
RemoteMethodMap & PLearn::SoftSlopeVariable::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 59 of file SoftSlopeVariable.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 74 of file SoftSlopeVariable.cc.
References i, PLearn::Variable::length(), PLERROR, PLearn::TVec< T >::size(), PLearn::NaryVariable::varray, w, and PLearn::Variable::width().
{ l = 0; w = 0; if (varray.size() == 4 && varray[0] && varray[1] && varray[2] && varray[3]) { for (int i = 0; i < 4; i++) { if (varray[i]->length() > l) l = varray[i]->length(); if (varray[i]->width() > w) w = varray[i]->width(); } for (int i = 0; i < 4; i++) { if (varray[i]->length() != l || varray[i]->width() != w) { if (varray[i]->length() != 1 || varray[i]->width() != 1) PLERROR("Each argument of SoftSlopeVariable should either have the same length/width as the others or length 1"); } } } }
void PLearn::SoftSlopeVariable::symbolicBprop | ( | ) | [virtual] |
compute a piece of new Var graph that represents the symbolic derivative of this Var
Reimplemented from PLearn::Variable.
Definition at line 164 of file SoftSlopeVariable.cc.
References PLERROR.
{ PLERROR("SoftSlopeVariable::symbolicBprop() not implemented"); }
Reimplemented from PLearn::NaryVariable.
Definition at line 70 of file SoftSlopeVariable.h.
bool PLearn::SoftSlopeVariable::tabulated [protected] |
Definition at line 63 of file SoftSlopeVariable.h.
Referenced by bprop(), declareOptions(), and fprop().