shark::PrecomputedMatrix< Matrix > Class Template Reference

Precomputed version of a matrix for quadratic programming. More...

#include <shark/LinAlg/PrecomputedMatrix.h>

Public Types

typedef Matrix::QpFloatType QpFloatType
 

Public Member Functions

 PrecomputedMatrix (Matrix *base)
 
void row (std::size_t k, std::size_t start, std::size_t end, QpFloatType *storage) const
 Computes the i-th row of the kernel matrix. More...
 
QpFloatTyperow (std::size_t k, std::size_t begin, std::size_t end)
 Return a subset of a matrix row. More...
 
QpFloatType operator() (std::size_t i, std::size_t j) const
 return a single matrix entry More...
 
QpFloatType entry (std::size_t i, std::size_t j) const
 return a single matrix entry More...
 
void flipColumnsAndRows (std::size_t i, std::size_t j)
 swap two variables More...
 
std::size_t size () const
 return the size of the quadratic matrix More...
 
std::size_t getMaxCacheSize ()
 for compatibility with CachedMatrix More...
 
std::size_t getCacheSize () const
 for compatibility with CachedMatrix More...
 
std::size_t getCacheRowSize (std::size_t k) const
 for compatibility with CachedMatrix More...
 
bool isCached (std::size_t)
 for compatibility with CachedMatrix More...
 
void setMaxCachedIndex (std::size_t n)
 for compatibility with CachedMatrix More...
 
void clear ()
 for compatibility with CachedMatrix More...
 

Protected Attributes

blas::matrix< QpFloatTypematrix
 container for precomputed values More...
 

Detailed Description

template<class Matrix>
class shark::PrecomputedMatrix< Matrix >

Precomputed version of a matrix for quadratic programming.

The PrecomputedMatrix class computes all pairs of kernel evaluations in its constructor and stores them im memory. This proceeding is only viable if the number of examples does not exceed, say, about 10000. In this case the memory demand is already \( 4 \cdot 10000^2 \approx 400\text{MB} \), growing quadratically.
Use of this class may be beneficial for certain model selection strategies, in particular if the kernel is fixed and the regularization parameter is varied.
Use of this class may, in certain situations, even mean a loss is speed, compared to CachedMatrix. This is the case in particular if the solution of the quadratic program is sparse, in which case most entries of the matrix do not need to be computed at all, and the problem is "simple" enough such that the solver's shrinking heuristic is not mislead.

Definition at line 77 of file PrecomputedMatrix.h.

Member Typedef Documentation

◆ QpFloatType

template<class Matrix>
typedef Matrix::QpFloatType shark::PrecomputedMatrix< Matrix >::QpFloatType

Definition at line 80 of file PrecomputedMatrix.h.

Constructor & Destructor Documentation

◆ PrecomputedMatrix()

template<class Matrix>
shark::PrecomputedMatrix< Matrix >::PrecomputedMatrix ( Matrix *  base)
inline

Constructor

Parameters
basematrix to be precomputed

Definition at line 84 of file PrecomputedMatrix.h.

References shark::PrecomputedMatrix< Matrix >::matrix.

Member Function Documentation

◆ clear()

template<class Matrix>
void shark::PrecomputedMatrix< Matrix >::clear ( )
inline

for compatibility with CachedMatrix

Definition at line 156 of file PrecomputedMatrix.h.

◆ entry()

template<class Matrix>
QpFloatType shark::PrecomputedMatrix< Matrix >::entry ( std::size_t  i,
std::size_t  j 
) const
inline

return a single matrix entry

Definition at line 120 of file PrecomputedMatrix.h.

References shark::PrecomputedMatrix< Matrix >::matrix.

Referenced by shark::PrecomputedMatrix< Matrix >::operator()().

◆ flipColumnsAndRows()

template<class Matrix>
void shark::PrecomputedMatrix< Matrix >::flipColumnsAndRows ( std::size_t  i,
std::size_t  j 
)
inline

swap two variables

Definition at line 126 of file PrecomputedMatrix.h.

References shark::PrecomputedMatrix< Matrix >::matrix.

◆ getCacheRowSize()

template<class Matrix>
std::size_t shark::PrecomputedMatrix< Matrix >::getCacheRowSize ( std::size_t  k) const
inline

for compatibility with CachedMatrix

Definition at line 145 of file PrecomputedMatrix.h.

References shark::PrecomputedMatrix< Matrix >::matrix.

◆ getCacheSize()

template<class Matrix>
std::size_t shark::PrecomputedMatrix< Matrix >::getCacheSize ( ) const
inline

for compatibility with CachedMatrix

Definition at line 141 of file PrecomputedMatrix.h.

References shark::PrecomputedMatrix< Matrix >::getMaxCacheSize().

◆ getMaxCacheSize()

template<class Matrix>
std::size_t shark::PrecomputedMatrix< Matrix >::getMaxCacheSize ( )
inline

for compatibility with CachedMatrix

Definition at line 137 of file PrecomputedMatrix.h.

References shark::PrecomputedMatrix< Matrix >::matrix.

Referenced by shark::PrecomputedMatrix< Matrix >::getCacheSize().

◆ isCached()

template<class Matrix>
bool shark::PrecomputedMatrix< Matrix >::isCached ( std::size_t  )
inline

for compatibility with CachedMatrix

Definition at line 149 of file PrecomputedMatrix.h.

◆ operator()()

template<class Matrix>
QpFloatType shark::PrecomputedMatrix< Matrix >::operator() ( std::size_t  i,
std::size_t  j 
) const
inline

return a single matrix entry

Definition at line 116 of file PrecomputedMatrix.h.

References shark::PrecomputedMatrix< Matrix >::entry().

◆ row() [1/2]

template<class Matrix>
void shark::PrecomputedMatrix< Matrix >::row ( std::size_t  k,
std::size_t  start,
std::size_t  end,
QpFloatType storage 
) const
inline

Computes the i-th row of the kernel matrix.

The entries start,...,end of the i-th row are computed and stored in storage. There must be enough room for this operation preallocated.

Definition at line 94 of file PrecomputedMatrix.h.

References shark::PrecomputedMatrix< Matrix >::matrix.

◆ row() [2/2]

template<class Matrix>
QpFloatType* shark::PrecomputedMatrix< Matrix >::row ( std::size_t  k,
std::size_t  begin,
std::size_t  end 
)
inline

Return a subset of a matrix row.

This method returns an array with at least the entries in the interval [begin, end[ filled in.
Parameters
kmatrix row
beginfirst column to be filled in
endlast column to be filled in +1

Definition at line 110 of file PrecomputedMatrix.h.

References shark::PrecomputedMatrix< Matrix >::matrix.

◆ setMaxCachedIndex()

template<class Matrix>
void shark::PrecomputedMatrix< Matrix >::setMaxCachedIndex ( std::size_t  n)
inline

for compatibility with CachedMatrix

Definition at line 153 of file PrecomputedMatrix.h.

◆ size()

template<class Matrix>
std::size_t shark::PrecomputedMatrix< Matrix >::size ( ) const
inline

return the size of the quadratic matrix

Definition at line 133 of file PrecomputedMatrix.h.

References shark::PrecomputedMatrix< Matrix >::matrix.

Member Data Documentation

◆ matrix


The documentation for this class was generated from the following file: