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

#include <ClassSubsetVMatrix.h>

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

List of all members.

Public Member Functions

 ClassSubsetVMatrix ()
 Default constructor.
 ClassSubsetVMatrix (VMat the_source, const TVec< int > &the_classes, bool call_build_=true)
 Convenience constructor.
 ClassSubsetVMatrix (VMat the_source, int the_class, bool call_build_=true)
 Convenience constructor.
virtual void build ()
 Simply calls inherited::build() then build_().
virtual real get (int i, int j) const
 These methods are implemented by buffering calls to getNewRow.
virtual void getSubRow (int i, int j, Vec v) const
 fills v with the subrow i laying between columns j (inclusive) and j+v.length() (exclusive)
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 ClassSubsetVMatrixdeepCopy (CopiesMap &copies) const

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

TVec< intclasses
 Classes of examples to keep.
bool redistribute_classes
 Indication that the class values should be redistributed between 0 and classes.length()-1, based on the order in classes.
bool one_vs_minus_one_classification
 Indication that, if classes contains 2 class indexes, than they should be mapped to -1 (the first index) and 1.

Static Public Attributes

static StaticInitializer _static_initializer_

Static Protected Member Functions

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

Private Types

typedef SelectRowsVMatrix inherited

Private Member Functions

void build_ ()
 This does the actual building.

Private Attributes

Vec input
Vec target
real weight

Detailed Description

Definition at line 52 of file ClassSubsetVMatrix.h.


Member Typedef Documentation

Reimplemented from PLearn::SelectRowsVMatrix.

Definition at line 57 of file ClassSubsetVMatrix.h.


Constructor & Destructor Documentation

PLearn::ClassSubsetVMatrix::ClassSubsetVMatrix ( )

Default constructor.

Definition at line 58 of file ClassSubsetVMatrix.cc.

PLearn::ClassSubsetVMatrix::ClassSubsetVMatrix ( VMat  the_source,
const TVec< int > &  the_classes,
bool  call_build_ = true 
)

Convenience constructor.

Note that the vector 'the_classes' is copied and thus may be modified afterwards.

Definition at line 63 of file ClassSubsetVMatrix.cc.

References build_(), and PLearn::SourceVMatrix::source.

                                                        :
    // There is no need to explicitely call the parent's constructor since
    // the whole build process will be done in build_() if necessary.
    classes(the_classes.copy()),
    redistribute_classes(false),
    one_vs_minus_one_classification(false)
{
  source = the_source;
  if (call_build_)
      build_();
}

Here is the call graph for this function:

PLearn::ClassSubsetVMatrix::ClassSubsetVMatrix ( VMat  the_source,
int  the_class,
bool  call_build_ = true 
)

Convenience constructor.

Definition at line 77 of file ClassSubsetVMatrix.cc.

References build_(), and PLearn::SourceVMatrix::source.

                                                        :
    // There is no need to explicitely call the parent's constructor since
    // the whole build process will be done in build_() if necessary.
    classes(TVec<int>(1, the_class)),
    redistribute_classes(false),
    one_vs_minus_one_classification(false)
{
    source = the_source;
    if (call_build_)
        build_();
}

Here is the call graph for this function:


Member Function Documentation

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

Declares name and deepCopy methods.

Reimplemented from PLearn::SelectRowsVMatrix.

Definition at line 53 of file ClassSubsetVMatrix.cc.

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

Reimplemented from PLearn::SelectRowsVMatrix.

Definition at line 53 of file ClassSubsetVMatrix.cc.

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

Reimplemented from PLearn::SelectRowsVMatrix.

Definition at line 53 of file ClassSubsetVMatrix.cc.

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

Reimplemented from PLearn::SelectRowsVMatrix.

Definition at line 53 of file ClassSubsetVMatrix.cc.

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

Reimplemented from PLearn::SelectRowsVMatrix.

Definition at line 53 of file ClassSubsetVMatrix.cc.

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

Reimplemented from PLearn::SelectRowsVMatrix.

Definition at line 53 of file ClassSubsetVMatrix.cc.

void PLearn::ClassSubsetVMatrix::build ( ) [virtual]

Simply calls inherited::build() then build_().

Reimplemented from PLearn::SelectRowsVMatrix.

Definition at line 119 of file ClassSubsetVMatrix.cc.

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

Here is the call graph for this function:

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

This does the actual building.

Reimplemented from PLearn::SelectRowsVMatrix.

Definition at line 128 of file ClassSubsetVMatrix.cc.

References PLearn::SelectRowsVMatrix::build(), classes, PLearn::TVec< T >::clear(), PLearn::TVec< T >::find(), PLearn::VMat::getExample(), i, PLearn::SelectRowsVMatrix::indices, input, PLearn::VMatrix::inputsize(), PLearn::TVec< T >::length(), PLearn::VMat::length(), one_vs_minus_one_classification, PLERROR, PLearn::TVec< T >::push_back(), PLearn::TVec< T >::resize(), PLearn::VMatrix::setMetaInfoFrom(), PLearn::SourceVMatrix::source, target, PLearn::VMatrix::targetsize(), and weight.

Referenced by build(), and ClassSubsetVMatrix().

{
  if (source) {
    setMetaInfoFrom(source);
    input.resize(inputsize());
    target.resize(targetsize());
    indices.clear();
    for(int i=0;i<source->length();i++)
    {
      source->getExample(i,input,target,weight);
      if(classes.find((int)target[0]) != -1)
        indices.push_back(i);
    }
    //if(indices.length() == 0)
    //  PLERROR("In ClassSubsetVMatrix::build_(): no examples kept");
    inherited::build();
    if(one_vs_minus_one_classification && classes.length()!=2)
      PLERROR("In ClassSubsetVMatrix::build_(): no examples kept");
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Reimplemented from PLearn::SelectRowsVMatrix.

Definition at line 53 of file ClassSubsetVMatrix.cc.

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

Declares this class' options.

Reimplemented from PLearn::SelectRowsVMatrix.

Definition at line 93 of file ClassSubsetVMatrix.cc.

References PLearn::OptionBase::buildoption, classes, PLearn::declareOption(), PLearn::SelectRowsVMatrix::declareOptions(), one_vs_minus_one_classification, and redistribute_classes.

{
  // ### 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. Another possible flag to be combined with
  // ### is OptionBase::nosave

  declareOption(ol, "classes", &ClassSubsetVMatrix::classes, OptionBase::buildoption,
                "Classes of examples to keep.\n");

  declareOption(ol, "redistribute_classes", &ClassSubsetVMatrix::redistribute_classes, OptionBase::buildoption,
                "Indication that the class values should be redistributed between 0 and classes.length()-1,\n"
                "based on the order of apperance in the vector classes.\n");

  declareOption(ol, "one_vs_minus_one_classification", &ClassSubsetVMatrix::one_vs_minus_one_classification, OptionBase::buildoption,
                "Indication that, if classes contains 2 class indexes,\n"
                "than they should be mapped to -1 (the first index) and 1.\n");

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

Here is the call graph for this function:

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

Reimplemented from PLearn::SelectRowsVMatrix.

Definition at line 128 of file ClassSubsetVMatrix.h.

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

Reimplemented from PLearn::SelectRowsVMatrix.

Definition at line 53 of file ClassSubsetVMatrix.cc.

real PLearn::ClassSubsetVMatrix::get ( int  i,
int  j 
) const [virtual]

These methods are implemented by buffering calls to getNewRow.

returns element (i,j)

Reimplemented from PLearn::SelectRowsVMatrix.

Definition at line 149 of file ClassSubsetVMatrix.cc.

References classes, PLearn::TVec< T >::find(), PLearn::SelectRowsVMatrix::indices, PLearn::VMatrix::inputsize(), one_vs_minus_one_classification, redistribute_classes, and PLearn::SourceVMatrix::source.

{
  if(!redistribute_classes || j != inputsize())
    return source->get(indices[i], j);
  else
  {
    if(one_vs_minus_one_classification)
      return 2*classes.find((int)source->get(indices[i], j))-1;
    else
      return classes.find((int)source->get(indices[i], j));
  }
}

Here is the call graph for this function:

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

Reimplemented from PLearn::SelectRowsVMatrix.

Definition at line 53 of file ClassSubsetVMatrix.cc.

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

Reimplemented from PLearn::SelectRowsVMatrix.

Definition at line 53 of file ClassSubsetVMatrix.cc.

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

Reimplemented from PLearn::SelectRowsVMatrix.

Definition at line 53 of file ClassSubsetVMatrix.cc.

void PLearn::ClassSubsetVMatrix::getSubRow ( int  i,
int  j,
Vec  v 
) const [virtual]

fills v with the subrow i laying between columns j (inclusive) and j+v.length() (exclusive)

Reimplemented from PLearn::SelectRowsVMatrix.

Definition at line 162 of file ClassSubsetVMatrix.cc.

References classes, PLearn::TVec< T >::find(), PLearn::VMat::getSubRow(), PLearn::SelectRowsVMatrix::indices, PLearn::VMatrix::inputsize(), j, PLearn::TVec< T >::length(), one_vs_minus_one_classification, redistribute_classes, and PLearn::SourceVMatrix::source.

{
  source->getSubRow(indices[i], j, v);
  if(redistribute_classes && j+v.length() > inputsize())
  {
    if(one_vs_minus_one_classification)
      v[inputsize()-j] = 2*classes.find((int)v[inputsize()-j])-1;
    else
      v[inputsize()-j] = classes.find((int)v[inputsize()-j]);
  }
}

Here is the call graph for this function:

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

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::SelectRowsVMatrix.

Definition at line 178 of file ClassSubsetVMatrix.cc.

References classes, PLearn::deepCopyField(), input, PLearn::SelectRowsVMatrix::makeDeepCopyFromShallowCopy(), and target.

{
  inherited::makeDeepCopyFromShallowCopy(copies);
  deepCopyField(classes,copies);
  deepCopyField(input,copies);
  deepCopyField(target,copies);
  //PLERROR("ClassSubsetVMatrix::makeDeepCopyFromShallowCopy not fully (correctly) implemented yet!");
}

Here is the call graph for this function:


Member Data Documentation

Reimplemented from PLearn::SelectRowsVMatrix.

Definition at line 128 of file ClassSubsetVMatrix.h.

Classes of examples to keep.

Definition at line 74 of file ClassSubsetVMatrix.h.

Referenced by build_(), declareOptions(), get(), getSubRow(), and makeDeepCopyFromShallowCopy().

Definition at line 59 of file ClassSubsetVMatrix.h.

Referenced by build_(), and makeDeepCopyFromShallowCopy().

Indication that, if classes contains 2 class indexes, than they should be mapped to -1 (the first index) and 1.

Definition at line 83 of file ClassSubsetVMatrix.h.

Referenced by build_(), declareOptions(), get(), and getSubRow().

Indication that the class values should be redistributed between 0 and classes.length()-1, based on the order in classes.

Definition at line 79 of file ClassSubsetVMatrix.h.

Referenced by declareOptions(), get(), and getSubRow().

Definition at line 59 of file ClassSubsetVMatrix.h.

Referenced by build_(), and makeDeepCopyFromShallowCopy().

Definition at line 60 of file ClassSubsetVMatrix.h.

Referenced by build_().


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