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

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

#include <ArgmaxModule.h>

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

List of all members.

Public Member Functions

 ArgmaxModule ()
 ### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //!
void fprop (const TVec< Mat * > &ports_value)
 Perform a fprop step.
virtual void bpropAccUpdate (const TVec< Mat * > &ports_value, const TVec< Mat * > &ports_gradient)
 Perform a back propagation step (also updating parameters according to the provided gradient).
virtual void forget ()
 Reset the parameters to the state they would be BEFORE starting training.
virtual const TVec< string > & getPorts ()
 Return the list of ports in the module.
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual ArgmaxModuledeepCopy (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 ()

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 ArgmaxModule.h.


Member Typedef Documentation

Reimplemented from PLearn::OnlineLearningModule.

Definition at line 59 of file ArgmaxModule.h.


Constructor & Destructor Documentation

PLearn::ArgmaxModule::ArgmaxModule ( )

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

Default constructor

Definition at line 54 of file ArgmaxModule.cc.

{
    output_size = 1;
}

Member Function Documentation

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

Reimplemented from PLearn::OnlineLearningModule.

Definition at line 52 of file ArgmaxModule.cc.

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

Reimplemented from PLearn::OnlineLearningModule.

Definition at line 52 of file ArgmaxModule.cc.

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

Reimplemented from PLearn::OnlineLearningModule.

Definition at line 52 of file ArgmaxModule.cc.

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

Reimplemented from PLearn::OnlineLearningModule.

Definition at line 52 of file ArgmaxModule.cc.

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

Reimplemented from PLearn::Object.

Definition at line 52 of file ArgmaxModule.cc.

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

Reimplemented from PLearn::OnlineLearningModule.

Definition at line 52 of file ArgmaxModule.cc.

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

Perform a back propagation step (also updating parameters according to the provided gradient).

The matrices in 'ports_value' must be the same as the ones given in a previous call to 'fprop' (and thus they should in particular contain the result of the fprop computation). However, they are not necessarily the same as the ones given in the LAST call to 'fprop': if there is a need to store an internal module state, this should be done using a specific port to store this state. Each Mat* pointer in the 'ports_gradient' vector can be one of:

  • a full matrix : this is the gradient that is provided to the module, and can be used to compute other ports' gradient.
  • an empty matrix: this is a gradient we want to compute and accumulate into. This matrix must have length 0 and a width equal to the width of the corresponding matrix in the 'ports_value' vector (we can thus accumulate gradients using PLearn's ability to keep intact stored values when resizing a matrix' length).
  • a NULL pointer : this is a gradient that is not available, but does not need to be returned (or even computed). The default version tries to use the standard mini-batch bpropUpdate method, when possible.

Reimplemented from PLearn::OnlineLearningModule.

Definition at line 136 of file ArgmaxModule.cc.

References PLearn::TVec< T >::length(), and PLASSERT.

{
    PLASSERT( ports_value.length() == nPorts() && ports_gradient.length() == nPorts());

    // Currently not implemented. Thus the check below should crash if we
    // actually ask to compute a gradient.

    // Ensure all required gradients have been computed.
    checkProp(ports_gradient);
}

Here is the call graph for this function:

void PLearn::ArgmaxModule::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 94 of file ArgmaxModule.cc.

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

This does the actual building.

Reimplemented from PLearn::OnlineLearningModule.

Definition at line 79 of file ArgmaxModule.cc.

{
    // ### 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.
}
string PLearn::ArgmaxModule::classname ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 52 of file ArgmaxModule.cc.

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

Declares the class options.

Reimplemented from PLearn::OnlineLearningModule.

Definition at line 59 of file ArgmaxModule.cc.

{
    // ### 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", &ArgmaxModule::myoption,
    //               OptionBase::buildoption,
    //               "Help text describing this option");
    // ...

    // Now call the parent class' declareOptions
    inherited::declareOptions(ol);
}
static const PPath& PLearn::ArgmaxModule::declaringFile ( ) [inline, static]

Reimplemented from PLearn::OnlineLearningModule.

Definition at line 235 of file ArgmaxModule.h.

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

Reimplemented from PLearn::OnlineLearningModule.

Definition at line 52 of file ArgmaxModule.cc.

void PLearn::ArgmaxModule::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 151 of file ArgmaxModule.cc.

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

Perform a fprop step.

Each Mat* pointer in the 'ports_value' vector can be one of:

  • a full matrix: this is data that is provided to the module, and can be used to compute other ports' values
  • an empty matrix: this is what we want to compute
  • a NULL pointer: this is data that is not available, but whose value does not need to be returned (or even computed) The default version will either:
  • call the mini-batch versions of standard fprop if 'ports_value' has size 2, with the first value being provided (and the second being the desired output)
  • crash otherwise

Reimplemented from PLearn::OnlineLearningModule.

Definition at line 118 of file ArgmaxModule.cc.

References PLearn::argmax(), i, PLearn::TMat< T >::isEmpty(), PLearn::TVec< T >::length(), PLASSERT, PLCHECK, and PLearn::TMat< T >::resize().

{
    PLASSERT( ports_value.length() == nPorts() );
    Mat* input = ports_value[0];
    Mat* output = ports_value[1];
    PLCHECK( input && output && !input->isEmpty() && output->isEmpty() );

    output->resize(input->length(), 1);
    for (int i = 0; i < input->length(); i++)
        (*output)(i, 0) = argmax((*input)(i));

    // Ensure all required ports have been computed.
    checkProp(ports_value);
}

Here is the call graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 52 of file ArgmaxModule.cc.

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

Reimplemented from PLearn::Object.

Definition at line 52 of file ArgmaxModule.cc.

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

Return the list of ports in the module.

The default implementation returns a pair ("input", "output") to handle the most common case.

Reimplemented from PLearn::OnlineLearningModule.

Definition at line 159 of file ArgmaxModule.cc.

                                           {
    return inherited::getPorts();
}
RemoteMethodMap & PLearn::ArgmaxModule::getRemoteMethodMap ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 52 of file ArgmaxModule.cc.

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

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::OnlineLearningModule.

Definition at line 101 of file ArgmaxModule.cc.

References PLERROR.

{
    inherited::makeDeepCopyFromShallowCopy(copies);

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

    // ### Remove this line when you have fully implemented this method.
    PLERROR("ArgmaxModule::makeDeepCopyFromShallowCopy not fully (correctly) implemented yet!");
}

Member Data Documentation

Reimplemented from PLearn::OnlineLearningModule.

Definition at line 235 of file ArgmaxModule.h.


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