Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

PLearn::ConcatRowsVMatrix Class Reference

#include <ConcatRowsVMatrix.h>

Inheritance diagram for PLearn::ConcatRowsVMatrix:

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

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ConcatRowsVMatrix (TVec< VMat > the_array=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)
virtual real get (int i, int j) const
 returns element (i,j)

virtual void getSubRow (int i, int j, Vec v) const
 fills v with the subrow i lying between columns j (inclusive) and j+v.length() (exclusive)

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
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

 PLEARN_DECLARE_OBJECT (ConcatRowsVMatrix)
virtual void build ()
 Should call simply inherited::build(), then this class's build_().

virtual void makeDeepCopyFromShallowCopy (map< const void *, void * > &copies)
 Transforms a shallow copy into a deep copy.


Public Attributes

bool fully_check_mappings
bool only_common_fields

Protected Member Functions

void getpositions (int i, int &whichvm, int &rowofvm) const
 Returns the index of the correct VMat in the array and the row number in this VMat that correspond to row i in the ConcatRowsVMat.


Static Protected Member Functions

void declareOptions (OptionList &ol)
 redefine this in subclasses: call declareOption(...) for each option, and then call inherited::declareOptions(options) ( see the declareOption function further down)


Protected Attributes

TVec< VMatarray
TVec< VMatto_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 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).


Member Typedef Documentation

typedef VMatrix PLearn::ConcatRowsVMatrix::inherited [private]
 

Reimplemented from PLearn::VMatrix.

Definition at line 57 of file ConcatRowsVMatrix.h.


Constructor & Destructor Documentation

PLearn::ConcatRowsVMatrix::ConcatRowsVMatrix TVec< VMat the_array = TVecVMat >()  ) 
 

The fields names are copied from the FIRST VMat, unless the 'only_common_fields' option is set to 'true'.

Definition at line 59 of file ConcatRowsVMatrix.cc.

References array, build_(), and PLearn::TVec< VMat >::size().

PLearn::ConcatRowsVMatrix::ConcatRowsVMatrix VMat  d1,
VMat  d2
 

Definition at line 68 of file ConcatRowsVMatrix.cc.

References array, build_(), and PLearn::TVec< VMat >::resize().


Member Function Documentation

void PLearn::ConcatRowsVMatrix::build  )  [virtual]
 

Should call simply inherited::build(), then this class's build_().

This method should be callable again at later times, after modifying some option fields to change the "architecture" of the object.

Reimplemented from PLearn::VMatrix.

Definition at line 100 of file ConcatRowsVMatrix.cc.

References build_().

void PLearn::ConcatRowsVMatrix::build_  )  [private]
 

This does the actual building.

Reimplemented from PLearn::VMatrix.

Definition at line 109 of file ConcatRowsVMatrix.cc.

References array, ensureMappingsConsistency(), findCommonFields(), fully_check_mappings, fullyCheckMappings(), need_fix_mappings, only_common_fields, PLERROR, PLWARNING, recomputeDimensions(), PLearn::TVec< VMat >::size(), and to_concat.

Referenced by build(), and ConcatRowsVMatrix().

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

redefine this in subclasses: call declareOption(...) for each option, and then call inherited::declareOptions(options) ( see the declareOption function further down)

ex: static void declareOptions(OptionList& ol) { declareOption(ol, "inputsize", &MyObject::inputsize_, OptionBase::buildoption, "the size of the input\n it must be provided"); declareOption(ol, "weights", &MyObject::weights, OptionBase::learntoption, "the learnt model weights"); inherited::declareOptions(ol); }

Reimplemented from PLearn::VMatrix.

Definition at line 81 of file ConcatRowsVMatrix.cc.

References PLearn::declareOption(), and PLearn::OptionList.

real PLearn::ConcatRowsVMatrix::dot int  i,
const Vec v
const [virtual]
 

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 154 of file ConcatRowsVMatrix.cc.

References getpositions(), need_fix_mappings, to_concat, and PLearn::Vec.

real PLearn::ConcatRowsVMatrix::dot int  i1,
int  i2,
int  inputsize
const [virtual]
 

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 142 of file ConcatRowsVMatrix.cc.

References getpositions(), need_fix_mappings, and to_concat.

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 168 of file ConcatRowsVMatrix.cc.

References fixed_mappings, PLearn::TVec< VMat >::length(), PLearn::max(), need_fix_mappings, REAL_MAX, PLearn::TMat< map< real, real > >::resize(), to_concat, PLearn::ProgressBar::update(), and PLearn::VMatrix::width().

Referenced by build_().

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 248 of file ConcatRowsVMatrix.cc.

References PLearn::TVec< T >::append(), array, PLearn::TVec< VMat >::length(), PLearn::TVec< T >::length(), PLearn::TVec< VMField >::length(), PLearn::TVec< VMat >::resize(), PLearn::TVec< T >::resize(), and to_concat.

Referenced by build_().

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 282 of file ConcatRowsVMatrix.cc.

References count, PLearn::TVec< map< real, string > >::end(), PLearn::TVec< map< real, string > >::find(), PLearn::VMatrix::getFieldInfos(), PLearn::is_missing(), k, PLearn::TVec< VMat >::length(), PLearn::VMatrix::length(), PLearn::max(), PLERROR, PLearn::TVec< map< string, real > >::size(), to_concat, PLearn::ProgressBar::update(), and PLearn::VMatrix::width().

Referenced by build_().

real PLearn::ConcatRowsVMatrix::get int  i,
int  j
const [virtual]
 

returns element (i,j)

Reimplemented from PLearn::VMatrix.

Definition at line 320 of file ConcatRowsVMatrix.cc.

References fixed_mappings, getpositions(), PLearn::is_missing(), need_fix_mappings, PLearn::TMat< map< real, real > >::size(), to_concat, and val.

void PLearn::ConcatRowsVMatrix::getpositions int  i,
int whichvm,
int rowofvm
const [protected]
 

Returns the index of the correct VMat in the array and the row number in this VMat that correspond to row i in the ConcatRowsVMat.

Definition at line 343 of file ConcatRowsVMatrix.cc.

References k, PLearn::TVec< VMat >::length(), PLearn::VMatrix::length(), PLERROR, and to_concat.

Referenced by dot(), get(), getSubRow(), and putMat().

void PLearn::ConcatRowsVMatrix::getSubRow int  i,
int  j,
Vec  v
const [virtual]
 

fills v with the subrow i lying between columns j (inclusive) and j+v.length() (exclusive)

Reimplemented from PLearn::VMatrix.

Definition at line 365 of file ConcatRowsVMatrix.cc.

References fixed_mappings, getpositions(), PLearn::is_missing(), k, PLearn::TVec< T >::length(), need_fix_mappings, and to_concat.

void PLearn::ConcatRowsVMatrix::makeDeepCopyFromShallowCopy map< const void *, void * > &  copies  )  [virtual]
 

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::VMatrix.

Definition at line 387 of file ConcatRowsVMatrix.cc.

References PLERROR.

PLearn::ConcatRowsVMatrix::PLEARN_DECLARE_OBJECT ConcatRowsVMatrix   ) 
 

void PLearn::ConcatRowsVMatrix::putMat int  i,
int  j,
Mat  m
[virtual]
 

copies matrix m at position i,j of this VMat

Reimplemented from PLearn::VMatrix.

Definition at line 404 of file ConcatRowsVMatrix.cc.

References getpositions(), PLearn::VMatrix::length(), PLearn::Mat, and to_concat.

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 415 of file ConcatRowsVMatrix.cc.

References array, PLERROR, to_concat, and PLearn::VMatrix::width().

Referenced by build_(), and reset_dimensions().

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 428 of file ConcatRowsVMatrix.cc.

References recomputeDimensions(), PLearn::TVec< VMat >::size(), and to_concat.


Member Data Documentation

TVec<VMat> PLearn::ConcatRowsVMatrix::array [protected]
 

Definition at line 61 of file ConcatRowsVMatrix.h.

Referenced by build_(), ConcatRowsVMatrix(), findCommonFields(), and recomputeDimensions().

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 77 of file ConcatRowsVMatrix.h.

Referenced by ensureMappingsConsistency(), get(), and getSubRow().

bool PLearn::ConcatRowsVMatrix::fully_check_mappings
 

Definition at line 81 of file ConcatRowsVMatrix.h.

Referenced by build_().

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 71 of file ConcatRowsVMatrix.h.

Referenced by build_(), dot(), ensureMappingsConsistency(), get(), and getSubRow().

bool PLearn::ConcatRowsVMatrix::only_common_fields
 

Definition at line 82 of file ConcatRowsVMatrix.h.

Referenced by build_().

TVec<VMat> PLearn::ConcatRowsVMatrix::to_concat [protected]
 

A vector containing the final VMats to concatenate.

These are either the same as the ones in 'array', or a selection of their fields when the 'only_common_fields' option is true.

Definition at line 66 of file ConcatRowsVMatrix.h.

Referenced by build_(), dot(), ensureMappingsConsistency(), findCommonFields(), fullyCheckMappings(), get(), getpositions(), getSubRow(), putMat(), recomputeDimensions(), and reset_dimensions().


The documentation for this class was generated from the following files:
Generated on Tue Aug 17 16:26:07 2004 for PLearn by doxygen 1.3.7