PLearn 0.1
|
#include <MatrixElementsVariable.h>
Public Member Functions | |
MatrixElementsVariable () | |
protected default constructor for persistence | |
MatrixElementsVariable (Variable *the_expression, const Var &i_index, const Var &j_index, int number_of_i_values, int number_of_j_values, const VarArray &the_parameters) | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual MatrixElementsVariable * | 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 | 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 () |
virtual void | fbprop () |
do both fprop and bprop | |
Static Public Member Functions | |
static string | _classname_ () |
MatrixElementsVariable. | |
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 Member Functions | |
void | build_ () |
Object-specific post-constructor. | |
Protected Attributes | |
Var | i |
Var | j |
int | ni |
int | nj |
Var | expression |
VarArray | parameters |
VarArray | full_fproppath |
output(inputs¶meters) | |
VarArray | fproppath |
output(inputs) | |
VarArray | bproppath |
output(parameters) | |
Private Types | |
typedef NaryVariable | inherited |
Definition at line 52 of file MatrixElementsVariable.h.
typedef NaryVariable PLearn::MatrixElementsVariable::inherited [private] |
Reimplemented from PLearn::NaryVariable.
Definition at line 54 of file MatrixElementsVariable.h.
PLearn::MatrixElementsVariable::MatrixElementsVariable | ( | ) | [inline] |
protected default constructor for persistence
Definition at line 70 of file MatrixElementsVariable.h.
: i(), j(), ni(), nj(), expression(), parameters(), full_fproppath(), fproppath(), bproppath() {}
PLearn::MatrixElementsVariable::MatrixElementsVariable | ( | Variable * | the_expression, |
const Var & | i_index, | ||
const Var & | j_index, | ||
int | number_of_i_values, | ||
int | number_of_j_values, | ||
const VarArray & | the_parameters | ||
) |
Definition at line 62 of file MatrixElementsVariable.cc.
References build_().
: inherited(the_parameters, number_of_i_values, number_of_j_values), i(i_index), j(j_index), ni(number_of_i_values), nj(number_of_j_values), expression(the_expression), parameters(the_parameters) { build_(); }
string PLearn::MatrixElementsVariable::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 59 of file MatrixElementsVariable.cc.
OptionList & PLearn::MatrixElementsVariable::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 59 of file MatrixElementsVariable.cc.
RemoteMethodMap & PLearn::MatrixElementsVariable::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 59 of file MatrixElementsVariable.cc.
Reimplemented from PLearn::NaryVariable.
Definition at line 59 of file MatrixElementsVariable.cc.
Object * PLearn::MatrixElementsVariable::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 59 of file MatrixElementsVariable.cc.
StaticInitializer MatrixElementsVariable::_static_initializer_ & PLearn::MatrixElementsVariable::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 59 of file MatrixElementsVariable.cc.
void PLearn::MatrixElementsVariable::bprop | ( | ) | [virtual] |
Implements PLearn::Variable.
Definition at line 151 of file MatrixElementsVariable.cc.
References PLearn::VarArray::bprop(), bproppath, PLearn::VarArray::clearGradient(), expression, PLearn::VarArray::fprop(), fproppath, full_fproppath, i, j, PLearn::Variable::matGradient, ni, and nj.
{ int ii,jj; for (ii=0;ii<ni;ii++) { i->value[0]=ii; for (jj=0;jj<nj;jj++) { j->value[0]=jj; if (ii==0 && jj==0) // effect of parameters is computed only once full_fproppath.fprop(); else fproppath.fprop(); bproppath.clearGradient(); // PASCAL: peut-etre qu'ici on devrait avoir += ? // (si l'expression est une Var utilisee ailleurs!) // REPONSE: Non! (expression ne devrait etre utilisee // nulle part ailleurs. To do: utilisation de Func // pour le garantir...) expression->gradient[0] = matGradient(ii,jj); bproppath.bprop(); } } }
void PLearn::MatrixElementsVariable::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::NaryVariable.
Definition at line 73 of file MatrixElementsVariable.cc.
References PLearn::NaryVariable::build().
{ inherited::build(); }
void PLearn::MatrixElementsVariable::build_ | ( | ) | [protected] |
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::NaryVariable.
Definition at line 79 of file MatrixElementsVariable.cc.
References bproppath, expression, fproppath, full_fproppath, i, j, parameters, PLERROR, PLearn::propagationPath(), and PLearn::TVec< T >::size().
Referenced by MatrixElementsVariable().
{ if (i && j && (parameters.size() > 0) && expression) { if (!i->isScalar()) PLERROR("MatrixElementsVariable expect a scalar index Var i_index"); if (!j->isScalar()) PLERROR("MatrixElementsVariable expect a scalar index Var j_index"); full_fproppath = propagationPath(parameters&(VarArray)i&(VarArray)j, expression); fproppath = propagationPath(i&j, expression); bproppath = propagationPath(parameters, expression); } }
string PLearn::MatrixElementsVariable::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 59 of file MatrixElementsVariable.cc.
void PLearn::MatrixElementsVariable::declareOptions | ( | OptionList & | ol | ) | [static] |
Default constructor for persistence.
Reimplemented from PLearn::NaryVariable.
Definition at line 94 of file MatrixElementsVariable.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::NaryVariable::declareOptions(), expression, i, j, ni, nj, and parameters.
{ declareOption(ol, "i", &MatrixElementsVariable::i, OptionBase::buildoption, ""); declareOption(ol, "j", &MatrixElementsVariable::j, OptionBase::buildoption, ""); declareOption(ol, "ni", &MatrixElementsVariable::ni, OptionBase::buildoption, ""); declareOption(ol, "nj", &MatrixElementsVariable::nj, OptionBase::buildoption, ""); declareOption(ol, "expression", &MatrixElementsVariable::expression, OptionBase::buildoption, ""); declareOption(ol, "parameters", &MatrixElementsVariable::parameters, OptionBase::buildoption, ""); inherited::declareOptions(ol); }
static const PPath& PLearn::MatrixElementsVariable::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 77 of file MatrixElementsVariable.h.
: void build_();
MatrixElementsVariable * PLearn::MatrixElementsVariable::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::NaryVariable.
Definition at line 59 of file MatrixElementsVariable.cc.
void PLearn::MatrixElementsVariable::fbprop | ( | ) | [virtual] |
do both fprop and bprop
Reimplemented from PLearn::Variable.
Definition at line 179 of file MatrixElementsVariable.cc.
References PLearn::VarArray::bprop(), bproppath, PLearn::VarArray::clearGradient(), expression, PLearn::VarArray::fprop(), fproppath, full_fproppath, i, j, PLearn::Variable::matGradient, PLearn::Variable::matValue, ni, and nj.
{ int ii,jj; for (ii=0;ii<ni;ii++) { i->value[0]=ii; for (jj=0;jj<nj;jj++) { j->value[0]=jj; if (ii==0 && jj==0) // effect of parameters is computed only once full_fproppath.fprop(); else fproppath.fprop(); matValue(ii,jj) = expression->value[0]; bproppath.clearGradient(); // PASCAL: peut-etre qu'ici on devrait avoir += ? // (si l'expression est une Var utilisee ailleurs!) // REPONSE: Non! (expression ne devrait etre utilisee // nulle part ailleurs. To do: utilisation de Func // pour le garantir...) expression->gradient[0] = matGradient(ii,jj); bproppath.bprop(); } } }
void PLearn::MatrixElementsVariable::fprop | ( | ) | [virtual] |
compute output given input
Implements PLearn::Variable.
Definition at line 130 of file MatrixElementsVariable.cc.
References expression, PLearn::VarArray::fprop(), fproppath, full_fproppath, i, j, PLearn::Variable::matValue, ni, and nj.
{ int ii,jj; for (ii=0;ii<ni;ii++) { i->value[0]=ii; for (jj=0;jj<nj;jj++) { j->value[0]=jj; if (ii==0 && jj==0) // effect of parameters is computed only once full_fproppath.fprop(); else fproppath.fprop(); matValue(ii,jj) = expression->value[0]; } } }
OptionList & PLearn::MatrixElementsVariable::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 59 of file MatrixElementsVariable.cc.
OptionMap & PLearn::MatrixElementsVariable::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 59 of file MatrixElementsVariable.cc.
RemoteMethodMap & PLearn::MatrixElementsVariable::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 59 of file MatrixElementsVariable.cc.
void PLearn::MatrixElementsVariable::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 117 of file MatrixElementsVariable.cc.
References bproppath, PLearn::deepCopyField(), expression, fproppath, full_fproppath, i, j, PLearn::NaryVariable::makeDeepCopyFromShallowCopy(), parameters, and PLearn::varDeepCopyField().
{ inherited::makeDeepCopyFromShallowCopy(copies); varDeepCopyField(i, copies); varDeepCopyField(j, copies); varDeepCopyField(expression, copies); deepCopyField(parameters, copies); deepCopyField(full_fproppath, copies); deepCopyField(fproppath, copies); deepCopyField(bproppath, 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 105 of file MatrixElementsVariable.cc.
Reimplemented from PLearn::NaryVariable.
Definition at line 77 of file MatrixElementsVariable.h.
VarArray PLearn::MatrixElementsVariable::bproppath [protected] |
output(parameters)
Definition at line 66 of file MatrixElementsVariable.h.
Referenced by bprop(), build_(), fbprop(), and makeDeepCopyFromShallowCopy().
Var PLearn::MatrixElementsVariable::expression [protected] |
Definition at line 61 of file MatrixElementsVariable.h.
Referenced by bprop(), build_(), declareOptions(), fbprop(), fprop(), and makeDeepCopyFromShallowCopy().
VarArray PLearn::MatrixElementsVariable::fproppath [protected] |
output(inputs)
Definition at line 65 of file MatrixElementsVariable.h.
Referenced by bprop(), build_(), fbprop(), fprop(), and makeDeepCopyFromShallowCopy().
output(inputs¶meters)
Definition at line 64 of file MatrixElementsVariable.h.
Referenced by bprop(), build_(), fbprop(), fprop(), and makeDeepCopyFromShallowCopy().
Var PLearn::MatrixElementsVariable::i [protected] |
Definition at line 57 of file MatrixElementsVariable.h.
Referenced by bprop(), build_(), declareOptions(), fbprop(), fprop(), and makeDeepCopyFromShallowCopy().
Var PLearn::MatrixElementsVariable::j [protected] |
Definition at line 58 of file MatrixElementsVariable.h.
Referenced by bprop(), build_(), declareOptions(), fbprop(), fprop(), and makeDeepCopyFromShallowCopy().
int PLearn::MatrixElementsVariable::ni [protected] |
Definition at line 59 of file MatrixElementsVariable.h.
Referenced by bprop(), declareOptions(), fbprop(), fprop(), and recomputeSize().
int PLearn::MatrixElementsVariable::nj [protected] |
Definition at line 60 of file MatrixElementsVariable.h.
Referenced by bprop(), declareOptions(), fbprop(), fprop(), and recomputeSize().
VarArray PLearn::MatrixElementsVariable::parameters [protected] |
Definition at line 62 of file MatrixElementsVariable.h.
Referenced by build_(), declareOptions(), and makeDeepCopyFromShallowCopy().