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

#include <ForwardVMatrix.h>

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

List of all members.

Public Member Functions

 ForwardVMatrix ()
 ForwardVMatrix (VMat vm)
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual ForwardVMatrixdeepCopy (CopiesMap &copies) const
virtual void build ()
 Simply calls inherited::build() then build_().
void setVMat (VMat the_vm)
 This allows to set the underlying vmat.
virtual string getValString (int col, real val) const
 returns the string associated with value val for field# col.
virtual real getStringVal (int col, const string &str) const
 return value associated with a string. Default returns NaN
virtual string getString (int row, int col) const
 returns element as a string, even if its a number (which is always the case unless class is StrTableVMatrix
map< string, realgetStringMapping (int col) const
 returns the whole string->value mapping
virtual const map< string, real > & getStringToRealMapping (int col) const
 Returns the string->real mapping for column 'col'.
virtual const map< real, string > & getRealToStringMapping (int col) const
 Returns the real->string mapping for column 'col'.
virtual void computeStats ()
virtual void save (const PPath &filename) const
 This method overloads the Object::save method which is deprecated.
virtual void savePMAT (const PPath &pmatfile) const
virtual void saveDMAT (const PPath &dmatdir) const
 Save the VMatrix in DMat format.
virtual void saveAMAT (const PPath &amatfile, bool verbose=true, bool no_header=false, bool save_strings=false) const
 Save the content of the matrix in the AMAT ASCII format into a file.
virtual real get (int i, int j) const
 This method must be implemented in all subclasses.
virtual void put (int i, int j, real value)
 This method must be implemented in all subclasses of writable matrices.
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 putSubRow (int i, int j, Vec v)
virtual void appendRow (Vec v)
 This method must be implemented for matrices that are allowed to grow.
virtual void getRow (int i, Vec v) const
 These methods do not usually need to be overridden in subclasses (default versions call getSubRow, which should do just fine)
virtual void putRow (int i, Vec v)
virtual void fill (real value)
virtual void getMat (int i, int j, Mat m) const
 copies the submatrix starting at i,j into m (which must have appropriate length and width)
virtual void putMat (int i, int j, Mat m)
 copies matrix m at position i,j of this VMat
virtual void getColumn (int i, Vec v) const
 copies column i into v (which must have appropriate length equal to the VMat's length)
virtual Mat toMat () const
virtual void compacify ()
 The default implementation of this method does nothing But subclasses may overload it to reallocate memory to exactly what is needed and no more.
virtual void reset_dimensions ()
 in case the dimensions of an underlying vmat has changed, recompute it
virtual VMat subMat (int i, int j, int l, int w)
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).
void makeDeepCopyFromShallowCopy (CopiesMap &copies)
 Does the necessary operations to transform a shallow copy (this) into a deep copy by deep-copying all the members that need to be.
virtual void accumulateXtY (int X_startcol, int X_ncols, int Y_startcol, int Y_ncols, Mat &result, int startrow=0, int nrows=-1, int ignore_this_row=-1) const
virtual void accumulateXtX (int X_startcol, int X_ncols, Mat &result, int startrow=0, int nrows=-1, int ignore_this_row=-1) const

Static Public Member Functions

static string _classname_ ()
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 ()
static void declareOptions (OptionList &ol)
 Declare this class' options.

Static Public Attributes

static StaticInitializer _static_initializer_

Protected Attributes

VMat vm

Private Types

typedef VMatrix inherited

Private Member Functions

void build_ ()
 This does the actual building.

Detailed Description

Definition at line 52 of file ForwardVMatrix.h.


Member Typedef Documentation


Constructor & Destructor Documentation

PLearn::ForwardVMatrix::ForwardVMatrix ( )

Definition at line 56 of file ForwardVMatrix.cc.

{}
PLearn::ForwardVMatrix::ForwardVMatrix ( VMat  vm)

Definition at line 59 of file ForwardVMatrix.cc.

    : vm(the_vm)
{
}

Member Function Documentation

string PLearn::ForwardVMatrix::_classname_ ( ) [static]
OptionList & PLearn::ForwardVMatrix::_getOptionList_ ( ) [static]
RemoteMethodMap & PLearn::ForwardVMatrix::_getRemoteMethodMap_ ( ) [static]
bool PLearn::ForwardVMatrix::_isa_ ( const Object o) [static]
Object * PLearn::ForwardVMatrix::_new_instance_for_typemap_ ( ) [static]
StaticInitializer ForwardVMatrix::_static_initializer_ & PLearn::ForwardVMatrix::_static_initialize_ ( ) [static]
void PLearn::ForwardVMatrix::accumulateXtX ( int  X_startcol,
int  X_ncols,
Mat result,
int  startrow = 0,
int  nrows = -1,
int  ignore_this_row = -1 
) const [virtual]

A special case of method accumulateXtY result += transpose(X).X Where X = this->subMatColumns(X_startcol,X_ncols)

Reimplemented from PLearn::VMatrix.

Definition at line 235 of file ForwardVMatrix.cc.

References vm.

{ vm->accumulateXtX(X_startcol, X_ncols,
                    result, startrow, nrows, ignore_this_row); }
void PLearn::ForwardVMatrix::accumulateXtY ( int  X_startcol,
int  X_ncols,
int  Y_startcol,
int  Y_ncols,
Mat result,
int  startrow = 0,
int  nrows = -1,
int  ignore_this_row = -1 
) const [virtual]

result += transpose(X).Y Where X = this->subMatColumns(X_startcol,X_ncols) and Y = this->subMatColumns(Y_startcol,Y_ncols);

Reimplemented from PLearn::VMatrix.

Definition at line 230 of file ForwardVMatrix.cc.

References vm.

{ vm->accumulateXtY(X_startcol, X_ncols, Y_startcol, Y_ncols,
                    result, startrow, nrows, ignore_this_row); }
void PLearn::ForwardVMatrix::appendRow ( Vec  v) [virtual]

This method must be implemented for matrices that are allowed to grow.

Reimplemented from PLearn::VMatrix.

Definition at line 177 of file ForwardVMatrix.cc.

References vm.

{ vm->appendRow(v); }
void PLearn::ForwardVMatrix::build ( ) [virtual]

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

Reimplemented from PLearn::VMatrix.

Reimplemented in PLearn::AutoVMatrix, PLearn::AutoVMatrixSaveSource, PLearn::ProcessDatasetVMatrix, and PLearn::UCIDataVMatrix.

Definition at line 65 of file ForwardVMatrix.cc.

References PLearn::VMatrix::build(), and build_().

Referenced by PLearn::ProcessDatasetVMatrix::build(), PLearn::AutoVMatrix::build(), and PLearn::ProcessDatasetVMatrix::build_().

Here is the call graph for this function:

Here is the caller graph for this function:

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

This does the actual building.

Reimplemented from PLearn::VMatrix.

Reimplemented in PLearn::AutoVMatrix, PLearn::AutoVMatrixSaveSource, PLearn::ProcessDatasetVMatrix, and PLearn::UCIDataVMatrix.

Definition at line 72 of file ForwardVMatrix.cc.

References PLearn::VMatrix::hasMetaDataDir(), PLearn::VMat::length(), PLearn::VMatrix::length_, PLearn::VMatrix::setMetaDataDir(), PLearn::VMatrix::setMetaInfoFrom(), vm, PLearn::VMat::width(), PLearn::VMatrix::width_, and PLearn::VMatrix::writable.

Referenced by build(), and setVMat().

{
    if (vm) {
        length_ = vm->length();
        width_ = vm->width();
        writable = vm->isWritable();
        setMetaInfoFrom(vm);
        if (vm->hasMetaDataDir() && !this->hasMetaDataDir())
            setMetaDataDir(vm->getMetaDataDir());

    } else {
        length_ = 0;
        width_ = 0;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

string PLearn::ForwardVMatrix::classname ( ) const [virtual]
void PLearn::ForwardVMatrix::compacify ( ) [virtual]

The default implementation of this method does nothing But subclasses may overload it to reallocate memory to exactly what is needed and no more.

Reimplemented from PLearn::VMatrix.

Definition at line 204 of file ForwardVMatrix.cc.

References vm.

{ vm->compacify(); }
void PLearn::ForwardVMatrix::computeStats ( ) [virtual]

Reimplemented from PLearn::VMatrix.

Definition at line 146 of file ForwardVMatrix.cc.

References vm.

{ vm->computeStats(); }
void PLearn::ForwardVMatrix::declareOptions ( OptionList ol) [static]

Declare this class' options.

Reimplemented from PLearn::VMatrix.

Reimplemented in PLearn::AutoVMatrix, PLearn::AutoVMatrixSaveSource, PLearn::ProcessDatasetVMatrix, and PLearn::UCIDataVMatrix.

Definition at line 98 of file ForwardVMatrix.cc.

References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::VMatrix::declareOptions(), PLearn::VMatrix::length_, PLearn::OptionBase::nosave, vm, PLearn::VMatrix::width_, and PLearn::VMatrix::writable.

Referenced by PLearn::ProcessDatasetVMatrix::declareOptions(), and PLearn::AutoVMatrix::declareOptions().

{
    declareOption(ol, "vm", &ForwardVMatrix::vm, OptionBase::buildoption,
                  "The underlying VMat to which all calls are forwarded.");

    inherited::declareOptions(ol);

    // Hide unused options (automatically defined at build time).

    declareOption(ol, "writable",    &ForwardVMatrix::writable, OptionBase::nosave, "");
    declareOption(ol, "length",      &ForwardVMatrix::length_,  OptionBase::nosave, "");
    declareOption(ol, "width",       &ForwardVMatrix::width_,   OptionBase::nosave, "");
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Reimplemented from PLearn::VMatrix.

Reimplemented in PLearn::AutoVMatrix, PLearn::AutoVMatrixSaveSource, PLearn::ProcessDatasetVMatrix, and PLearn::UCIDataVMatrix.

Definition at line 64 of file ForwardVMatrix.h.

:
    void build_();
ForwardVMatrix * PLearn::ForwardVMatrix::deepCopy ( CopiesMap copies) const [virtual]
real PLearn::ForwardVMatrix::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 223 of file ForwardVMatrix.cc.

References vm.

{ return vm->dot(i1, i2, inputsize); }
real PLearn::ForwardVMatrix::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 227 of file ForwardVMatrix.cc.

References vm.

{ return vm->dot(i,  v); }
void PLearn::ForwardVMatrix::fill ( real  value) [virtual]

Reimplemented from PLearn::VMatrix.

Definition at line 188 of file ForwardVMatrix.cc.

References vm.

{ vm->fill(value); }
real PLearn::ForwardVMatrix::get ( int  i,
int  j 
) const [virtual]

This method must be implemented in all subclasses.

returns element (i,j)

Implements PLearn::VMatrix.

Definition at line 164 of file ForwardVMatrix.cc.

References vm.

{ return vm->get(i, j); }
void PLearn::ForwardVMatrix::getColumn ( int  i,
Vec  v 
) const [virtual]

copies column i into v (which must have appropriate length equal to the VMat's length)

Reimplemented from PLearn::VMatrix.

Definition at line 196 of file ForwardVMatrix.cc.

References PLearn::VMat::getColumn(), and vm.

{ vm->getColumn(i, v); }

Here is the call graph for this function:

void PLearn::ForwardVMatrix::getMat ( int  i,
int  j,
Mat  m 
) const [virtual]

copies the submatrix starting at i,j into m (which must have appropriate length and width)

Reimplemented from PLearn::VMatrix.

Definition at line 190 of file ForwardVMatrix.cc.

References vm.

{ vm->getMat(i, j, m); }
OptionList & PLearn::ForwardVMatrix::getOptionList ( ) const [virtual]
OptionMap & PLearn::ForwardVMatrix::getOptionMap ( ) const [virtual]
const map< real, string > & PLearn::ForwardVMatrix::getRealToStringMapping ( int  col) const [virtual]

Returns the real->string mapping for column 'col'.

Reimplemented from PLearn::VMatrix.

Definition at line 142 of file ForwardVMatrix.cc.

References vm.

                                                                            {
    return vm->getRealToStringMapping(col);
}
RemoteMethodMap & PLearn::ForwardVMatrix::getRemoteMethodMap ( ) const [virtual]
void PLearn::ForwardVMatrix::getRow ( int  i,
Vec  v 
) const [virtual]

These methods do not usually need to be overridden in subclasses (default versions call getSubRow, which should do just fine)

copies row i into v (which must have appropriate length equal to the VMat's width)

Reimplemented from PLearn::VMatrix.

Definition at line 180 of file ForwardVMatrix.cc.

References PLearn::TVec< T >::length(), PLASSERT, vm, and PLearn::VMatrix::width().

{
    PLASSERT( v.length() == width() );
    vm->getRow(i, v);
}

Here is the call graph for this function:

string PLearn::ForwardVMatrix::getString ( int  row,
int  col 
) const [virtual]

returns element as a string, even if its a number (which is always the case unless class is StrTableVMatrix

Reimplemented from PLearn::VMatrix.

Definition at line 120 of file ForwardVMatrix.cc.

References vm.

{ return vm->getString(row,col); }
map< string, real > PLearn::ForwardVMatrix::getStringMapping ( int  col) const

returns the whole string->value mapping

Definition at line 123 of file ForwardVMatrix.cc.

References PLERROR.

{
    PLERROR("ForwardVMatrix::getStringMapping not implemented yet");
    // making the compiler happy:
    return map<string,real>();

    //  return vm->getStringMapping(col);
}
const map< string, real > & PLearn::ForwardVMatrix::getStringToRealMapping ( int  col) const [virtual]

Returns the string->real mapping for column 'col'.

Reimplemented from PLearn::VMatrix.

Definition at line 135 of file ForwardVMatrix.cc.

References vm.

                                                                            {
    return vm->getStringToRealMapping(col);
}
real PLearn::ForwardVMatrix::getStringVal ( int  col,
const string &  str 
) const [virtual]

return value associated with a string. Default returns NaN

Reimplemented from PLearn::VMatrix.

Definition at line 116 of file ForwardVMatrix.cc.

References vm.

{ return vm->getStringVal(col, str); }
void PLearn::ForwardVMatrix::getSubRow ( int  i,
int  j,
Vec  v 
) const [virtual]

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 171 of file ForwardVMatrix.cc.

References PLearn::VMat::getSubRow(), and vm.

{ vm->getSubRow(i, j, v); }

Here is the call graph for this function:

string PLearn::ForwardVMatrix::getValString ( int  col,
real  val 
) const [virtual]

returns the string associated with value val for field# col.

Or returns "" if no string is associated.

Reimplemented from PLearn::VMatrix.

Definition at line 112 of file ForwardVMatrix.cc.

References vm.

{ return vm->getValString(col, val); }
void PLearn::ForwardVMatrix::makeDeepCopyFromShallowCopy ( CopiesMap copies) [virtual]

Does the necessary operations to transform a shallow copy (this) into a deep copy by deep-copying all the members that need to be.

This needs to be overridden by every class that adds "complex" data members to the class, such as Vec, Mat, PP<Something>, etc. Typical implementation:

  void CLASS_OF_THIS::makeDeepCopyFromShallowCopy(CopiesMap& copies)
  {
      inherited::makeDeepCopyFromShallowCopy(copies);
      deepCopyField(complex_data_member1, copies);
      deepCopyField(complex_data_member2, copies);
      ...
  }
Parameters:
copiesA map used by the deep-copy mechanism to keep track of already-copied objects.

Reimplemented from PLearn::VMatrix.

Reimplemented in PLearn::AutoVMatrix, PLearn::AutoVMatrixSaveSource, PLearn::ProcessDatasetVMatrix, and PLearn::UCIDataVMatrix.

Definition at line 240 of file ForwardVMatrix.cc.

References PLearn::deepCopyField(), PLearn::VMatrix::makeDeepCopyFromShallowCopy(), and vm.

Referenced by PLearn::ProcessDatasetVMatrix::makeDeepCopyFromShallowCopy(), and PLearn::AutoVMatrix::makeDeepCopyFromShallowCopy().

Here is the call graph for this function:

Here is the caller graph for this function:

void PLearn::ForwardVMatrix::put ( int  i,
int  j,
real  value 
) [virtual]

This method must be implemented in all subclasses of writable matrices.

sets element (i,j) to value

Reimplemented from PLearn::VMatrix.

Definition at line 168 of file ForwardVMatrix.cc.

References vm.

{ vm->put(i, j, value); }
void PLearn::ForwardVMatrix::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 192 of file ForwardVMatrix.cc.

References vm.

{ vm->putMat(i, j, m); }
void PLearn::ForwardVMatrix::putRow ( int  i,
Vec  v 
) [virtual]

Reimplemented from PLearn::VMatrix.

Definition at line 186 of file ForwardVMatrix.cc.

References vm.

{ vm->putRow(i, v); }
void PLearn::ForwardVMatrix::putSubRow ( int  i,
int  j,
Vec  v 
) [virtual]

It is suggested that this method be implemented in subclasses of writable matrices to speed up accesses (default version repeatedly calls put(i,j,value) which may have a significant overhead)

Reimplemented from PLearn::VMatrix.

Definition at line 174 of file ForwardVMatrix.cc.

References vm.

{ vm->putSubRow(i, j, v); }
void PLearn::ForwardVMatrix::reset_dimensions ( ) [virtual]

in case the dimensions of an underlying vmat has changed, recompute it

Reimplemented from PLearn::VMatrix.

Definition at line 208 of file ForwardVMatrix.cc.

References PLearn::VMatrix::inputsize_, PLearn::VMat::length(), PLearn::VMatrix::length_, PLearn::VMatrix::targetsize_, vm, PLearn::VMatrix::weightsize_, PLearn::VMat::width(), and PLearn::VMatrix::width_.

{
    if (vm) {
        vm->reset_dimensions();
        length_ = vm->length();
        width_ = vm->width();
        inputsize_ = vm->inputsize();
        targetsize_ = vm->targetsize();
        weightsize_ = vm->weightsize();
    }
}

Here is the call graph for this function:

void PLearn::ForwardVMatrix::save ( const PPath filename) const [virtual]

This method overloads the Object::save method which is deprecated.

This method is therefore deprecated and you should call directly the savePMAT() method.

Deprecated:
Use savePMAT() instead.

Reimplemented from PLearn::VMatrix.

Definition at line 150 of file ForwardVMatrix.cc.

References PLearn::VMat::save(), and vm.

{ vm->save(filename); }

Here is the call graph for this function:

void PLearn::ForwardVMatrix::saveAMAT ( const PPath amatfile,
bool  verbose = true,
bool  no_header = false,
bool  save_strings = false 
) const [virtual]

Save the content of the matrix in the AMAT ASCII format into a file.

If 'no_header' is set to 'true', then the AMAT header won't be saved, which can be useful to export data to other applications. If 'save_strings' is set to 'true', then the string mappings will be used so as to save strings where they exist (instead of saving the corresponding real value).

Reimplemented from PLearn::VMatrix.

Definition at line 161 of file ForwardVMatrix.cc.

References vm.

Referenced by PLearn::save_load_compare().

{ vm->saveAMAT(amatfile, verbose, no_header, save_strings); }

Here is the caller graph for this function:

void PLearn::ForwardVMatrix::saveDMAT ( const PPath dmatdir) const [virtual]

Save the VMatrix in DMat format.

Reimplemented from PLearn::VMatrix.

Definition at line 155 of file ForwardVMatrix.cc.

References vm.

Referenced by PLearn::save_load_compare().

{ vm->saveDMAT(dmatdir); }

Here is the caller graph for this function:

void PLearn::ForwardVMatrix::savePMAT ( const PPath pmatfile) const [virtual]

Definition at line 153 of file ForwardVMatrix.cc.

References vm.

Referenced by PLearn::save_load_compare().

{ vm->savePMAT(pmatfile); }

Here is the caller graph for this function:

void PLearn::ForwardVMatrix::setVMat ( VMat  the_vm)

This allows to set the underlying vmat.

Definition at line 88 of file ForwardVMatrix.cc.

References build_(), vm, and PLearn::VMatrix::VMat.

Referenced by PLearn::AutoVMatrix::build_().

{
    if(the_vm)
        vm = the_vm;
    else
        vm = VMat();
    build_();
}

Here is the call graph for this function:

Here is the caller graph for this function:

VMat PLearn::ForwardVMatrix::subMat ( int  i,
int  j,
int  l,
int  w 
) [virtual]

default version returns a SubVMatrix referencing the current VMatrix however this can be overridden to provide more efficient shortcuts (see MemoryVMatrix::subMat and SubVMatrix::subMat for examples)

Reimplemented from PLearn::VMatrix.

Definition at line 220 of file ForwardVMatrix.cc.

References PLearn::VMat::subMat(), and vm.

{ return vm->subMat(i,j,l,w); }

Here is the call graph for this function:

Mat PLearn::ForwardVMatrix::toMat ( ) const [virtual]

returns a Mat with the same data as this VMat The default version of this method copies the data in a fresh Mat created in memory However this method will typically be overrided by subclasses (such as MemoryVMatrix) whose internal representation is already a Mat in order to return this Mat directly to avoid a new memory allocation and copy of elements. In this case, and in this case only, modifying the elements of the returned Mat will logically result in modified elements in the original VMatrix view of it.

Reimplemented from PLearn::VMatrix.

Definition at line 199 of file ForwardVMatrix.cc.

References PLearn::VMat::toMat(), and vm.

Referenced by PLearn::save_load_compare().

{ return vm->toMat(); }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation


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