PLearn 0.1
|
Re-order samples in a source VMat by their missing attributes. More...
#include <ReorderByMissingVMatrix.h>
Public Member Functions | |
ReorderByMissingVMatrix () | |
Default constructor. | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual ReorderByMissingVMatrix * | 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_ () |
SelectRowsVMatrix. | |
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 | |
int | verbosity |
TVec< bool > | missing_pattern_change |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
Declares the class options. | |
Private Types | |
typedef SelectRowsVMatrix | inherited |
Private Member Functions | |
void | build_ () |
This does the actual building. |
Re-order samples in a source VMat by their missing attributes.
Definition at line 54 of file ReorderByMissingVMatrix.h.
typedef SelectRowsVMatrix PLearn::ReorderByMissingVMatrix::inherited [private] |
Reimplemented from PLearn::SelectRowsVMatrix.
Definition at line 56 of file ReorderByMissingVMatrix.h.
PLearn::ReorderByMissingVMatrix::ReorderByMissingVMatrix | ( | ) |
string PLearn::ReorderByMissingVMatrix::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::SelectRowsVMatrix.
Definition at line 60 of file ReorderByMissingVMatrix.cc.
OptionList & PLearn::ReorderByMissingVMatrix::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::SelectRowsVMatrix.
Definition at line 60 of file ReorderByMissingVMatrix.cc.
RemoteMethodMap & PLearn::ReorderByMissingVMatrix::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::SelectRowsVMatrix.
Definition at line 60 of file ReorderByMissingVMatrix.cc.
Reimplemented from PLearn::SelectRowsVMatrix.
Definition at line 60 of file ReorderByMissingVMatrix.cc.
Object * PLearn::ReorderByMissingVMatrix::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::SelectRowsVMatrix.
Definition at line 60 of file ReorderByMissingVMatrix.cc.
StaticInitializer ReorderByMissingVMatrix::_static_initializer_ & PLearn::ReorderByMissingVMatrix::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::SelectRowsVMatrix.
Definition at line 60 of file ReorderByMissingVMatrix.cc.
void PLearn::ReorderByMissingVMatrix::build | ( | ) | [virtual] |
Simply calls inherited::build() then build_().
Reimplemented from PLearn::SelectRowsVMatrix.
Definition at line 106 of file ReorderByMissingVMatrix.cc.
References PLearn::SelectRowsVMatrix::build(), and build_().
{ inherited::build(); build_(); }
void PLearn::ReorderByMissingVMatrix::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::SelectRowsVMatrix.
Definition at line 132 of file ReorderByMissingVMatrix.cc.
References PLearn::TVec< T >::append(), PLearn::SelectRowsVMatrix::build(), PLearn::compare_index_and_missing_flags, PLearn::endl(), i, PLearn::IndexAndMissingFlags::index, PLearn::SelectRowsVMatrix::indices, PLearn::SelectRowsVMatrix::indices_vmat, PLearn::is_missing(), j, PLearn::VMat::length(), PLearn::IndexAndMissingFlags::missing_flags, missing_pattern_change, n, PLearn::pout, PLearn::TVec< T >::resize(), PLearn::SourceVMatrix::source, PLearn::SourceVMatrix::sourcerow, PLearn::VMatrix::updateMtime(), verbosity, w, and PLearn::VMat::width().
Referenced by build().
{ updateMtime(indices_vmat); updateMtime(source); if (source) { // Construct a vector containing each sample index associated with its // missing flags. vector<IndexAndMissingFlags> vec; int n = source.length(); int w = source.width(); sourcerow.resize(w); string previous_flags; int n_flag_changes = 0; for (int i = 0; i < n; i++) { source->getRow(i, sourcerow); string missing_flags; for (int j = 0; j < w; j++) if (is_missing(sourcerow[j])) missing_flags += '0'; else missing_flags += '1'; IndexAndMissingFlags ex; ex.index = i; ex.missing_flags = missing_flags; vec.push_back(ex); if (!previous_flags.empty() && missing_flags != previous_flags) n_flag_changes++; previous_flags = missing_flags; } if (verbosity >= 1) pout << "Number of flag changes before sorting: " << n_flag_changes << endl; // Sort this vector. sort(vec.begin(), vec.end(), compare_index_and_missing_flags); // Build the 'indices' vector. indices.resize(n); indices.resize(0); vector<IndexAndMissingFlags>::const_iterator it = vec.begin(); previous_flags = ""; n_flag_changes = 0; int index = 0; missing_pattern_change.resize(int(vec.size())); for (; it != vec.end(); it++) { indices.append(it->index); const string& missing_flags = it->missing_flags; if (missing_flags != previous_flags) { if (!previous_flags.empty()) n_flag_changes++; missing_pattern_change[index++] = true; } else missing_pattern_change[index++] = false; previous_flags = missing_flags; } if (verbosity >= 1) pout << "Number of flag changes after sorting: " << n_flag_changes << endl; // Re-build the parent class according to the new 'indices' vector. inherited::build(); } }
string PLearn::ReorderByMissingVMatrix::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::SelectRowsVMatrix.
Definition at line 60 of file ReorderByMissingVMatrix.cc.
void PLearn::ReorderByMissingVMatrix::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares the class options.
Reimplemented from PLearn::SelectRowsVMatrix.
Definition at line 72 of file ReorderByMissingVMatrix.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::SelectRowsVMatrix::declareOptions(), PLearn::SelectRowsVMatrix::indices, PLearn::SelectRowsVMatrix::indices_vmat, PLearn::OptionBase::learntoption, missing_pattern_change, PLearn::OptionBase::nosave, PLearn::redeclareOption(), and verbosity.
{ // Build options. declareOption(ol, "verbosity", &ReorderByMissingVMatrix::verbosity, OptionBase::buildoption, "Control the amount of output."); // Learnt options. declareOption(ol, "missing_pattern_change", &ReorderByMissingVMatrix::missing_pattern_change, OptionBase::learntoption, "A vector whose i-th element is a boolean indicating whether the\n" "missing pattern has changed going from the (i-1)-th sample to the\n" "i-th sample (note: the first element is always true)."); // Now call the parent class' declareOptions inherited::declareOptions(ol); // Hide unused options. redeclareOption(ol, "indices", &ReorderByMissingVMatrix::indices, OptionBase::nosave, "Not used."); redeclareOption(ol, "indices_vmat", &ReorderByMissingVMatrix::indices_vmat, OptionBase::nosave, "Not used."); }
static const PPath& PLearn::ReorderByMissingVMatrix::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::SelectRowsVMatrix.
Definition at line 77 of file ReorderByMissingVMatrix.h.
:
//##### Protected Options ###############################################
ReorderByMissingVMatrix * PLearn::ReorderByMissingVMatrix::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::SelectRowsVMatrix.
Definition at line 60 of file ReorderByMissingVMatrix.cc.
OptionList & PLearn::ReorderByMissingVMatrix::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::SelectRowsVMatrix.
Definition at line 60 of file ReorderByMissingVMatrix.cc.
OptionMap & PLearn::ReorderByMissingVMatrix::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::SelectRowsVMatrix.
Definition at line 60 of file ReorderByMissingVMatrix.cc.
RemoteMethodMap & PLearn::ReorderByMissingVMatrix::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::SelectRowsVMatrix.
Definition at line 60 of file ReorderByMissingVMatrix.cc.
void PLearn::ReorderByMissingVMatrix::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::SelectRowsVMatrix.
Definition at line 196 of file ReorderByMissingVMatrix.cc.
References PLearn::deepCopyField(), PLearn::SelectRowsVMatrix::makeDeepCopyFromShallowCopy(), and missing_pattern_change.
{ inherited::makeDeepCopyFromShallowCopy(copies); deepCopyField(missing_pattern_change, copies); }
Reimplemented from PLearn::SelectRowsVMatrix.
Definition at line 77 of file ReorderByMissingVMatrix.h.
Definition at line 65 of file ReorderByMissingVMatrix.h.
Referenced by build_(), declareOptions(), makeDeepCopyFromShallowCopy(), and PLearn::GaussMix::setTrainingSet().
Definition at line 61 of file ReorderByMissingVMatrix.h.
Referenced by build_(), and declareOptions().