PLearn 0.1
|
#include <ConstrainVariable.h>
Public Member Functions | |
ConstrainVariable () | |
Default constructor. | |
ConstrainVariable (Variable *input, bool call_build_=true) | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual ConstrainVariable * | 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 () |
Nothing to do by default. | |
virtual void | bprop () |
Nothing to do by default. | |
virtual void | bbprop () |
here don't approximate, do d2C/dx^2 = 4 x^2 d2C/dy^2 + 2 dC/dy | |
virtual void | symbolicBprop () |
compute a piece of new Var graph that represents the symbolic derivative of this Var | |
virtual void | rfprop () |
real | box_constrain (real x) const |
Static Public Member Functions | |
static string | _classname_ () |
ConstrainVariable. | |
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 () |
Public Attributes | |
double | max_rowsum |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Private Types | |
typedef UnaryVariable | inherited |
Private Member Functions | |
void | build_ () |
Object-specific post-constructor. |
Definition at line 48 of file ConstrainVariable.h.
typedef UnaryVariable PLearn::ConstrainVariable::inherited [private] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 50 of file ConstrainVariable.h.
PLearn::ConstrainVariable::ConstrainVariable | ( | ) |
Definition at line 70 of file ConstrainVariable.cc.
References build_().
: inherited(input, min(input->length(), input->width()), 1, call_build_), max_rowsum(FLT_MAX) { if (call_build_) build_(); }
string PLearn::ConstrainVariable::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 60 of file ConstrainVariable.cc.
OptionList & PLearn::ConstrainVariable::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 60 of file ConstrainVariable.cc.
RemoteMethodMap & PLearn::ConstrainVariable::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 60 of file ConstrainVariable.cc.
Reimplemented from PLearn::UnaryVariable.
Definition at line 60 of file ConstrainVariable.cc.
Object * PLearn::ConstrainVariable::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 60 of file ConstrainVariable.cc.
StaticInitializer ConstrainVariable::_static_initializer_ & PLearn::ConstrainVariable::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 60 of file ConstrainVariable.cc.
void PLearn::ConstrainVariable::bbprop | ( | ) | [virtual] |
here don't approximate, do d2C/dx^2 = 4 x^2 d2C/dy^2 + 2 dC/dy
Reimplemented from PLearn::Variable.
Definition at line 176 of file ConstrainVariable.cc.
References PLERROR.
{ PLERROR("bbprop not implemented for this variable"); }
void PLearn::ConstrainVariable::bprop | ( | ) | [virtual] |
Nothing to do by default.
Reimplemented from PLearn::UnaryVariable.
Definition at line 144 of file ConstrainVariable.cc.
References box_constrain(), PLearn::Variable::g, i, PLearn::UnaryVariable::input, j, PLearn::TMat< T >::length(), PLearn::Variable::matGradient, max_rowsum, PLearn::Variable::max_value, PLearn::Variable::min_value, w, and PLearn::TMat< T >::width().
{ Mat U = input->matValue; Mat Ug = input->matGradient; int l = U.length(); int w = U.width(); for(int i=0; i<l; i++) { real* ui = U[i]; real* ugi = Ug[i]; real* vgi = matGradient[i]; real tot = 0; for(int j=0; j<w; j++) tot += box_constrain(ui[j]); real coef = 1; if(tot>max_rowsum) coef = max_rowsum/tot; for(int j=0; j<w; j++) { real v = ui[j]; real g = vgi[j]; if((g<0 && v>min_value) || (g>0 && v<max_value)) ugi[j] += g*coef; } } }
void PLearn::ConstrainVariable::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::UnaryVariable.
Definition at line 92 of file ConstrainVariable.cc.
References PLearn::UnaryVariable::build(), and build_().
{ inherited::build(); build_(); }
void PLearn::ConstrainVariable::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::UnaryVariable.
Definition at line 100 of file ConstrainVariable.cc.
Referenced by build(), and ConstrainVariable().
{
// Nothing to do here.
}
string PLearn::ConstrainVariable::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 60 of file ConstrainVariable.cc.
static const PPath& PLearn::ConstrainVariable::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 60 of file ConstrainVariable.h.
ConstrainVariable * PLearn::ConstrainVariable::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 60 of file ConstrainVariable.cc.
void PLearn::ConstrainVariable::fprop | ( | ) | [virtual] |
Nothing to do by default.
Reimplemented from PLearn::UnaryVariable.
Definition at line 119 of file ConstrainVariable.cc.
References box_constrain(), i, PLearn::UnaryVariable::input, j, PLearn::TMat< T >::length(), PLearn::Variable::matValue, max_rowsum, w, PLearn::TMat< T >::width(), and x.
{ Mat U = input->matValue; int l = U.length(); int w = U.width(); for(int i=0; i<l; i++) { real* ui = U[i]; real* vi = matValue[i]; real tot = 0; for(int j=0; j<w; j++) { real x = box_constrain(ui[j]); tot += x; vi[j] = x; } if(tot>max_rowsum) { real coef = max_rowsum/tot; for(int j=0; j<w; j++) vi[j] *= coef; } } }
OptionList & PLearn::ConstrainVariable::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 60 of file ConstrainVariable.cc.
OptionMap & PLearn::ConstrainVariable::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 60 of file ConstrainVariable.cc.
RemoteMethodMap & PLearn::ConstrainVariable::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 60 of file ConstrainVariable.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 107 of file ConstrainVariable.cc.
References PLearn::UnaryVariable::input, PLearn::Var::length(), and PLearn::Var::width().
void PLearn::ConstrainVariable::rfprop | ( | ) | [virtual] |
Reimplemented from PLearn::Variable.
Definition at line 188 of file ConstrainVariable.cc.
References PLERROR.
{ PLERROR("rfprop no yet implemented for this vairable"); }
void PLearn::ConstrainVariable::symbolicBprop | ( | ) | [virtual] |
compute a piece of new Var graph that represents the symbolic derivative of this Var
Reimplemented from PLearn::Variable.
Definition at line 182 of file ConstrainVariable.cc.
References PLERROR.
{ PLERROR("symbolic bprop not yet implemented for this variable"); }
Reimplemented from PLearn::UnaryVariable.
Definition at line 60 of file ConstrainVariable.h.
Definition at line 53 of file ConstrainVariable.h.
Referenced by bprop(), PLearn::Variable::declareOptions(), and fprop().