|
PLearn 0.1
|
#include <TextStreamVMatrix.h>


Public Member Functions | |
| TextStreamVMatrix () | |
| Default constructor. | |
| virtual string | classname () const |
| virtual OptionList & | getOptionList () const |
| virtual OptionMap & | getOptionMap () const |
| virtual RemoteMethodMap & | getRemoteMethodMap () const |
| virtual TextStreamVMatrix * | 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_ () |
| 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 PPath & | declaringFile () |
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< int > | data |
| TVec< int > | target |
Definition at line 47 of file TextStreamVMatrix.h.
typedef RowBufferedVMatrix PLearn::TextStreamVMatrix::inherited [private] |
Reimplemented from PLearn::RowBufferedVMatrix.
Definition at line 49 of file TextStreamVMatrix.h.
| PLearn::TextStreamVMatrix::TextStreamVMatrix | ( | ) |
| string PLearn::TextStreamVMatrix::_classname_ | ( | ) | [static] |
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.
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.
{
inherited::build();
build_();
}
| void PLearn::TextStreamVMatrix::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::VMatrix.
Definition at line 91 of file TextStreamVMatrix.cc.
{
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);
}

| 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.
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];
}

| 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.
{
inherited::makeDeepCopyFromShallowCopy(copies);
}
Reimplemented from PLearn::RowBufferedVMatrix.
Definition at line 76 of file TextStreamVMatrix.h.
TVec<int> PLearn::TextStreamVMatrix::data [private] |
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().
int PLearn::TextStreamVMatrix::symbol_width [private] |
Definition at line 113 of file TextStreamVMatrix.h.
Definition at line 61 of file TextStreamVMatrix.h.
Referenced by declareOptions().
TVec<int> PLearn::TextStreamVMatrix::target [private] |
Definition at line 115 of file TextStreamVMatrix.h.
1.7.4