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

Splitter that separates examples of some classes (test) from the examples of other classes (train). More...

#include <ClassSeparationSplitter.h>

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

List of all members.

Public Member Functions

 ClassSeparationSplitter ()
 Default constructor.
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.
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual ClassSeparationSplitterdeepCopy (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

TVec< TVec< int > > classes
 Classes to isolate from the others.
int numsplits
 Number of splits. If <= 0, then it is set to nclasses.
int nclasses
 Number of classes. Ignored if classes if defined.
int nclasses_test_set
 Number of classes in the test sets.
bool select_classes_randomly
 Indication that the classes should be chosen at random.
bool append_train
 Indication that the training set should be appended to the split sets lists.
int32_t seed
 Seed of random generator.

Static Public Attributes

static StaticInitializer _static_initializer_

Static Protected Member Functions

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

Protected Attributes

PP< PRandomrandom_gen

Private Types

typedef Splitter inherited

Private Member Functions

void build_ ()
 This does the actual building.

Detailed Description

Splitter that separates examples of some classes (test) from the examples of other classes (train).

This splitter is intended to measure inductive transfer performance from some tasks to other tasks.

Definition at line 56 of file ClassSeparationSplitter.h.


Member Typedef Documentation

Reimplemented from PLearn::Splitter.

Definition at line 58 of file ClassSeparationSplitter.h.


Constructor & Destructor Documentation

PLearn::ClassSeparationSplitter::ClassSeparationSplitter ( )

Default constructor.

Definition at line 55 of file ClassSeparationSplitter.cc.

References random_gen.


Member Function Documentation

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

Reimplemented from PLearn::Splitter.

Definition at line 53 of file ClassSeparationSplitter.cc.

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

Reimplemented from PLearn::Splitter.

Definition at line 53 of file ClassSeparationSplitter.cc.

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

Reimplemented from PLearn::Splitter.

Definition at line 53 of file ClassSeparationSplitter.cc.

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

Reimplemented from PLearn::Splitter.

Definition at line 53 of file ClassSeparationSplitter.cc.

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

Reimplemented from PLearn::Object.

Definition at line 53 of file ClassSeparationSplitter.cc.

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

Reimplemented from PLearn::Splitter.

Definition at line 53 of file ClassSeparationSplitter.cc.

void PLearn::ClassSeparationSplitter::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 123 of file ClassSeparationSplitter.cc.

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

Here is the call graph for this function:

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

This does the actual building.

Reimplemented from PLearn::Object.

Definition at line 85 of file ClassSeparationSplitter.cc.

References classes, i, j, PLearn::TVec< T >::length(), nclasses, nclasses_test_set, numsplits, PLERROR, random_gen, PLearn::TVec< T >::resize(), seed, and select_classes_randomly.

Referenced by build().

{
    if (seed != 0)
        random_gen->manual_seed(seed);

    if(classes.length() == 0)
    {
        if(nclasses <= 0) PLERROR("In ClassSeparationSplitter::build_(): nclasses should be > 0");
        if(nclasses_test_set <= 0) PLERROR("In ClassSeparationSplitter::build_(): nclasses_test_set should be > 0");
        if(nclasses_test_set >= nclasses) PLERROR("In ClassSeparationSplitter::build_(): nclasses_test_set should be < nclasses");
        if(numsplits <= 0) numsplits = nclasses;

        classes.resize(numsplits);
        int it = 0;
        for(int i=0; i<numsplits; i++)
        {
            if(select_classes_randomly)
            {
                classes[i].resize(nclasses);
                for(int j=0; j<nclasses; j++)
                    classes[i][j] = j;
                random_gen->shuffleElements(classes[i]);
                classes.resize(nclasses_test_set);
            }
            else
            {
                classes[i].resize(nclasses_test_set);
                for(int j=0; j<nclasses_test_set; j++)
                {
                    classes[i][j] = it%nclasses;
                    it++;
                }
            }
        }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 53 of file ClassSeparationSplitter.cc.

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

Declares the class options.

Reimplemented from PLearn::Splitter.

Definition at line 61 of file ClassSeparationSplitter.cc.

References append_train, PLearn::OptionBase::buildoption, classes, PLearn::declareOption(), PLearn::Splitter::declareOptions(), nclasses, nclasses_test_set, numsplits, seed, and select_classes_randomly.

{
    declareOption(ol, "numsplits", &ClassSeparationSplitter::numsplits, OptionBase::buildoption,
                  "Number of splits. If <= 0, then it is set to nclasses.");
    declareOption(ol, "nclasses", &ClassSeparationSplitter::nclasses, OptionBase::buildoption,
                  "Number of classes.");
    declareOption(ol, "nclasses_test_set", &ClassSeparationSplitter::nclasses_test_set, OptionBase::buildoption,
                  "Number of classes in the test sets.");
    declareOption(ol, "classes", &ClassSeparationSplitter::classes, OptionBase::buildoption,
                  "Classes to isolate from the others, for each split. When this field is specified,\n"
                  "then nclasses, nclasses_test_set and nsplit are ignored.");
    declareOption(ol, "select_classes_randomly", &ClassSeparationSplitter::select_classes_randomly, OptionBase::buildoption,
                  "Indication that the classes should be chosen at random.\n"
                  "Otherwise, the classes are selected by order of their index.");
    declareOption(ol, "append_train", &ClassSeparationSplitter::append_train, OptionBase::buildoption,
                  "Indication that the training set should be appended to the split sets lists.");

    declareOption(ol, "seed", &ClassSeparationSplitter::seed, OptionBase::buildoption,
                  "Seed of random generator");

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

Here is the call graph for this function:

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

Reimplemented from PLearn::Splitter.

Definition at line 112 of file ClassSeparationSplitter.h.

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

Reimplemented from PLearn::Splitter.

Definition at line 53 of file ClassSeparationSplitter.cc.

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

Reimplemented from PLearn::Object.

Definition at line 53 of file ClassSeparationSplitter.cc.

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

Reimplemented from PLearn::Object.

Definition at line 53 of file ClassSeparationSplitter.cc.

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

Reimplemented from PLearn::Object.

Definition at line 53 of file ClassSeparationSplitter.cc.

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

Returns split number i.

Implements PLearn::Splitter.

Definition at line 149 of file ClassSeparationSplitter.cc.

References PLearn::TVec< T >::append(), append_train, classes, PLearn::Splitter::dataset, PLearn::TVec< T >::find(), i, PLearn::VMat::length(), nsplits(), PLERROR, PLearn::split(), and PLearn::VMat::width().

{

    if (k >= nsplits())
        PLERROR("ClassSeparationSplitter::getSplit() - k (%d) cannot be greater than "
                " the number of splits (%d)", k, nsplits());

    TVec<int> classes_k = classes[k];
    Vec row(dataset->width());
    TVec<int> indices(0);
    for(int i=0; i<dataset->length(); i++)
    {
        dataset->getRow(i,row);
        if(classes_k.find((int)row[dataset->inputsize()]) >= 0)
        {
            indices.push_back(i);
        }
    }

    TVec<VMat> split(2);
    split[0] = new SelectRowsVMatrix(dataset,indices, true);
    split[1] = new SelectRowsVMatrix(dataset,indices);
    if(append_train) split.append(split[0]);
    return split;
}

Here is the call graph for this function:

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

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::Splitter.

Definition at line 129 of file ClassSeparationSplitter.cc.

References classes, PLearn::deepCopyField(), PLearn::Splitter::makeDeepCopyFromShallowCopy(), and random_gen.

{
    inherited::makeDeepCopyFromShallowCopy(copies);

    deepCopyField(classes, copies);
    deepCopyField(random_gen, copies);

    //PLERROR("ClassSeparationSplitter::makeDeepCopyFromShallowCopy not fully (correctly) implemented yet!");
}

Here is the call graph for this function:

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

Returns the number of sets per split.

Implements PLearn::Splitter.

Definition at line 144 of file ClassSeparationSplitter.cc.

References append_train.

{
    return append_train ? 3 : 2;
}
int PLearn::ClassSeparationSplitter::nsplits ( ) const [virtual]

Returns the number of available different "splits".

Implements PLearn::Splitter.

Definition at line 139 of file ClassSeparationSplitter.cc.

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

Referenced by getSplit().

{
    return classes.length();
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Reimplemented from PLearn::Splitter.

Definition at line 112 of file ClassSeparationSplitter.h.

Indication that the training set should be appended to the split sets lists.

Definition at line 81 of file ClassSeparationSplitter.h.

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

Classes to isolate from the others.

Definition at line 64 of file ClassSeparationSplitter.h.

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

Number of classes. Ignored if classes if defined.

Definition at line 70 of file ClassSeparationSplitter.h.

Referenced by build_(), and declareOptions().

Number of classes in the test sets.

Definition at line 73 of file ClassSeparationSplitter.h.

Referenced by build_(), and declareOptions().

Number of splits. If <= 0, then it is set to nclasses.

Definition at line 67 of file ClassSeparationSplitter.h.

Referenced by build_(), and declareOptions().

Seed of random generator.

Definition at line 84 of file ClassSeparationSplitter.h.

Referenced by build_(), and declareOptions().

Indication that the classes should be chosen at random.

Otherwise, the classes are selected by order of their index.

Definition at line 77 of file ClassSeparationSplitter.h.

Referenced by build_(), and declareOptions().


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