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
PLearn::MaxSubsamplingTest Class Reference

Tests MaxSubsampling2DModule. More...

#include <MaxSubsamplingTest.h>

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

List of all members.

Public Member Functions

 MaxSubsamplingTest ()
 Default constructor.
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual MaxSubsamplingTestdeepCopy (CopiesMap &copies) const
virtual void build ()
 Post-constructor.
virtual void makeDeepCopyFromShallowCopy (CopiesMap &copies)
 Transforms a shallow copy into a deep copy.
virtual void perform ()
 The method performing the test.

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

int batch_size
int n_input_images
int input_images_length
int input_images_width
int kernel_length
int kernel_width

Static Public Attributes

static StaticInitializer _static_initializer_

Static Protected Member Functions

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

Protected Attributes

int output_images_length
int output_images_width
int input_images_size
int output_images_size
int input_size
int output_size
PP< MaxSubsampling2DModulemax_module
PP< PRandomrandom_gen

Private Types

typedef PTest inherited

Private Member Functions

void build_ ()
 This does the actual building.

Detailed Description

Tests MaxSubsampling2DModule.

Definition at line 52 of file MaxSubsamplingTest.h.


Member Typedef Documentation

Reimplemented from PLearn::PTest.

Definition at line 54 of file MaxSubsamplingTest.h.


Constructor & Destructor Documentation

PLearn::MaxSubsamplingTest::MaxSubsamplingTest ( )

Default constructor.

Definition at line 54 of file MaxSubsamplingTest.cc.

{
}

Member Function Documentation

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

Reimplemented from PLearn::PTest.

Definition at line 49 of file MaxSubsamplingTest.cc.

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

Reimplemented from PLearn::PTest.

Definition at line 49 of file MaxSubsamplingTest.cc.

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

Reimplemented from PLearn::PTest.

Definition at line 49 of file MaxSubsamplingTest.cc.

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

Reimplemented from PLearn::PTest.

Definition at line 49 of file MaxSubsamplingTest.cc.

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

Reimplemented from PLearn::PTest.

Definition at line 49 of file MaxSubsamplingTest.cc.

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

Reimplemented from PLearn::PTest.

Definition at line 49 of file MaxSubsamplingTest.cc.

void PLearn::MaxSubsamplingTest::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::PTest.

Definition at line 61 of file MaxSubsamplingTest.cc.

void PLearn::MaxSubsamplingTest::build_ ( ) [private]
string PLearn::MaxSubsamplingTest::classname ( ) const [virtual]

Reimplemented from PLearn::PTest.

Definition at line 49 of file MaxSubsamplingTest.cc.

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

Declares the class options.

Reimplemented from PLearn::PTest.

Definition at line 81 of file MaxSubsamplingTest.cc.

References batch_size, PLearn::OptionBase::buildoption, PLearn::declareOption(), input_images_length, input_images_size, input_images_width, input_size, kernel_length, kernel_width, PLearn::OptionBase::learntoption, max_module, n_input_images, output_images_length, output_images_size, output_images_width, and output_size.

{
    declareOption(ol, "batch_size", &MaxSubsamplingTest::batch_size,
                  OptionBase::buildoption,
                  "Size of batch");

    declareOption(ol, "n_input_images", &MaxSubsamplingTest::n_input_images,
                  OptionBase::buildoption,
                  "Number of images in each input vector");

    declareOption(ol, "input_images_length",
                  &MaxSubsamplingTest::input_images_length,
                  OptionBase::buildoption,
                  "Length of input images");

    declareOption(ol, "input_images_width",
                  &MaxSubsamplingTest::input_images_width,
                  OptionBase::buildoption,
                  "Width of input images");

    declareOption(ol, "kernel_length", &MaxSubsamplingTest::kernel_length,
                  OptionBase::buildoption,
                  "Length of the subsampling zone");

    declareOption(ol, "kernel_width", &MaxSubsamplingTest::kernel_width,
                  OptionBase::buildoption,
                  "Width of the subsampling zone");

    declareOption(ol, "output_images_length",
                  &MaxSubsamplingTest::output_images_length,
                  OptionBase::learntoption,
                  "Length of output images");

    declareOption(ol, "output_images_width",
                  &MaxSubsamplingTest::output_images_width,
                  OptionBase::learntoption,
                  "Width of output images");

    declareOption(ol, "input_images_size",
                  &MaxSubsamplingTest::input_images_size,
                  OptionBase::learntoption,
                  "input_images_length*input_images_width");

    declareOption(ol, "output_images_size",
                  &MaxSubsamplingTest::output_images_size,
                  OptionBase::learntoption,
                  "output_images_length*output_images_width");

    declareOption(ol, "input_size",
                  &MaxSubsamplingTest::input_size,
                  OptionBase::learntoption,
                  "n_input_images*input_images_size");

    declareOption(ol, "output_size",
                  &MaxSubsamplingTest::output_size,
                  OptionBase::learntoption,
                  "n_input_images*output_images_size");

    declareOption(ol, "max_module", &MaxSubsamplingTest::max_module,
                  OptionBase::learntoption,
                  "The MaxSubsampling2DModule we build and test");
    /*
    declareOption(ol, "", &MaxSubsamplingTest::,
                  OptionBase::buildoption,
                  "");
    */

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

Here is the call graph for this function:

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

Reimplemented from PLearn::PTest.

Definition at line 86 of file MaxSubsamplingTest.h.

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

Reimplemented from PLearn::PTest.

Definition at line 49 of file MaxSubsamplingTest.cc.

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

Reimplemented from PLearn::PTest.

Definition at line 49 of file MaxSubsamplingTest.cc.

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

Reimplemented from PLearn::PTest.

Definition at line 49 of file MaxSubsamplingTest.cc.

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

Reimplemented from PLearn::PTest.

Definition at line 49 of file MaxSubsamplingTest.cc.

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

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::PTest.

Definition at line 70 of file MaxSubsamplingTest.cc.

References PLearn::deepCopyField().

Here is the call graph for this function:

void PLearn::MaxSubsamplingTest::perform ( ) [virtual]

The method performing the test.

A typical test consists in some output (to pout and / or perr), and updates of this object's options.

Reimplemented from PLearn::PTest.

Definition at line 188 of file MaxSubsamplingTest.cc.

References PLearn::argmax(), PLearn::endl(), i, in, PLearn::pout, and PLearn::TMat< T >::resize().

{
    Mat in_(batch_size, input_size);
    Mat out_(batch_size, output_size);
    Mat argmax_(batch_size, output_size);

    TMat<Mat> in(batch_size, n_input_images);
    TMat<Mat> out(batch_size, n_input_images);
    TMat<Mat> argmax(batch_size, n_input_images);

    for( int k=0; k<batch_size; k++ )
        for( int i=0; i<n_input_images; i++ )
        {
            in(k,i) = in_(k).subVec(i*input_images_size, input_images_size)
                .toMat(input_images_length, input_images_width);
            random_gen->fill_random_uniform(in(k,i), -1, 1);

            out(k,i) = out_(k)
                .subVec(i*output_images_size, output_images_size)
                .toMat(output_images_length, output_images_width);

            argmax(k,i) = argmax_(k)
                .subVec( i*output_images_size, output_images_size)
                .toMat(output_images_length, output_images_width);
        }

    TVec<Mat*> ports_values(3);
    ports_values[0] = &in_;
    ports_values[1] = &out_;
    ports_values[2] = &argmax_;

    out_.resize(0, output_size);
    argmax_.resize(0, output_size);
    max_module->fprop(ports_values);


    Mat out_grad_(batch_size, output_size, 1.);
    Mat in_grad_(batch_size, input_size);
    TMat<Mat> in_grad(batch_size, n_input_images);

    for( int k=0; k<batch_size; k++ )
        for( int i=0; i<n_input_images; i++ )
        {
            in_grad(k,i) = in_grad_(k)
                .subVec(i*input_images_size, input_images_size)
                .toMat(input_images_length, input_images_width);
        }

    TVec<Mat*> ports_grad(3);
    ports_grad[0] = &in_grad_;
    ports_grad[1] = &out_grad_;
    ports_grad[2] = NULL;

    in_grad_.resize(0, input_size);
    max_module->bpropAccUpdate( ports_values, ports_grad );

    for( int k=0; k<batch_size; k++ )
        for( int i=0; i<n_input_images; i++ )
        {
            pout << "in("<<k<<","<<i<<") = " << endl << in(k,i) << endl;
            pout << "out("<<k<<","<<i<<") = " << endl << out(k,i) << endl;
            pout << "argmax("<<k<<","<<i<<") = " << endl
                << argmax(k,i) << endl;
            pout << "in_grad("<<k<<","<<i<<") = " << endl
                << in_grad(k,i) << endl;
        }

}

Here is the call graph for this function:


Member Data Documentation

Reimplemented from PLearn::PTest.

Definition at line 86 of file MaxSubsamplingTest.h.

Definition at line 63 of file MaxSubsamplingTest.h.

Referenced by declareOptions().

Definition at line 65 of file MaxSubsamplingTest.h.

Referenced by declareOptions().

Definition at line 107 of file MaxSubsamplingTest.h.

Referenced by declareOptions().

Definition at line 66 of file MaxSubsamplingTest.h.

Referenced by declareOptions().

Definition at line 109 of file MaxSubsamplingTest.h.

Referenced by declareOptions().

Definition at line 67 of file MaxSubsamplingTest.h.

Referenced by declareOptions().

Definition at line 68 of file MaxSubsamplingTest.h.

Referenced by declareOptions().

Definition at line 112 of file MaxSubsamplingTest.h.

Referenced by declareOptions().

Definition at line 64 of file MaxSubsamplingTest.h.

Referenced by declareOptions().

Definition at line 105 of file MaxSubsamplingTest.h.

Referenced by declareOptions().

Definition at line 108 of file MaxSubsamplingTest.h.

Referenced by declareOptions().

Definition at line 106 of file MaxSubsamplingTest.h.

Referenced by declareOptions().

Definition at line 110 of file MaxSubsamplingTest.h.

Referenced by declareOptions().

Definition at line 113 of file MaxSubsamplingTest.h.


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