PLearn 0.1
|
#include <DiagonalizedFactorsProductVariable.h>
Public Member Functions | |
DiagonalizedFactorsProductVariable () | |
Default constructor for persistence. | |
DiagonalizedFactorsProductVariable (Var left_matrix, Var center_diagonal, Var right_matrix, bool transpose_left=false, bool transpose_right=false) | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual DiagonalizedFactorsProductVariable * | 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 () |
Var & | leftMatrix () |
Var & | centerDiagonal () |
Var & | rightMatrix () |
Static Public Member Functions | |
static string | _classname_ () |
DiagonalizedFactorsProductVariable. | |
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 | |
bool | transpose_left |
bool | transpose_right |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Protected Member Functions | |
void | build_ () |
Object-specific post-constructor. | |
Private Types | |
typedef NaryVariable | inherited |
Variable that computes the matrix*diag(vector)*matrix product like the one found in singular value decomposition or eigen-decomposition. It has three parents: left_matrix U, center_diagonal_vector d, and right_matrix V. The output value has elements (i,j) equal to sum_k U_{ik} d_k V_{kj}. Optionally the right_matrix or the left_matrix is transposed before being applied.
Definition at line 58 of file DiagonalizedFactorsProductVariable.h.
typedef NaryVariable PLearn::DiagonalizedFactorsProductVariable::inherited [private] |
Reimplemented from PLearn::NaryVariable.
Definition at line 60 of file DiagonalizedFactorsProductVariable.h.
PLearn::DiagonalizedFactorsProductVariable::DiagonalizedFactorsProductVariable | ( | ) | [inline] |
Default constructor for persistence.
Definition at line 66 of file DiagonalizedFactorsProductVariable.h.
{}
PLearn::DiagonalizedFactorsProductVariable::DiagonalizedFactorsProductVariable | ( | Var | left_matrix, |
Var | center_diagonal, | ||
Var | right_matrix, | ||
bool | transpose_left = false , |
||
bool | transpose_right = false |
||
) |
Definition at line 60 of file DiagonalizedFactorsProductVariable.cc.
References build_().
: inherited(left_matrix & center_diagonal & (VarArray)right_matrix, transpose_left_?left_matrix->width():left_matrix->length(), transpose_right_?right_matrix->length():right_matrix->width()), transpose_left(transpose_left_), transpose_right(transpose_right_) { build_(); }
string PLearn::DiagonalizedFactorsProductVariable::_classname_ | ( | ) | [static] |
DiagonalizedFactorsProductVariable.
Reimplemented from PLearn::NaryVariable.
Definition at line 58 of file DiagonalizedFactorsProductVariable.cc.
OptionList & PLearn::DiagonalizedFactorsProductVariable::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 58 of file DiagonalizedFactorsProductVariable.cc.
RemoteMethodMap & PLearn::DiagonalizedFactorsProductVariable::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 58 of file DiagonalizedFactorsProductVariable.cc.
Reimplemented from PLearn::NaryVariable.
Definition at line 58 of file DiagonalizedFactorsProductVariable.cc.
Object * PLearn::DiagonalizedFactorsProductVariable::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 58 of file DiagonalizedFactorsProductVariable.cc.
StaticInitializer DiagonalizedFactorsProductVariable::_static_initializer_ & PLearn::DiagonalizedFactorsProductVariable::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 58 of file DiagonalizedFactorsProductVariable.cc.
void PLearn::DiagonalizedFactorsProductVariable::bprop | ( | ) | [virtual] |
Implements PLearn::Variable.
Definition at line 118 of file DiagonalizedFactorsProductVariable.cc.
References centerDiagonal(), PLearn::diagonalizedFactorsProductBprop(), PLearn::diagonalizedFactorsProductTransposeBprop(), PLearn::diagonalizedFactorsTransposeProductBprop(), PLearn::diagonalizedFactorsTransposeProductTransposeBprop(), PLearn::Variable::gradient, leftMatrix(), PLearn::Variable::matGradient, PLearn::Variable::matValue, rightMatrix(), transpose_left, transpose_right, and PLearn::Variable::value.
{ if (transpose_left) { if (transpose_right) { // SINCE res[i,j] = sum_k U[k,i] d[k] V[j,k] ==> // dC/dU[k,i] = d_k * sum_j dC/dres[i,j] V[j,k] // dC/dd[k] = sum_{ij} dC/dres[i,j] U[k,i] V[j,k] // dC/dV[j,k] = d_k * sum_i dC/dres[i,j] U[k,i] diagonalizedFactorsTransposeProductTransposeBprop(matGradient,leftMatrix()->matValue, centerDiagonal()->value,rightMatrix()->matValue, leftMatrix()->matGradient, centerDiagonal()->gradient,rightMatrix()->matGradient); } else { // SINCE res[i,j] = sum_k U[k,i] d[k] V[k,j] ==> // dC/dU[k,i] = d_k * sum_j dC/dres[i,j] V[k,j] // dC/dd[k] = sum_{ij} dC/dres[i,j] U[k,i] V[k,j] // dC/dV[k,j] = d_k sum_i dC/dres[i,j] U[k,i] diagonalizedFactorsTransposeProductBprop(matGradient,leftMatrix()->matValue,centerDiagonal()->value, rightMatrix()->matValue, leftMatrix()->matGradient, centerDiagonal()->gradient,rightMatrix()->matGradient); } } else { if (transpose_right) { // SINCE res[i,j] = sum_k U[i,k] d[k] V[j,k] ==> // dC/dU[i,k] = sum_j dC/dres[i,j] d_k V[j,k] // dC/dd[k] = sum_{ij} dC/dres[i,j] U[i,k] V[j,k] // dC/dV[j,k] = sum_i dC/dres[i,j] d_k U[i,k] diagonalizedFactorsProductTransposeBprop(matGradient,leftMatrix()->matValue,centerDiagonal()->value, rightMatrix()->matValue, leftMatrix()->matGradient, centerDiagonal()->gradient,rightMatrix()->matGradient); } else { // SINCE res[i,j] = sum_k U[i,k] d[k] V[k,j] ==> // dC/dU[i,k] += sum_j dC/dres[i,j] d_k V[k,j] // dC/dd[k] += sum_{ij} dC/dres[i,j] U[i,k] V[k,j] // dC/dV[k,j] += d_k * sum_i U[i,k] dC/dres[i,j] diagonalizedFactorsProductBprop(matGradient,leftMatrix()->matValue,centerDiagonal()->value, rightMatrix()->matValue,leftMatrix()->matGradient, centerDiagonal()->gradient,rightMatrix()->matGradient); } } }
void PLearn::DiagonalizedFactorsProductVariable::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 74 of file DiagonalizedFactorsProductVariable.cc.
References PLearn::NaryVariable::build(), and build_().
{ inherited::build(); build_(); }
void PLearn::DiagonalizedFactorsProductVariable::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 81 of file DiagonalizedFactorsProductVariable.cc.
References centerDiagonal(), leftMatrix(), PLearn::Var::length(), PLERROR, rightMatrix(), PLearn::TVec< T >::size(), transpose_left, transpose_right, PLearn::NaryVariable::varray, and PLearn::Var::width().
Referenced by build(), and DiagonalizedFactorsProductVariable().
{ if (varray.size()) { int nl = transpose_left?leftMatrix()->length():leftMatrix()->width(); int nr = transpose_right?rightMatrix()->width():rightMatrix()->length(); int nc = centerDiagonal()->size(); if (nl != nc || nr != nc) PLERROR("In DiagonalizedFactorsProductVariable: arguments have incompatible sizes!"); } }
Var& PLearn::DiagonalizedFactorsProductVariable::centerDiagonal | ( | ) | [inline] |
string PLearn::DiagonalizedFactorsProductVariable::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 58 of file DiagonalizedFactorsProductVariable.cc.
static const PPath& PLearn::DiagonalizedFactorsProductVariable::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 70 of file DiagonalizedFactorsProductVariable.h.
{ return varray[0]; }
DiagonalizedFactorsProductVariable * PLearn::DiagonalizedFactorsProductVariable::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::NaryVariable.
Definition at line 58 of file DiagonalizedFactorsProductVariable.cc.
void PLearn::DiagonalizedFactorsProductVariable::fprop | ( | ) | [virtual] |
compute output given input
Implements PLearn::Variable.
Definition at line 101 of file DiagonalizedFactorsProductVariable.cc.
References centerDiagonal(), PLearn::diagonalizedFactorsProduct(), PLearn::diagonalizedFactorsProductTranspose(), PLearn::diagonalizedFactorsTransposeProduct(), PLearn::diagonalizedFactorsTransposeProductTranspose(), leftMatrix(), PLearn::Variable::matValue, rightMatrix(), transpose_left, transpose_right, and PLearn::Variable::value.
{ if (transpose_left) { if (transpose_right) diagonalizedFactorsTransposeProductTranspose(matValue,leftMatrix()->matValue,centerDiagonal()->value,rightMatrix()->matValue); else diagonalizedFactorsTransposeProduct(matValue,leftMatrix()->matValue,centerDiagonal()->value,rightMatrix()->matValue); } else { if (transpose_right) diagonalizedFactorsProductTranspose(matValue,leftMatrix()->matValue,centerDiagonal()->value,rightMatrix()->matValue); else diagonalizedFactorsProduct(matValue,leftMatrix()->matValue,centerDiagonal()->value,rightMatrix()->matValue); } }
OptionList & PLearn::DiagonalizedFactorsProductVariable::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 58 of file DiagonalizedFactorsProductVariable.cc.
OptionMap & PLearn::DiagonalizedFactorsProductVariable::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 58 of file DiagonalizedFactorsProductVariable.cc.
RemoteMethodMap & PLearn::DiagonalizedFactorsProductVariable::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 58 of file DiagonalizedFactorsProductVariable.cc.
Var& PLearn::DiagonalizedFactorsProductVariable::leftMatrix | ( | ) | [inline] |
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 92 of file DiagonalizedFactorsProductVariable.cc.
References PLearn::TVec< T >::length(), PLearn::TVec< T >::size(), transpose_left, transpose_right, and PLearn::NaryVariable::varray.
{ if (varray.size()) { l = transpose_left?varray[0]->width():varray[0]->length(); w = transpose_right?varray[2]->length():varray[2]->width(); } else l = w = 0; }
Var& PLearn::DiagonalizedFactorsProductVariable::rightMatrix | ( | ) | [inline] |
Reimplemented from PLearn::NaryVariable.
Definition at line 70 of file DiagonalizedFactorsProductVariable.h.
Definition at line 63 of file DiagonalizedFactorsProductVariable.h.
Referenced by bprop(), build_(), fprop(), and recomputeSize().
Definition at line 63 of file DiagonalizedFactorsProductVariable.h.
Referenced by bprop(), build_(), fprop(), and recomputeSize().