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

PLearn::SparseVMatrix Class Reference

#include <SparseVMatrix.h>

Inheritance diagram for PLearn::SparseVMatrix:

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

Collaboration graph
[legend]
List of all members.

Public Member Functions

 SparseVMatrix ()
 SparseVMatrix (VMat m)
 This builds a sparse representation in memory of the VMat m passed as argument.

 SparseVMatrix (const string &filename)
 This reloads a previously saved sparse VMatrix.

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

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 save (const string &filename)
 calls write

virtual ~SparseVMatrix ()

Protected Member Functions

virtual void getNewRow (int i, const Vec &v) const
 This is the only method requiring implementation in subclasses.


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

int nelements
 total number of non-zero elements in the VMatrix

unsigned short * positions
float * values
SparseVMatrixRowrows

Private Types

typedef RowBufferedVMatrix inherited

Private Member Functions

void build_ ()
 This does the actual building.


Member Typedef Documentation

typedef RowBufferedVMatrix PLearn::SparseVMatrix::inherited [private]
 

Reimplemented from PLearn::RowBufferedVMatrix.

Definition at line 70 of file SparseVMatrix.h.

Referenced by SparseVMatrix().


Constructor & Destructor Documentation

PLearn::SparseVMatrix::SparseVMatrix  )  [inline]
 

Definition at line 81 of file SparseVMatrix.h.

References nelements, positions, rows, and values.

PLearn::SparseVMatrix::SparseVMatrix VMat  m  ) 
 

This builds a sparse representation in memory of the VMat m passed as argument.

The original fieldinfos are copied as-is.

Definition at line 57 of file SparseVMatrix.cc.

References PLearn::TVec< T >::data(), inherited, PLearn::VMatrix::length(), PLearn::TVec< T >::length(), PLearn::VMat::length(), PLearn::SparseVMatrixRow::nelements, nelements, PLearn::VMFieldStat::nmissing(), PLearn::VMFieldStat::nnegative(), PLearn::VMFieldStat::npositive(), PLERROR, positions, PLearn::SparseVMatrixRow::row_startpos, rows, values, PLearn::Vec, and PLearn::VMat::width().

PLearn::SparseVMatrix::SparseVMatrix const string filename  ) 
 

This reloads a previously saved sparse VMatrix.

Definition at line 51 of file SparseVMatrix.cc.

References PLearn::load().

PLearn::SparseVMatrix::~SparseVMatrix  )  [virtual]
 

Definition at line 300 of file SparseVMatrix.cc.

References nelements, positions, rows, and values.


Member Function Documentation

void PLearn::SparseVMatrix::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 118 of file SparseVMatrix.cc.

References build_().

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

This does the actual building.

Reimplemented from PLearn::VMatrix.

Definition at line 125 of file SparseVMatrix.cc.

Referenced by build().

void PLearn::SparseVMatrix::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 131 of file SparseVMatrix.cc.

References PLearn::OptionList.

real PLearn::SparseVMatrix::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::RowBufferedVMatrix.

Definition at line 223 of file SparseVMatrix.cc.

References PLearn::TVec< T >::data(), PLearn::TVec< T >::length(), PLearn::VMatrix::length(), PLearn::SparseVMatrixRow::nelements, nelements, PLERROR, positions, PLearn::SparseVMatrixRow::row_startpos, rows, values, and PLearn::VMatrix::width().

real PLearn::SparseVMatrix::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::RowBufferedVMatrix.

Definition at line 170 of file SparseVMatrix.cc.

References PLearn::VMatrix::length(), PLearn::SparseVMatrixRow::nelements, nelements, PLERROR, positions, PLearn::SparseVMatrixRow::row_startpos, rows, values, and PLearn::VMatrix::width().

void PLearn::SparseVMatrix::getNewRow int  i,
const Vec v
const [protected, virtual]
 

This is the only method requiring implementation in subclasses.

Implements PLearn::RowBufferedVMatrix.

Definition at line 136 of file SparseVMatrix.cc.

References PLearn::TVec< T >::clear(), PLearn::TVec< T >::data(), PLearn::TVec< T >::length(), PLearn::VMatrix::length(), PLearn::SparseVMatrixRow::nelements, nelements, PLERROR, positions, PLearn::SparseVMatrixRow::row_startpos, rows, values, and PLearn::VMatrix::width().

PLearn::SparseVMatrix::PLEARN_DECLARE_OBJECT SparseVMatrix   ) 
 

virtual void PLearn::SparseVMatrix::save const string filename  )  [inline, virtual]
 

calls write

Definition at line 109 of file SparseVMatrix.h.


Member Data Documentation

int PLearn::SparseVMatrix::nelements [protected]
 

total number of non-zero elements in the VMatrix

Definition at line 73 of file SparseVMatrix.h.

Referenced by dot(), getNewRow(), SparseVMatrix(), and ~SparseVMatrix().

unsigned short* PLearn::SparseVMatrix::positions [protected]
 

Definition at line 74 of file SparseVMatrix.h.

Referenced by dot(), getNewRow(), SparseVMatrix(), and ~SparseVMatrix().

SparseVMatrixRow* PLearn::SparseVMatrix::rows [protected]
 

Definition at line 77 of file SparseVMatrix.h.

Referenced by dot(), getNewRow(), SparseVMatrix(), and ~SparseVMatrix().

float* PLearn::SparseVMatrix::values [protected]
 

Definition at line 75 of file SparseVMatrix.h.

Referenced by dot(), getNewRow(), SparseVMatrix(), and ~SparseVMatrix().


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