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

The first sentence should be a BRIEF DESCRIPTION of what the class does. More...

#include <MixUnlabeledNeighbourVMatrix.h>

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

List of all members.

Public Member Functions

 MixUnlabeledNeighbourVMatrix ()
 Default constructor.
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual
MixUnlabeledNeighbourVMatrix
deepCopy (CopiesMap &copies) const
virtual void build ()
 Simply calls inherited::build() then build_().
virtual void makeDeepCopyFromShallowCopy (CopiesMap &copies)
 Transforms a shallow copy into a deep copy.

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

long seed
 ### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //!
TVec< intindices
VMat source_select
double frac

Static Public Attributes

static StaticInitializer _static_initializer_

Protected Member Functions

virtual void getNewRow (int i, const Vec &v) const
 Fill the vector 'v' with the content of the i-th row.

Static Protected Member Functions

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

Protected Attributes

PP< PRandomrandom_generator
 Used to shuffle the related unlabeled examples.
PP< SortRowsVMatrixsorted_source_select
 The sorted source_select.
Vec row_buffer
 Used to store temporary data.
Vec neighbor_weights
 The weights for each neighbor (set equal to the weight of the original sample).

Private Types

typedef SourceVMatrix inherited

Private Member Functions

void build_ ()
 This does the actual building.

Detailed Description

The first sentence should be a BRIEF DESCRIPTION of what the class does.

Place the rest of the class programmer documentation here. Doxygen supports Javadoc-style comments. See http://www.doxygen.org/manual.html

Todo:
Write class to-do's here if there are any.
Deprecated:
Write deprecated stuff here if there is any. Indicate what else should be used instead.

Definition at line 60 of file MixUnlabeledNeighbourVMatrix.h.


Member Typedef Documentation

Reimplemented from PLearn::SourceVMatrix.

Definition at line 62 of file MixUnlabeledNeighbourVMatrix.h.


Constructor & Destructor Documentation

PLearn::MixUnlabeledNeighbourVMatrix::MixUnlabeledNeighbourVMatrix ( )

Default constructor.

Definition at line 60 of file MixUnlabeledNeighbourVMatrix.cc.

                                                           :
/* ### Initialize all fields to their default value */
    seed(-1),
    frac(1),
    random_generator(new PRandom())
{
    // ...
    // ### You may (or not) want to call build_() to finish building the object
    // ### (doing so assumes the parent classes' build_() have been called too
    // ### in the parent classes' constructors, something that you must ensure)
}

Member Function Documentation

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

Declares name and deepCopy methods.

Reimplemented from PLearn::SourceVMatrix.

Definition at line 55 of file MixUnlabeledNeighbourVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 55 of file MixUnlabeledNeighbourVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 55 of file MixUnlabeledNeighbourVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 55 of file MixUnlabeledNeighbourVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 55 of file MixUnlabeledNeighbourVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 55 of file MixUnlabeledNeighbourVMatrix.cc.

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

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 94 of file MixUnlabeledNeighbourVMatrix.cc.

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

{
    // ### Nothing to add here, simply calls build_
    inherited::build();
    build_();
}

Here is the call graph for this function:

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

This does the actual building.

Reimplemented from PLearn::SourceVMatrix.

Definition at line 104 of file MixUnlabeledNeighbourVMatrix.cc.

References PLearn::TVec< T >::append(), PLearn::VMatrix::declareFieldNames(), frac, PLearn::VMat::getExample(), i, indices, PLearn::VMatrix::inputsize(), PLearn::VMatrix::inputsize_, PLearn::TVec< T >::lastElement(), PLearn::TVec< T >::length(), PLearn::VMat::length(), PLearn::VMatrix::length(), PLearn::VMatrix::length_, neighbor_weights, PLASSERT, PLERROR, PLearn::TVec< T >::push_back(), random_generator, PLearn::TVec< T >::remove(), PLearn::TVec< T >::resize(), seed, PLearn::SourceVMatrix::setMetaInfoFromSource(), sorted_source_select, PLearn::SourceVMatrix::source, source_select, PLearn::VMatrix::targetsize(), PLearn::VMatrix::targetsize_, PLearn::VMatrix::updateMtime(), PLearn::VMatrix::weightsize_, PLearn::VMat::width(), and PLearn::VMatrix::width_.

Referenced by build().

{
    // ### This method should do the real building of the object,
    // ### according to set 'options', in *any* situation.
    // ### Typical situations include:
    // ###  - Initial building of an object from a few user-specified options
    // ###  - Building of a "reloaded" object: i.e. from the complete set of all serialised options.
    // ###  - Updating or "re-building" of an object after a few "tuning" options have been modified.
    // ### You should assume that the parent class' build_() has already been called.

    random_generator->manual_seed(seed);

    if (!source)
        return;

    if (source && ( source->targetsize() < 1))
        PLERROR("In MixUnlabeledNeighbourVMatrix::build_ - We need a key column for 'source'");
    if (source_select && (source_select->targetsize() < 1))
        PLERROR("In MixUnlabeledNeighbourVMatrix::build_ - We need a key column for 'source_select'");
    if (source_select && source && source_select->inputsize() != source->inputsize())
        PLERROR("In MixUnlabeledNeighbourVMatrix::build_ - VMats 'source_select'"
                "and 'source' should have the same inputsize().");

    indices.resize(0); // This get rid of the user's build option value.
    TVec<int> bag_indices;
    Vec input,target,targetSel;
    string lastKey;
    real weight;
    bool sourceFound;
    int rowSel,row;
    int keyCol = source->inputsize() + source->targetsize()-1;
    neighbor_weights.resize(0);

    if (source_select){ // If it was given, find the related example
        int keyCol_select = source_select->inputsize() + source_select->targetsize()-1;
        sorted_source_select = new SortRowsVMatrix();
        sorted_source_select->source = source_select;
        sorted_source_select->sort_columns = TVec<int>(1,keyCol_select);
        sorted_source_select->build();
        sorted_source_select->getExample(0,input,targetSel,weight);
        lastKey = sorted_source_select->getValString(keyCol_select,targetSel.lastElement());
        rowSel = 0;
        bag_indices.resize(0);
        while(rowSel < sorted_source_select->length()){
            sorted_source_select->getExample(rowSel,input,targetSel,weight);
            if (lastKey == sorted_source_select->getValString(keyCol_select,
                                                       targetSel.lastElement())){
                bag_indices.push_back(rowSel);
            }else{
                sourceFound = (lastKey == "all");
                for(row=0; row < source->length() && !sourceFound; row++){
                    source->getExample(row,input,target,weight);
                    if(lastKey == source->getValString(keyCol,target.lastElement())) sourceFound=true;
                }
                if (sourceFound){
                    random_generator->shuffleElements(bag_indices);
                    int n_kept = int(round(frac*bag_indices.length()));
                    for(int i=0; i < n_kept; i++) {
                        if (source->weightsize() > 0) {
                            PLASSERT( source->weightsize() == 1 );
                            neighbor_weights.append(weight); // normally still pointing to the correct weight
                        }
                        indices.push_back(bag_indices[i]);
                    }
                }
                bag_indices.resize(0);
                lastKey = sorted_source_select->getValString(keyCol_select,targetSel.lastElement());
                bag_indices.push_back(rowSel);
            }
            rowSel++;
            if (rowSel == sorted_source_select->length()){
                sourceFound = (lastKey == "all");
                for(row=0; row < source->length() && !sourceFound; row++){
                    source->getExample(row,input,target,weight);
                    if(lastKey == source->getValString(keyCol,target.lastElement())) sourceFound=true;
                }
                if (sourceFound){
                    random_generator->shuffleElements(bag_indices);
                    int n_kept = int(round(frac*bag_indices.length()));
                    for(int i=0; i < n_kept; i++) {
                        if (source->weightsize() > 0) {
                            PLASSERT( source->weightsize() == 1 );
                            neighbor_weights.append(weight); // normally still pointing to the correct weight
                        }
                        indices.push_back(bag_indices[i]);
                    }
                }
            }
        }
        updateMtime(source_select);
    }
    // ?? Modify the width, length, (targetsize, inputsize and weight) size attribute.
    inputsize_ = source->inputsize();
    targetsize_ = source->targetsize()-1;
    weightsize_ = source->weightsize();
    width_ = source->width()-1;

    if(source_select) {
        length_ = source->length() + indices.length();
    }else{
        length_ = source->length();
    }

    TVec<string>tempofn = source->fieldNames();
    tempofn.remove(inputsize()+targetsize());
    declareFieldNames(tempofn);
    // ### In a SourceVMatrix, you will typically end build_() with:
    setMetaInfoFromSource();
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 55 of file MixUnlabeledNeighbourVMatrix.cc.

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

Declares the class options.

Reimplemented from PLearn::SourceVMatrix.

Definition at line 75 of file MixUnlabeledNeighbourVMatrix.cc.

References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::SourceVMatrix::declareOptions(), frac, seed, and source_select.

{
    // ### 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, "seed", &MixUnlabeledNeighbourVMatrix::seed, OptionBase::buildoption, "Random generator seed (>0) (exceptions : -1 = initialized from clock, 0 = no initialization).");
    declareOption(ol, "source_select", &MixUnlabeledNeighbourVMatrix::source_select, OptionBase::buildoption, "The VMat containing the related examples.");
    declareOption(ol, "frac", &MixUnlabeledNeighbourVMatrix::frac, OptionBase::buildoption, "Fraction of the bag of related examples to be randomly chosen");

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

Here is the call graph for this function:

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 89 of file MixUnlabeledNeighbourVMatrix.h.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 55 of file MixUnlabeledNeighbourVMatrix.cc.

void PLearn::MixUnlabeledNeighbourVMatrix::getNewRow ( int  i,
const Vec v 
) const [protected, virtual]

Fill the vector 'v' with the content of the i-th row.

v is assumed to be the right size. ### This function must be overridden in your class

Reimplemented from PLearn::SourceVMatrix.

Definition at line 217 of file MixUnlabeledNeighbourVMatrix.cc.

References indices, PLearn::VMatrix::inputsize(), PLearn::TVec< T >::isEmpty(), j, PLearn::VMatrix::length(), PLearn::TVec< T >::length(), PLearn::VMat::length(), MISSING_VALUE, neighbor_weights, PLearn::TVec< T >::resize(), row_buffer, sorted_source_select, PLearn::SourceVMatrix::source, PLearn::TVec< T >::subVec(), PLearn::VMatrix::targetsize(), PLearn::VMat::width(), and PLearn::VMatrix::width().

{
    if (i < source->length()) {
        row_buffer.resize(source->width());
        source->getRow(i, row_buffer);
        int rest_size = width() - inputsize() - targetsize();
        int input_target_size = inputsize() + targetsize();
        v.subVec(0, input_target_size)
            << row_buffer.subVec(0, input_target_size);
        v.subVec(input_target_size, rest_size)
            << row_buffer.subVec(input_target_size + 1, rest_size);
    } else {
        sorted_source_select->getSubRow(indices[i - source->length()],0,
                                 v.subVec(0,inputsize()));
        for (int j=inputsize(); j < inputsize() + targetsize(); j++)
            v[j]=MISSING_VALUE;
        if (!neighbor_weights.isEmpty())
            v[v.length() - 1] = neighbor_weights[i - source->length()];
    }
}

Here is the call graph for this function:

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 55 of file MixUnlabeledNeighbourVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 55 of file MixUnlabeledNeighbourVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 55 of file MixUnlabeledNeighbourVMatrix.cc.

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

Member Data Documentation

Reimplemented from PLearn::SourceVMatrix.

Definition at line 89 of file MixUnlabeledNeighbourVMatrix.h.

Definition at line 73 of file MixUnlabeledNeighbourVMatrix.h.

Referenced by build_(), and declareOptions().

Definition at line 71 of file MixUnlabeledNeighbourVMatrix.h.

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

The weights for each neighbor (set equal to the weight of the original sample).

Definition at line 112 of file MixUnlabeledNeighbourVMatrix.h.

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

Used to shuffle the related unlabeled examples.

Definition at line 103 of file MixUnlabeledNeighbourVMatrix.h.

Referenced by build_(), and makeDeepCopyFromShallowCopy().

Used to store temporary data.

Definition at line 108 of file MixUnlabeledNeighbourVMatrix.h.

Referenced by getNewRow(), and makeDeepCopyFromShallowCopy().

### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //!

Definition at line 70 of file MixUnlabeledNeighbourVMatrix.h.

Referenced by build_(), and declareOptions().

The sorted source_select.

Definition at line 106 of file MixUnlabeledNeighbourVMatrix.h.

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


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