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

Computes a mean-field approximate of p(y|x), with y a binary vector. More...

#include <RBMMultitaskClassificationModule.h>

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

List of all members.

Public Member Functions

 RBMMultitaskClassificationModule ()
 Default constructor.
virtual void fprop (const Vec &input, Vec &output) const
 given the input, compute the output (possibly resize it appropriately)
virtual void bpropUpdate (const Vec &input, const Vec &output, Vec &input_gradient, const Vec &output_gradient, bool accumulate=false)
 Adapt based on the output gradient: this method should only be called just after a corresponding fprop; it should be called with the same arguments as fprop for the first two arguments (and output should not have been modified since then).
virtual void forget ()
 Similar to bpropUpdate, but adapt based also on the estimation of the diagonal of the Hessian matrix, and propagates this back.
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual
RBMMultitaskClassificationModule
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_ ()
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

PP< RBMConnectionprevious_to_last
 Connection between the previous layer, and last_layer.
PP< RBMBinomialLayerlast_layer
 Top-level layer (the one in the middle if we unfold)
PP< RBMMatrixConnectionlast_to_target
 Connection between last_layer and target_layer.
PP< RBMBinomialLayertarget_layer
 Layer containing the one-hot vector containing the target (or its prediction)
int n_mean_field_iterations
 Number of mean-field iterations.
bool fprop_outputs_activation
 Indication that fprop should output the value of the activation before the squashing function and the application of the bias, instead of the mean-field approximation.
PP< RBMMixedConnectionjoint_connection
 Connection grouping previous_to_last and last_to_target.
int last_size
 Size of last_layer.

Static Public Attributes

static StaticInitializer _static_initializer_

Static Protected Member Functions

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

Protected Attributes

TVec< Vecmean_field_activations_target
TVec< Vecmean_field_approximations_target
TVec< Vecmean_field_activations_hidden
TVec< Vecmean_field_approximations_hidden

Private Types

typedef OnlineLearningModule inherited

Private Member Functions

void build_ ()
 This does the actual building.

Private Attributes

Mat last_to_target_gradient
 Stores the gradient of the weights between the target and the hidden layer.
Vec mean_field_activations_gradient_target
 Mean gradient propagation.
Vec mean_field_approximations_gradient_target
Vec mean_field_activations_gradient_hidden
Vec mean_field_approximations_gradient_hidden

Detailed Description

Computes a mean-field approximate of p(y|x), with y a binary vector.

This module contains an RBMConnection, an RBMBinomialLayer (hidden), an RBMMatrixConnection (transposed) and an RBMBinomialLayer (target). The two RBMConnections are combined in joint_connection.

Definition at line 59 of file RBMMultitaskClassificationModule.h.


Member Typedef Documentation

Reimplemented from PLearn::OnlineLearningModule.

Definition at line 61 of file RBMMultitaskClassificationModule.h.


Constructor & Destructor Documentation

PLearn::RBMMultitaskClassificationModule::RBMMultitaskClassificationModule ( )

Default constructor.

Definition at line 59 of file RBMMultitaskClassificationModule.cc.


Member Function Documentation

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

Reimplemented from PLearn::OnlineLearningModule.

Definition at line 57 of file RBMMultitaskClassificationModule.cc.

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

Reimplemented from PLearn::OnlineLearningModule.

Definition at line 57 of file RBMMultitaskClassificationModule.cc.

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

Reimplemented from PLearn::OnlineLearningModule.

Definition at line 57 of file RBMMultitaskClassificationModule.cc.

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

Reimplemented from PLearn::OnlineLearningModule.

Definition at line 57 of file RBMMultitaskClassificationModule.cc.

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

Reimplemented from PLearn::Object.

Definition at line 57 of file RBMMultitaskClassificationModule.cc.

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

Reimplemented from PLearn::OnlineLearningModule.

Definition at line 57 of file RBMMultitaskClassificationModule.cc.

void PLearn::RBMMultitaskClassificationModule::bpropUpdate ( const Vec input,
const Vec output,
Vec input_gradient,
const Vec output_gradient,
bool  accumulate = false 
) [virtual]

Adapt based on the output gradient: this method should only be called just after a corresponding fprop; it should be called with the same arguments as fprop for the first two arguments (and output should not have been modified since then).

this version allows to obtain the input gradient as well

Since sub-classes are supposed to learn ONLINE, the object is 'ready-to-be-used' just after any bpropUpdate. N.B. A DEFAULT IMPLEMENTATION IS PROVIDED IN THE SUPER-CLASS, WHICH JUST CALLS bpropUpdate(input, output, input_gradient, output_gradient) AND IGNORES INPUT GRADIENT. this version allows to obtain the input gradient as well

Reimplemented from PLearn::OnlineLearningModule.

Definition at line 284 of file RBMMultitaskClassificationModule.cc.

References PLearn::TMat< T >::clear(), PLearn::externalProductAcc(), fprop_outputs_activation, PLearn::OnlineLearningModule::input_size, last_layer, last_to_target, last_to_target_gradient, mean_field_activations_gradient_hidden, mean_field_activations_gradient_target, mean_field_activations_hidden, mean_field_activations_target, mean_field_approximations_gradient_hidden, mean_field_approximations_gradient_target, mean_field_approximations_hidden, mean_field_approximations_target, PLearn::multiplyAcc(), n_mean_field_iterations, PLearn::OnlineLearningModule::output_size, PLASSERT, PLASSERT_MSG, previous_to_last, PLearn::product(), PLearn::TVec< T >::size(), target_layer, and PLearn::transposeProduct().

{
    // size checks
    PLASSERT( input.size() == input_size );
    PLASSERT( output.size() == output_size );
    PLASSERT( output_gradient.size() == output_size );

    if( accumulate )
    {
        PLASSERT_MSG( input_gradient.size() == input_size,
                      "Cannot resize input_gradient AND accumulate into it" );
    }

    last_to_target_gradient.clear();
    Mat weights = last_to_target->weights;
    if( fprop_outputs_activation )
        mean_field_activations_gradient_target << output_gradient;
    else
        mean_field_approximations_gradient_target << output_gradient;

    for( int t=n_mean_field_iterations-1; t>=0; t-- )
    {
        if( t != n_mean_field_iterations-1 || !fprop_outputs_activation )
            target_layer->bpropUpdate( mean_field_activations_target[t],
                                       mean_field_approximations_target[t],
                                       mean_field_activations_gradient_target,
                                       mean_field_approximations_gradient_target
                );

        externalProductAcc( last_to_target_gradient,
                            mean_field_approximations_hidden[t],
                            mean_field_activations_gradient_target);

        product( mean_field_approximations_gradient_hidden, weights,
                          mean_field_activations_gradient_target);

        if( t != 0 )
        {
            last_layer->bpropUpdate( mean_field_activations_hidden[t],
                                       mean_field_approximations_hidden[t],
                                       mean_field_activations_gradient_hidden,
                                       mean_field_approximations_gradient_hidden
                );

            externalProductAcc( last_to_target_gradient,
                                mean_field_activations_gradient_hidden,
                                mean_field_approximations_target[t-1]
                                );

            transposeProduct( mean_field_approximations_gradient_target, weights,
                              mean_field_activations_gradient_hidden);
        }
    }

    last_layer->bpropUpdate( mean_field_activations_hidden[0],
                             mean_field_approximations_hidden[0],
                             mean_field_activations_gradient_hidden,
                             mean_field_approximations_gradient_hidden
        );

    previous_to_last->bpropUpdate( input, mean_field_activations_hidden[0],
                                   input_gradient,
                                   mean_field_activations_gradient_hidden,
                                   accumulate);

    multiplyAcc( weights, last_to_target_gradient,
                 - (last_to_target->learning_rate) );
}

Here is the call graph for this function:

void PLearn::RBMMultitaskClassificationModule::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 203 of file RBMMultitaskClassificationModule.cc.

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

Here is the call graph for this function:

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

This does the actual building.

Check (and set) sizes

build joint_connection

Reimplemented from PLearn::OnlineLearningModule.

Definition at line 117 of file RBMMultitaskClassificationModule.cc.

References PLearn::endl(), i, PLearn::OnlineLearningModule::input_size, joint_connection, last_layer, last_size, last_to_target, last_to_target_gradient, mean_field_activations_gradient_hidden, mean_field_activations_gradient_target, mean_field_activations_hidden, mean_field_activations_target, mean_field_approximations_gradient_hidden, mean_field_approximations_gradient_target, mean_field_approximations_hidden, mean_field_approximations_target, n_mean_field_iterations, PLearn::OnlineLearningModule::output_size, PLASSERT, PLERROR, previous_to_last, PLearn::OnlineLearningModule::random_gen, PLearn::TMat< T >::resize(), PLearn::TVec< T >::resize(), and target_layer.

Referenced by build().

{
    MODULE_LOG << "build_() called" << endl;

    if( !previous_to_last || !last_layer || !last_to_target || !target_layer )
    {
        MODULE_LOG << "build_() aborted because layers and connections were"
           " not set" << endl;
        return;
    }

    input_size = previous_to_last->down_size;
    last_size = last_layer->size;
    output_size = target_layer->size;

    PLASSERT( previous_to_last->up_size == last_size );
    PLASSERT( last_to_target->up_size == last_size );
    PLASSERT( last_to_target->down_size == output_size );

    if( !joint_connection )
        joint_connection = new RBMMixedConnection();

    joint_connection->sub_connections.resize(1,2);
    joint_connection->sub_connections(0,0) = previous_to_last;
    joint_connection->sub_connections(0,1) = last_to_target;
    joint_connection->build();

    if( n_mean_field_iterations > 0 )
    {
        mean_field_activations_target.resize( n_mean_field_iterations );
        mean_field_approximations_target.resize( n_mean_field_iterations );
        mean_field_activations_hidden.resize( n_mean_field_iterations );
        mean_field_approximations_hidden.resize( n_mean_field_iterations );
        for( int i=0; i<n_mean_field_iterations; i++ )
        {
            mean_field_activations_target[i].resize( output_size );
            mean_field_approximations_target[i].resize( output_size );
            mean_field_activations_hidden[i].resize( last_size );
            mean_field_approximations_hidden[i].resize( last_size );
        }
        mean_field_activations_gradient_target.resize( output_size );
        mean_field_approximations_gradient_target.resize( output_size );
        mean_field_activations_gradient_hidden.resize( last_size );
        mean_field_approximations_gradient_hidden.resize( last_size );
    }
    else
        PLERROR("In RBMMultitaskClassificationModule::build_(): "
                "n_mean_field_iterations should be > 0\n");

    last_to_target_gradient.resize( last_to_target->up_size,
                                    last_to_target->down_size );

    // If we have a random_gen, share it with the ones who do not
    if( random_gen )
    {
        if( !(previous_to_last->random_gen) )
        {
            previous_to_last->random_gen = random_gen;
            previous_to_last->forget();
        }
        if( !(last_layer->random_gen) )
        {
            last_layer->random_gen = random_gen;
            last_layer->forget();
        }
        if( !(last_to_target->random_gen) )
        {
            last_to_target->random_gen = random_gen;
            last_to_target->forget();
        }
        if( !(target_layer->random_gen) )
        {
            target_layer->random_gen = random_gen;
            target_layer->forget();
        }
        if( !(joint_connection->random_gen) )
        {
            joint_connection->random_gen = random_gen;
            joint_connection->forget();
        }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 57 of file RBMMultitaskClassificationModule.cc.

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

Declares the class options.

Reimplemented from PLearn::OnlineLearningModule.

Definition at line 65 of file RBMMultitaskClassificationModule.cc.

References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::OnlineLearningModule::declareOptions(), fprop_outputs_activation, joint_connection, last_layer, last_size, last_to_target, PLearn::OptionBase::learntoption, n_mean_field_iterations, previous_to_last, and target_layer.

{
    declareOption(ol, "previous_to_last",
                  &RBMMultitaskClassificationModule::previous_to_last,
                  OptionBase::buildoption,
                  "Connection between the previous layer, and last_layer.\n");

    declareOption(ol, "last_layer", &RBMMultitaskClassificationModule::last_layer,
                  OptionBase::buildoption,
                  "Top-level layer (the one in the middle if we unfold).\n");

    declareOption(ol, "last_to_target",
                  &RBMMultitaskClassificationModule::last_to_target,
                  OptionBase::buildoption,
                  "Connection between last_layer and target_layer.\n");

    declareOption(ol, "target_layer", &RBMMultitaskClassificationModule::target_layer,
                  OptionBase::buildoption,
                  "Layer containing the one-hot vector containing the target\n"
                  "(or its prediction).\n");

    declareOption(ol, "joint_connection",
                  &RBMMultitaskClassificationModule::joint_connection,
                  OptionBase::learntoption,
                  "Connection grouping previous_to_last and last_to_target.\n");

    declareOption(ol, "n_mean_field_iterations",
                  &RBMMultitaskClassificationModule::n_mean_field_iterations,
                  OptionBase::buildoption,
                  "Number of mean-field iterations.\n");

    declareOption(ol, "fprop_outputs_activation",
                  &RBMMultitaskClassificationModule::fprop_outputs_activation,
                  OptionBase::buildoption,
                  "Indication that fprop should output the value of the "
                  "activation\n"
                  "before the squashing function and the application of the bias,\n"
                  "instead of the mean-field approximation.\n");

    declareOption(ol, "last_size", &RBMMultitaskClassificationModule::last_size,
                  OptionBase::learntoption,
                  "Size of last_layer.\n");
    /*
    declareOption(ol, "", &RBMMultitaskClassificationModule::,
                  OptionBase::buildoption,
                  "");
     */

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

Here is the call graph for this function:

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

Reimplemented from PLearn::OnlineLearningModule.

Definition at line 158 of file RBMMultitaskClassificationModule.h.

:
    //#####  Not Options  #####################################################
RBMMultitaskClassificationModule * PLearn::RBMMultitaskClassificationModule::deepCopy ( CopiesMap copies) const [virtual]

Reimplemented from PLearn::OnlineLearningModule.

Definition at line 57 of file RBMMultitaskClassificationModule.cc.

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

Similar to bpropUpdate, but adapt based also on the estimation of the diagonal of the Hessian matrix, and propagates this back.

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

If these methods are defined, you can use them INSTEAD of bpropUpdate(...) N.B. A DEFAULT IMPLEMENTATION IS PROVIDED IN THE SUPER-CLASS, WHICH JUST CALLS bbpropUpdate(input, output, input_gradient, output_gradient, out_hess, in_hess) AND IGNORES INPUT HESSIAN AND INPUT GRADIENT. this version allows to obtain the input gradient and diag_hessian N.B. A DEFAULT IMPLEMENTATION IS PROVIDED IN THE SUPER-CLASS, WHICH RAISES A PLERROR. reset the parameters to the state they would be BEFORE starting training. Note that this method is necessarily called from build().

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

Implements PLearn::OnlineLearningModule.

Definition at line 358 of file RBMMultitaskClassificationModule.cc.

References joint_connection, last_to_target, PLWARNING, previous_to_last, and PLearn::OnlineLearningModule::random_gen.

{
    if( !random_gen )
    {
        PLWARNING("RBMMultitaskClassificationModule: cannot forget() without"
                  " random_gen");
        return;
    }

    if( !(previous_to_last->random_gen) )
        previous_to_last->random_gen = random_gen;
    previous_to_last->forget();
    if( !(last_to_target->random_gen) )
        last_to_target->random_gen = random_gen;
    last_to_target->forget();
    if( !(joint_connection->random_gen) )
        joint_connection->random_gen = random_gen;
    joint_connection->forget();
}
void PLearn::RBMMultitaskClassificationModule::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 230 of file RBMMultitaskClassificationModule.cc.

References fprop_outputs_activation, PLearn::OnlineLearningModule::input_size, PLearn::TVec< T >::last(), last_layer, last_to_target, mean_field_activations_hidden, mean_field_activations_target, mean_field_approximations_hidden, mean_field_approximations_target, n_mean_field_iterations, PLearn::OnlineLearningModule::output_size, PLASSERT, previous_to_last, PLearn::product(), PLearn::TVec< T >::resize(), PLearn::TVec< T >::size(), target_layer, and PLearn::transposeProduct().

Here is the call graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 57 of file RBMMultitaskClassificationModule.cc.

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

Reimplemented from PLearn::Object.

Definition at line 57 of file RBMMultitaskClassificationModule.cc.

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

Reimplemented from PLearn::Object.

Definition at line 57 of file RBMMultitaskClassificationModule.cc.

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

Member Data Documentation

Reimplemented from PLearn::OnlineLearningModule.

Definition at line 158 of file RBMMultitaskClassificationModule.h.

Indication that fprop should output the value of the activation before the squashing function and the application of the bias, instead of the mean-field approximation.

Definition at line 84 of file RBMMultitaskClassificationModule.h.

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

Connection grouping previous_to_last and last_to_target.

Definition at line 88 of file RBMMultitaskClassificationModule.h.

Referenced by build_(), declareOptions(), forget(), and makeDeepCopyFromShallowCopy().

Top-level layer (the one in the middle if we unfold)

Definition at line 69 of file RBMMultitaskClassificationModule.h.

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

Size of last_layer.

Definition at line 91 of file RBMMultitaskClassificationModule.h.

Referenced by build_(), and declareOptions().

Connection between last_layer and target_layer.

Definition at line 72 of file RBMMultitaskClassificationModule.h.

Referenced by bpropUpdate(), build_(), declareOptions(), forget(), fprop(), and makeDeepCopyFromShallowCopy().

Stores the gradient of the weights between the target and the hidden layer.

Definition at line 190 of file RBMMultitaskClassificationModule.h.

Referenced by bpropUpdate(), build_(), and makeDeepCopyFromShallowCopy().

Mean gradient propagation.

Definition at line 193 of file RBMMultitaskClassificationModule.h.

Referenced by bpropUpdate(), build_(), and makeDeepCopyFromShallowCopy().

Number of mean-field iterations.

Definition at line 79 of file RBMMultitaskClassificationModule.h.

Referenced by bpropUpdate(), build_(), declareOptions(), and fprop().

Connection between the previous layer, and last_layer.

Definition at line 66 of file RBMMultitaskClassificationModule.h.

Referenced by bpropUpdate(), build_(), declareOptions(), forget(), fprop(), and makeDeepCopyFromShallowCopy().

Layer containing the one-hot vector containing the target (or its prediction)

Definition at line 76 of file RBMMultitaskClassificationModule.h.

Referenced by bpropUpdate(), 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