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

Affine transformation of a vector variable, from a weight and bias variable. More...

#include <BiasWeightAffineTransformVariable.h>

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

List of all members.

Public Member Functions

 BiasWeightAffineTransformVariable ()
 Default constructor for persistence.
 BiasWeightAffineTransformVariable (const VarArray &the_varray, bool the_transpose_weights=false)
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual
BiasWeightAffineTransformVariable
deepCopy (CopiesMap &copies) const
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 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 symbolicBprop ()
 compute a piece of new Var graph that represents the symbolic derivative of this Var

Static Public Member Functions

static string _classname_ ()
 NaryVariable.
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_weights
 Indication that the transpose of the weights should be used for the linear transformation.

Static Public Attributes

static StaticInitializer _static_initializer_

Protected Member Functions

void build_ ()
 Object-specific post-constructor.

Protected Attributes

Var vec
 Input vector.
Var weights
 Weight matrix.
Var bias
 Bias vector.

Private Types

typedef NaryVariable inherited

Detailed Description

Affine transformation of a vector variable, from a weight and bias variable.

Should work for both column and row vectors: result vector will be of same kind (row or col) Will compute b + x.T (if you consider b and x to be row vectors) or b + x.T' if transpose_weights is true.

Definition at line 56 of file BiasWeightAffineTransformVariable.h.


Member Typedef Documentation

Reimplemented from PLearn::NaryVariable.

Definition at line 58 of file BiasWeightAffineTransformVariable.h.


Constructor & Destructor Documentation

PLearn::BiasWeightAffineTransformVariable::BiasWeightAffineTransformVariable ( ) [inline]

Default constructor for persistence.

Definition at line 70 of file BiasWeightAffineTransformVariable.h.

{}
PLearn::BiasWeightAffineTransformVariable::BiasWeightAffineTransformVariable ( const VarArray the_varray,
bool  the_transpose_weights = false 
)

Definition at line 54 of file BiasWeightAffineTransformVariable.cc.

References build_().

    : inherited(the_varray, 
                (the_varray[0]->size() == 1) ? 
                the_varray[2]->size() : 
                (the_varray[0]->isRowVec() ? 1 : the_varray[2]->size()),
                (the_varray[0]->size() == 1) ? 
                1 : (the_varray[0]->isRowVec() ? the_varray[2]->size() : 1)),
      transpose_weights(the_transpose_weights)
{
    build_();
}

Here is the call graph for this function:


Member Function Documentation

string PLearn::BiasWeightAffineTransformVariable::_classname_ ( ) [static]

NaryVariable.

Reimplemented from PLearn::NaryVariable.

Definition at line 52 of file BiasWeightAffineTransformVariable.cc.

OptionList & PLearn::BiasWeightAffineTransformVariable::_getOptionList_ ( ) [static]

Reimplemented from PLearn::NaryVariable.

Definition at line 52 of file BiasWeightAffineTransformVariable.cc.

RemoteMethodMap & PLearn::BiasWeightAffineTransformVariable::_getRemoteMethodMap_ ( ) [static]

Reimplemented from PLearn::NaryVariable.

Definition at line 52 of file BiasWeightAffineTransformVariable.cc.

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

Reimplemented from PLearn::NaryVariable.

Definition at line 52 of file BiasWeightAffineTransformVariable.cc.

Object * PLearn::BiasWeightAffineTransformVariable::_new_instance_for_typemap_ ( ) [static]

Reimplemented from PLearn::Object.

Definition at line 52 of file BiasWeightAffineTransformVariable.cc.

StaticInitializer BiasWeightAffineTransformVariable::_static_initializer_ & PLearn::BiasWeightAffineTransformVariable::_static_initialize_ ( ) [static]

Reimplemented from PLearn::NaryVariable.

Definition at line 52 of file BiasWeightAffineTransformVariable.cc.

void PLearn::BiasWeightAffineTransformVariable::bprop ( ) [virtual]

Implements PLearn::Variable.

Definition at line 127 of file BiasWeightAffineTransformVariable.cc.

References bias, PLearn::externalProductAcc(), PLearn::Variable::gradient, PLearn::productAcc(), transpose_weights, PLearn::transposeProductAcc(), vec, and weights.

{    
    bias->gradient += gradient;    
    if(!vec->dont_bprop_here)
    {
        if(transpose_weights)
            transposeProductAcc(vec->gradient, weights->matValue, gradient);
        else
            productAcc(vec->gradient, weights->matValue, gradient);
    }

    if(transpose_weights)
        externalProductAcc(weights->matGradient, gradient, vec->value);
    else
        externalProductAcc(weights->matGradient, vec->value, gradient);
}

Here is the call graph for this function:

void PLearn::BiasWeightAffineTransformVariable::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 79 of file BiasWeightAffineTransformVariable.cc.

References PLearn::NaryVariable::build(), and build_().

Here is the call graph for this function:

void PLearn::BiasWeightAffineTransformVariable::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 86 of file BiasWeightAffineTransformVariable.cc.

References bias, PLearn::Var::length(), PLearn::TVec< T >::length(), PLERROR, transpose_weights, PLearn::NaryVariable::varray, vec, weights, and PLearn::Var::width().

Referenced by BiasWeightAffineTransformVariable(), and build().

{
    if(varray.length() != 3)
        PLERROR("In BiasWeightAffineTransformVariable():build_(): needs an input"
                " vector, a weight matrix and a bias vector");

    vec = varray[0];
    weights = varray[1];
    bias = varray[2];

    if (!vec->isVec())
        PLERROR("In BiasWeightAffineTransformVariable: expecting a vector Var"
            " for the input vector");
    if(vec->size() != (!transpose_weights ? weights->length() : weights->width()))
        PLERROR("In BiasWeightAffineTransformVariable: weight matrix has"
                " incompatible size");
}

Here is the call graph for this function:

Here is the caller graph for this function:

string PLearn::BiasWeightAffineTransformVariable::classname ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 52 of file BiasWeightAffineTransformVariable.cc.

static const PPath& PLearn::BiasWeightAffineTransformVariable::declaringFile ( ) [inline, static]

Reimplemented from PLearn::NaryVariable.

Definition at line 74 of file BiasWeightAffineTransformVariable.h.

:

BiasWeightAffineTransformVariable * PLearn::BiasWeightAffineTransformVariable::deepCopy ( CopiesMap copies) const [virtual]

Reimplemented from PLearn::NaryVariable.

Definition at line 52 of file BiasWeightAffineTransformVariable.cc.

void PLearn::BiasWeightAffineTransformVariable::fprop ( ) [virtual]

compute output given input

Implements PLearn::Variable.

Definition at line 114 of file BiasWeightAffineTransformVariable.cc.

References bias, PLearn::productAcc(), transpose_weights, PLearn::transposeProductAcc(), PLearn::Variable::value, vec, and weights.

{
    value << bias->value;

    // Seems contradictive, but we are considering x.T versus x.T',
    // not T.x versus T'.x, for consistency with AffineTransformVariable!
    if(transpose_weights)
        productAcc(value, weights->matValue, vec->value);
    else
        transposeProductAcc(value, weights->matValue, vec->value);
}

Here is the call graph for this function:

OptionList & PLearn::BiasWeightAffineTransformVariable::getOptionList ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 52 of file BiasWeightAffineTransformVariable.cc.

OptionMap & PLearn::BiasWeightAffineTransformVariable::getOptionMap ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 52 of file BiasWeightAffineTransformVariable.cc.

RemoteMethodMap & PLearn::BiasWeightAffineTransformVariable::getRemoteMethodMap ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 52 of file BiasWeightAffineTransformVariable.cc.

void PLearn::BiasWeightAffineTransformVariable::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);
      ...
  }
Parameters:
copiesA map used by the deep-copy mechanism to keep track of already-copied objects.

Reimplemented from PLearn::NaryVariable.

Definition at line 69 of file BiasWeightAffineTransformVariable.cc.

References bias, PLearn::NaryVariable::makeDeepCopyFromShallowCopy(), PLearn::varDeepCopyField(), vec, and weights.

Here is the call graph for this function:

void PLearn::BiasWeightAffineTransformVariable::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 104 of file BiasWeightAffineTransformVariable.cc.

References bias, vec, and weights.

{ 
    if (vec && weights) {
        l = (vec->isRowVec() && vec->size() != 1) ? 1 : bias->size();
        w = vec->isColumnVec() ? 1 : bias->size(); 
    } else
        l = w = 0;
}
void PLearn::BiasWeightAffineTransformVariable::symbolicBprop ( ) [virtual]

compute a piece of new Var graph that represents the symbolic derivative of this Var

Reimplemented from PLearn::Variable.

Definition at line 145 of file BiasWeightAffineTransformVariable.cc.

References PLERROR.

{
    PLERROR("BiasWeightAffineTransformVariable::symbolicBprop() not implemented");
}

Member Data Documentation

Reimplemented from PLearn::NaryVariable.

Definition at line 74 of file BiasWeightAffineTransformVariable.h.

Bias vector.

Definition at line 91 of file BiasWeightAffineTransformVariable.h.

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

Indication that the transpose of the weights should be used for the linear transformation.

The transformation then corresponds to row-wise scalar products, instead of column wise.

Definition at line 66 of file BiasWeightAffineTransformVariable.h.

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

Input vector.

Definition at line 87 of file BiasWeightAffineTransformVariable.h.

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

Weight matrix.

Definition at line 89 of file BiasWeightAffineTransformVariable.h.

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


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