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

PLearn::ForwardVMatrix Class Reference

This class is a simple wrapper to an underlying VMatrix of another type All it does is forward the method calls. More...

#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)
 PLEARN_DECLARE_OBJECT (ForwardVMatrix)
virtual void build ()
 Should call simply inherited::build(), then this class's 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->value mapping for field 'fld'

virtual const map< real, string > & getRealToStringMapping (int col) const
 returns the value->string mapping for field 'fld'

virtual void computeStats ()
virtual void save (const string &filename) const
 returns the cooccurence statistics conditioned on the given field (within the ranges returned by getRanges() ) The results are cached in file stats#.psave (where # stands for the condfield index)

virtual void savePMAT (const string &pmatfile) const
virtual void saveDMAT (const string &dmatdir) const
virtual void saveAMAT (const string &amatfile) const
virtual real get (int i, int j) const
 returns element (i,j)

virtual void put (int i, int j, real value)
 sets element (i,j) to value

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 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
 copies row i into v (which must have appropriate length equal to the VMat's width)

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

virtual void getRow (int i, VarArray &inputs) const
 Assigns the value of the Vars in the list (the total size of all the vars in the list must equal width() ).

virtual void oldwrite (ostream &out) const
virtual void oldread (istream &in)
 DEPRECATED For backward compatibility with old saved object.

void makeDeepCopyFromShallowCopy (map< const void *, void * > &copies)
virtual void evaluateKernel (Ker ker, int v1_startcol, int v1_ncols, const Vec &v2, const Vec &result, int startrow=0, int nrows=-1) const
virtual real evaluateKernelSum (Ker ker, int v1_startcol, int v1_ncols, const Vec &v2, int startrow=0, int nrows=-1, int ignore_this_row=-1) const
 returns sum_i [ ker( m(i).subVec(v1_startcol,v1_ncols) , v2) ]

virtual real evaluateKernelWeightedTargetSum (Ker ker, int v1_startcol, int v1_ncols, const Vec &v2, int t_startcol, int t_ncols, Vec &targetsum, int startrow=0, int nrows=-1, int ignore_this_row=-1) const
 targetsum := sum_i [ m(i).subVec(t_startcol,t_ncols) * ker( m(i).subVec(v1_startcol,v1_ncols) , v2) ] and returns sum_i [ ker( m(i).subVec(v1_startcol,v1_ncols) , v2) ]

virtual TVec< pair< real,
int > > 
evaluateKernelTopN (int N, Ker ker, int v1_startcol, int v1_ncols, const Vec &v2, int startrow=0, int nrows=-1, int ignore_this_row=-1) const
virtual TVec< pair< real,
int > > 
evaluateKernelBottomN (int N, Ker ker, int v1_startcol, int v1_ncols, const Vec &v2, int startrow=0, int nrows=-1, int ignore_this_row=-1) const
 same as evaluateKernelTopN but will look for the N smallest values instead of top values.

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
virtual void evaluateSumOfFprop (Func f, Vec &output_result, int nsamples=-1)
 compute fprop or fbprop of a sumOf operation

virtual void evaluateSumOfFbprop (Func f, Vec &output_result, Vec &output_gradient, int nsamples=-1)

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

VMat vm

Private Types

typedef VMatrix inherited

Private Member Functions

void build_ ()
 This does the actual building.


Detailed Description

This class is a simple wrapper to an underlying VMatrix of another type All it does is forward the method calls.

Definition at line 55 of file ForwardVMatrix.h.


Member Typedef Documentation

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

Reimplemented from PLearn::VMatrix.

Reimplemented in PLearn::AutoVMatrix.

Definition at line 57 of file ForwardVMatrix.h.


Constructor & Destructor Documentation

PLearn::ForwardVMatrix::ForwardVMatrix  ) 
 

Definition at line 55 of file ForwardVMatrix.cc.

PLearn::ForwardVMatrix::ForwardVMatrix VMat  vm  ) 
 

Definition at line 58 of file ForwardVMatrix.cc.


Member Function Documentation

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

References vm.

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

References vm.

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

References vm.

void PLearn::ForwardVMatrix::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.

Reimplemented in PLearn::AutoVMatrix.

Definition at line 64 of file ForwardVMatrix.cc.

References build_().

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

This does the actual building.

Reimplemented from PLearn::VMatrix.

Reimplemented in PLearn::AutoVMatrix.

Definition at line 71 of file ForwardVMatrix.cc.

References PLearn::VMatrix::hasFieldInfos(), PLearn::VMat::length(), vm, PLearn::VMatrix::width(), and PLearn::VMat::width().

Referenced by build(), and setVMat().

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

References vm.

void PLearn::ForwardVMatrix::computeStats  )  [virtual]
 

Reimplemented from PLearn::VMatrix.

Definition at line 148 of file ForwardVMatrix.cc.

References vm.

void PLearn::ForwardVMatrix::declareOptions OptionList ol  )  [static]
 

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.

Reimplemented in PLearn::AutoVMatrix.

Definition at line 108 of file ForwardVMatrix.cc.

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

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

References vm.

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

References vm.

void PLearn::ForwardVMatrix::evaluateKernel Ker  ker,
int  v1_startcol,
int  v1_ncols,
const Vec v2,
const Vec result,
int  startrow = 0,
int  nrows = -1
const [virtual]
 

This will compute for this vmat m a result vector (whose length must be tha same as m's) s.t. result[i] = ker( m(i).subVec(v1_startcol,v1_ncols) , v2) i.e. the kernel value betweeen each (sub)row of m and v2

Reimplemented from PLearn::VMatrix.

Definition at line 235 of file ForwardVMatrix.cc.

References vm.

TVec< pair< real, int > > PLearn::ForwardVMatrix::evaluateKernelBottomN int  N,
Ker  ker,
int  v1_startcol,
int  v1_ncols,
const Vec v2,
int  startrow = 0,
int  nrows = -1,
int  ignore_this_row = -1
const [virtual]
 

same as evaluateKernelTopN but will look for the N smallest values instead of top values.

results are sorted with smallest kernel value first

Reimplemented from PLearn::VMatrix.

Definition at line 265 of file ForwardVMatrix.cc.

References vm.

real PLearn::ForwardVMatrix::evaluateKernelSum Ker  ker,
int  v1_startcol,
int  v1_ncols,
const Vec v2,
int  startrow = 0,
int  nrows = -1,
int  ignore_this_row = -1
const [virtual]
 

returns sum_i [ ker( m(i).subVec(v1_startcol,v1_ncols) , v2) ]

Reimplemented from PLearn::VMatrix.

Definition at line 241 of file ForwardVMatrix.cc.

References vm.

TVec< pair< real, int > > PLearn::ForwardVMatrix::evaluateKernelTopN int  N,
Ker  ker,
int  v1_startcol,
int  v1_ncols,
const Vec v2,
int  startrow = 0,
int  nrows = -1,
int  ignore_this_row = -1
const [virtual]
 

This will return the Top N kernel evaluated values (between vmat (sub)rows and v2) and their associated row_index. Result is returned as a vector of length N of pairs (kernel_value,row_index) Results are sorted with largest kernel value first

Reimplemented from PLearn::VMatrix.

Definition at line 258 of file ForwardVMatrix.cc.

References vm.

real PLearn::ForwardVMatrix::evaluateKernelWeightedTargetSum Ker  ker,
int  v1_startcol,
int  v1_ncols,
const Vec v2,
int  t_startcol,
int  t_ncols,
Vec targetsum,
int  startrow = 0,
int  nrows = -1,
int  ignore_this_row = -1
const [virtual]
 

targetsum := sum_i [ m(i).subVec(t_startcol,t_ncols) * ker( m(i).subVec(v1_startcol,v1_ncols) , v2) ] and returns sum_i [ ker( m(i).subVec(v1_startcol,v1_ncols) , v2) ]

Reimplemented from PLearn::VMatrix.

Definition at line 248 of file ForwardVMatrix.cc.

References vm.

void PLearn::ForwardVMatrix::evaluateSumOfFbprop Func  f,
Vec output_result,
Vec output_gradient,
int  nsamples = -1
[virtual]
 

Reimplemented from PLearn::VMatrix.

Definition at line 283 of file ForwardVMatrix.cc.

References vm.

void PLearn::ForwardVMatrix::evaluateSumOfFprop Func  f,
Vec output_result,
int  nsamples = -1
[virtual]
 

compute fprop or fbprop of a sumOf operation

Reimplemented from PLearn::VMatrix.

Definition at line 280 of file ForwardVMatrix.cc.

References vm.

void PLearn::ForwardVMatrix::fill real  value  )  [virtual]
 

Reimplemented from PLearn::VMatrix.

Definition at line 183 of file ForwardVMatrix.cc.

References vm.

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

returns element (i,j)

Reimplemented from PLearn::VMatrix.

Definition at line 163 of file ForwardVMatrix.cc.

References vm.

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

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

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

References PLearn::Mat, and vm.

const map< real, string > & PLearn::ForwardVMatrix::getRealToStringMapping int  col  )  const [virtual]
 

returns the value->string mapping for field 'fld'

Reimplemented from PLearn::VMatrix.

Definition at line 144 of file ForwardVMatrix.cc.

References vm.

void PLearn::ForwardVMatrix::getRow int  i,
VarArray inputs
const [virtual]
 

Assigns the value of the Vars in the list (the total size of all the vars in the list must equal width() ).

Reimplemented from PLearn::VMatrix.

Definition at line 227 of file ForwardVMatrix.cc.

References vm.

void PLearn::ForwardVMatrix::getRow int  i,
Vec  v
const [virtual]
 

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

Reimplemented from PLearn::VMatrix.

Definition at line 179 of file ForwardVMatrix.cc.

References vm.

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

References vm.

map< string, real > PLearn::ForwardVMatrix::getStringMapping int  col  )  const
 

returns the whole string->value mapping

Definition at line 125 of file ForwardVMatrix.cc.

References PLERROR.

const map< string, real > & PLearn::ForwardVMatrix::getStringToRealMapping int  col  )  const [virtual]
 

returns the string->value mapping for field 'fld'

Reimplemented from PLearn::VMatrix.

Definition at line 137 of file ForwardVMatrix.cc.

References vm.

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

References vm.

void PLearn::ForwardVMatrix::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 170 of file ForwardVMatrix.cc.

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

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

References val, and vm.

void PLearn::ForwardVMatrix::makeDeepCopyFromShallowCopy map< const void *, void * > &  copies  ) 
 

Reimplemented from PLearn::VMatrix.

Reimplemented in PLearn::AutoVMatrix.

Definition at line 286 of file ForwardVMatrix.cc.

References PLearn::deepCopyField(), and vm.

void PLearn::ForwardVMatrix::oldread istream &  in  )  [virtual]
 

DEPRECATED For backward compatibility with old saved object.

Reimplemented from PLearn::VMatrix.

Definition at line 232 of file ForwardVMatrix.cc.

References vm.

void PLearn::ForwardVMatrix::oldwrite ostream &  out  )  const [virtual]
 

Reimplemented from PLearn::VMatrix.

Definition at line 230 of file ForwardVMatrix.cc.

References vm.

PLearn::ForwardVMatrix::PLEARN_DECLARE_OBJECT ForwardVMatrix   ) 
 

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

sets element (i,j) to value

Reimplemented from PLearn::VMatrix.

Definition at line 167 of file ForwardVMatrix.cc.

References vm.

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

References vm.

void PLearn::ForwardVMatrix::putRow int  i,
Vec  v
[virtual]
 

Reimplemented from PLearn::VMatrix.

Definition at line 181 of file ForwardVMatrix.cc.

References vm.

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

References vm.

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

References PLearn::VMat::length(), vm, and PLearn::VMat::width().

void PLearn::ForwardVMatrix::save const string filename  )  const [virtual]
 

returns the cooccurence statistics conditioned on the given field (within the ranges returned by getRanges() ) The results are cached in file stats#.psave (where # stands for the condfield index)

Reimplemented from PLearn::VMatrix.

Definition at line 152 of file ForwardVMatrix.cc.

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

void PLearn::ForwardVMatrix::saveAMAT const string amatfile  )  const [virtual]
 

Definition at line 159 of file ForwardVMatrix.cc.

References vm.

void PLearn::ForwardVMatrix::saveDMAT const string dmatdir  )  const [virtual]
 

Reimplemented from PLearn::VMatrix.

Definition at line 157 of file ForwardVMatrix.cc.

References vm.

void PLearn::ForwardVMatrix::savePMAT const string pmatfile  )  const [virtual]
 

Reimplemented from PLearn::VMatrix.

Definition at line 155 of file ForwardVMatrix.cc.

References vm.

void PLearn::ForwardVMatrix::setVMat VMat  the_vm  ) 
 

This allows to set the underlying vmat.

Definition at line 98 of file ForwardVMatrix.cc.

References build_(), and vm.

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

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

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

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


Member Data Documentation

VMat PLearn::ForwardVMatrix::vm [protected]
 

Definition at line 60 of file ForwardVMatrix.h.

Referenced by accumulateXtX(), accumulateXtY(), appendRow(), build_(), compacify(), computeStats(), dot(), evaluateKernel(), evaluateKernelBottomN(), evaluateKernelSum(), evaluateKernelTopN(), evaluateKernelWeightedTargetSum(), evaluateSumOfFbprop(), evaluateSumOfFprop(), fill(), get(), getColumn(), getMat(), getRealToStringMapping(), getRow(), getString(), getStringToRealMapping(), getStringVal(), getSubRow(), getValString(), makeDeepCopyFromShallowCopy(), oldread(), oldwrite(), put(), putMat(), putRow(), putSubRow(), reset_dimensions(), save(), saveAMAT(), saveDMAT(), savePMAT(), setVMat(), subMat(), and toMat().


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