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

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

#include <MatrixModule.h>

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

List of all members.

Public Member Functions

 MatrixModule (const string &the_name="", bool call_build_=false)
 Default constructor.
void setData (const Mat &the_data)
 Make this module see the provided 'the_data' matrix.
MatgetData ()
 Return the current matrix viewed by this module.
virtual void fprop (const Vec &input, Vec &output) const
 given the input, compute the output (possibly resize it appropriately)
virtual void forget ()
 Reset the parameters to the state they would be BEFORE starting training.
virtual void fprop (const TVec< Mat * > &ports_value)
 If provided, the matrix value is used to fill 'data'.
virtual void bpropAccUpdate (const TVec< Mat * > &ports_value, const TVec< Mat * > &ports_gradient)
 If provided, the gradient is used to update 'data' (and fill 'data_gradient').
virtual const TVec< string > & getPorts ()
 Overridden.
virtual const TMat< int > & getPortSizes ()
 Overridden.
void setGradientTo (real g)
 Set the gradient w.r.t.
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual MatrixModuledeepCopy (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_ ()
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

Mat data
Mat data_gradient

Static Public Attributes

static StaticInitializer _static_initializer_

Static Protected Member Functions

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

Private Types

typedef OnlineLearningModule 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.

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 57 of file MatrixModule.h.


Member Typedef Documentation

Reimplemented from PLearn::OnlineLearningModule.

Definition at line 59 of file MatrixModule.h.


Constructor & Destructor Documentation

PLearn::MatrixModule::MatrixModule ( const string &  the_name = "",
bool  call_build_ = false 
)

Default constructor.

If 'the_name' is empty, and 'call_build_' is true, then the name is set to the name of this class (otherwise it is kept to an empty string, and it will be properly initialized at build time).

Definition at line 56 of file MatrixModule.cc.

References build_().

                                                                  :
    inherited(the_name.empty() && call_build_ ? classname() : the_name,
              call_build_)
{
    if (call_build_)
        build_();
}

Here is the call graph for this function:


Member Function Documentation

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

Reimplemented from PLearn::OnlineLearningModule.

Definition at line 51 of file MatrixModule.cc.

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

Reimplemented from PLearn::OnlineLearningModule.

Definition at line 51 of file MatrixModule.cc.

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

Reimplemented from PLearn::OnlineLearningModule.

Definition at line 51 of file MatrixModule.cc.

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

Reimplemented from PLearn::OnlineLearningModule.

Definition at line 51 of file MatrixModule.cc.

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

Reimplemented from PLearn::Object.

Definition at line 51 of file MatrixModule.cc.

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

Reimplemented from PLearn::OnlineLearningModule.

Definition at line 51 of file MatrixModule.cc.

void PLearn::MatrixModule::bpropAccUpdate ( const TVec< Mat * > &  ports_value,
const TVec< Mat * > &  ports_gradient 
) [virtual]

If provided, the gradient is used to update 'data' (and fill 'data_gradient').

If required, it is filled with 'gradient'.

Reimplemented from PLearn::OnlineLearningModule.

Definition at line 107 of file MatrixModule.cc.

References data, data_gradient, grad, PLearn::TMat< T >::isEmpty(), PLearn::TMat< T >::length(), PLearn::TVec< T >::length(), PLASSERT, PLERROR, PLearn::TMat< T >::resize(), PLearn::TVec< T >::resize(), and PLearn::TMat< T >::width().

{
    PLASSERT( ports_gradient.length() == 1 );
    Mat* grad = ports_gradient[0];
    if (!grad)
        return;
    if (grad->isEmpty()) {
        // Accumulate 'data_gradient' into gradient (if there actually is a
        // gradient).
        grad->resize(data.length(), data.width());
        if (!data_gradient.isEmpty()) {
            PLASSERT( data.length() == data_gradient.length() &&
                      data.width()  == data_gradient.width() );
            *grad += data_gradient;
        }
    } else {
        data_gradient.resize(grad->length(), grad->width());
        data_gradient << *grad;
        PLERROR("In MatrixModule::bpropAccUpdate - Update of the underlying "
                "data matrix is not yet implemented");
    }
}

Here is the call graph for this function:

void PLearn::MatrixModule::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::OnlineLearningModule.

Definition at line 98 of file MatrixModule.cc.

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

Here is the call graph for this function:

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

This does the actual building.

Reimplemented from PLearn::OnlineLearningModule.

Definition at line 92 of file MatrixModule.cc.

Referenced by build(), and MatrixModule().

{}

Here is the caller graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 51 of file MatrixModule.cc.

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

Declares the class options.

Reimplemented from PLearn::OnlineLearningModule.

Definition at line 67 of file MatrixModule.cc.

References PLearn::OptionBase::buildoption, data, data_gradient, PLearn::declareOption(), and PLearn::OnlineLearningModule::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, "data", &MatrixModule::data,
                  OptionBase::buildoption,
        "The matrix seen by this module.");

    declareOption(ol, "data_gradient", &MatrixModule::data_gradient,
                  OptionBase::buildoption,
        "The gradient w.r.t. 'data'. If not provided, is assumed to be 0.");

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

Here is the call graph for this function:

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

Reimplemented from PLearn::OnlineLearningModule.

Definition at line 197 of file MatrixModule.h.

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

Reimplemented from PLearn::OnlineLearningModule.

Definition at line 51 of file MatrixModule.cc.

void PLearn::MatrixModule::forget ( ) [virtual]

Reset the parameters to the state they would be BEFORE starting training.

Note that this method is necessarily called from build().

Implements PLearn::OnlineLearningModule.

Definition at line 212 of file MatrixModule.cc.

{
    // Nothing to forget.
}
void PLearn::MatrixModule::fprop ( const TVec< Mat * > &  ports_value) [virtual]

If provided, the matrix value is used to fill 'data'.

If required, it is filled with 'data'.

Reimplemented from PLearn::OnlineLearningModule.

Definition at line 151 of file MatrixModule.cc.

References data, PLearn::TMat< T >::length(), PLearn::TVec< T >::length(), PLASSERT, PLearn::TMat< T >::resize(), PLearn::TVec< T >::resize(), and PLearn::TMat< T >::width().

{
    PLASSERT( ports_value.length() == 1 );
    Mat* mat = ports_value[0];
    if (!mat)
        return;
    if (mat->isEmpty()) {
        // We want to query the value of the matrix.
        mat->resize(data.length(), data.width());
        *mat << data;
    } else {
        // We want to store the value of the matrix.
        data.resize(mat->length(), mat->width());
        data << *mat;
    }
}

Here is the call graph for this function:

void PLearn::MatrixModule::fprop ( const Vec input,
Vec output 
) const [virtual]

given the input, compute the output (possibly resize it appropriately)

Reimplemented from PLearn::OnlineLearningModule.

Definition at line 146 of file MatrixModule.cc.

References PLERROR.

{
    PLERROR("In MatrixModule::fprop - Not implemented");
}
Mat & PLearn::MatrixModule::getData ( )

Return the current matrix viewed by this module.

Definition at line 250 of file MatrixModule.cc.

References data.

{
    return this->data;
}
OptionList & PLearn::MatrixModule::getOptionList ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 51 of file MatrixModule.cc.

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

Reimplemented from PLearn::Object.

Definition at line 51 of file MatrixModule.cc.

const TVec< string > & PLearn::MatrixModule::getPorts ( ) [virtual]

Overridden.

Reimplemented from PLearn::OnlineLearningModule.

Definition at line 220 of file MatrixModule.cc.

References PLearn::TVec< T >::append(), and PLearn::TVec< T >::isEmpty().

{
    static TVec<string> ports;
    if (ports.isEmpty())
        ports.append("data");
    return ports;
}

Here is the call graph for this function:

const TMat< int > & PLearn::MatrixModule::getPortSizes ( ) [virtual]

Overridden.

Reimplemented from PLearn::OnlineLearningModule.

Definition at line 231 of file MatrixModule.cc.

References data, PLearn::TMat< T >::length(), PLearn::OnlineLearningModule::port_sizes, PLearn::TMat< T >::resize(), and PLearn::TMat< T >::width().

                                            {
    port_sizes.resize(1, 2);
    port_sizes(0, 0) = data.length();
    port_sizes(0, 1) = data.width();
    return port_sizes;
}

Here is the call graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 51 of file MatrixModule.cc.

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

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::OnlineLearningModule.

Definition at line 135 of file MatrixModule.cc.

References data, data_gradient, PLearn::deepCopyField(), and PLearn::OnlineLearningModule::makeDeepCopyFromShallowCopy().

Here is the call graph for this function:

void PLearn::MatrixModule::setData ( const Mat the_data)

Make this module see the provided 'the_data' matrix.

Note that no copy is made, so 'the_data' should not be modified afterwards.

Definition at line 285 of file MatrixModule.cc.

References data.

{
    this->data = the_data;
}
void PLearn::MatrixModule::setGradientTo ( real  g)

Set the gradient w.r.t.

'data' to the provided constant value 'g'. The result is that 'data_gradient' is resized to the same size as 'data' and filled with 'g'.

Definition at line 267 of file MatrixModule.cc.

References data, data_gradient, PLearn::TMat< T >::fill(), PLearn::TMat< T >::length(), PLearn::TMat< T >::resize(), and PLearn::TMat< T >::width().

{
    data_gradient.resize(data.length(), data.width());
    data_gradient.fill(g);
}

Here is the call graph for this function:


Member Data Documentation

Reimplemented from PLearn::OnlineLearningModule.

Definition at line 197 of file MatrixModule.h.


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