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

#include <TextStreamVMatrix.h>

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

List of all members.

Public Member Functions

 TextStreamVMatrix ()
 Default constructor.
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual TextStreamVMatrixdeepCopy (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_ ()
 RowBufferedVMatrix.
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

string data_file
int number_of_symbols
string symbols

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.

Private Types

typedef RowBufferedVMatrix inherited

Private Member Functions

void build_ ()
 This does the actual building.

Private Attributes

int symbol_width
TVec< intdata
TVec< inttarget

Detailed Description

Definition at line 47 of file TextStreamVMatrix.h.


Member Typedef Documentation

Reimplemented from PLearn::RowBufferedVMatrix.

Definition at line 49 of file TextStreamVMatrix.h.


Constructor & Destructor Documentation

PLearn::TextStreamVMatrix::TextStreamVMatrix ( )

Default constructor.

Definition at line 63 of file TextStreamVMatrix.cc.

{
}

Member Function Documentation

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

RowBufferedVMatrix.

Reimplemented from PLearn::RowBufferedVMatrix.

Definition at line 61 of file TextStreamVMatrix.cc.

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

Reimplemented from PLearn::RowBufferedVMatrix.

Definition at line 61 of file TextStreamVMatrix.cc.

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

Reimplemented from PLearn::RowBufferedVMatrix.

Definition at line 61 of file TextStreamVMatrix.cc.

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

Reimplemented from PLearn::RowBufferedVMatrix.

Definition at line 61 of file TextStreamVMatrix.cc.

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

Reimplemented from PLearn::Object.

Definition at line 61 of file TextStreamVMatrix.cc.

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

Reimplemented from PLearn::RowBufferedVMatrix.

Definition at line 61 of file TextStreamVMatrix.cc.

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

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

Reimplemented from PLearn::VMatrix.

Definition at line 146 of file TextStreamVMatrix.cc.

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

This does the actual building.

Reimplemented from PLearn::VMatrix.

Definition at line 91 of file TextStreamVMatrix.cc.

References i, and in.

{
        int ids[256];

        symbol_width = symbols.length();

        // Calculate id table
        memset(ids, -1, sizeof(ids));
        for (int i = 0; i < symbol_width; ++i)
                ids[(unsigned int)symbols[i]] = i;

        updateMtime(data_file);

        int text_length = 0;
        string text;

        // Read text from file
        // TODO: optimize
        ifstream fin(data_file.c_str(), ios::in | ios::binary);
        unsigned char chr;
        
        fin.unsetf(ios::skipws);

        while (fin >> chr) {
                if (ids[(unsigned int)chr] == -1) continue;
                text += chr;
                ++text_length;
        }

        fin.close();

        data.resize(symbol_width*text_length);
        data.fill(0);

        target.resize(text_length - number_of_symbols);

        //cout << text_length << endl;
        for (int i = 0; i < text_length; ++i) {
                //cout << symbol_width*i << endl;
                //cout << "id: " << ids[text[i]] << " " << i << endl;
                data[ symbol_width*i + ids[(unsigned int)text[i]] ] = 1;
        }

        for (int i = 0; i < text_length-number_of_symbols; ++i)
                target[i] = ids[(unsigned int)text[i + number_of_symbols]];

        length_ = text_length - number_of_symbols;
        width_ = symbol_width*number_of_symbols + 1;
        inputsize_ = symbol_width*number_of_symbols;
        targetsize_ = 1;
        weightsize_ = 0;
        extrasize_ = 0;
}
string PLearn::TextStreamVMatrix::classname ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 61 of file TextStreamVMatrix.cc.

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

Declares the class options.

Reimplemented from PLearn::VMatrix.

Definition at line 74 of file TextStreamVMatrix.cc.

References PLearn::OptionBase::buildoption, data_file, PLearn::declareOption(), number_of_symbols, and symbols.

{
     declareOption(ol, "data_file", &TextStreamVMatrix::data_file,
                   OptionBase::buildoption,
                   "File that contains data.");
     declareOption(ol, "number_of_symbols", &TextStreamVMatrix::number_of_symbols,
                   OptionBase::buildoption,
                   "Number of symbols to represent in one row (window size).");
     declareOption(ol, "symbols", &TextStreamVMatrix::symbols,
                   OptionBase::buildoption,
                   "Symbols that are represented. All symbols that are not in this string will be ignored. "
                        "Also the index of a symbol will show which bit will be set to one in the one-hot vector.");

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

Here is the call graph for this function:

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

Reimplemented from PLearn::RowBufferedVMatrix.

Definition at line 76 of file TextStreamVMatrix.h.

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

Reimplemented from PLearn::RowBufferedVMatrix.

Definition at line 61 of file TextStreamVMatrix.cc.

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

Implements PLearn::RowBufferedVMatrix.

Definition at line 68 of file TextStreamVMatrix.cc.

References i, and PLearn::TVec< T >::subVec().

{
    v.subVec(0, symbol_width*number_of_symbols) << data.subVec( i*symbol_width, symbol_width*number_of_symbols);
    v[symbol_width*number_of_symbols] = target[i];
}

Here is the call graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 61 of file TextStreamVMatrix.cc.

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

Reimplemented from PLearn::Object.

Definition at line 61 of file TextStreamVMatrix.cc.

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

Reimplemented from PLearn::Object.

Definition at line 61 of file TextStreamVMatrix.cc.

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

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::RowBufferedVMatrix.

Definition at line 152 of file TextStreamVMatrix.cc.


Member Data Documentation

Reimplemented from PLearn::RowBufferedVMatrix.

Definition at line 76 of file TextStreamVMatrix.h.

Definition at line 114 of file TextStreamVMatrix.h.

Definition at line 55 of file TextStreamVMatrix.h.

Referenced by declareOptions().

Definition at line 58 of file TextStreamVMatrix.h.

Referenced by declareOptions().

Definition at line 113 of file TextStreamVMatrix.h.

Definition at line 61 of file TextStreamVMatrix.h.

Referenced by declareOptions().

Definition at line 115 of file TextStreamVMatrix.h.


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