PLearn 0.1
|
#include <ConcatRowsVMatrix.h>
Public Member Functions | |
ConcatRowsVMatrix (TVec< VMat > the_sources=TVec< VMat >()) | |
The fields names are copied from the FIRST VMat, unless the 'only_common_fields' option is set to 'true'. | |
ConcatRowsVMatrix (VMat d1, VMat d2, bool fully_check_mappings=false) | |
virtual real | get (int i, int j) const |
This method must be implemented in all subclasses. | |
virtual void | getSubRow (int i, int j, Vec v) const |
It is suggested that this method be implemented in subclasses to speed up accesses (default version repeatedly calls get(i,j) which may have a significant overhead). | |
virtual void | reset_dimensions () |
In case the dimensions of an underlying VMat has changed, recompute it. | |
virtual real | dot (int i1, int i2, int inputsize) const |
Returns the dot product between row i1 and row i2 (considering only the inputsize first elements). | |
virtual real | dot (int i, const Vec &v) const |
Returns the result of the dot product between row i and the given vec (only v.length() first elements of row i are considered). | |
virtual void | putMat (int i, int j, Mat m) |
Copies matrix m at position i,j of this VMat. | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual ConcatRowsVMatrix * | 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_ () |
ConcatRowsVMatrix. | |
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 | |
bool | fill_missing |
bool | fully_check_mappings |
bool | only_common_fields |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Protected Member Functions | |
void | getpositions (int i, int &whichvm, int &rowofvm) const |
Return the index of the correct VMat in the sources and the row number in this VMat that correspond to row i in the ConcatRowsVMat. | |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
Declare this class' options. | |
Protected Attributes | |
TVec< VMat > | sources |
The (original) VMats to concatenate. | |
TVec< VMat > | to_concat |
A vector containing the final VMats to concatenate. | |
bool | need_fix_mappings |
Will be set to 'true' iff two VMats concatenated have not the same mapping for a given string. | |
TMat< map< real, real > > | fixed_mappings |
This is a matrix of size (number of matrices to concatenate, number of columns). | |
Private Types | |
typedef VMatrix | inherited |
Private Member Functions | |
void | build_ () |
This does the actual building. | |
void | ensureMappingsConsistency () |
Build the string <-> real mappings so that they are consistent with the different mappings from the concatenated VMats (the same string must be mapped to the same value). | |
void | fullyCheckMappings (bool report_progress=true) |
Browse through all data in the VMats to make sure there is no numerical value conflicting with a string mapping. | |
void | findAllFields () |
Selects all the fields that appear in any of the concatenated VMat. | |
void | findCommonFields () |
Selects the fields common to all VMats to concatenate (called at build time if 'only_common_fields' is true). | |
void | recomputeDimensions () |
Recompute length and width (same as reset_dimensions(), except it does not forward to the underlying VMats). | |
void | getPositionsAux (int i, int &whichvm, int &rowofvm) const |
Used in the implementation of getpositions (out-of-line version) | |
Private Attributes | |
int | m_last_vmat_index |
Cache of the index of the last-recently used VMat; -1 if invalid. | |
int | m_last_vmat_startrow |
Cache of the starting row in the ConcatRowsVMatrix corresponding to to the first row of m_last_vmat_index; -1 if invalid. | |
int | m_last_vmat_lastrow |
Cache of the last row (inclusive) in the ConcatRowsVMatrix corresponding to m_last_vmat_index; -1 if invalid. |
Definition at line 52 of file ConcatRowsVMatrix.h.
typedef VMatrix PLearn::ConcatRowsVMatrix::inherited [private] |
Reimplemented from PLearn::VMatrix.
Definition at line 54 of file ConcatRowsVMatrix.h.
The fields names are copied from the FIRST VMat, unless the 'only_common_fields' option is set to 'true'.
Definition at line 63 of file ConcatRowsVMatrix.cc.
References build_(), PLearn::TVec< T >::size(), and sources.
: sources(the_sources), fill_missing(false), fully_check_mappings(false), only_common_fields(false), m_last_vmat_index(-1), m_last_vmat_startrow(-1), m_last_vmat_lastrow(-1) { if (sources.size() > 0) build_(); }
PLearn::ConcatRowsVMatrix::ConcatRowsVMatrix | ( | VMat | d1, |
VMat | d2, | ||
bool | fully_check_mappings = false |
||
) |
Definition at line 76 of file ConcatRowsVMatrix.cc.
References build_(), and sources.
: sources(2), fill_missing(false), fully_check_mappings(the_fully_check_mapping), only_common_fields(false), m_last_vmat_index(-1), m_last_vmat_startrow(-1), m_last_vmat_lastrow(-1) { sources[0] = d1; sources[1] = d2; build_(); }
string PLearn::ConcatRowsVMatrix::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::VMatrix.
Definition at line 57 of file ConcatRowsVMatrix.cc.
OptionList & PLearn::ConcatRowsVMatrix::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::VMatrix.
Definition at line 57 of file ConcatRowsVMatrix.cc.
RemoteMethodMap & PLearn::ConcatRowsVMatrix::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::VMatrix.
Definition at line 57 of file ConcatRowsVMatrix.cc.
Reimplemented from PLearn::VMatrix.
Definition at line 57 of file ConcatRowsVMatrix.cc.
Object * PLearn::ConcatRowsVMatrix::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 57 of file ConcatRowsVMatrix.cc.
StaticInitializer ConcatRowsVMatrix::_static_initializer_ & PLearn::ConcatRowsVMatrix::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::VMatrix.
Definition at line 57 of file ConcatRowsVMatrix.cc.
void PLearn::ConcatRowsVMatrix::build | ( | ) | [virtual] |
Simply calls inherited::build() then build_().
Reimplemented from PLearn::VMatrix.
Definition at line 132 of file ConcatRowsVMatrix.cc.
References PLearn::VMatrix::build(), and build_().
{ inherited::build(); build_(); }
void PLearn::ConcatRowsVMatrix::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::VMatrix.
Definition at line 141 of file ConcatRowsVMatrix.cc.
References PLearn::VMatrix::computeMissingSizeValue(), ensureMappingsConsistency(), PLearn::VMatrix::extrasize_, PLearn::VMatrix::fieldinfos, fill_missing, findAllFields(), findCommonFields(), fully_check_mappings, fullyCheckMappings(), i, PLearn::VMatrix::inputsize_, m_last_vmat_index, m_last_vmat_lastrow, m_last_vmat_startrow, n, need_fix_mappings, only_common_fields, PLERROR, PLWARNING, recomputeDimensions(), PLearn::TVec< T >::size(), sources, PLearn::VMatrix::targetsize_, to_concat, PLearn::VMatrix::updateMtime(), and PLearn::VMatrix::weightsize_.
Referenced by build(), and ConcatRowsVMatrix().
{ int n = sources.size(); if (n < 1) // No sources provided yet: nothing to do. return; for(int i=0;i<sources.size();i++) updateMtime(sources[i]); if (only_common_fields && fill_missing) PLERROR("In ConcatRowsVMatrix::build_ - You can't set both 'only_common_fields' and 'fill_missing'"); // Get the fields info. fieldinfos = sources[0]->getFieldInfos(); if (only_common_fields) { findCommonFields(); } else if (fill_missing) { findAllFields(); } else { to_concat = sources; } // Set length_ and width_. recomputeDimensions(); // Note that the 4 lines below will overwrite any provided sizes. if(inputsize_<0 && targetsize_<0 && weightsize_<0){ inputsize_ = to_concat[0]->inputsize(); targetsize_ = to_concat[0]->targetsize(); weightsize_ = to_concat[0]->weightsize(); extrasize_ = to_concat[0]->extrasize(); if(fieldinfos.size()!=to_concat[0].width()) PLERROR("In ConcatRowsVMatrix::build_() - We override " "inputsize, targetsize and weightsize with the value" " of sources[0] and this cause inconsistency"); } computeMissingSizeValue(); // Make sure mappings are correct. ensureMappingsConsistency(); if (fully_check_mappings) fullyCheckMappings(); if (need_fix_mappings && !fully_check_mappings) PLWARNING("In ConcatRowsVMatrix::build_ - Mappings need to be fixed, but you did not set 'fully_check_mappings' to true, this might be dangerous"); // Reset last-used cache for completeness m_last_vmat_index = m_last_vmat_startrow = m_last_vmat_lastrow = -1; }
string PLearn::ConcatRowsVMatrix::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 57 of file ConcatRowsVMatrix.cc.
void PLearn::ConcatRowsVMatrix::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declare this class' options.
Reimplemented from PLearn::VMatrix.
Definition at line 94 of file ConcatRowsVMatrix.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::VMatrix::declareOptions(), fill_missing, fully_check_mappings, PLearn::OptionBase::learntoption, PLearn::OptionBase::nosave, only_common_fields, and sources.
{ declareOption(ol, "array", &ConcatRowsVMatrix::sources, (OptionBase::learntoption | OptionBase::nosave), "DEPRECATED - Use 'sources' instead."); declareOption(ol, "sources", &ConcatRowsVMatrix::sources, OptionBase::buildoption, "The VMat to concatenate (horizontally)."); declareOption(ol, "fill_missing", &ConcatRowsVMatrix::fill_missing, OptionBase::buildoption, "If set to 1, then all fields will be kept, and in each VMat" " missing fields\n" "will be filled with missing values.\n"); declareOption(ol, "fully_check_mappings", &ConcatRowsVMatrix::fully_check_mappings, OptionBase::buildoption, "If set to 1, then columns for which there is a string <->" " real mapping\n" "will be examined to ensure that no numerical data in a VMat" " conflicts with\n" "a mapping in another VMat.\n"); declareOption(ol, "only_common_fields", &ConcatRowsVMatrix::only_common_fields, OptionBase::buildoption, "If set to 1, then only the fields whose names are common to" " all VMat\n" "in 'sources' will be kept (and reordered if needed).\n"); inherited::declareOptions(ol); }
static const PPath& PLearn::ConcatRowsVMatrix::declaringFile | ( | ) | [inline, static] |
ConcatRowsVMatrix * PLearn::ConcatRowsVMatrix::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::VMatrix.
Definition at line 57 of file ConcatRowsVMatrix.cc.
Returns the result of the dot product between row i and the given vec (only v.length() first elements of row i are considered).
Reimplemented from PLearn::VMatrix.
Definition at line 204 of file ConcatRowsVMatrix.cc.
References dot(), getpositions(), need_fix_mappings, and to_concat.
{ if (!need_fix_mappings) { int whichvm, rowofvm; getpositions(i,whichvm,rowofvm); return to_concat[whichvm]->dot(rowofvm,v); } else return VMatrix::dot(i, v); }
Returns the dot product between row i1 and row i2 (considering only the inputsize first elements).
The default version in VMatrix is somewhat inefficient, as it repeatedly calls get(i,j) The default version in RowBufferedVMatrix is a little better as it buffers the 2 Vecs between calls in case one of them is needed again. But the real strength of this method is for specialised and efficient versions in subbclasses. This method is typically used by SmartKernels so that they can compute kernel values between input samples efficiently.
Reimplemented from PLearn::VMatrix.
Definition at line 192 of file ConcatRowsVMatrix.cc.
References getpositions(), need_fix_mappings, and to_concat.
Referenced by dot().
{ int whichvm1, rowofvm1; getpositions(i1,whichvm1,rowofvm1); int whichvm2, rowofvm2; getpositions(i2,whichvm2,rowofvm2); if(whichvm1==whichvm2 && !need_fix_mappings) return to_concat[whichvm1]->dot(rowofvm1, rowofvm2, inputsize); else return VMatrix::dot(i1,i2,inputsize); }
void PLearn::ConcatRowsVMatrix::ensureMappingsConsistency | ( | ) | [private] |
Build the string <-> real mappings so that they are consistent with the different mappings from the concatenated VMats (the same string must be mapped to the same value).
Definition at line 218 of file ConcatRowsVMatrix.cc.
References PLearn::VMatrix::addStringMapping(), PLearn::VMatrix::copyStringMappingsFrom(), PLearn::fast_exact_is_equal(), PLearn::TVec< T >::find(), fixed_mappings, PLearn::VMatrix::getValString(), i, j, PLearn::TVec< T >::length(), PLearn::VMatrix::map_sr, PLearn::max(), need_fix_mappings, PLearn::TMat< T >::resize(), to_concat, and PLearn::VMatrix::width().
Referenced by build_().
{ // Make sure the string mappings are consistent. // For this, we start from the mappings of the first VMat, and add missing // mappings obtained from the other VMats. If another VMat has a different // mapping for the same string, we remember it in order to fix the output // when a getxxxx() method is called. need_fix_mappings = false; copyStringMappingsFrom(to_concat[0]); map<string, real> other_map; map<string, real>* cur_map; map<string, real>::iterator it, find_map, jt; bool report_progress = false; // Turn it on for debugging. PP<ProgressBar> pb; if (report_progress) pb = new ProgressBar("Checking mappings consistency", width()); for (int j = 0; j < width(); j++) { cur_map = &map_sr[j]; // Find the maximum mapping value for this column. real max = -REAL_MAX; for (jt = cur_map->begin(); jt != cur_map->end(); jt++) if (jt->second > max) max = jt->second; for (int i = 1; i < to_concat.length(); i++) { other_map = to_concat[i]->getStringToRealMapping(j); for(it = other_map.begin(); it != other_map.end(); it++) { find_map = cur_map->find(it->first); if (find_map != cur_map->end()) { // The string mapped in VMat 'i' is also mapped in our current mapping. if (!fast_exact_is_equal(find_map->second, it->second)) { // But the same string is not mapped to the same value. // This needs to be fixed. /*cout << find_map->first << endl; cout << find_map->second << endl;*/ need_fix_mappings = true; fixed_mappings.resize(to_concat.length(), width()); fixed_mappings(i, j)[it->second] = find_map->second; } } else { // The string mapped in VMat 'i' is not mapped in our current mapping. // We need to add this mapping. But we must make sure there is no // existing mapping to the same real number. real new_map_val = it->second; if (getValString(j, it->second) != "") { // There is already a mapping to this real number. need_fix_mappings = true; fixed_mappings.resize(to_concat.length(), width()); // We pick for the number the maximum of the current mapped numbers, +1. max++; fixed_mappings(i, j)[it->second] = max; new_map_val = max; } else { // There is no mapping to this real number, it is thus ok to add it. if (new_map_val > max) max = new_map_val; } addStringMapping(j, it->first, new_map_val); } } } if (report_progress) pb->update(j + 1); } }
void PLearn::ConcatRowsVMatrix::findAllFields | ( | ) | [private] |
Selects all the fields that appear in any of the concatenated VMat.
Definition at line 286 of file ConcatRowsVMatrix.cc.
References PLearn::TVec< T >::append(), PLearn::VMatrix::fieldinfos, PLearn::VMatrix::getFieldInfos(), i, j, PLearn::TVec< T >::length(), PLearn::TVec< T >::resize(), sources, and to_concat.
Referenced by build_().
{ // At this point, fieldinfos already contains the fields of the first // concatenated VMat. bool report_progress = true; TVec<VMField> other_fields; PP<ProgressBar> pb; int count; if (report_progress) { count = 0; for (int i = 1; i < sources.length(); i++) count += sources[i]->getFieldInfos().length(); pb = new ProgressBar("Computing the whole set of fields", count); } count = 0; for (int i = 1; i < sources.length(); i++) { other_fields = sources[i]->getFieldInfos(); for (int j = 0; j < other_fields.length(); j++) { bool present_already = false; for (int k = 0; !present_already && k < fieldinfos.length(); k++) if (fieldinfos[k].name == other_fields[j].name) present_already = true; if (!present_already) { // We need to add this field. fieldinfos.append(other_fields[j]); } if (report_progress) pb->update(++count); } } // Create the vector of field names. TVec<string> fnames(fieldinfos.length()); for (int i = 0; i < fieldinfos.length(); i++) fnames[i] = fieldinfos[i].name; // Now fill 'to_concat' with the corresponding VMats. to_concat.resize(sources.length()); for (int i = 0; i < sources.length(); i++) { TVec<string> source_fnames=sources[i]->fieldNames(); if(fnames!=source_fnames){ to_concat[i] = new SelectColumnsVMatrix(sources[i], fnames, true); } else to_concat[i] = sources[i]; } }
void PLearn::ConcatRowsVMatrix::findCommonFields | ( | ) | [private] |
Selects the fields common to all VMats to concatenate (called at build time if 'only_common_fields' is true).
Definition at line 335 of file ConcatRowsVMatrix.cc.
References PLearn::VMatrix::fieldinfos, i, j, PLearn::TVec< T >::length(), PLearn::TVec< T >::resize(), sources, and to_concat.
Referenced by build_().
{ // Find out which fields need to be kept. TVec<VMField> final_fields(fieldinfos.length()); final_fields << fieldinfos; TVec<VMField> other_fields; TVec<VMField> tmp(final_fields.length()); for (int i = 1; i < sources.length(); i++) { map<string, bool> can_be_kept; other_fields = sources[i]->getFieldInfos(); for (int j = 0; j < other_fields.length(); j++) { can_be_kept[other_fields[j].name] = true; } tmp.resize(0); for (int j = 0; j < final_fields.length(); j++) if (can_be_kept.count(final_fields[j].name) > 0) tmp.append(final_fields[j]); final_fields.resize(tmp.length()); final_fields << tmp; } fieldinfos.resize(final_fields.length()); fieldinfos << final_fields; // Get the corresponding field names. TVec<string> final_fieldnames(final_fields.length()); for (int i = 0; i < final_fields.length(); i++) final_fieldnames[i] = final_fields[i].name; // Now fill 'to_concat' with the selected columns of each VMat in 'sources' to_concat.resize(sources.length()); for (int i = 0; i < sources.length(); i++) to_concat[i] = new SelectColumnsVMatrix(sources[i], final_fieldnames); }
void PLearn::ConcatRowsVMatrix::fullyCheckMappings | ( | bool | report_progress = true | ) | [private] |
Browse through all data in the VMats to make sure there is no numerical value conflicting with a string mapping.
An error occurs if it is the case.
Definition at line 370 of file ConcatRowsVMatrix.cc.
References PLearn::TVec< T >::end(), PLearn::VMatrix::find(), PLearn::VMatrix::getFieldInfos(), PLearn::VMatrix::getValString(), i, PLearn::is_missing(), j, PLearn::VMatrix::length(), PLearn::TVec< T >::length(), PLearn::VMatrix::map_rs, PLearn::VMatrix::map_sr, PLearn::max(), PLERROR, PLearn::TVec< T >::size(), to_concat, and PLearn::VMatrix::width().
Referenced by build_().
{ Vec row(width()); TVec<int> max(width()); PP<ProgressBar> pb; if (report_progress) pb = new ProgressBar("Full check of string mappings", length()); int count = 0; for (int i = 0; i < to_concat.length(); i++) { for (int j = 0; j < to_concat[i]->length(); j++) { to_concat[i]->getRow(j, row); for (int k = 0; k < width(); k++) { if (!is_missing(row[k]) && map_sr[k].size() > 0) { // There is a string mapping for this column. // Note that if the value is missing, we should not look for a mapping // from this value, because it would find it even if it does not exist // (see the STL map documentation to understand why this happens). if (to_concat[i]->getValString(k, row[k]) == "") { // But it is a numerical value for the i-th VMat. if (map_rs[k].find(row[k]) != map_rs[k].end()) { // And, unfortunately, we have used this numerical value in // the column string mapping. It could be fixed, but // this would be pretty annoying, thus we just raise an error. PLERROR("In ConcatRowsVMatrix::fullyCheckMappings - In column %s of concatenated VMat number %d, the row %d (%s) contains a numerical value (%f) that is used in a string mapping (mapped to %s)", getFieldInfos(k).name.c_str(), i, j, to_concat[i]->fieldName(j).c_str(), row[k], map_rs[k][row[k]].c_str()); } } } } if (report_progress) pb->update(++count); } } }
This method must be implemented in all subclasses.
Returns element (i,j).
Implements PLearn::VMatrix.
Definition at line 407 of file ConcatRowsVMatrix.cc.
References fixed_mappings, getpositions(), PLearn::is_missing(), need_fix_mappings, and to_concat.
{ int whichvm, rowofvm; getpositions(i,whichvm,rowofvm); if (!need_fix_mappings || fixed_mappings(whichvm, j).size() == 0) return to_concat[whichvm]->get(rowofvm,j); else { real val = to_concat[whichvm]->get(rowofvm,j); if (!is_missing(val)) { map<real, real>::iterator it = fixed_mappings(whichvm, j).find(val); if (it != fixed_mappings(whichvm, j).end()) { // We need to modify this value. return it->second; } } return val; } }
OptionList & PLearn::ConcatRowsVMatrix::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 57 of file ConcatRowsVMatrix.cc.
OptionMap & PLearn::ConcatRowsVMatrix::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 57 of file ConcatRowsVMatrix.cc.
void PLearn::ConcatRowsVMatrix::getpositions | ( | int | i, |
int & | whichvm, | ||
int & | rowofvm | ||
) | const [inline, protected] |
Return the index of the correct VMat in the sources and the row number in this VMat that correspond to row i in the ConcatRowsVMat.
The inline version performs a cache lookup, or calls the out-of-line version getPositionsAux, which performs a linear search
Definition at line 168 of file ConcatRowsVMatrix.h.
References PLASSERT, and PLERROR.
Referenced by dot(), get(), getSubRow(), and putMat().
{ #ifdef BOUNDCHECK if(i<0 || i>=length()) PLERROR("In ConcatRowsVMatrix::getpositions OUT OF BOUNDS"); #endif // Start by looking if i belongs to the most-recently-used VMat. If so, no // need to search for it if (i >= m_last_vmat_startrow && i <= m_last_vmat_lastrow) { PLASSERT( m_last_vmat_index >= 0 ); whichvm = m_last_vmat_index; rowofvm = i - m_last_vmat_startrow; return; } // Now in cache: perform linear search out-of-line getPositionsAux(i, whichvm, rowofvm); }
void PLearn::ConcatRowsVMatrix::getPositionsAux | ( | int | i, |
int & | whichvm, | ||
int & | rowofvm | ||
) | const [private] |
Used in the implementation of getpositions (out-of-line version)
Definition at line 495 of file ConcatRowsVMatrix.cc.
References PLearn::VMatrix::length(), PLearn::TVec< T >::length(), m_last_vmat_index, m_last_vmat_lastrow, m_last_vmat_startrow, and to_concat.
{ int pos = 0; int k=0; while(i>=pos+to_concat[k]->length()) { pos += to_concat[k]->length(); k++; } // Update cache of last-used VMat m_last_vmat_index = k; m_last_vmat_startrow = pos; m_last_vmat_lastrow = pos + to_concat[k]->length() - 1; whichvm = k; rowofvm = i-pos; }
RemoteMethodMap & PLearn::ConcatRowsVMatrix::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 57 of file ConcatRowsVMatrix.cc.
It is suggested that this method be implemented in subclasses to speed up accesses (default version repeatedly calls get(i,j) which may have a significant overhead).
Fills v with the subrow i lying between columns j (inclusive) and j+v.length() (exclusive).
Reimplemented from PLearn::VMatrix.
Definition at line 429 of file ConcatRowsVMatrix.cc.
References fixed_mappings, getpositions(), PLearn::is_missing(), PLearn::TVec< T >::length(), need_fix_mappings, and to_concat.
{ static map<real, real> fixed; static map<real, real>::iterator it; int whichvm, rowofvm; getpositions(i,whichvm,rowofvm); to_concat[whichvm]->getSubRow(rowofvm, j, v); if (need_fix_mappings) { for (int k = j; k < j + v.length(); k++) { fixed = fixed_mappings(whichvm, k); if (!is_missing(v[k-j])) { it = fixed.find(v[k -j]); if (it != fixed.end()) v[k - j] = it->second; } } } }
void PLearn::ConcatRowsVMatrix::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::VMatrix.
Definition at line 451 of file ConcatRowsVMatrix.cc.
References PLearn::deepCopyField(), fixed_mappings, PLearn::VMatrix::makeDeepCopyFromShallowCopy(), sources, and to_concat.
{ inherited::makeDeepCopyFromShallowCopy(copies); deepCopyField(sources, copies); deepCopyField(to_concat, copies); deepCopyField(fixed_mappings, copies); }
Copies matrix m at position i,j of this VMat.
Reimplemented from PLearn::VMatrix.
Definition at line 461 of file ConcatRowsVMatrix.cc.
References getpositions(), PLearn::VMatrix::length(), m, and to_concat.
{ int whichvm, rowofvm; for (int row = 0; row < length(); row++) { getpositions(row + i, whichvm, rowofvm); to_concat[whichvm]->putSubRow(rowofvm, j, m(row)); } }
void PLearn::ConcatRowsVMatrix::recomputeDimensions | ( | ) | [private] |
Recompute length and width (same as reset_dimensions(), except it does not forward to the underlying VMats).
Definition at line 472 of file ConcatRowsVMatrix.cc.
References i, PLearn::TVec< T >::length(), PLearn::VMatrix::length_, PLERROR, sources, to_concat, PLearn::VMatrix::width(), and PLearn::VMatrix::width_.
Referenced by build_(), and reset_dimensions().
{ width_ = to_concat[0]->width(); length_ = 0; for (int i=0; i<to_concat.length(); i++) { if (to_concat[i]->width() != width_) PLERROR("ConcatRowsVMatrix: underlying-VMat %d has %d width, while" " 0-th has %d", i, sources[i]->width(), width_); length_ += to_concat[i]->length(); } }
void PLearn::ConcatRowsVMatrix::reset_dimensions | ( | ) | [virtual] |
In case the dimensions of an underlying VMat has changed, recompute it.
Reimplemented from PLearn::VMatrix.
Definition at line 486 of file ConcatRowsVMatrix.cc.
References i, recomputeDimensions(), PLearn::TVec< T >::size(), and to_concat.
{ for (int i=0;i<to_concat.size();i++) to_concat[i]->reset_dimensions(); recomputeDimensions(); }
Reimplemented from PLearn::VMatrix.
Definition at line 96 of file ConcatRowsVMatrix.h.
Definition at line 78 of file ConcatRowsVMatrix.h.
Referenced by build_(), and declareOptions().
TMat< map<real, real> > PLearn::ConcatRowsVMatrix::fixed_mappings [protected] |
This is a matrix of size (number of matrices to concatenate, number of columns).
The element (i, j) is a mapping that says which value needs to be replaced with what in the j-th column of the i-th matrix. This is to fix the mappings when 'need_fix_mappings' is true.
Definition at line 74 of file ConcatRowsVMatrix.h.
Referenced by ensureMappingsConsistency(), get(), getSubRow(), and makeDeepCopyFromShallowCopy().
Definition at line 79 of file ConcatRowsVMatrix.h.
Referenced by build_(), and declareOptions().
int PLearn::ConcatRowsVMatrix::m_last_vmat_index [mutable, private] |
Cache of the index of the last-recently used VMat; -1 if invalid.
Definition at line 140 of file ConcatRowsVMatrix.h.
Referenced by build_(), and getPositionsAux().
int PLearn::ConcatRowsVMatrix::m_last_vmat_lastrow [mutable, private] |
Cache of the last row (inclusive) in the ConcatRowsVMatrix corresponding to m_last_vmat_index; -1 if invalid.
Definition at line 148 of file ConcatRowsVMatrix.h.
Referenced by build_(), and getPositionsAux().
int PLearn::ConcatRowsVMatrix::m_last_vmat_startrow [mutable, private] |
Cache of the starting row in the ConcatRowsVMatrix corresponding to to the first row of m_last_vmat_index; -1 if invalid.
Definition at line 144 of file ConcatRowsVMatrix.h.
Referenced by build_(), and getPositionsAux().
bool PLearn::ConcatRowsVMatrix::need_fix_mappings [protected] |
Will be set to 'true' iff two VMats concatenated have not the same mapping for a given string.
This means the output must systematically be checked to ensure consistency.
Definition at line 68 of file ConcatRowsVMatrix.h.
Referenced by build_(), dot(), ensureMappingsConsistency(), get(), and getSubRow().
Definition at line 80 of file ConcatRowsVMatrix.h.
Referenced by build_(), and declareOptions().
TVec<VMat> PLearn::ConcatRowsVMatrix::sources [protected] |
The (original) VMats to concatenate.
Definition at line 58 of file ConcatRowsVMatrix.h.
Referenced by build_(), ConcatRowsVMatrix(), declareOptions(), findAllFields(), findCommonFields(), makeDeepCopyFromShallowCopy(), and recomputeDimensions().
TVec<VMat> PLearn::ConcatRowsVMatrix::to_concat [protected] |
A vector containing the final VMats to concatenate.
These are either the same as the ones in 'sources', or a selection of their fields when the 'only_common_fields' option is true.
Definition at line 63 of file ConcatRowsVMatrix.h.
Referenced by build_(), dot(), ensureMappingsConsistency(), findAllFields(), findCommonFields(), fullyCheckMappings(), get(), getPositionsAux(), getSubRow(), makeDeepCopyFromShallowCopy(), putMat(), recomputeDimensions(), and reset_dimensions().