CachedMatrix Class Reference

Efficient quadratic matrix cache. More...

#include <QuadraticProgram.h>

Inheritance diagram for CachedMatrix:

QPMatrix

List of all members.

Classes

struct  tCacheEntry

Public Member Functions

 CachedMatrix (QPMatrix *base, unsigned int cachesize=0x4000000)
 Constructor.
 ~CachedMatrix ()
 Destructor.
float * Row (unsigned int k, unsigned int begin, unsigned int end, bool temp=false)
 Return a subset of a matrix row.
float Entry (unsigned int i, unsigned int j)
 overriden virtual function
void FlipColumnsAndRows (unsigned int i, unsigned int j)
 Exchange the rows i and j and the columns i and j.
unsigned int getMaxCacheSize () const
unsigned int getCacheSize () const
unsigned int getCacheRowSize (unsigned int k)
void Clear ()
void CacheRowResize (unsigned int k, unsigned int newsize)
void CacheRowRelease (unsigned int k)

Protected Member Functions

void cacheAppend (int var)
 append the entry to the ordered list
void cacheRemove (int var)
 remove the entry from the ordered list
void cacheAdd (int var, unsigned int length)
 add an entry to the cache and append it to the ordered list
void cacheDelete (int var)
 remove an entry from the cache and the ordered list
void cacheResize (int var, unsigned int newlength)
 resize a cache entry
void cacheClear ()
 completely clear the cache

Protected Attributes

QPMatrixbaseMatrix
 matrix to be cached
unsigned int cacheSize
unsigned int cacheMaxSize
std::vector< tCacheEntrycacheEntry
std::vector< float > cacheTemp
int cacheNewest
int cacheOldest


Detailed Description

Efficient quadratic matrix cache.

The access operations of the CachedMatrix class are specially tuned towards the iterative solution of quadratic programs resulting in sparse solutions.
In contrast to the QPMatrix base class, the desired access operation is Row. Algorithms should try to rely on the Row method for retreiving matrix values because the Entry method does not cache its computations.

Definition at line 289 of file QuadraticProgram.h.


Constructor & Destructor Documentation

CachedMatrix::CachedMatrix ( QPMatrix base,
unsigned int  cachesize = 0x4000000 
)

Constructor.

Parameters:
base Matrix to cache
cachesize Main memory to use as a kernel cache, in floats. Default is 256MB

Definition at line 242 of file QuadraticProgram.cpp.

References baseMatrix, cacheEntry, cacheMaxSize, cacheNewest, cacheOldest, cacheSize, i, and QPMatrix::matrixsize.

CachedMatrix::~CachedMatrix (  ) 

Destructor.

Definition at line 265 of file QuadraticProgram.cpp.

References cacheClear().


Member Function Documentation

void CachedMatrix::cacheAdd ( int  var,
unsigned int  length 
) [protected]

add an entry to the cache and append it to the ordered list

Definition at line 425 of file QuadraticProgram.cpp.

References cacheAppend(), cacheEntry, and cacheSize.

Referenced by CacheRowResize(), and Row().

void CachedMatrix::cacheAppend ( int  var  )  [protected]

append the entry to the ordered list

Definition at line 391 of file QuadraticProgram.cpp.

References cacheEntry, cacheNewest, and cacheOldest.

Referenced by cacheAdd(), and Row().

void CachedMatrix::cacheClear (  )  [protected]

completely clear the cache

Definition at line 456 of file QuadraticProgram.cpp.

References cacheEntry, cacheNewest, cacheOldest, and cacheSize.

Referenced by Clear(), and ~CachedMatrix().

void CachedMatrix::cacheDelete ( int  var  )  [protected]

remove an entry from the cache and the ordered list

Definition at line 435 of file QuadraticProgram.cpp.

References cacheEntry, cacheRemove(), and cacheSize.

Referenced by CacheRowRelease(), and Row().

void CachedMatrix::cacheRemove ( int  var  )  [protected]

remove the entry from the ordered list

Definition at line 409 of file QuadraticProgram.cpp.

References cacheEntry, cacheNewest, and cacheOldest.

Referenced by cacheDelete(), and Row().

void CachedMatrix::cacheResize ( int  var,
unsigned int  newlength 
) [protected]

resize a cache entry

Definition at line 446 of file QuadraticProgram.cpp.

References cacheEntry, and cacheSize.

Referenced by CacheRowResize(), and Row().

void CachedMatrix::CacheRowRelease ( unsigned int  k  ) 

void CachedMatrix::CacheRowResize ( unsigned int  k,
unsigned int  newsize 
)

void CachedMatrix::Clear (  )  [inline]

Definition at line 345 of file QuadraticProgram.h.

References cacheClear().

float CachedMatrix::Entry ( unsigned int  i,
unsigned int  j 
) [virtual]

void CachedMatrix::FlipColumnsAndRows ( unsigned int  i,
unsigned int  j 
) [virtual]

Exchange the rows i and j and the columns i and j.

W.l.o.g. it is assumed that $ i \leq j $. It may be advantageous for caching to reorganize the column order. In order to keep symmetric matrices symmetric the rows are swapped, too.
Parameters:
i first row/column index
j second row/column index

Implements QPMatrix.

Definition at line 334 of file QuadraticProgram.cpp.

References baseMatrix, cacheEntry, cacheNewest, cacheOldest, QPMatrix::Entry(), QPMatrix::FlipColumnsAndRows(), QPMatrix::matrixsize, and XCHG_V.

Referenced by QpCrammerSingerDecomp::DeactivateExample(), QpBoxAllInOneDecomp::DeactivateExample(), QpBoxDecomp::FlipCoordinates(), and QpSvmDecomp::FlipCoordinates().

unsigned int CachedMatrix::getCacheRowSize ( unsigned int  k  )  [inline]

unsigned int CachedMatrix::getCacheSize (  )  const [inline]

Definition at line 335 of file QuadraticProgram.h.

References cacheSize.

unsigned int CachedMatrix::getMaxCacheSize (  )  const [inline]

Definition at line 330 of file QuadraticProgram.h.

References cacheMaxSize.

Referenced by QpSvmDecomp::SelectWSS().

float * CachedMatrix::Row ( unsigned int  k,
unsigned int  begin,
unsigned int  end,
bool  temp = false 
)

Return a subset of a matrix row.

This method returns an array of float with at least the entries in the interval [begin, end[ filled in. If temp is set to true, the computed values are not stored in the cache.
Parameters:
k matrix row
begin first column to be filled in
end last column to be filled in +1
temp are the return values temporary or should they be cached?

Definition at line 271 of file QuadraticProgram.cpp.

References baseMatrix, cacheAdd(), cacheAppend(), cacheDelete(), cacheEntry, cacheMaxSize, cacheNewest, cacheOldest, cacheRemove(), cacheResize(), cacheSize, cacheTemp, and QPMatrix::Entry().

Referenced by QpSvmDecomp::ComputeInnerProduct(), QpBoxAllInOneDecomp::Continue(), QpSvmDecomp::HMG(), QpSvmDecomp::Libsvm28(), QpBoxDecomp::SMO(), QpCrammerSingerDecomp::Solve(), QpBoxAllInOneDecomp::Solve(), QpBoxDecomp::Solve(), QpSvmDecomp::Solve(), QpCrammerSingerDecomp::Unshrink(), QpBoxAllInOneDecomp::Unshrink(), QpBoxDecomp::Unshrink(), and QpSvmDecomp::Unshrink().


Member Data Documentation

matrix to be cached

Definition at line 353 of file QuadraticProgram.h.

Referenced by CachedMatrix(), Entry(), FlipColumnsAndRows(), and Row().

std::vector<tCacheEntry> CachedMatrix::cacheEntry [protected]

unsigned int CachedMatrix::cacheMaxSize [protected]

Definition at line 357 of file QuadraticProgram.h.

Referenced by CachedMatrix(), getMaxCacheSize(), and Row().

int CachedMatrix::cacheNewest [protected]

int CachedMatrix::cacheOldest [protected]

unsigned int CachedMatrix::cacheSize [protected]

std::vector<float> CachedMatrix::cacheTemp [protected]

Definition at line 366 of file QuadraticProgram.h.

Referenced by Row().


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