PLearn 0.1
|
SourceVariable that after each update, modifies values as needed to satisfy simple constraints. More...
#include <ConstrainedSourceVariable.h>
Public Member Functions | |
ConstrainedSourceVariable () | |
Default constructor for persistence. | |
ConstrainedSourceVariable (int thelength, int thewidth, int the_constraint_mode=2, bool call_build_=true) | |
ConstrainedSourceVariable (const Vec &v, bool vertical=true, int the_constraint_mode=2, bool call_build_=true) | |
ConstrainedSourceVariable (const Mat &m, int the_constraint_mode=2, bool call_build_=true) | |
virtual void | satisfyConstraints () |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual ConstrainedSourceVariable * | deepCopy (CopiesMap &copies) const |
virtual void | build () |
Post-constructor. | |
virtual void | makeDeepCopyFromShallowCopy (CopiesMap &copies) |
Transforms a shallow copy into a deep copy. | |
virtual bool | update (real step_size, Vec direction_vec, real coeff=1.0, real b=0.0) |
set value = value + (step_size * coeff + b) * direction | |
virtual bool | update (Vec step_sizes, Vec direction_vec, real coeff=1.0, real b=0.0) |
set value[i] = value[i] + (step_sizes[i]*coeff + b) * direction[i] | |
virtual bool | update (real step_size, bool clear=false) |
set value = value + step_size * gradient | |
virtual bool | update (Vec new_value) |
set value = new_value | |
virtual void | updateAndClear () |
Set value += gradient (respecting potential box constraints), and clear the gradient. | |
virtual void | updateWithWeightDecay (real step_size, real weight_decay, bool L1, bool clear=true) |
if (L1) value += learning_rate*gradient decrease |value| by learning_rate*weight_decay if it does not make value change sign else // L2 value += learning_rate*(gradient - weight_decay*value) if (clear) gradient=0 | |
Static Public Member Functions | |
static string | _classname_ () |
ConstrainedSourceVariable. | |
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 | |
int | constraint_mode |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
Declares the class options. | |
Private Types | |
typedef SourceVariable | inherited |
Private Member Functions | |
void | build_ () |
This does the actual building. |
SourceVariable that after each update, modifies values as needed to satisfy simple constraints.
The currently supported constraint is rows having norm 1. i.e. after each update rows are divided by their norm.
Definition at line 54 of file ConstrainedSourceVariable.h.
typedef SourceVariable PLearn::ConstrainedSourceVariable::inherited [private] |
Reimplemented from PLearn::SourceVariable.
Definition at line 56 of file ConstrainedSourceVariable.h.
PLearn::ConstrainedSourceVariable::ConstrainedSourceVariable | ( | ) | [inline] |
Default constructor for persistence.
Definition at line 65 of file ConstrainedSourceVariable.h.
:SourceVariable(), constraint_mode(2) {}
PLearn::ConstrainedSourceVariable::ConstrainedSourceVariable | ( | int | thelength, |
int | thewidth, | ||
int | the_constraint_mode = 2 , |
||
bool | call_build_ = true |
||
) | [inline] |
Definition at line 70 of file ConstrainedSourceVariable.h.
:SourceVariable(thelength, thewidth, call_build_), constraint_mode(the_constraint_mode) {}
PLearn::ConstrainedSourceVariable::ConstrainedSourceVariable | ( | const Vec & | v, |
bool | vertical = true , |
||
int | the_constraint_mode = 2 , |
||
bool | call_build_ = true |
||
) | [inline] |
Definition at line 75 of file ConstrainedSourceVariable.h.
:SourceVariable(v, vertical, call_build_), constraint_mode(the_constraint_mode) {}
PLearn::ConstrainedSourceVariable::ConstrainedSourceVariable | ( | const Mat & | m, |
int | the_constraint_mode = 2 , |
||
bool | call_build_ = true |
||
) | [inline] |
Definition at line 80 of file ConstrainedSourceVariable.h.
:SourceVariable(m, call_build_), constraint_mode(the_constraint_mode) {}
string PLearn::ConstrainedSourceVariable::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::SourceVariable.
Definition at line 52 of file ConstrainedSourceVariable.cc.
OptionList & PLearn::ConstrainedSourceVariable::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::SourceVariable.
Definition at line 52 of file ConstrainedSourceVariable.cc.
RemoteMethodMap & PLearn::ConstrainedSourceVariable::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::SourceVariable.
Definition at line 52 of file ConstrainedSourceVariable.cc.
Reimplemented from PLearn::SourceVariable.
Definition at line 52 of file ConstrainedSourceVariable.cc.
Object * PLearn::ConstrainedSourceVariable::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::SourceVariable.
Definition at line 52 of file ConstrainedSourceVariable.cc.
StaticInitializer ConstrainedSourceVariable::_static_initializer_ & PLearn::ConstrainedSourceVariable::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::SourceVariable.
Definition at line 52 of file ConstrainedSourceVariable.cc.
void PLearn::ConstrainedSourceVariable::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::SourceVariable.
Definition at line 87 of file ConstrainedSourceVariable.cc.
{ inherited::build(); build_(); }
void PLearn::ConstrainedSourceVariable::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::SourceVariable.
Definition at line 84 of file ConstrainedSourceVariable.cc.
{ }
string PLearn::ConstrainedSourceVariable::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::SourceVariable.
Definition at line 52 of file ConstrainedSourceVariable.cc.
void PLearn::ConstrainedSourceVariable::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares the class options.
Reimplemented from PLearn::SourceVariable.
Definition at line 73 of file ConstrainedSourceVariable.cc.
References PLearn::OptionBase::buildoption, constraint_mode, and PLearn::declareOption().
{ declareOption( ol, "constraint_mode", &ConstrainedSourceVariable::constraint_mode, OptionBase::buildoption, "The constraint_mode: \n" "2: divide each row by its L2 norm after each update\n" "1: divide each row by its L1 norm after each update"); inherited::declareOptions(ol); }
static const PPath& PLearn::ConstrainedSourceVariable::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::SourceVariable.
Definition at line 91 of file ConstrainedSourceVariable.h.
:
ConstrainedSourceVariable * PLearn::ConstrainedSourceVariable::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::SourceVariable.
Definition at line 52 of file ConstrainedSourceVariable.cc.
OptionList & PLearn::ConstrainedSourceVariable::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::SourceVariable.
Definition at line 52 of file ConstrainedSourceVariable.cc.
OptionMap & PLearn::ConstrainedSourceVariable::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::SourceVariable.
Definition at line 52 of file ConstrainedSourceVariable.cc.
RemoteMethodMap & PLearn::ConstrainedSourceVariable::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::SourceVariable.
Definition at line 52 of file ConstrainedSourceVariable.cc.
void PLearn::ConstrainedSourceVariable::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::SourceVariable.
Definition at line 93 of file ConstrainedSourceVariable.cc.
{ inherited::makeDeepCopyFromShallowCopy(copies); }
void PLearn::ConstrainedSourceVariable::satisfyConstraints | ( | ) | [virtual] |
Definition at line 55 of file ConstrainedSourceVariable.cc.
References i, PLearn::normalize(), and PLERROR.
{ switch(constraint_mode) { case 2: for(int i=0; i<matValue.length(); i++) normalize(matValue(i), 2); break; case 1: for(int i=0; i<matValue.length(); i++) normalize(matValue(i), 1); break; default: PLERROR("Invalid constraint_mode %d",constraint_mode); } }
set value = new_value
projected down in each direction independently in the subspace in which the box constraints are satisfied. return true if box constraints have been hit with the update
Reimplemented from PLearn::Variable.
Definition at line 122 of file ConstrainedSourceVariable.cc.
References PLearn::update().
{ bool ret = inherited::update(new_value); satisfyConstraints(); return ret; }
bool PLearn::ConstrainedSourceVariable::update | ( | real | step_size, |
Vec | direction_vec, | ||
real | coeff = 1.0 , |
||
real | b = 0.0 |
||
) | [virtual] |
set value = value + (step_size * coeff + b) * direction
with step_size possibly scaled down s.t. box constraints are satisfied return true if box constraints have been hit with the update If (allows_partial_update) the update is done where necessary. NB: Wrong ?
Reimplemented from PLearn::Variable.
Definition at line 101 of file ConstrainedSourceVariable.cc.
References PLearn::update().
{ bool ret = inherited::update(step_size, direction_vec, coeff, b); satisfyConstraints(); return ret; }
bool PLearn::ConstrainedSourceVariable::update | ( | Vec | step_sizes, |
Vec | direction_vec, | ||
real | coeff = 1.0 , |
||
real | b = 0.0 |
||
) | [virtual] |
set value[i] = value[i] + (step_sizes[i]*coeff + b) * direction[i]
with step_size possibly scaled down s.t. box constraints are satisfied return true if box constraints have been hit with the update
Reimplemented from PLearn::Variable.
Definition at line 108 of file ConstrainedSourceVariable.cc.
References PLearn::update().
{ bool ret = inherited::update(step_sizes, direction_vec, coeff, b); satisfyConstraints(); return ret; }
set value = value + step_size * gradient
with step_size possibly scaled down s.t. box constraints are satisfied return true if box constraints have been hit with the update
Reimplemented from PLearn::Variable.
Definition at line 115 of file ConstrainedSourceVariable.cc.
References PLearn::update().
{ bool ret = inherited::update(step_size, clear); satisfyConstraints(); return ret; }
void PLearn::ConstrainedSourceVariable::updateAndClear | ( | ) | [virtual] |
Set value += gradient (respecting potential box constraints), and clear the gradient.
Reimplemented from PLearn::Variable.
Definition at line 129 of file ConstrainedSourceVariable.cc.
{ inherited::updateAndClear(); satisfyConstraints(); }
void PLearn::ConstrainedSourceVariable::updateWithWeightDecay | ( | real | step_size, |
real | weight_decay, | ||
bool | L1, | ||
bool | clear = true |
||
) | [virtual] |
if (L1) value += learning_rate*gradient decrease |value| by learning_rate*weight_decay if it does not make value change sign else // L2 value += learning_rate*(gradient - weight_decay*value) if (clear) gradient=0
Reimplemented from PLearn::Variable.
Definition at line 135 of file ConstrainedSourceVariable.cc.
{ inherited::updateWithWeightDecay(step_size, weight_decay, L1, clear); satisfyConstraints(); }
Reimplemented from PLearn::SourceVariable.
Definition at line 91 of file ConstrainedSourceVariable.h.
Definition at line 61 of file ConstrainedSourceVariable.h.
Referenced by declareOptions().