PLearn 0.1
|
#include <MatrixSumOfVariable.h>
Public Member Functions | |
MatrixSumOfVariable () | |
protected default constructor for persistence | |
MatrixSumOfVariable (VMat the_distr, Func the_f, int the_nsamples=-1, int the_input_size=-1) | |
![]() | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual MatrixSumOfVariable * | 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 | |
virtual void | symbolicBprop () |
compute a piece of new Var graph that represents the symbolic derivative of this Var | |
virtual void | rfprop () |
void | printInfo (bool print_gradient) |
Static Public Member Functions | |
static string | _classname_ () |
MatrixSumOfVariable. | |
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. | |
Public Attributes | |
VMat | distr |
Func | f |
int | nsamples |
int | input_size |
int | curpos |
current pos in VMat | |
Vec | input_value |
Vec | input_gradient |
Vec | output_value |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Protected Member Functions | |
void | build_ () |
Object-specific post-constructor. | |
Private Types | |
typedef NaryVariable | inherited |
Definition at line 53 of file MatrixSumOfVariable.h.
typedef NaryVariable PLearn::MatrixSumOfVariable::inherited [private] |
Reimplemented from PLearn::NaryVariable.
Definition at line 55 of file MatrixSumOfVariable.h.
PLearn::MatrixSumOfVariable::MatrixSumOfVariable | ( | ) | [inline] |
protected default constructor for persistence
Definition at line 71 of file MatrixSumOfVariable.h.
: distr(), f(), nsamples(), input_size(), curpos() {}
PLearn::MatrixSumOfVariable::MatrixSumOfVariable | ( | VMat | the_distr, |
Func | the_f, | ||
int | the_nsamples = -1 , |
||
int | the_input_size = -1 |
||
) |
Definition at line 55 of file MatrixSumOfVariable.cc.
References build_().
: inherited(nonInputParentsOfPath(the_f->inputs,the_f->outputs), the_f->outputs[0]->length(), the_f->outputs[0]->width()), distr(the_distr), f(the_f), nsamples(the_nsamples), input_size(the_input_size) //, curpos(0), input_value(the_distr->width()*nsamples), input_gradient(the_distr->width()*nsamples), output_value(the_f->outputs[0]->size()) { build_(); }
string PLearn::MatrixSumOfVariable::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 53 of file MatrixSumOfVariable.cc.
OptionList & PLearn::MatrixSumOfVariable::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 53 of file MatrixSumOfVariable.cc.
RemoteMethodMap & PLearn::MatrixSumOfVariable::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 53 of file MatrixSumOfVariable.cc.
Reimplemented from PLearn::NaryVariable.
Definition at line 53 of file MatrixSumOfVariable.cc.
Object * PLearn::MatrixSumOfVariable::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 53 of file MatrixSumOfVariable.cc.
StaticInitializer MatrixSumOfVariable::_static_initializer_ & PLearn::MatrixSumOfVariable::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 53 of file MatrixSumOfVariable.cc.
void PLearn::MatrixSumOfVariable::bprop | ( | ) | [virtual] |
Implements PLearn::Variable.
Definition at line 137 of file MatrixSumOfVariable.cc.
References fbprop().
{ fbprop(); }
void PLearn::MatrixSumOfVariable::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 64 of file MatrixSumOfVariable.cc.
References PLearn::NaryVariable::build(), and build_().
{ inherited::build(); build_(); }
void PLearn::MatrixSumOfVariable::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 71 of file MatrixSumOfVariable.cc.
References curpos, distr, f, input_gradient, input_value, PLearn::VMat::length(), nsamples, output_value, PLERROR, PLearn::TVec< T >::resize(), and PLearn::VMat::width().
Referenced by build(), and MatrixSumOfVariable().
{ curpos = 0; if (f && distr) { if(f->outputs.size()!=1) PLERROR("In MatrixSumOfVariable: function must have a single variable output (maybe you can vconcat the vars into a single one prior to calling sumOf, if this is really what you want)"); input_value.resize(distr->width() * nsamples); input_gradient.resize(distr->width() * nsamples); output_value.resize(f->outputs[0]->size()); if(nsamples == -1) nsamples = distr->length(); f->inputs.setDontBpropHere(true); } }
string PLearn::MatrixSumOfVariable::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 53 of file MatrixSumOfVariable.cc.
void PLearn::MatrixSumOfVariable::declareOptions | ( | OptionList & | ol | ) | [static] |
Default constructor for persistence.
Reimplemented from PLearn::NaryVariable.
Definition at line 89 of file MatrixSumOfVariable.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::NaryVariable::declareOptions(), distr, f, input_size, and nsamples.
{ declareOption(ol, "distr", &MatrixSumOfVariable::distr, OptionBase::buildoption, ""); declareOption(ol, "f", &MatrixSumOfVariable::f, OptionBase::buildoption, ""); declareOption(ol, "nsamples", &MatrixSumOfVariable::nsamples, OptionBase::buildoption, ""); declareOption(ol, "input_size", &MatrixSumOfVariable::input_size, OptionBase::buildoption, ""); inherited::declareOptions(ol); }
static const PPath& PLearn::MatrixSumOfVariable::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 75 of file MatrixSumOfVariable.h.
: void build_();
MatrixSumOfVariable * PLearn::MatrixSumOfVariable::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::NaryVariable.
Definition at line 53 of file MatrixSumOfVariable.cc.
void PLearn::MatrixSumOfVariable::fbprop | ( | ) | [virtual] |
do both fprop and bprop
Reimplemented from PLearn::Variable.
Definition at line 141 of file MatrixSumOfVariable.cc.
References curpos, distr, f, PLearn::Variable::gradient, i, input_gradient, input_size, input_value, j, PLearn::VMat::length(), nsamples, PLearn::Variable::value, and PLearn::VMat::width().
Referenced by bprop().
{ Vec oneInput_value(distr->width()); f->recomputeParents(); int inputpos=0; int targetpos=nsamples*input_size; for (int i=0; i<nsamples; i++) { distr->getRow(curpos, oneInput_value); for (int j=0; j<input_size; j++,inputpos++) input_value[inputpos]=oneInput_value[j]; for (int j=input_size; j<distr.width(); j++,targetpos++) input_value[targetpos] = oneInput_value[j]; if(++curpos==distr.length()) curpos=0; } f->fbprop(input_value, value, input_gradient, gradient); }
void PLearn::MatrixSumOfVariable::fprop | ( | ) | [virtual] |
compute output given input
Implements PLearn::Variable.
Definition at line 116 of file MatrixSumOfVariable.cc.
References curpos, distr, f, i, input_size, input_value, j, PLearn::VMat::length(), nsamples, PLearn::Variable::value, and PLearn::VMat::width().
{ Vec oneInput_value(distr->width()); f->recomputeParents(); int inputpos=0; int targetpos=nsamples*input_size; for (int i=0; i<nsamples; i++) { distr->getRow(curpos, oneInput_value); for (int j=0; j<input_size; j++,inputpos++) input_value[inputpos]=oneInput_value[j]; for (int j=input_size; j<distr.width(); j++,targetpos++) input_value[targetpos] = oneInput_value[j]; if(++curpos==distr.length()) curpos=0; } f->fprop(input_value, value); }
OptionList & PLearn::MatrixSumOfVariable::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 53 of file MatrixSumOfVariable.cc.
OptionMap & PLearn::MatrixSumOfVariable::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 53 of file MatrixSumOfVariable.cc.
RemoteMethodMap & PLearn::MatrixSumOfVariable::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 53 of file MatrixSumOfVariable.cc.
void PLearn::MatrixSumOfVariable::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 108 of file MatrixSumOfVariable.cc.
References PLearn::deepCopyField(), distr, f, and PLearn::NaryVariable::makeDeepCopyFromShallowCopy().
{ inherited::makeDeepCopyFromShallowCopy(copies); deepCopyField(distr, copies); deepCopyField(f, copies); }
void PLearn::MatrixSumOfVariable::printInfo | ( | bool | print_gradient | ) | [virtual] |
Reimplemented from PLearn::NaryVariable.
Definition at line 174 of file MatrixSumOfVariable.cc.
References PLearn::TVec< T >::clear(), curpos, distr, PLearn::endl(), f, PLearn::Variable::getName(), PLearn::Variable::gradient, i, PLearn::Object::info(), input_gradient, input_value, PLearn::VMat::length(), PLearn::Variable::nelems(), nsamples, output_value, PLERROR, PLearn::Variable::value, and PLearn::VMat::width().
{ PLERROR("MatrixSumOfVariable::printInfo not implemented."); Vec input_value(distr->width()); Vec input_gradient(distr->width()); Vec output_value(nelems()); f->recomputeParents(); value.clear(); for(int i=0; i<nsamples; i++) { distr->getRow(curpos++,input_value); if (print_gradient) f->fbprop(input_value, output_value, input_gradient, gradient); else f->fprop(input_value, output_value); value += output_value; if(++curpos>=distr->length()) curpos = 0; f->fproppath.printInfo(print_gradient); } cout << info() << " : " << getName() << " = " << value; if (print_gradient) cout << " gradient=" << gradient; cout << endl; }
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 98 of file MatrixSumOfVariable.cc.
References f.
void PLearn::MatrixSumOfVariable::rfprop | ( | ) | [virtual] |
Reimplemented from PLearn::Variable.
Definition at line 168 of file MatrixSumOfVariable.cc.
References PLERROR.
{ PLERROR("MatrixSumOfVariable::rfprop not implemented."); }
void PLearn::MatrixSumOfVariable::symbolicBprop | ( | ) | [virtual] |
compute a piece of new Var graph that represents the symbolic derivative of this Var
Reimplemented from PLearn::Variable.
Definition at line 162 of file MatrixSumOfVariable.cc.
References PLERROR.
{ PLERROR("MatrixSumOfVariable::symbolicBprop not implemented."); }
Reimplemented from PLearn::NaryVariable.
Definition at line 75 of file MatrixSumOfVariable.h.
current pos in VMat
Definition at line 63 of file MatrixSumOfVariable.h.
Referenced by build_(), fbprop(), fprop(), and printInfo().
Definition at line 59 of file MatrixSumOfVariable.h.
Referenced by build_(), declareOptions(), fbprop(), fprop(), makeDeepCopyFromShallowCopy(), and printInfo().
Definition at line 60 of file MatrixSumOfVariable.h.
Referenced by build_(), declareOptions(), fbprop(), fprop(), makeDeepCopyFromShallowCopy(), printInfo(), and recomputeSize().
Definition at line 66 of file MatrixSumOfVariable.h.
Referenced by build_(), fbprop(), and printInfo().
Definition at line 62 of file MatrixSumOfVariable.h.
Referenced by declareOptions(), fbprop(), and fprop().
Definition at line 65 of file MatrixSumOfVariable.h.
Referenced by build_(), fbprop(), fprop(), and printInfo().
Definition at line 61 of file MatrixSumOfVariable.h.
Referenced by build_(), declareOptions(), fbprop(), fprop(), and printInfo().
Definition at line 67 of file MatrixSumOfVariable.h.
Referenced by build_(), and printInfo().