PLearn 0.1
|
#include <ArgminOfVariable.h>
Public Member Functions | |
ArgminOfVariable (Variable *the_v, Variable *the_expression, Variable *the_values_of_v, const VarArray &the_inputs) | |
ArgminOfVariable. | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual ArgminOfVariable * | 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 | makeDeepCopyFromShallowCopy (CopiesMap &copies) |
Does the necessary operations to transform a shallow copy (this) into a deep copy by deep-copying all the members that need to be. | |
virtual void | fprop () |
compute output given input | |
virtual void | bprop () |
Static Public Member Functions | |
static string | _classname_ () |
NaryVariable. | |
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 | |
ArgminOfVariable () | |
protected default constructor for persistence | |
Protected Attributes | |
VarArray | inputs |
Var | expression |
Var | values_of_v |
Var | v |
int | index_of_argmin |
VarArray | vv_path |
values_of_v(inputs) | |
VarArray | e_path |
expression(v&inputs) | |
VarArray | v_path |
expression(v) | |
Private Types | |
typedef NaryVariable | inherited |
returns the value of v within the_values_of_v that gives the lowest value of expression (which may depend on inputs).
Definition at line 54 of file ArgminOfVariable.h.
typedef NaryVariable PLearn::ArgminOfVariable::inherited [private] |
Reimplemented from PLearn::NaryVariable.
Definition at line 57 of file ArgminOfVariable.h.
PLearn::ArgminOfVariable::ArgminOfVariable | ( | ) | [inline, protected] |
protected default constructor for persistence
Definition at line 61 of file ArgminOfVariable.h.
: inputs(), expression(), values_of_v(), v(), index_of_argmin(), vv_path(), e_path(), v_path() {}
PLearn::ArgminOfVariable::ArgminOfVariable | ( | Variable * | the_v, |
Variable * | the_expression, | ||
Variable * | the_values_of_v, | ||
const VarArray & | the_inputs | ||
) |
Definition at line 52 of file ArgminOfVariable.cc.
References e_path, expression, inputs, PLERROR, PLearn::propagationPath(), v, v_path, values_of_v, and vv_path.
:NaryVariable(the_inputs,1,1), inputs(the_inputs), expression(the_expression), values_of_v(the_values_of_v), v(the_v) { if (!v->isScalar() || !values_of_v->isVec()) PLERROR("ArgminOfVariable currently implemented only for a scalar v and a vector values_of_v"); vv_path = propagationPath(inputs,values_of_v); e_path = propagationPath(inputs& (VarArray)v, expression); v_path = propagationPath(v, expression); }
string PLearn::ArgminOfVariable::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 67 of file ArgminOfVariable.cc.
OptionList & PLearn::ArgminOfVariable::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 67 of file ArgminOfVariable.cc.
RemoteMethodMap & PLearn::ArgminOfVariable::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 67 of file ArgminOfVariable.cc.
Reimplemented from PLearn::NaryVariable.
Definition at line 67 of file ArgminOfVariable.cc.
Object * PLearn::ArgminOfVariable::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 67 of file ArgminOfVariable.cc.
StaticInitializer ArgminOfVariable::_static_initializer_ & PLearn::ArgminOfVariable::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 67 of file ArgminOfVariable.cc.
void PLearn::ArgminOfVariable::bprop | ( | ) | [virtual] |
Implements PLearn::Variable.
Definition at line 111 of file ArgminOfVariable.cc.
References PLearn::VarArray::bprop(), PLearn::VarArray::clearGradient(), PLearn::Variable::gradientdata, index_of_argmin, values_of_v, and vv_path.
{ vv_path.clearGradient(); values_of_v->gradientdata[index_of_argmin] = gradientdata[0]; vv_path.bprop(); }
string PLearn::ArgminOfVariable::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 67 of file ArgminOfVariable.cc.
static const PPath& PLearn::ArgminOfVariable::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 80 of file ArgminOfVariable.h.
{ return new ArgminOfVariable(v, expression, values_of_v, inputs); }
ArgminOfVariable * PLearn::ArgminOfVariable::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::NaryVariable.
Definition at line 67 of file ArgminOfVariable.cc.
void PLearn::ArgminOfVariable::fprop | ( | ) | [virtual] |
compute output given input
Implements PLearn::Variable.
Definition at line 87 of file ArgminOfVariable.cc.
References e_path, expression, PLearn::VarArray::fprop(), i, index_of_argmin, v, v_path, PLearn::Variable::value, values_of_v, and vv_path.
{ vv_path.fprop(); // compute influence of inputs on values_of_v real min_value_of_expression = FLT_MAX; real argmin_value_of_v = values_of_v->value[0]; for (int i=0;i<values_of_v->nelems();i++) { v->value[0] = values_of_v->value[i]; if (i==0) e_path.fprop(); // compute influence of v and inputs on expression else v_path.fprop(); // otherwise, keep influence of inputs fixed real e = expression->value[0]; if (e<min_value_of_expression) { min_value_of_expression = e; argmin_value_of_v = v->value[0]; index_of_argmin = i; } } value[0] = argmin_value_of_v; }
OptionList & PLearn::ArgminOfVariable::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 67 of file ArgminOfVariable.cc.
OptionMap & PLearn::ArgminOfVariable::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 67 of file ArgminOfVariable.cc.
RemoteMethodMap & PLearn::ArgminOfVariable::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 67 of file ArgminOfVariable.cc.
void PLearn::ArgminOfVariable::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Does the necessary operations to transform a shallow copy (this) into a deep copy by deep-copying all the members that need to be.
This needs to be overridden by every class that adds "complex" data members to the class, such as Vec
, Mat
, PP<Something>
, etc. Typical implementation:
void CLASS_OF_THIS::makeDeepCopyFromShallowCopy(CopiesMap& copies) { inherited::makeDeepCopyFromShallowCopy(copies); deepCopyField(complex_data_member1, copies); deepCopyField(complex_data_member2, copies); ... }
copies | A map used by the deep-copy mechanism to keep track of already-copied objects. |
Reimplemented from PLearn::NaryVariable.
Definition at line 73 of file ArgminOfVariable.cc.
References PLearn::deepCopyField(), e_path, expression, inputs, PLearn::NaryVariable::makeDeepCopyFromShallowCopy(), v, v_path, values_of_v, and vv_path.
{ inherited::makeDeepCopyFromShallowCopy(copies); deepCopyField(inputs, copies); deepCopyField(expression, copies); deepCopyField(values_of_v, copies); deepCopyField(v, copies); deepCopyField(vv_path, copies); deepCopyField(e_path, copies); deepCopyField(v_path, copies); }
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 69 of file ArgminOfVariable.cc.
{ l=1; w=1; }
Reimplemented from PLearn::NaryVariable.
Definition at line 80 of file ArgminOfVariable.h.
VarArray PLearn::ArgminOfVariable::e_path [protected] |
expression(v&inputs)
Definition at line 72 of file ArgminOfVariable.h.
Referenced by ArgminOfVariable(), fprop(), and makeDeepCopyFromShallowCopy().
Var PLearn::ArgminOfVariable::expression [protected] |
Definition at line 66 of file ArgminOfVariable.h.
Referenced by ArgminOfVariable(), fprop(), and makeDeepCopyFromShallowCopy().
int PLearn::ArgminOfVariable::index_of_argmin [protected] |
Definition at line 69 of file ArgminOfVariable.h.
VarArray PLearn::ArgminOfVariable::inputs [protected] |
Definition at line 65 of file ArgminOfVariable.h.
Referenced by ArgminOfVariable(), and makeDeepCopyFromShallowCopy().
Var PLearn::ArgminOfVariable::v [protected] |
Definition at line 68 of file ArgminOfVariable.h.
Referenced by ArgminOfVariable(), fprop(), and makeDeepCopyFromShallowCopy().
VarArray PLearn::ArgminOfVariable::v_path [protected] |
expression(v)
Definition at line 73 of file ArgminOfVariable.h.
Referenced by ArgminOfVariable(), fprop(), and makeDeepCopyFromShallowCopy().
Var PLearn::ArgminOfVariable::values_of_v [protected] |
Definition at line 67 of file ArgminOfVariable.h.
Referenced by ArgminOfVariable(), bprop(), fprop(), and makeDeepCopyFromShallowCopy().
VarArray PLearn::ArgminOfVariable::vv_path [protected] |
values_of_v(inputs)
Definition at line 71 of file ArgminOfVariable.h.
Referenced by ArgminOfVariable(), bprop(), fprop(), and makeDeepCopyFromShallowCopy().