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

#include <MultiInstanceVMatrix.h>

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

List of all members.

Public Member Functions

 MultiInstanceVMatrix ()
virtual void build ()
 Simply calls inherited::build() then build_().
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 MultiInstanceVMatrixdeepCopy (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

int header_lines_to_skip

Static Public Attributes

static StaticInitializer _static_initializer_

Protected Member Functions

virtual void getNewRow (int i, const Vec &v) const
 This is the only method requiring implementation in subclasses.

Static Protected Member Functions

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

Protected Attributes

Mat data_
PPath filename_
vector< string > configs_
vector< pair< string, int > > names_
int source_targetsize

Private Types

typedef RowBufferedVMatrix inherited

Private Member Functions

void build_ ()
 This does the actual building.

Detailed Description

Definition at line 55 of file MultiInstanceVMatrix.h.


Member Typedef Documentation

Reimplemented from PLearn::RowBufferedVMatrix.

Definition at line 57 of file MultiInstanceVMatrix.h.


Constructor & Destructor Documentation

PLearn::MultiInstanceVMatrix::MultiInstanceVMatrix ( )

Definition at line 55 of file MultiInstanceVMatrix.cc.

    :inherited(), data_(Mat()), source_targetsize(1),
     header_lines_to_skip(0)
{
    // ### You may or may not want to call build_() to finish building the object
    //build_();
}

Member Function Documentation

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

Declares name and deepCopy methods.

Reimplemented from PLearn::RowBufferedVMatrix.

Definition at line 85 of file MultiInstanceVMatrix.cc.

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

Reimplemented from PLearn::RowBufferedVMatrix.

Definition at line 85 of file MultiInstanceVMatrix.cc.

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

Reimplemented from PLearn::RowBufferedVMatrix.

Definition at line 85 of file MultiInstanceVMatrix.cc.

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

Reimplemented from PLearn::RowBufferedVMatrix.

Definition at line 85 of file MultiInstanceVMatrix.cc.

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

Reimplemented from PLearn::Object.

Definition at line 85 of file MultiInstanceVMatrix.cc.

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

Reimplemented from PLearn::RowBufferedVMatrix.

Definition at line 85 of file MultiInstanceVMatrix.cc.

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

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

Reimplemented from PLearn::VMatrix.

Definition at line 250 of file MultiInstanceVMatrix.cc.

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

Here is the call graph for this function:

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

This does the actual building.

Reimplemented from PLearn::VMatrix.

Definition at line 117 of file MultiInstanceVMatrix.cc.

References configs_, PLearn::PStream::count(), data_, PLearn::PStream::eof(), filename_, PLearn::PStream::getline(), header_lines_to_skip, i, PLearn::VMatrix::inputsize_, PLearn::VMatrix::length_, names_, PLearn::openFile(), PLearn::pl_strtod(), PLERROR, PLearn::PStream::raw_ascii, PLearn::TMat< T >::resize(), PLearn::skipBlanksAndComments(), source_targetsize, PLearn::split(), PLearn::SumOverBagsVariable::TARGET_COLUMN_FIRST, PLearn::SumOverBagsVariable::TARGET_COLUMN_INTERMEDIATE, PLearn::SumOverBagsVariable::TARGET_COLUMN_LAST, PLearn::SumOverBagsVariable::TARGET_COLUMN_SINGLE, PLearn::VMatrix::targetsize_, PLearn::VMatrix::updateMtime(), and PLearn::VMatrix::width_.

Referenced by build().

{

    updateMtime(filename_);
    //this->setMetaDataDir(filename_ + ".metadata");

    // To be used in the end.. it is about 5 secs slower in debug
    //int nRows = countNonBlankLinesOfFile(filename_);
    
    PStream inFile = openFile(filename_, PStream::raw_ascii, "r");
//    PStream inFile = openFile(filename_, PStream::raw_ascii, "r");

    // inFile.seekg(0); TODO See if it still works without this.
    skipBlanksAndComments(inFile);

    string lastName = "";
    string newName,configNum;
    string aLine;
    string inp_element;
    int bagType;
    int nComp = 0;
        
    int i;

    real* mat_i = NULL;

    // one more column for the bag signal
    targetsize_ = source_targetsize + 1;

    // Check the number of columns
    for (i = 0; i < header_lines_to_skip; i++) {
        inFile.getline(aLine, '\n');
    }
    inFile.getline(aLine, '\n');
    vector<string> entries = split(aLine);
    int nFields = (int)entries.size();
    if (inputsize_>=0)
    {
        if ( (nFields-2) != inputsize_ + source_targetsize) // 2 for the object name and the instance number
        {
            PLERROR("Either inputsize or source_targetsize are inconsistent with the specified file!\n"
                    " Got %d+%d (inputsize+source_targetsize) = %d, and found %d! If unsure about inputsize, don't specify it or set to -1.",
                    inputsize_, source_targetsize, inputsize_+source_targetsize, nFields - 2);
        }
    } else inputsize_ = nFields-2-source_targetsize;

    int lastColumn = inputsize_ + source_targetsize;

    inFile = openFile(filename_, PStream::raw_ascii, "r");
    // inFile.seekg(0); // TODO See if it still works without this.
    skipBlanksAndComments(inFile);
    for (i = 0; i < header_lines_to_skip; i++) {
        inFile.getline(aLine, '\n');
    }
    skipBlanksAndComments(inFile);

    int nRows = inFile.count('\n');
    /* TODO Make sure it works like the old code:
       int nRows = count(istreambuf_iterator<char>(inFile),
       istreambuf_iterator<char>(), '\n');
    */

    inFile = openFile(filename_, PStream::raw_ascii, "r");
    // inFile.seekg(0); // TODO See if it still works without this.
    skipBlanksAndComments(inFile);
    for (i = 0; i < header_lines_to_skip; i++) {
        inFile.getline(aLine, '\n');
    }
    skipBlanksAndComments(inFile);

    data_.resize(nRows, inputsize_ + targetsize_);

    width_ = inputsize_ + targetsize_;
    length_ = nRows;

    for (int lineNum = 0; !inFile.eof() && lineNum < nRows; ++lineNum)
    {
        // first column: name of the compound
        inFile >> newName;
        if (newName != lastName)
        {
            lastName = newName;
            names_.push_back( make_pair(newName, lineNum) );
            bagType = SumOverBagsVariable::TARGET_COLUMN_FIRST;
            if (mat_i != NULL)
            {
                if (nComp > 1)
                    mat_i[lastColumn] = SumOverBagsVariable::TARGET_COLUMN_LAST;
                else
                    mat_i[lastColumn] = SumOverBagsVariable::TARGET_COLUMN_SINGLE;
            }
            nComp = 0;
        }
        else
        {
            bagType = SumOverBagsVariable::TARGET_COLUMN_INTERMEDIATE;
        }
        nComp++;

        // get next column: the number of the compound
        inFile >> configNum;

        configs_.push_back(configNum);

        // get the actual data columns + the target
        mat_i = data_[lineNum];
        for(int k = 0; k < inputsize_ + source_targetsize; k++)
        {
            inFile >> inp_element;
            mat_i[k] = pl_strtod(inp_element.c_str(), 0);
        }

        // close the last bag if necessary
        if (lineNum+1==nRows)
        {
            if (nComp > 1)
                mat_i[lastColumn] = SumOverBagsVariable::TARGET_COLUMN_LAST;
            else
                mat_i[lastColumn] = SumOverBagsVariable::TARGET_COLUMN_SINGLE;
        }
        else
            mat_i[lastColumn] = bagType;
    }


    //ofstream test("g:/test.txt");
    //test << data_;
    //test.close();

    this->updateMtime(filename_);
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 85 of file MultiInstanceVMatrix.cc.

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

Declare this class' options.

Reimplemented from PLearn::VMatrix.

Definition at line 92 of file MultiInstanceVMatrix.cc.

References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::VMatrix::declareOptions(), filename_, header_lines_to_skip, and source_targetsize.

{
    declareOption(ol, "source_targetsize", &MultiInstanceVMatrix::source_targetsize, OptionBase::buildoption,
                  "The source targetsize");

    declareOption(ol, "filename", &MultiInstanceVMatrix::filename_, OptionBase::buildoption,
                  "This is the name of the ascii 'mimat' format filename. It is a supervised learning dataset\n"
                  "in which each input object can come in several instances (e.g. conformations) and the target is given to the\n"
                  "whole bag of these instances, not to individual instances. The expected format is the following:\n"
                  "Each row contains:\n"
                  "  - the object name (a string without white space)\n"
                  "  - the instance number (a non-negative integer)\n"
                  "  - the inputsize features for that instance (numeric, white-separated)\n"
                  "  - the source_targetsize target values for the bag (repeated on each row).\n"
                  "If the inputsize option is not specified it is inferred from the text file.\n"
        );

    declareOption(ol, "header_lines_to_skip", &MultiInstanceVMatrix::header_lines_to_skip, OptionBase::buildoption,
                  "The number of lines to skip at the beginning of the file (they may be garbage, or \n"
                  "a header for a TextFilesVMatrix for instance).");

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

Here is the call graph for this function:

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

Reimplemented from PLearn::RowBufferedVMatrix.

Definition at line 106 of file MultiInstanceVMatrix.h.

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

Reimplemented from PLearn::RowBufferedVMatrix.

Definition at line 85 of file MultiInstanceVMatrix.cc.

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

This is the only method requiring implementation in subclasses.

Implements PLearn::RowBufferedVMatrix.

Definition at line 87 of file MultiInstanceVMatrix.cc.

References data_.

{
    v << data_(i);
}
OptionList & PLearn::MultiInstanceVMatrix::getOptionList ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 85 of file MultiInstanceVMatrix.cc.

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

Reimplemented from PLearn::Object.

Definition at line 85 of file MultiInstanceVMatrix.cc.

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

Reimplemented from PLearn::Object.

Definition at line 85 of file MultiInstanceVMatrix.cc.

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

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::RowBufferedVMatrix.

Definition at line 256 of file MultiInstanceVMatrix.cc.

References data_, PLearn::deepCopyField(), PLearn::RowBufferedVMatrix::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(data_, copies);

    // TODO: Copy also the other features

    // ### Remove this line when you have fully implemented this method.
    PLERROR("MultiInstanceVMatrix::makeDeepCopyFromShallowCopy not fully implemented yet!");
}

Here is the call graph for this function:


Member Data Documentation

Reimplemented from PLearn::RowBufferedVMatrix.

Definition at line 106 of file MultiInstanceVMatrix.h.

vector<string> PLearn::MultiInstanceVMatrix::configs_ [protected]

Definition at line 63 of file MultiInstanceVMatrix.h.

Referenced by build_().

Definition at line 61 of file MultiInstanceVMatrix.h.

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

Definition at line 62 of file MultiInstanceVMatrix.h.

Referenced by build_(), and declareOptions().

Definition at line 73 of file MultiInstanceVMatrix.h.

Referenced by build_(), and declareOptions().

vector< pair<string, int> > PLearn::MultiInstanceVMatrix::names_ [protected]

Definition at line 64 of file MultiInstanceVMatrix.h.

Referenced by build_().

Definition at line 65 of file MultiInstanceVMatrix.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