PLearn 0.1
|
Matrix product. More...
#include <ProductVariable.h>
Public Member Functions | |
ProductVariable () | |
Default constructor for persistence. | |
ProductVariable (Variable *input1, Variable *input2) | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual ProductVariable * | 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 () |
compute output given input | |
virtual void | bprop () |
virtual void | bbprop () |
compute an approximation to diag(d^2/dinput^2) given diag(d^2/doutput^2), with diag(d^2/dinput^2) ~=~ (doutput/dinput)' diag(d^2/doutput^2) (doutput/dinput) In particular: if 'C' depends on 'y' and 'y' depends on x ... | |
virtual void | symbolicBprop () |
compute a piece of new Var graph that represents the symbolic derivative of this Var | |
virtual void | rfprop () |
Static Public Member Functions | |
static string | _classname_ () |
ProductVariable. | |
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 | |
void | build_ () |
This does the actual building. | |
Private Types | |
typedef BinaryVariable | inherited |
Matrix product.
Definition at line 53 of file ProductVariable.h.
typedef BinaryVariable PLearn::ProductVariable::inherited [private] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 55 of file ProductVariable.h.
PLearn::ProductVariable::ProductVariable | ( | ) | [inline] |
Definition at line 61 of file ProductVariable.cc.
References build_().
string PLearn::ProductVariable::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 59 of file ProductVariable.cc.
OptionList & PLearn::ProductVariable::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 59 of file ProductVariable.cc.
RemoteMethodMap & PLearn::ProductVariable::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 59 of file ProductVariable.cc.
Reimplemented from PLearn::BinaryVariable.
Definition at line 59 of file ProductVariable.cc.
Object * PLearn::ProductVariable::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 59 of file ProductVariable.cc.
StaticInitializer ProductVariable::_static_initializer_ & PLearn::ProductVariable::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 59 of file ProductVariable.cc.
void PLearn::ProductVariable::bbprop | ( | ) | [virtual] |
compute an approximation to diag(d^2/dinput^2) given diag(d^2/doutput^2), with diag(d^2/dinput^2) ~=~ (doutput/dinput)' diag(d^2/doutput^2) (doutput/dinput) In particular: if 'C' depends on 'y' and 'y' depends on x ...
d^2C/dx^2 = d^2C/dy^2 * (dy/dx)^2 + dC/dy * d^2y/dx^2 (diaghessian) (gradient)
Reimplemented from PLearn::Variable.
Definition at line 110 of file ProductVariable.cc.
References PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, PLearn::Var::length(), PLearn::Variable::matGradient, PLearn::product2TransposeAcc(), and PLearn::transposeProduct2Acc().
{ if (input1->diaghessian.length()==0) input1->resizeDiagHessian(); if (input2->diaghessian.length()==0) input2->resizeDiagHessian(); // d^2C/dinput1[i,k]^2 = sum_j d^2C/dm[i,j]^2 input2[k,j]*input2[k,j] product2TransposeAcc(input1->matGradient, matGradient, input2->matValue); // dC/dinput2[k,j] += sum_i d^2C/dm[i,j]^2 input1[i,k]*input1[i,k] transposeProduct2Acc(input2->matGradient, input1->matValue, matGradient); }
void PLearn::ProductVariable::bprop | ( | ) | [virtual] |
Implements PLearn::Variable.
Definition at line 101 of file ProductVariable.cc.
References PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, PLearn::Variable::matGradient, PLearn::productTransposeAcc(), and PLearn::transposeProductAcc().
{ // dC/dinput1[i,k] = sum_j dC/dm[i,j] input2[k,j] productTransposeAcc(input1->matGradient, matGradient, input2->matValue); // dC/dinput2[k,j] += sum_i dC/dm[i,j] input1[i,k] transposeProductAcc(input2->matGradient, input1->matValue, matGradient); }
void PLearn::ProductVariable::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::BinaryVariable.
Definition at line 68 of file ProductVariable.cc.
References PLearn::BinaryVariable::build(), and build_().
{ inherited::build(); build_(); }
void PLearn::ProductVariable::build_ | ( | ) | [protected] |
This does the actual building.
Reimplemented from PLearn::BinaryVariable.
Definition at line 75 of file ProductVariable.cc.
References PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, PLearn::Var::length(), PLERROR, and PLearn::Var::width().
Referenced by build(), and ProductVariable().
{ if (input1 && input2) { // input1 and input2 are (respectively) m1 and m2 from constructor if (input1->width() != input2->length()) PLERROR("In ProductVariable: the size of m1 and m2 are not compatible for a matrix product"); } }
string PLearn::ProductVariable::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 59 of file ProductVariable.cc.
static const PPath& PLearn::ProductVariable::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 62 of file ProductVariable.h.
: void build_();
ProductVariable * PLearn::ProductVariable::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 59 of file ProductVariable.cc.
void PLearn::ProductVariable::fprop | ( | ) | [virtual] |
compute output given input
Implements PLearn::Variable.
Definition at line 94 of file ProductVariable.cc.
References PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, PLearn::Variable::matValue, and PLearn::product().
{ // m[i,j] = sum_k input1[i,k] * input2[k,j] product(matValue, input1->matValue, input2->matValue); }
OptionList & PLearn::ProductVariable::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 59 of file ProductVariable.cc.
OptionMap & PLearn::ProductVariable::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 59 of file ProductVariable.cc.
RemoteMethodMap & PLearn::ProductVariable::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 59 of file ProductVariable.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 85 of file ProductVariable.cc.
References PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, PLearn::Var::length(), and PLearn::Var::width().
void PLearn::ProductVariable::rfprop | ( | ) | [virtual] |
Reimplemented from PLearn::Variable.
Definition at line 133 of file ProductVariable.cc.
References PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, PLearn::TVec< T >::length(), PLearn::Variable::matRValue, PLearn::product(), PLearn::productAcc(), PLearn::BinaryVariable::resizeRValue(), and PLearn::Variable::rValue.
{ if (rValue.length()==0) resizeRValue(); product(matRValue, input1->matValue, input2->matRValue); productAcc(matRValue,input1->matRValue, input2->matValue); }
void PLearn::ProductVariable::symbolicBprop | ( | ) | [virtual] |
compute a piece of new Var graph that represents the symbolic derivative of this Var
Reimplemented from PLearn::Variable.
Definition at line 123 of file ProductVariable.cc.
References PLearn::Variable::g, PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, PLearn::productTranspose(), and PLearn::transposeProduct().
{ // dC/dinput1[i,k] = sum_j dC/dm[i,j] input2[k,j] input1->accg(productTranspose(g, input2)); // dC/dinput2[k,j] += sum_i dC/dm[i,j] input1[i,k] input2->accg(transposeProduct(input1, g)); }
Reimplemented from PLearn::BinaryVariable.
Definition at line 62 of file ProductVariable.h.