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::LinearCombinationOfScalarVariables Class Reference

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

#include <LinearCombinationOfScalarVariables.h>

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

List of all members.

Public Member Functions

 LinearCombinationOfScalarVariables ()
 Default constructor, usually does nothing.
 LinearCombinationOfScalarVariables (const VarArray &vararray, Vec the_coefs)
 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
LinearCombinationOfScalarVariables
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_ ()
 LinearCombinationOfScalarVariables.
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

Vec coefs
 ### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //!
real constant_term
bool appendinputs

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.

* LinearCombinationOfScalarVariables * 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 LinearCombinationOfScalarVariables.h.


Member Typedef Documentation

Reimplemented from PLearn::NaryVariable.

Definition at line 62 of file LinearCombinationOfScalarVariables.h.


Constructor & Destructor Documentation

PLearn::LinearCombinationOfScalarVariables::LinearCombinationOfScalarVariables ( )

Default constructor, usually does nothing.

Definition at line 54 of file LinearCombinationOfScalarVariables.cc.

    :constant_term(0),
     appendinputs(false)
{}
PLearn::LinearCombinationOfScalarVariables::LinearCombinationOfScalarVariables ( const VarArray vararray,
Vec  the_coefs 
)

Constructor initializing from input variables.

Definition at line 88 of file LinearCombinationOfScalarVariables.cc.

References build_().

    : inherited(vararray, 1, appendinputs?(1+vararray.length()):1), 
      coefs(the_coefs), constant_term(0), appendinputs(false)
{
    build_();
}

Here is the call graph for this function:


Member Function Documentation

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

Reimplemented from PLearn::NaryVariable.

Definition at line 52 of file LinearCombinationOfScalarVariables.cc.

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

Reimplemented from PLearn::NaryVariable.

Definition at line 52 of file LinearCombinationOfScalarVariables.cc.

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

Reimplemented from PLearn::NaryVariable.

Definition at line 52 of file LinearCombinationOfScalarVariables.cc.

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

Reimplemented from PLearn::Object.

Definition at line 52 of file LinearCombinationOfScalarVariables.cc.

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

Reimplemented from PLearn::NaryVariable.

Definition at line 52 of file LinearCombinationOfScalarVariables.cc.

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

Implements PLearn::Variable.

Definition at line 142 of file LinearCombinationOfScalarVariables.cc.

References coefs, PLearn::Variable::gradientdata, PLearn::TVec< T >::length(), and PLearn::NaryVariable::varray.

{
    real gr = gradientdata[0];
    for(int k=0; k<varray.length(); k++)
        varray[k]->gradientdata[0] += gr*coefs[k];
}

Here is the call graph for this function:

void PLearn::LinearCombinationOfScalarVariables::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 156 of file LinearCombinationOfScalarVariables.cc.

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

Here is the call graph for this function:

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

This does the actual building.

Reimplemented from PLearn::NaryVariable.

Definition at line 198 of file LinearCombinationOfScalarVariables.cc.

Referenced by build(), and LinearCombinationOfScalarVariables().

{
    // ### This method should do the real building 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.
}

Here is the caller graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 52 of file LinearCombinationOfScalarVariables.cc.

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

Declares the class options.

Reimplemented from PLearn::NaryVariable.

Definition at line 168 of file LinearCombinationOfScalarVariables.cc.

References appendinputs, PLearn::OptionBase::buildoption, coefs, constant_term, PLearn::declareOption(), and 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)

    declareOption(ol, "coefs", &LinearCombinationOfScalarVariables::coefs,
                  OptionBase::buildoption,
                  "The vector of coefficients for the linear combination (weights for the sum)");

    declareOption(ol, "constant_term", &LinearCombinationOfScalarVariables::constant_term,
                  OptionBase::buildoption,
                  "A constant term whose valiue will be added to the linear combination");

    declareOption(ol, "appendinputs", &LinearCombinationOfScalarVariables::appendinputs,
                  OptionBase::buildoption,
                  "If true, the values of the first element of all input variables \n"
                  "(with which we compute the weighted sum) will be appended in the \n"
                  "produced output vector (just after their weighted sum). \n"
                  "Note: gradient received on those appended elements is ignored (i.e. not backpropagated).\n"
                  "  these are only useful as extra information (a decomposition of the cost) for reporting purpose");

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

Here is the call graph for this function:

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

Reimplemented from PLearn::NaryVariable.

Definition at line 121 of file LinearCombinationOfScalarVariables.h.

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

Reimplemented from PLearn::NaryVariable.

Definition at line 52 of file LinearCombinationOfScalarVariables.cc.

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

compute output given input

Implements PLearn::Variable.

Definition at line 120 of file LinearCombinationOfScalarVariables.cc.

References appendinputs, coefs, constant_term, PLearn::TVec< T >::length(), n, PLearn::Variable::valuedata, and PLearn::NaryVariable::varray.

{
    real res = constant_term;
    int n = varray.length();
    if(appendinputs)
    {
        for(int k=0; k<n; k++)
        {
            real val = varray[k]->valuedata[0];
            valuedata[1+k] = val;
            res += coefs[k]*val;
        }
    }
    else
    {
        for(int k=0; k<n; k++)
            res += coefs[k]*varray[k]->valuedata[0];
    }
    valuedata[0] = res;
}

Here is the call graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 52 of file LinearCombinationOfScalarVariables.cc.

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

Reimplemented from PLearn::Object.

Definition at line 52 of file LinearCombinationOfScalarVariables.cc.

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

Reimplemented from PLearn::Object.

Definition at line 52 of file LinearCombinationOfScalarVariables.cc.

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

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::NaryVariable.

Definition at line 162 of file LinearCombinationOfScalarVariables.cc.

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

Here is the call graph for this function:

void PLearn::LinearCombinationOfScalarVariables::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 110 of file LinearCombinationOfScalarVariables.cc.

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

{
    l = 1;
    if(!appendinputs)
        w = 1;
    else
        w = 1+varray.length();
}

Here is the call graph for this function:


Member Data Documentation

Reimplemented from PLearn::NaryVariable.

Definition at line 121 of file LinearCombinationOfScalarVariables.h.

Definition at line 73 of file LinearCombinationOfScalarVariables.h.

Referenced by declareOptions(), fprop(), and recomputeSize().

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

The coeficients for the linear combination

Definition at line 71 of file LinearCombinationOfScalarVariables.h.

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

Definition at line 72 of file LinearCombinationOfScalarVariables.h.

Referenced by declareOptions(), and fprop().


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