Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions

SGMatrix< T > Class Template Reference


Detailed Description

template<class T>
class shogun::SGMatrix< T >

shogun matrix

Definition at line 24 of file SGMatrix.h.

Inheritance diagram for SGMatrix< T >:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 SGMatrix ()
 SGMatrix (T *m, index_t nrows, index_t ncols, bool ref_counting=true)
 SGMatrix (index_t nrows, index_t ncols, bool ref_counting=true)
 SGMatrix (const SGMatrix &orig)
virtual ~SGMatrix ()
T * get_column_vector (index_t col) const
const T & operator() (index_t i_row, index_t i_col) const
const T & operator[] (index_t index) const
T & operator() (index_t i_row, index_t i_col)
T & operator[] (index_t index)
bool operator== (SGMatrix< T > &other)
bool equals (SGMatrix< T > &other)
void set_const (T const_elem)
void zero ()
SGMatrix< T > clone ()
void compute_few_eigenvectors (double *matrix_, double *&eigenvalues, double *&eigenvectors, int n, int il, int iu)
void center ()
void remove_column_mean ()
void display_matrix (const char *name="matrix") const
template<>
void display_matrix (const bool *matrix, int32_t rows, int32_t cols, const char *name, const char *prefix)
template<>
void display_matrix (const char *matrix, int32_t rows, int32_t cols, const char *name, const char *prefix)
template<>
void display_matrix (const int8_t *matrix, int32_t rows, int32_t cols, const char *name, const char *prefix)
template<>
void display_matrix (const uint8_t *matrix, int32_t rows, int32_t cols, const char *name, const char *prefix)
template<>
void display_matrix (const int16_t *matrix, int32_t rows, int32_t cols, const char *name, const char *prefix)
template<>
void display_matrix (const uint16_t *matrix, int32_t rows, int32_t cols, const char *name, const char *prefix)
template<>
void display_matrix (const int32_t *matrix, int32_t rows, int32_t cols, const char *name, const char *prefix)
template<>
void display_matrix (const uint32_t *matrix, int32_t rows, int32_t cols, const char *name, const char *prefix)
template<>
void display_matrix (const int64_t *matrix, int32_t rows, int32_t cols, const char *name, const char *prefix)
template<>
void display_matrix (const uint64_t *matrix, int32_t rows, int32_t cols, const char *name, const char *prefix)
template<>
void display_matrix (const float32_t *matrix, int32_t rows, int32_t cols, const char *name, const char *prefix)
template<>
void display_matrix (const float64_t *matrix, int32_t rows, int32_t cols, const char *name, const char *prefix)
template<>
void display_matrix (const floatmax_t *matrix, int32_t rows, int32_t cols, const char *name, const char *prefix)
template<>
SGMatrix< char > create_identity_matrix (index_t size, char scale)
template<>
SGMatrix< int8_t > create_identity_matrix (index_t size, int8_t scale)
template<>
SGMatrix< uint8_t > create_identity_matrix (index_t size, uint8_t scale)
template<>
SGMatrix< bool > create_identity_matrix (index_t size, bool scale)
template<>
SGMatrix< int16_t > create_identity_matrix (index_t size, int16_t scale)
template<>
SGMatrix< uint16_t > create_identity_matrix (index_t size, uint16_t scale)
template<>
SGMatrix< int32_t > create_identity_matrix (index_t size, int32_t scale)
template<>
SGMatrix< uint32_t > create_identity_matrix (index_t size, uint32_t scale)
template<>
SGMatrix< int64_t > create_identity_matrix (index_t size, int64_t scale)
template<>
SGMatrix< uint64_t > create_identity_matrix (index_t size, uint64_t scale)
template<>
SGMatrix< float32_tcreate_identity_matrix (index_t size, float32_t scale)
template<>
SGMatrix< float64_tcreate_identity_matrix (index_t size, float64_t scale)
template<>
SGMatrix< floatmax_tcreate_identity_matrix (index_t size, floatmax_t scale)
int32_t ref_count ()

Static Public Member Functions

static T * clone_matrix (const T *matrix, int32_t nrows, int32_t ncols)
static void transpose_matrix (T *&matrix, int32_t &num_feat, int32_t &num_vec)
static void create_diagonal_matrix (T *matrix, T *v, int32_t size)
static SGMatrix< T > create_identity_matrix (index_t size, T scale)
static SGMatrix< float64_tcreate_centering_matrix (index_t size)
static SGVector< float64_tcompute_eigenvectors (SGMatrix< float64_t > matrix)
static double * compute_eigenvectors (double *matrix, int n, int m)
static SGMatrix< float64_tmatrix_multiply (SGMatrix< float64_t > A, SGMatrix< float64_t > B, bool transpose_A=false, bool transpose_B=false, float64_t scale=1.0)
static void inverse (SGMatrix< float64_t > matrix)
static float64_tpinv (float64_t *matrix, int32_t rows, int32_t cols, float64_t *target=NULL)
static float64_t trace (float64_t *mat, int32_t cols, int32_t rows)
static T * get_row_sum (T *matrix, int32_t m, int32_t n)
static T * get_column_sum (T *matrix, int32_t m, int32_t n)
static void center_matrix (T *matrix, int32_t m, int32_t n)
static void display_matrix (const T *matrix, int32_t rows, int32_t cols, const char *name="matrix", const char *prefix="")
static void display_matrix (const SGMatrix< T > matrix, const char *name="matrix", const char *prefix="")
static SGMatrix< T > get_allocated_matrix (index_t num_rows, index_t num_cols, SGMatrix< T > pre_allocated=SGMatrix< T >())

Public Attributes

T * matrix
index_t num_rows
index_t num_cols

Protected Member Functions

virtual void copy_data (const SGReferencedData &orig)
virtual void init_data ()
virtual void free_data ()
void copy_refcount (const SGReferencedData &orig)
int32_t ref ()
int32_t unref ()

Constructor & Destructor Documentation

SGMatrix (  ) 

default constructor

Definition at line 28 of file SGMatrix.h.

SGMatrix ( T *  m,
index_t  nrows,
index_t  ncols,
bool  ref_counting = true 
)

constructor for setting params

Definition at line 34 of file SGMatrix.h.

SGMatrix ( index_t  nrows,
index_t  ncols,
bool  ref_counting = true 
)

constructor to create new matrix in memory

Definition at line 39 of file SGMatrix.h.

SGMatrix ( const SGMatrix< T > &  orig  ) 

copy constructor

Definition at line 46 of file SGMatrix.h.

virtual ~SGMatrix (  )  [virtual]

empty destructor

Definition at line 52 of file SGMatrix.h.


Member Function Documentation

void center (  ) 

Centers the matrix, i.e. removes column/row mean from columns/rows

Definition at line 297 of file SGMatrix.h.

void center_matrix ( T *  matrix,
int32_t  m,
int32_t  n 
) [static]

Centers matrix (e.g. kernel matrix in feature space INPLACE

Definition at line 30 of file SGMatrix.cpp.

SGMatrix<T> clone (  ) 

clone matrix

Definition at line 146 of file SGMatrix.h.

static T* clone_matrix ( const T *  matrix,
int32_t  nrows,
int32_t  ncols 
) [static]

clone vector

Definition at line 153 of file SGMatrix.h.

SGVector< float64_t > compute_eigenvectors ( SGMatrix< float64_t matrix  )  [static]

compute eigenvalues and eigenvectors of symmetric matrix using LAPACK

Parameters:
matrix symmetric matrix to compute eigenproblem. Is overwritten and contains orthonormal eigenvectors afterwards
Returns:
eigenvalues vector with eigenvalues equal to number of rows in matrix

Definition at line 558 of file SGMatrix.cpp.

double * compute_eigenvectors ( double *  matrix,
int  n,
int  m 
) [static]

compute eigenvalues and eigenvectors of symmetric matrix

Parameters:
matrix overwritten and contains n orthonormal eigenvectors
n 
m 
Returns:
eigenvalues (array of length n, to be deleted[])

Definition at line 575 of file SGMatrix.cpp.

void compute_few_eigenvectors ( double *  matrix_,
double *&  eigenvalues,
double *&  eigenvectors,
int  n,
int  il,
int  iu 
)

compute few eigenpairs of a symmetric matrix using LAPACK DSYEVR method (Relatively Robust Representations). Has at least O(n^3/3) complexity

Parameters:
matrix_ symmetric matrix
eigenvalues contains iu-il+1 eigenvalues in ascending order (to be free'd)
eigenvectors contains iu-il+1 orthonormal eigenvectors of given matrix column-wise (to be free'd)
n dimension of matrix
il low index of requested eigenpairs (1<=il<=n)
iu high index of requested eigenpairs (1<=il<=iu<=n)

Definition at line 597 of file SGMatrix.cpp.

virtual void copy_data ( const SGReferencedData orig  )  [protected, virtual]

needs to be overridden to copy data

Implements SGReferencedData.

Definition at line 337 of file SGMatrix.h.

void copy_refcount ( const SGReferencedData orig  )  [protected, inherited]

copy refcount

Definition at line 102 of file SGReferencedData.h.

SGMatrix< float64_t > create_centering_matrix ( index_t  size  )  [static]

returns the centering matrix, given by H=I-1/n*O, where I is the identity matrix, O is a square matrix of ones of size n Multiplied from the left hand side, subtracts from each column its mean. Multiplied from the right hand side, subtracts from each row its mean (so from each dimension of a SHOGUN feature)

Note that H*H=H=H^T

Parameters:
size size of centering matrix

Definition at line 484 of file SGMatrix.cpp.

static void create_diagonal_matrix ( T *  matrix,
T *  v,
int32_t  size 
) [static]

create diagonal matrix

Definition at line 167 of file SGMatrix.h.

SGMatrix< float64_t > create_identity_matrix ( index_t  size,
float64_t  scale 
)

Definition at line 457 of file SGMatrix.cpp.

SGMatrix< uint32_t > create_identity_matrix ( index_t  size,
uint32_t  scale 
)

Definition at line 405 of file SGMatrix.cpp.

SGMatrix< char > create_identity_matrix ( index_t  size,
char  scale 
)

Definition at line 320 of file SGMatrix.cpp.

SGMatrix< int8_t > create_identity_matrix ( index_t  size,
int8_t  scale 
)

Definition at line 327 of file SGMatrix.cpp.

SGMatrix< uint8_t > create_identity_matrix ( index_t  size,
uint8_t  scale 
)

Definition at line 340 of file SGMatrix.cpp.

SGMatrix< bool > create_identity_matrix ( index_t  size,
bool  scale 
)

Definition at line 353 of file SGMatrix.cpp.

SGMatrix< int16_t > create_identity_matrix ( index_t  size,
int16_t  scale 
)

Definition at line 366 of file SGMatrix.cpp.

SGMatrix< uint16_t > create_identity_matrix ( index_t  size,
uint16_t  scale 
)

Definition at line 379 of file SGMatrix.cpp.

SGMatrix< int32_t > create_identity_matrix ( index_t  size,
int32_t  scale 
)

Definition at line 392 of file SGMatrix.cpp.

SGMatrix< int64_t > create_identity_matrix ( index_t  size,
int64_t  scale 
)

Definition at line 418 of file SGMatrix.cpp.

SGMatrix< uint64_t > create_identity_matrix ( index_t  size,
uint64_t  scale 
)

Definition at line 431 of file SGMatrix.cpp.

SGMatrix< float32_t > create_identity_matrix ( index_t  size,
float32_t  scale 
)

Definition at line 444 of file SGMatrix.cpp.

SGMatrix< floatmax_t > create_identity_matrix ( index_t  size,
floatmax_t  scale 
)

Definition at line 470 of file SGMatrix.cpp.

static SGMatrix<T> create_identity_matrix ( index_t  size,
scale 
) [static]

returns the identity matrix, scaled by a factor

Parameters:
size size of square identity matrix
scale (optional) scaling factor
static void display_matrix ( const T *  matrix,
int32_t  rows,
int32_t  cols,
const char *  name = "matrix",
const char *  prefix = "" 
) [static]

display matrix (useful for debugging)

void display_matrix ( const int16_t *  matrix,
int32_t  rows,
int32_t  cols,
const char *  name,
const char *  prefix 
)

Definition at line 158 of file SGMatrix.cpp.

void display_matrix ( const bool *  matrix,
int32_t  rows,
int32_t  cols,
const char *  name,
const char *  prefix 
)

Definition at line 86 of file SGMatrix.cpp.

void display_matrix ( const char *  matrix,
int32_t  rows,
int32_t  cols,
const char *  name,
const char *  prefix 
)

Definition at line 104 of file SGMatrix.cpp.

void display_matrix ( const int8_t *  matrix,
int32_t  rows,
int32_t  cols,
const char *  name,
const char *  prefix 
)

Definition at line 122 of file SGMatrix.cpp.

void display_matrix ( const uint8_t *  matrix,
int32_t  rows,
int32_t  cols,
const char *  name,
const char *  prefix 
)

Definition at line 140 of file SGMatrix.cpp.

void display_matrix ( const uint16_t *  matrix,
int32_t  rows,
int32_t  cols,
const char *  name,
const char *  prefix 
)

Definition at line 176 of file SGMatrix.cpp.

void display_matrix ( const int32_t *  matrix,
int32_t  rows,
int32_t  cols,
const char *  name,
const char *  prefix 
)

Definition at line 195 of file SGMatrix.cpp.

void display_matrix ( const uint32_t *  matrix,
int32_t  rows,
int32_t  cols,
const char *  name,
const char *  prefix 
)

Definition at line 213 of file SGMatrix.cpp.

void display_matrix ( const uint64_t *  matrix,
int32_t  rows,
int32_t  cols,
const char *  name,
const char *  prefix 
)

Definition at line 248 of file SGMatrix.cpp.

void display_matrix ( const float32_t matrix,
int32_t  rows,
int32_t  cols,
const char *  name,
const char *  prefix 
)

Definition at line 266 of file SGMatrix.cpp.

void display_matrix ( const float64_t matrix,
int32_t  rows,
int32_t  cols,
const char *  name,
const char *  prefix 
)

Definition at line 284 of file SGMatrix.cpp.

void display_matrix ( const floatmax_t matrix,
int32_t  rows,
int32_t  cols,
const char *  name,
const char *  prefix 
)

Definition at line 302 of file SGMatrix.cpp.

void display_matrix ( const char *  name = "matrix"  )  const

display matrix

Definition at line 72 of file SGMatrix.cpp.

void display_matrix ( const int64_t *  matrix,
int32_t  rows,
int32_t  cols,
const char *  name,
const char *  prefix 
)

Definition at line 230 of file SGMatrix.cpp.

void display_matrix ( const SGMatrix< T >  matrix,
const char *  name = "matrix",
const char *  prefix = "" 
) [static]

display matrix

Definition at line 78 of file SGMatrix.cpp.

bool equals ( SGMatrix< T > &  other  ) 

operator overload for element-wise matrix comparison. Note that only numerical data is compared

Parameters:
other matrix to compare with
Returns:
true iff all elements are equal

Definition at line 117 of file SGMatrix.h.

virtual void free_data (  )  [protected, virtual]

needs to be overridden to free data

Implements SGReferencedData.

Definition at line 353 of file SGMatrix.h.

SGMatrix< T > get_allocated_matrix ( index_t  num_rows,
index_t  num_cols,
SGMatrix< T >  pre_allocated = SGMatrix<T>() 
) [static]

Simple helper method that returns a matrix with allocated memory for a given size. A pre_allocated one can optionally be specified in order to use that. Basically just for having dimension check encapsulated.

Parameters:
num_rows rows of returned matrix
num_cols columns of returned matrix
pre_allocated optional matrix that is returned instead of new matrix. Make sure dimensions match
Returns:
matrix with allocated memory of specified size

Definition at line 653 of file SGMatrix.cpp.

static T* get_column_sum ( T *  matrix,
int32_t  m,
int32_t  n 
) [static]

sums up all columns of a matrix and returns the resulting columnvector

Definition at line 284 of file SGMatrix.h.

T* get_column_vector ( index_t  col  )  const

get a column vector

Parameters:
col column index

Definition at line 60 of file SGMatrix.h.

static T* get_row_sum ( T *  matrix,
int32_t  m,
int32_t  n 
) [static]

sums up all rows of a matrix and returns the resulting rowvector

Definition at line 271 of file SGMatrix.h.

virtual void init_data (  )  [protected, virtual]

needs to be overridden to initialize empty data

Implements SGReferencedData.

Definition at line 345 of file SGMatrix.h.

void inverse ( SGMatrix< float64_t matrix  )  [static]

inverses square matrix in-place

Definition at line 548 of file SGMatrix.cpp.

SGMatrix< float64_t > matrix_multiply ( SGMatrix< float64_t A,
SGMatrix< float64_t B,
bool  transpose_A = false,
bool  transpose_B = false,
float64_t  scale = 1.0 
) [static]

Computes scale* A*B, where A and B may be transposed. Asserts for matching inner dimensions.

Parameters:
A matrix A
transpose_A optional whether A should be transposed before
B matrix B
transpose_B optional whether B should be transposed before
scale optional scaling factor for result

Definition at line 610 of file SGMatrix.cpp.

T& operator() ( index_t  i_row,
index_t  i_col 
)

operator overload for matrix r/w access

Parameters:
i_row 
i_col 

Definition at line 86 of file SGMatrix.h.

const T& operator() ( index_t  i_row,
index_t  i_col 
) const

operator overload for matrix read only access

Parameters:
i_row 
i_col 

Definition at line 69 of file SGMatrix.h.

bool operator== ( SGMatrix< T > &  other  ) 

check for pointer identity

Definition at line 100 of file SGMatrix.h.

T& operator[] ( index_t  index  ) 

operator overload for matrix r/w access

Parameters:
index to access

Definition at line 94 of file SGMatrix.h.

const T& operator[] ( index_t  index  )  const

operator overload for matrix read only access

Parameters:
index to access

Definition at line 77 of file SGMatrix.h.

float64_t * pinv ( float64_t matrix,
int32_t  rows,
int32_t  cols,
float64_t target = NULL 
) [static]

return the pseudo inverse for matrix when matrix has shape (rows, cols) the pseudo inverse has (cols, rows)

Definition at line 509 of file SGMatrix.cpp.

int32_t ref (  )  [protected, inherited]

increase reference counter

Returns:
reference count

Definition at line 111 of file SGReferencedData.h.

int32_t ref_count (  )  [inherited]

display reference counter

Returns:
reference count

Definition at line 81 of file SGReferencedData.h.

void remove_column_mean (  ) 

remove column mean

Definition at line 55 of file SGMatrix.cpp.

void set_const ( const_elem  ) 

set matrix to a constant

Definition at line 132 of file SGMatrix.h.

static float64_t trace ( float64_t mat,
int32_t  cols,
int32_t  rows 
) [static]

compute trace

Definition at line 261 of file SGMatrix.h.

void transpose_matrix ( T *&  matrix,
int32_t &  num_feat,
int32_t &  num_vec 
) [static]

transpose matrix

Definition at line 12 of file SGMatrix.cpp.

int32_t unref (  )  [protected, inherited]

decrement reference counter and deallocate object if refcount is zero before or after decrementing it

Returns:
reference count

Definition at line 136 of file SGReferencedData.h.

void zero (  ) 

fill matrix with zeros

Definition at line 139 of file SGMatrix.h.


Member Data Documentation

T* matrix

matrix

Definition at line 363 of file SGMatrix.h.

number of columns of matrix

Definition at line 367 of file SGMatrix.h.

number of rows of matrix

Definition at line 365 of file SGMatrix.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation