shark::PartlyPrecomputedMatrix< Matrix > Class Template Reference

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

#include <shark/LinAlg/PartlyPrecomputedMatrix.h>

Public Types

typedef Matrix::QpFloatType QpFloatType
 

Public Member Functions

 PartlyPrecomputedMatrix (Matrix *base, std::size_t cachesize=0x4000000)
 
bool isCached (std::size_t k) const
 
void row (std::size_t k, blas::vector< QpFloatType > &storage) const
 
QpFloatType operator() (std::size_t i, std::size_t j) const
 
QpFloatType entry (std::size_t i, std::size_t j) const
 
std::size_t size () const
 
std::size_t getMaxCacheSize ()
 
std::size_t getCacheRowSize () const
 

Protected Attributes

blas::matrix< QpFloatTypem_cachedMatrix
 container for precomputed values More...
 
size_t m_cacheSize
 
Matrix * m_baseMatrix
 
size_t m_originalNumberOfRows
 

Detailed Description

template<class Matrix>
class shark::PartlyPrecomputedMatrix< Matrix >

Partly Precomputed version of a matrix for quadratic programming.

The PartlyPrecomputedMatrix class computes all pairs of kernel evaluations that fits the given cachesize in its constructor and stores them im memory.
Use of this class may be beneficial for certain model selection strategies, where the whole matrix does not fit into memory, and the LRU cache will produce too much hit rates, so that at least partially caching the kernel matrix will help. In particular this will help the KernelSGD/Pegasos algorithm.

Definition at line 68 of file PartlyPrecomputedMatrix.h.

Member Typedef Documentation

◆ QpFloatType

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

Definition at line 71 of file PartlyPrecomputedMatrix.h.

Constructor & Destructor Documentation

◆ PartlyPrecomputedMatrix()

template<class Matrix >
shark::PartlyPrecomputedMatrix< Matrix >::PartlyPrecomputedMatrix ( Matrix *  base,
std::size_t  cachesize = 0x4000000 
)
inline

Constructor

Parameters
[in]basematrix to be cached. it is assumed that this matrix is not precomputed, but the (costy) computation takes place every time an entry is queried.
[in]cachesizesize of the cache to use in bytes. the size of the cached matrix will

Definition at line 78 of file PartlyPrecomputedMatrix.h.

References shark::PartlyPrecomputedMatrix< Matrix >::m_baseMatrix, shark::PartlyPrecomputedMatrix< Matrix >::m_cachedMatrix, shark::PartlyPrecomputedMatrix< Matrix >::m_cacheSize, shark::PartlyPrecomputedMatrix< Matrix >::m_originalNumberOfRows, SHARK_RUNTIME_CHECK, and shark::PartlyPrecomputedMatrix< Matrix >::size().

Member Function Documentation

◆ entry()

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

return a single matrix entry param[in] i row of entry param[in] j column entry

Returns
value of matrix at given position

Definition at line 168 of file PartlyPrecomputedMatrix.h.

References shark::PartlyPrecomputedMatrix< Matrix >::isCached(), shark::PartlyPrecomputedMatrix< Matrix >::m_baseMatrix, and shark::PartlyPrecomputedMatrix< Matrix >::m_cachedMatrix.

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

◆ getCacheRowSize()

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

return the dimension of a row in the cache (as we do not shorten our rows, this must be the same as the dimension of a row in the original kernel matrix).

Returns
dimension of any cached row

Definition at line 201 of file PartlyPrecomputedMatrix.h.

References shark::PartlyPrecomputedMatrix< Matrix >::m_cachedMatrix.

◆ getMaxCacheSize()

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

return size of cached matrix in QpFloatType units

Returns
the capacity of the cached matrix in QpFloatType units

Definition at line 191 of file PartlyPrecomputedMatrix.h.

References shark::PartlyPrecomputedMatrix< Matrix >::m_cachedMatrix.

◆ isCached()

template<class Matrix >
bool shark::PartlyPrecomputedMatrix< Matrix >::isCached ( std::size_t  k) const
inline

return, if a given row is cached

Parameters
[in]krow to check
Returns
is given row in cached matrix or not?

Definition at line 116 of file PartlyPrecomputedMatrix.h.

References shark::PartlyPrecomputedMatrix< Matrix >::m_cachedMatrix.

Referenced by shark::PartlyPrecomputedMatrix< Matrix >::entry(), and shark::PartlyPrecomputedMatrix< Matrix >::row().

◆ operator()()

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

return a single matrix entry param[in] i row of entry param[in] j column entry

Returns
value of matrix at given position

Definition at line 157 of file PartlyPrecomputedMatrix.h.

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

◆ row()

template<class Matrix >
void shark::PartlyPrecomputedMatrix< Matrix >::row ( std::size_t  k,
blas::vector< QpFloatType > &  storage 
) const
inline

return a complete row of the matrix. if the row is cached, it will be returned from there, if not, it will be recomputed on-the-fly and not stored. param[in] k row to compute param[in] storage vector to store the row. must be the same size as a row!

Definition at line 130 of file PartlyPrecomputedMatrix.h.

References shark::PartlyPrecomputedMatrix< Matrix >::isCached(), shark::PartlyPrecomputedMatrix< Matrix >::m_cachedMatrix, shark::PartlyPrecomputedMatrix< Matrix >::m_originalNumberOfRows, RANGE_CHECK, and SIZE_CHECK.

◆ size()

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

return the number of cached rows

Returns
number of rows that are cached

Definition at line 182 of file PartlyPrecomputedMatrix.h.

References shark::PartlyPrecomputedMatrix< Matrix >::m_cachedMatrix.

Referenced by shark::PartlyPrecomputedMatrix< Matrix >::PartlyPrecomputedMatrix().

Member Data Documentation

◆ m_baseMatrix

template<class Matrix >
Matrix* shark::PartlyPrecomputedMatrix< Matrix >::m_baseMatrix
protected

◆ m_cachedMatrix

◆ m_cacheSize

template<class Matrix >
size_t shark::PartlyPrecomputedMatrix< Matrix >::m_cacheSize
protected

◆ m_originalNumberOfRows

template<class Matrix >
size_t shark::PartlyPrecomputedMatrix< Matrix >::m_originalNumberOfRows
protected

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