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

Dot product between 2 vectors (or possibly 2 matrices, which are then simply seen as vectors) More...

#include <DotProductVariable.h>

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

List of all members.

Public Member Functions

 DotProductVariable ()
 Default constructor for persistence.
 DotProductVariable (Variable *input1, Variable *input2)
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual DotProductVariabledeepCopy (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_ ()
 DotProductVariable.
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_

Protected Member Functions

void build_ ()
 This does the actual building.

Private Types

typedef BinaryVariable inherited

Detailed Description

Dot product between 2 vectors (or possibly 2 matrices, which are then simply seen as vectors)

* Dot and Matrix products... *

Definition at line 55 of file DotProductVariable.h.


Member Typedef Documentation

Reimplemented from PLearn::BinaryVariable.

Definition at line 57 of file DotProductVariable.h.


Constructor & Destructor Documentation

PLearn::DotProductVariable::DotProductVariable ( ) [inline]

Default constructor for persistence.

Definition at line 61 of file DotProductVariable.h.

{}
PLearn::DotProductVariable::DotProductVariable ( Variable input1,
Variable input2 
)

Definition at line 59 of file DotProductVariable.cc.

References build_().

    : inherited(input1, input2, 1, 1)
{
    build_();
}

Here is the call graph for this function:


Member Function Documentation

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

DotProductVariable.

Reimplemented from PLearn::BinaryVariable.

Definition at line 57 of file DotProductVariable.cc.

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

Reimplemented from PLearn::BinaryVariable.

Definition at line 57 of file DotProductVariable.cc.

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

Reimplemented from PLearn::BinaryVariable.

Definition at line 57 of file DotProductVariable.cc.

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

Reimplemented from PLearn::BinaryVariable.

Definition at line 57 of file DotProductVariable.cc.

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

Reimplemented from PLearn::Object.

Definition at line 57 of file DotProductVariable.cc.

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

Reimplemented from PLearn::BinaryVariable.

Definition at line 57 of file DotProductVariable.cc.

void PLearn::DotProductVariable::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 111 of file DotProductVariable.cc.

References PLearn::Variable::diaghessiandata, PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, and PLearn::Var::length().

{
    if (input1->diaghessian.length()==0)
        input1->resizeDiagHessian();
    if (input2->diaghessian.length()==0)
        input2->resizeDiagHessian();
    real h = diaghessiandata[0];
    for (int k=0; k<input1->nelems(); k++)
    {
        real in2v=input2->valuedata[k];
        input1->diaghessiandata[k] += in2v * in2v * h;
        real in1v=input1->valuedata[k];
        input2->diaghessiandata[k] += in1v * in1v * h;
    }
}

Here is the call graph for this function:

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

Implements PLearn::Variable.

Definition at line 100 of file DotProductVariable.cc.

References grad, PLearn::Variable::gradientdata, PLearn::BinaryVariable::input1, and PLearn::BinaryVariable::input2.

{
    real grad = gradientdata[0];
    for (int k=0; k<input1->nelems(); k++)
    {
        input1->gradientdata[k] += input2->valuedata[k] * grad;
        input2->gradientdata[k] += input1->valuedata[k] * grad;
    }
}
void PLearn::DotProductVariable::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 66 of file DotProductVariable.cc.

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

Here is the call graph for this function:

void PLearn::DotProductVariable::build_ ( ) [protected]

This does the actual building.

Reimplemented from PLearn::BinaryVariable.

Definition at line 73 of file DotProductVariable.cc.

References PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, PLearn::Var::length(), PLERROR, and PLearn::Var::width().

Referenced by build(), and DotProductVariable().

{
    if(input1 && input2 && (input1->nelems() != input2->nelems()))
        PLERROR("IN DotProductVariable input1 and input2 must have the "
                "same number of elements: %dx%d != %dx%d", 
                input1->length(), input1->width(), input2->length(), input2->width());
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 57 of file DotProductVariable.cc.

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

Reimplemented from PLearn::BinaryVariable.

Definition at line 64 of file DotProductVariable.h.

:
    void build_();
DotProductVariable * PLearn::DotProductVariable::deepCopy ( CopiesMap copies) const [virtual]

Reimplemented from PLearn::BinaryVariable.

Definition at line 57 of file DotProductVariable.cc.

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

compute output given input

Implements PLearn::Variable.

Definition at line 91 of file DotProductVariable.cc.

References PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, PLearn::sum(), and PLearn::Variable::valuedata.

{
    real sum = 0.0;
    for (int k=0; k<input1->nelems(); k++)
        sum += input1->valuedata[k] * input2->valuedata[k];
    valuedata[0] = sum;
}

Here is the call graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 57 of file DotProductVariable.cc.

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

Reimplemented from PLearn::Object.

Definition at line 57 of file DotProductVariable.cc.

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

Reimplemented from PLearn::Object.

Definition at line 57 of file DotProductVariable.cc.

void PLearn::DotProductVariable::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 81 of file DotProductVariable.cc.

{ l=1; w=1; }
void PLearn::DotProductVariable::rfprop ( ) [virtual]

Reimplemented from PLearn::Variable.

Definition at line 135 of file DotProductVariable.cc.

References PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, PLearn::TVec< T >::length(), PLearn::BinaryVariable::resizeRValue(), PLearn::Variable::rValue, PLearn::Variable::rvaluedata, and PLearn::sum().

{
    if (rValue.length()==0) resizeRValue(); 
    real sum = 0.0;
    for (int k=0; k<input1->nelems(); k++)
        sum += input1->rvaluedata[k] * input2->valuedata[k] + input1->valuedata[k] * input2->rvaluedata[k];
    rvaluedata[0] = sum;
}

Here is the call graph for this function:

void PLearn::DotProductVariable::symbolicBprop ( ) [virtual]

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

Reimplemented from PLearn::Variable.

Definition at line 128 of file DotProductVariable.cc.

References PLearn::Variable::g, PLearn::BinaryVariable::input1, and PLearn::BinaryVariable::input2.

{
    input1->accg(input2*g);
    input2->accg(input1*g);
}

Member Data Documentation

Reimplemented from PLearn::BinaryVariable.

Definition at line 64 of file DotProductVariable.h.


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