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

Affine transform with continuous and discrete input. More...

#include <HeterogenuousAffineTransformVariable.h>

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

List of all members.

Public Member Functions

 HeterogenuousAffineTransformVariable ()
 Default constructor, usually does nothing.
 HeterogenuousAffineTransformVariable (Var input, VarArray weights, TVec< bool > the_input_is_discrete)
 Constructor initializing from input variables.
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
HeterogenuousAffineTransformVariable
deepCopy (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_ ()
 HeterogenuousAffineTransformVariable.
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

TVec< boolinput_is_discrete
 Indication whether the input components are discrete.

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

Affine transform with continuous and discrete input.

* HeterogenuousAffineTransformVariable *

Definition at line 53 of file HeterogenuousAffineTransformVariable.h.


Member Typedef Documentation

Reimplemented from PLearn::NaryVariable.

Definition at line 55 of file HeterogenuousAffineTransformVariable.h.


Constructor & Destructor Documentation

PLearn::HeterogenuousAffineTransformVariable::HeterogenuousAffineTransformVariable ( )

Default constructor, usually does nothing.

Definition at line 60 of file HeterogenuousAffineTransformVariable.cc.

{}
PLearn::HeterogenuousAffineTransformVariable::HeterogenuousAffineTransformVariable ( Var  input,
VarArray  weights,
TVec< bool the_input_is_discrete 
)

Constructor initializing from input variables.

Definition at line 64 of file HeterogenuousAffineTransformVariable.cc.

References build().

     : inherited(input & weights, 1, 1), input_is_discrete(the_input_is_discrete)
//     : inherited(input & weights, input->length() != 1 ? weights[0]->width() : 1 , input->width() != 1 ? weights[0]->width() : 1)
 {
     build();
 }

Here is the call graph for this function:


Member Function Documentation

string PLearn::HeterogenuousAffineTransformVariable::_classname_ ( ) [static]
OptionList & PLearn::HeterogenuousAffineTransformVariable::_getOptionList_ ( ) [static]

Reimplemented from PLearn::NaryVariable.

Definition at line 58 of file HeterogenuousAffineTransformVariable.cc.

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

Reimplemented from PLearn::NaryVariable.

Definition at line 58 of file HeterogenuousAffineTransformVariable.cc.

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

Reimplemented from PLearn::NaryVariable.

Definition at line 58 of file HeterogenuousAffineTransformVariable.cc.

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

Reimplemented from PLearn::Object.

Definition at line 58 of file HeterogenuousAffineTransformVariable.cc.

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

Reimplemented from PLearn::NaryVariable.

Definition at line 58 of file HeterogenuousAffineTransformVariable.cc.

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

Implements PLearn::Variable.

Definition at line 111 of file HeterogenuousAffineTransformVariable.cc.

References PLearn::TVec< T >::data(), PLearn::Variable::gradient, PLearn::Variable::gradientdata, i, input_is_discrete, j, PLearn::TVec< T >::last(), PLearn::TVec< T >::length(), n, PLearn::Variable::row(), PLearn::Variable::size(), PLearn::Variable::valuedata, and PLearn::NaryVariable::varray.

{
    varray.last()->gradient += gradient;
    int n = size();
    int l = varray.length()-1;
    for(int i=1; i<l; i++)
    {
        if(input_is_discrete[i-1])
        {
            int r = (int)varray[0]->valuedata[i-1];
            real* row = varray[i]->matGradient.row(r).data();
            for(int j=0; j<n; j++)
                row[j] += gradientdata[j] ;
            varray[i]->updateRow(r);
        }
        else
        {
            for(int j=0; j<n; j++)
            {
                varray[i]->gradientdata[j] += gradientdata[j]*varray[0]->valuedata[i-1];
                varray[0]->gradientdata[i-1] += gradientdata[j]*varray[i]->valuedata[j];
            }
        }
    }

}

Here is the call graph for this function:

void PLearn::HeterogenuousAffineTransformVariable::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 138 of file HeterogenuousAffineTransformVariable.cc.

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

Referenced by HeterogenuousAffineTransformVariable().

Here is the call graph for this function:

Here is the caller graph for this function:

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

This does the actual building.

Reimplemented from PLearn::NaryVariable.

Definition at line 162 of file HeterogenuousAffineTransformVariable.cc.

References PLearn::Variable::allowPartialUpdates(), i, input_is_discrete, PLearn::Variable::isVec(), PLearn::TVec< T >::length(), PLERROR, PLearn::TVec< T >::size(), PLearn::Variable::size(), PLearn::NaryVariable::varray, and PLearn::Variable::width().

Referenced by build().

{
    if(varray[0]->size() != varray.length()-2)
        PLERROR("In HeterogenuousAffineTransformVariable::build_(): The number of weight variables (%d) and input size (%d) is not the same", varray.length()-2, varray[0]->size());
    if(input_is_discrete.length() != varray[0]->size())
        PLERROR("In HeterogenuousAffineTransformVariable::build_(): input_is_discrete size (%d) and input size (%d) does not match", input_is_discrete.length(), varray[0]->size());
    if(!varray[0]->isVec())
        PLERROR("In HeterogenuousAffineTransformVariable::build_(): input should be a vector");
    for(int i=1; i<varray.length(); i++)
    {
        if(varray[i]->width() != varray[1]->width())
            PLERROR("In HeterogenuousAffineTransformVariable::build_(): %dth weight matrix has width %d, should be %d", i, varray[i]->width(), size());
        if(i<varray.length()-1 && input_is_discrete[i-1])
            varray[i-1]->allowPartialUpdates();
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 58 of file HeterogenuousAffineTransformVariable.cc.

void PLearn::HeterogenuousAffineTransformVariable::declareOptions ( OptionList ol) [static, protected]

Declares the class options.

Reimplemented from PLearn::NaryVariable.

Definition at line 152 of file HeterogenuousAffineTransformVariable.cc.

References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::NaryVariable::declareOptions(), and input_is_discrete.

{    
    declareOption(ol, "input_is_discrete", &HeterogenuousAffineTransformVariable::input_is_discrete,
                  OptionBase::buildoption,
                  "Indication whether each component of the input is discrete or not.");
    
    // Now call the parent class' declareOptions
    inherited::declareOptions(ol);
}

Here is the call graph for this function:

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

Reimplemented from PLearn::NaryVariable.

Definition at line 86 of file HeterogenuousAffineTransformVariable.h.

:
    //#####  Protected Member Functions  ######################################
HeterogenuousAffineTransformVariable * PLearn::HeterogenuousAffineTransformVariable::deepCopy ( CopiesMap copies) const [virtual]

Reimplemented from PLearn::NaryVariable.

Definition at line 58 of file HeterogenuousAffineTransformVariable.cc.

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

compute output given input

Implements PLearn::Variable.

Definition at line 90 of file HeterogenuousAffineTransformVariable.cc.

References PLearn::TVec< T >::data(), i, input_is_discrete, j, PLearn::TVec< T >::last(), PLearn::TVec< T >::length(), PLearn::Variable::matValue, n, PLearn::Variable::row(), PLearn::Variable::size(), PLearn::Variable::valuedata, and PLearn::NaryVariable::varray.

{
    matValue << varray.last()->matValue;
    int n = size();
    int l = varray.length()-1;
    for(int i=1; i<l; i++)
    {
        if(input_is_discrete[i-1])
        {
            real* row = varray[i]->matValue.row((int)varray[0]->valuedata[i-1]).data();
            for(int j=0; j<n; j++)
                valuedata[j] += *row++;
        }
        else
        {
            for(int j=0; j<n; j++)
                valuedata[j] += varray[0]->valuedata[i-1]*varray[i]->valuedata[j];
        }
    }
}

Here is the call graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 58 of file HeterogenuousAffineTransformVariable.cc.

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

Reimplemented from PLearn::Object.

Definition at line 58 of file HeterogenuousAffineTransformVariable.cc.

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

Reimplemented from PLearn::Object.

Definition at line 58 of file HeterogenuousAffineTransformVariable.cc.

void PLearn::HeterogenuousAffineTransformVariable::makeDeepCopyFromShallowCopy ( CopiesMap copies) [virtual]

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::NaryVariable.

Definition at line 144 of file HeterogenuousAffineTransformVariable.cc.

References PLearn::deepCopyField(), input_is_discrete, and PLearn::NaryVariable::makeDeepCopyFromShallowCopy().

{
    inherited::makeDeepCopyFromShallowCopy(copies);

    deepCopyField(input_is_discrete, copies);
    //PLERROR("HeterogenuousAffineTransformVariable::makeDeepCopyFromShallowCopy not fully (correctly) implemented yet!");
}

Here is the call graph for this function:

void PLearn::HeterogenuousAffineTransformVariable::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 71 of file HeterogenuousAffineTransformVariable.cc.

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

{
    if (varray.size() > 1) 
    {
        if(varray[0]->width() != 1)
        {
            l = 1;
            w = varray[1]->width();
        }
        else
        {
            l = varray[1]->width() ;
            w = 1;
        }

    } else
        l = w = 0;
}

Here is the call graph for this function:


Member Data Documentation

Reimplemented from PLearn::NaryVariable.

Definition at line 86 of file HeterogenuousAffineTransformVariable.h.

Indication whether the input components are discrete.

Definition at line 61 of file HeterogenuousAffineTransformVariable.h.

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


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