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

The first sentence should be a BRIEF DESCRIPTION of what the class does. More...

#include <DoubleProductVariable.h>

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

List of all members.

Public Member Functions

 DoubleProductVariable ()
 ### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //!
 DoubleProductVariable (Var &input1, Var &input2, Var &input3)
 Constructor initializing from input variables.
VarvarX ()
VarvarW ()
VarvarM ()
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 string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual DoubleProductVariabledeepCopy (CopiesMap &copies) const
virtual void build ()
 Post-constructor.
virtual void makeDeepCopyFromShallowCopy (CopiesMap &copies)
 Transforms a shallow copy into a deep copy.

Static Public Member Functions

static string _classname_ ()
 DoubleProductVariable.
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 ()

Static Public Attributes

static StaticInitializer _static_initializer_

Static Protected Member Functions

static void declareOptions (OptionList &ol)
 Declares the class options.

Private Types

typedef NaryVariable inherited

Private Member Functions

void build_ ()
 This does the actual building.

Detailed Description

The first sentence should be a BRIEF DESCRIPTION of what the class does.

* DoubleProductVariable * Place the rest of the class programmer documentation here. Doxygen supports Javadoc-style comments. See http://www.doxygen.org/manual.html

Todo:
Write class to-do's here if there are any.
Deprecated:
Write deprecated stuff here if there is any. Indicate what else should be used instead.

Definition at line 60 of file DoubleProductVariable.h.


Member Typedef Documentation

Reimplemented from PLearn::NaryVariable.

Definition at line 62 of file DoubleProductVariable.h.


Constructor & Destructor Documentation

PLearn::DoubleProductVariable::DoubleProductVariable ( ) [inline]

### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //!

Default constructor, usually does nothing

Definition at line 74 of file DoubleProductVariable.h.

{}
PLearn::DoubleProductVariable::DoubleProductVariable ( Var input1,
Var input2,
Var input3 
)

Constructor initializing from input variables.

Definition at line 53 of file DoubleProductVariable.cc.

References build_().

    : inherited(x & w & m, x.length(), w.length()*m.length())
{
    build_();
}

Here is the call graph for this function:


Member Function Documentation

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

DoubleProductVariable.

Reimplemented from PLearn::NaryVariable.

Definition at line 51 of file DoubleProductVariable.cc.

{X(n,k)*W(i,k)*M(j,k)}");
OptionList & PLearn::DoubleProductVariable::_getOptionList_ ( ) [static]

Reimplemented from PLearn::NaryVariable.

Definition at line 51 of file DoubleProductVariable.cc.

{X(n,k)*W(i,k)*M(j,k)}");
RemoteMethodMap & PLearn::DoubleProductVariable::_getRemoteMethodMap_ ( ) [static]

Reimplemented from PLearn::NaryVariable.

Definition at line 51 of file DoubleProductVariable.cc.

{X(n,k)*W(i,k)*M(j,k)}");
bool PLearn::DoubleProductVariable::_isa_ ( const Object o) [static]

Reimplemented from PLearn::NaryVariable.

Definition at line 51 of file DoubleProductVariable.cc.

{X(n,k)*W(i,k)*M(j,k)}");
Object * PLearn::DoubleProductVariable::_new_instance_for_typemap_ ( ) [static]

Reimplemented from PLearn::Object.

Definition at line 51 of file DoubleProductVariable.cc.

{X(n,k)*W(i,k)*M(j,k)}");
StaticInitializer DoubleProductVariable::_static_initializer_ & PLearn::DoubleProductVariable::_static_initialize_ ( ) [static]

Reimplemented from PLearn::NaryVariable.

Definition at line 51 of file DoubleProductVariable.cc.

{X(n,k)*W(i,k)*M(j,k)}");
void PLearn::DoubleProductVariable::bprop ( ) [virtual]

Implements PLearn::Variable.

Definition at line 112 of file DoubleProductVariable.cc.

References d, i, j, PLearn::TMat< T >::length(), m, PLearn::Variable::matGradient, n, PLearn::NaryVariable::varray, w, PLearn::TMat< T >::width(), and x.

{
    Mat x = varray[0]->matValue,
        w = varray[1]->matValue,
        m = varray[2]->matValue,
        x_grad = varray[0]->matGradient,
        w_grad = varray[1]->matGradient,
        m_grad = varray[2]->matGradient,
        s_grad = matGradient;

    int nx = x.length(),
        nw = w.length(),
        nm = m.length(),
        d = x.width();// ( = w.width()= m.width() )

    /*
     for(int n=0; n<nx; n++)
        for(int i=0 ;i<nw; i++)
            for(int j=0; j<nm; j++)
            {
                for(int k=0; k<d; k++)
                {
                    x_grad(n,k) += s_grad(n,i+j*nw)*w(i,k)*m(j,k);
                    w_grad(i,k) += s_grad(n,i+j*nw)*x(n,k)*m(j,k);
                    m_grad(j,k) += s_grad(n,i+j*nw)*x(n,k)*w(i,k);
                }
            }
    */

    for(int n=0; n<nx; n++)
    {
        const real* s_grad_n = s_grad[n];
        const real* x_n = x[n];
        real* x_grad_n = x_grad[n];
        for(int j=0; j<nm; j++)
        {
            const real* m_j = m[j];
            real* m_grad_j = m_grad[j];
            for(int i=0 ;i<nw; i++)
            {
                const real* w_i = w[i];
                real* w_grad_i = w_grad[i];
                real s_grad_n_val = s_grad_n[i+j*nw];
                for(int k=0; k<d; k++)
                {             
                    x_grad_n[k] += s_grad_n_val*w_i[k]*m_j[k];
                    w_grad_i[k] += s_grad_n_val*x_n[k]*m_j[k];
                    m_grad_j[k] += s_grad_n_val*x_n[k]*w_i[k];
                }                
            }
        }
    }
}

Here is the call graph for this function:

void PLearn::DoubleProductVariable::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 172 of file DoubleProductVariable.cc.

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

Here is the call graph for this function:

void PLearn::DoubleProductVariable::build_ ( ) [private]

This does the actual building.

Reimplemented from PLearn::NaryVariable.

Definition at line 212 of file DoubleProductVariable.cc.

References PLERROR, varM(), varW(), varX(), and PLearn::Variable::width().

Referenced by build(), and DoubleProductVariable().

{
    // ### This method should do the real buildincg of the object,
    // ### according to set 'options', in *any* situation.
    // ### Typical situations include:
    // ###  - Initial building of an object from a few user-specified options
    // ###  - Building of a "reloaded" object: i.e. from the complete set of
    // ###    all serialised options.
    // ###  - Updating or "re-building" of an object after a few "tuning"
    // ###    options have been modified.
    // ### You should assume that the parent class' build_() has already been
    // ### called.
   
    if (varW().width() != varX().width() || varW().width() != varM().width())
        PLERROR("All input matrix widths must be equal in DoubleProductVariable");
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 51 of file DoubleProductVariable.cc.

{X(n,k)*W(i,k)*M(j,k)}");
void PLearn::DoubleProductVariable::declareOptions ( OptionList ol) [static, protected]

Declares the class options.

Reimplemented from PLearn::NaryVariable.

Definition at line 192 of file DoubleProductVariable.cc.

References PLearn::NaryVariable::declareOptions().

{
    // ### Declare all of this object's options here.
    // ### For the "flags" of each option, you should typically specify
    // ### one of OptionBase::buildoption, OptionBase::learntoption or
    // ### OptionBase::tuningoption. If you don't provide one of these three,
    // ### this option will be ignored when loading values from a script.
    // ### You can also combine flags, for example with OptionBase::nosave:
    // ### (OptionBase::buildoption | OptionBase::nosave)

    // ### ex:
    // declareOption(ol, "myoption", &DoubleProductVariable::myoption,
    //               OptionBase::buildoption,
    //               "Help text describing this option");
    // ...

    // Now call the parent class' declareOptions
    inherited::declareOptions(ol);
}

Here is the call graph for this function:

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

Reimplemented from PLearn::NaryVariable.

Definition at line 102 of file DoubleProductVariable.h.

:
    //#####  Protected Options  ###############################################
DoubleProductVariable * PLearn::DoubleProductVariable::deepCopy ( CopiesMap copies) const [virtual]

Reimplemented from PLearn::NaryVariable.

Definition at line 51 of file DoubleProductVariable.cc.

{X(n,k)*W(i,k)*M(j,k)}");
void PLearn::DoubleProductVariable::fprop ( ) [virtual]

compute output given input

Implements PLearn::Variable.

Definition at line 70 of file DoubleProductVariable.cc.

References d, i, j, PLearn::TMat< T >::length(), m, PLearn::Variable::matValue, n, PLearn::NaryVariable::varray, w, PLearn::TMat< T >::width(), and x.

{
    Mat x = varray[0]->matValue,
        w = varray[1]->matValue,
        m = varray[2]->matValue;

    int nx = x.length(),
        nw = w.length(),
        nm = m.length(),
        d = x.width();// ( = w.width() = m.width() )


    /*
    for(int n=0; n<nx; n++)
        for(int i=0; i<nw; i++)        
            for(int j=0; j<nm; j++)
            {
                matValue(n,i+j*nw) = 0.;
                for(int k=0; k<d; k++)
                    matValue(n,i+j*nw) += x(n,k)*w(i,k)*m(j,k);
            }
    */

    for(int n=0; n<nx; n++)
    {
        real* matValue_n = matValue[n];
        const real* x_n = x[n];
        for(int j=0; j<nm; j++)
        {
            const real* m_j = m[j];
            for(int i=0; i<nw; i++)
            {
                const real* w_i = w[i];
                real val = 0;
                for(int k=0; k<d; k++)
                    val += x_n[k]*w_i[k]*m_j[k];
                matValue_n[i+j*nw] = val;
            }
        }
    }
}

Here is the call graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 51 of file DoubleProductVariable.cc.

{X(n,k)*W(i,k)*M(j,k)}");
OptionMap & PLearn::DoubleProductVariable::getOptionMap ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 51 of file DoubleProductVariable.cc.

{X(n,k)*W(i,k)*M(j,k)}");
RemoteMethodMap & PLearn::DoubleProductVariable::getRemoteMethodMap ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 51 of file DoubleProductVariable.cc.

{X(n,k)*W(i,k)*M(j,k)}");
void PLearn::DoubleProductVariable::makeDeepCopyFromShallowCopy ( CopiesMap copies) [virtual]

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::NaryVariable.

Definition at line 178 of file DoubleProductVariable.cc.

References PLearn::NaryVariable::makeDeepCopyFromShallowCopy().

{
    inherited::makeDeepCopyFromShallowCopy(copies);

    // ### Call deepCopyField on all "pointer-like" fields
    // ### that you wish to be deepCopied rather than
    // ### shallow-copied.
    // ### ex:
    // deepCopyField(trainvec, copies);

    // ### If you want to deepCopy a Var field:
    // varDeepCopyField(somevariable, copies);
}

Here is the call graph for this function:

void PLearn::DoubleProductVariable::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 60 of file DoubleProductVariable.cc.

References PLearn::TVec< T >::length(), PLearn::TVec< T >::size(), and PLearn::NaryVariable::varray.

{   
        if (varray.size() > 0) {
            l = varray[0].length() ; // the computed length of this Var
            w = varray[1].length()*varray[2].length(); // the computed width
        } else
            l = w = 0;    
}

Here is the call graph for this function:

Var& PLearn::DoubleProductVariable::varM ( ) [inline]

Definition at line 82 of file DoubleProductVariable.h.

Referenced by build_().

{ return varray[2]; }

Here is the caller graph for this function:

Var& PLearn::DoubleProductVariable::varW ( ) [inline]

Definition at line 81 of file DoubleProductVariable.h.

Referenced by build_().

{ return varray[1]; }

Here is the caller graph for this function:

Var& PLearn::DoubleProductVariable::varX ( ) [inline]

Definition at line 80 of file DoubleProductVariable.h.

Referenced by build_().

{ return varray[0]; }

Here is the caller graph for this function:


Member Data Documentation

Reimplemented from PLearn::NaryVariable.

Definition at line 102 of file DoubleProductVariable.h.


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