PLearn 0.1
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Private Types
PLearn::DiagonalizedFactorsProductVariable Class Reference

#include <DiagonalizedFactorsProductVariable.h>

Inheritance diagram for PLearn::DiagonalizedFactorsProductVariable:
Inheritance graph
[legend]
Collaboration diagram for PLearn::DiagonalizedFactorsProductVariable:
Collaboration graph
[legend]

List of all members.

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 OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () 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 ()
VarleftMatrix ()
VarcenterDiagonal ()
VarrightMatrix ()

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 PPathdeclaringFile ()

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

Detailed Description

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.


Member Typedef Documentation

Reimplemented from PLearn::NaryVariable.

Definition at line 60 of file DiagonalizedFactorsProductVariable.h.


Constructor & Destructor Documentation

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_();
}

Here is the call graph for this function:


Member Function Documentation

string PLearn::DiagonalizedFactorsProductVariable::_classname_ ( ) [static]
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.

bool PLearn::DiagonalizedFactorsProductVariable::_isa_ ( const Object o) [static]

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);
        }  
    }
}

Here is the call graph for this function:

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_().

Here is the call graph for this function:

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!");
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Var& PLearn::DiagonalizedFactorsProductVariable::centerDiagonal ( ) [inline]

Definition at line 78 of file DiagonalizedFactorsProductVariable.h.

Referenced by bprop(), build_(), and fprop().

{ return varray[1]; }

Here is the caller graph for this function:

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]
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]

Definition at line 77 of file DiagonalizedFactorsProductVariable.h.

Referenced by bprop(), build_(), and fprop().

{ return varray[0]; }

Here is the caller graph for this function:

void PLearn::DiagonalizedFactorsProductVariable::recomputeSize ( int l,
int w 
) const [virtual]

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;
}

Here is the call graph for this function:

Var& PLearn::DiagonalizedFactorsProductVariable::rightMatrix ( ) [inline]

Definition at line 79 of file DiagonalizedFactorsProductVariable.h.

Referenced by bprop(), build_(), and fprop().

{ return varray[2]; }

Here is the caller graph for this function:


Member Data Documentation

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().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines