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

#include <TrainValidTestSplitter.h>

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

List of all members.

Public Member Functions

 TrainValidTestSplitter ()
virtual void build ()
 Post-constructor.
virtual void makeDeepCopyFromShallowCopy (CopiesMap &copies)
 Transforms a shallow copy into a deep copy.
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual TrainValidTestSplitterdeepCopy (CopiesMap &copies) const
virtual void setDataSet (VMat the_dataset)
 Sets the dataset on which the splits are to be based (overridden because build() needs to be called).
virtual int nsplits () const
 Returns the number of available different "splits".
virtual int nSetsPerSplit () const
 Returns the number of sets per split.
virtual TVec< VMatgetSplit (int i=0)
 Returns split number i.

Static Public Member Functions

static string _classname_ ()
 Declares name and deepCopy methods.
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

bool append_train
bool append_valid
int n_splits
int n_train
int n_valid
bool shuffle_valid_and_test

Static Public Attributes

static StaticInitializer _static_initializer_

Static Protected Member Functions

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

Protected Attributes

VMat train_set
 The first n_train samples of the dataset.
TMat< intvalid_indices
 Matrix containing the indices of the validation samples.
TMat< inttest_indices
 Matrix containing the indices of the test samples.

Private Types

typedef Splitter inherited

Private Member Functions

void build_ ()
 This does the actual building.

Detailed Description

Definition at line 52 of file TrainValidTestSplitter.h.


Member Typedef Documentation

Reimplemented from PLearn::Splitter.

Definition at line 54 of file TrainValidTestSplitter.h.


Constructor & Destructor Documentation

PLearn::TrainValidTestSplitter::TrainValidTestSplitter ( )

Definition at line 55 of file TrainValidTestSplitter.cc.


Member Function Documentation

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

Declares name and deepCopy methods.

Reimplemented from PLearn::Splitter.

Definition at line 71 of file TrainValidTestSplitter.cc.

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

Reimplemented from PLearn::Splitter.

Definition at line 71 of file TrainValidTestSplitter.cc.

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

Reimplemented from PLearn::Splitter.

Definition at line 71 of file TrainValidTestSplitter.cc.

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

Reimplemented from PLearn::Splitter.

Definition at line 71 of file TrainValidTestSplitter.cc.

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

Reimplemented from PLearn::Object.

Definition at line 71 of file TrainValidTestSplitter.cc.

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

Reimplemented from PLearn::Splitter.

Definition at line 71 of file TrainValidTestSplitter.cc.

void PLearn::TrainValidTestSplitter::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::Object.

Definition at line 109 of file TrainValidTestSplitter.cc.

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

Here is the call graph for this function:

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

This does the actual building.

Reimplemented from PLearn::Object.

Definition at line 118 of file TrainValidTestSplitter.cc.

References PLearn::Splitter::dataset, i, j, PLearn::VMat::length(), n, n_splits, n_train, n_valid, PLERROR, PLearn::TMat< T >::resize(), shuffle_valid_and_test, PLearn::shuffleElements(), PLearn::sortElements(), PLearn::TVec< T >::subVec(), test_indices, train_set, valid_indices, and PLearn::VMat::width().

Referenced by build(), and setDataSet().

{
    if (dataset) {
        if (n_train < 0 || n_valid < 0) {
            PLERROR("In TrainValidTestSplitter::build_ - Please initialize correctly 'n_train' and 'n_valid'");
        }
        int n = dataset->length();
        int n_test = n - n_train - n_valid;
        // Define the train set.
        train_set = new SubVMatrix(dataset, 0, 0, n_train, dataset->width());
        // Precompute all the indices.
        valid_indices.resize(n_splits, n_valid);
        test_indices.resize(n_splits, n_test);
        TVec<int> valid_and_test_indices(n_valid + n_test);
        for (int i = 0; i < n_splits; i++) {
            for (int j = 0; j < n_valid + n_test; j++) {
                valid_and_test_indices[j] = j + n_train;
            }
            if (shuffle_valid_and_test) {
                shuffleElements(valid_and_test_indices);
            }
            valid_indices(i) << valid_and_test_indices.subVec(0, n_valid);
            test_indices(i) << valid_and_test_indices.subVec(n_valid, n_test);
            if (shuffle_valid_and_test) {
                // Now sort the indices for (hopefully) faster access.
                sortElements(valid_indices(i));
                sortElements(test_indices(i));
            }
        }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 71 of file TrainValidTestSplitter.cc.

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

Declares this class' options.

Reimplemented from PLearn::Splitter.

Definition at line 76 of file TrainValidTestSplitter.cc.

References append_train, append_valid, PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::Splitter::declareOptions(), n_splits, n_train, n_valid, and shuffle_valid_and_test.

{
    declareOption(ol, "append_train", &TrainValidTestSplitter::append_train, OptionBase::buildoption,
                  "If set to 1, the train set will be appended to each split, after the test set\n"
                  "(the train set means the first n_train samples).");

    declareOption(ol, "append_valid", &TrainValidTestSplitter::append_valid, OptionBase::buildoption,
                  "If set to 1, the validation set will be appended to each split, after the test set\n"
                  "(or the train set if append_train is also set to 1).");

    declareOption(ol, "n_splits", &TrainValidTestSplitter::n_splits, OptionBase::buildoption,
                  "The number of splits we want (a value > 1 is useful with shuffle_valid_and_test = 1).");

    declareOption(ol, "n_train", &TrainValidTestSplitter::n_train, OptionBase::buildoption,
                  "The number of samples that define the train set, assumed to be at the beginning\n"
                  "of the dataset.");

    declareOption(ol, "n_valid", &TrainValidTestSplitter::n_valid, OptionBase::buildoption,
                  "The number of samples that define the validation set (they are taken among\n"
                  "the samples after the n_train first ones).");

    declareOption(ol, "shuffle_valid_and_test", &TrainValidTestSplitter::shuffle_valid_and_test, OptionBase::buildoption,
                  "If set to 1, then the part of the dataset after the first n_train ones will\n"
                  "be shuffled before taking the validation and test sets. Note that if you want\n"
                  "to set it to 0, then using a TrainTestSplitter is probably more appropriate.");

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

Here is the call graph for this function:

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

Reimplemented from PLearn::Splitter.

Definition at line 118 of file TrainValidTestSplitter.h.

TrainValidTestSplitter * PLearn::TrainValidTestSplitter::deepCopy ( CopiesMap copies) const [virtual]

Reimplemented from PLearn::Splitter.

Definition at line 71 of file TrainValidTestSplitter.cc.

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

Reimplemented from PLearn::Object.

Definition at line 71 of file TrainValidTestSplitter.cc.

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

Reimplemented from PLearn::Object.

Definition at line 71 of file TrainValidTestSplitter.cc.

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

Reimplemented from PLearn::Object.

Definition at line 71 of file TrainValidTestSplitter.cc.

TVec< VMat > PLearn::TrainValidTestSplitter::getSplit ( int  i = 0) [virtual]

Returns split number i.

Implements PLearn::Splitter.

Definition at line 153 of file TrainValidTestSplitter.cc.

References PLearn::TVec< T >::append(), append_train, append_valid, PLearn::Splitter::dataset, test_indices, train_set, valid_indices, and PLearn::vconcat().

{
    // ### Build and return the kth split .
    TVec<VMat> result(2);
    VMat valid_set = new SelectRowsVMatrix(dataset, valid_indices(k));
    result[0] = vconcat(train_set, valid_set);
    result[1] = new SelectRowsVMatrix(dataset, test_indices(k));
    if (append_train) {
        result.append(train_set);
    }
    if (append_valid) {
        result.append(valid_set);
    }
    return result;
}

Here is the call graph for this function:

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

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::Splitter.

Definition at line 172 of file TrainValidTestSplitter.cc.

References PLearn::Splitter::makeDeepCopyFromShallowCopy(), and 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("TrainValidTestSplitter::makeDeepCopyFromShallowCopy not fully (correctly) implemented yet!");
}

Here is the call graph for this function:

int PLearn::TrainValidTestSplitter::nSetsPerSplit ( ) const [virtual]

Returns the number of sets per split.

Implements PLearn::Splitter.

Definition at line 198 of file TrainValidTestSplitter.cc.

References append_train, and append_valid.

{
    // ### Return the number of sets per split
    int result = 2;
    if (append_train) {
        result++;
    }
    if (append_valid) {
        result++;
    }
    return result;
}
int PLearn::TrainValidTestSplitter::nsplits ( ) const [virtual]

Returns the number of available different "splits".

Implements PLearn::Splitter.

Definition at line 189 of file TrainValidTestSplitter.cc.

References n_splits.

{
    // ### Return the number of available splits
    return this->n_splits;
}
void PLearn::TrainValidTestSplitter::setDataSet ( VMat  the_dataset) [virtual]

Sets the dataset on which the splits are to be based (overridden because build() needs to be called).

Reimplemented from PLearn::Splitter.

Definition at line 214 of file TrainValidTestSplitter.cc.

References build_(), and PLearn::Splitter::setDataSet().

                                                        {
    inherited::setDataSet(the_dataset);
    build_(); // To recompute the indices.
}

Here is the call graph for this function:


Member Data Documentation

Reimplemented from PLearn::Splitter.

Definition at line 118 of file TrainValidTestSplitter.h.

Definition at line 82 of file TrainValidTestSplitter.h.

Referenced by declareOptions(), getSplit(), and nSetsPerSplit().

Definition at line 83 of file TrainValidTestSplitter.h.

Referenced by declareOptions(), getSplit(), and nSetsPerSplit().

Definition at line 84 of file TrainValidTestSplitter.h.

Referenced by build_(), declareOptions(), and nsplits().

Definition at line 85 of file TrainValidTestSplitter.h.

Referenced by build_(), and declareOptions().

Definition at line 86 of file TrainValidTestSplitter.h.

Referenced by build_(), and declareOptions().

Definition at line 87 of file TrainValidTestSplitter.h.

Referenced by build_(), and declareOptions().

Matrix containing the indices of the test samples.

Definition at line 74 of file TrainValidTestSplitter.h.

Referenced by build_(), and getSplit().

The first n_train samples of the dataset.

Definition at line 68 of file TrainValidTestSplitter.h.

Referenced by build_(), and getSplit().

Matrix containing the indices of the validation samples.

Definition at line 71 of file TrainValidTestSplitter.h.

Referenced by build_(), and getSplit().


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