SHOGUN
3.2.1
|
shogun matrix
Definition at line 26 of file Parameter.h.
Public Member Functions | |
SGMatrix () | |
SGMatrix (bool ref_counting) | |
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 |
SGVector< T > | get_row_vector (index_t row) const |
SGVector< T > | get_diagonal_vector () 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) |
SGMatrix< T > | get () |
bool | operator== (SGMatrix< T > &other) |
bool | equals (SGMatrix< T > &other) |
void | set_const (T const_elem) |
void | zero () |
bool | is_symmetric () |
T | max_single () |
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 |
void | load (CFile *loader) |
void | save (CFile *saver) |
template<> | |
void | zero () |
template<> | |
bool | is_symmetric () |
template<> | |
bool | is_symmetric () |
template<> | |
bool | is_symmetric () |
template<> | |
bool | is_symmetric () |
template<> | |
complex128_t | max_single () |
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<> | |
void | display_matrix (const complex128_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_t > | create_identity_matrix (index_t size, float32_t scale) |
template<> | |
SGMatrix< float64_t > | create_identity_matrix (index_t size, float64_t scale) |
template<> | |
SGMatrix< floatmax_t > | create_identity_matrix (index_t size, floatmax_t scale) |
template<> | |
SGMatrix< complex128_t > | create_identity_matrix (index_t size, complex128_t scale) |
template<> | |
void | load (CFile *loader) |
template<> | |
void | save (CFile *saver) |
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 SGVector< float64_t > | compute_eigenvectors (SGMatrix< float64_t > matrix) |
static double * | compute_eigenvectors (double *matrix, int n, int m) |
static 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 void | inverse (SGMatrix< float64_t > matrix) |
inverses square matrix in-place More... | |
static float64_t * | pinv (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 () |
SGMatrix | ( | ) |
default constructor
Definition at line 26 of file SGMatrix.cpp.
SGMatrix | ( | bool | ref_counting | ) |
constructor for setting reference counting while not creating the matrix in memory (use this for static SGMatrix instances)
Definition at line 32 of file SGMatrix.cpp.
constructor for setting params
Definition at line 38 of file SGMatrix.cpp.
constructor to create new matrix in memory
Definition at line 43 of file SGMatrix.cpp.
copy constructor
Definition at line 50 of file SGMatrix.cpp.
|
virtual |
empty destructor
Definition at line 56 of file SGMatrix.cpp.
void center | ( | ) |
Centers the matrix, i.e. removes column/row mean from columns/rows
Definition at line 302 of file SGMatrix.cpp.
|
static |
Centers matrix (e.g. kernel matrix in feature space INPLACE
Definition at line 308 of file SGMatrix.cpp.
SGMatrix< T > clone | ( | ) |
clone matrix
Definition at line 216 of file SGMatrix.cpp.
|
static |
clone matrix
Definition at line 223 of file SGMatrix.cpp.
compute eigenvalues and eigenvectors of symmetric matrix using LAPACK
matrix | symmetric matrix to compute eigenproblem. Is overwritten and contains orthonormal eigenvectors afterwards |
Definition at line 851 of file SGMatrix.cpp.
|
static |
compute eigenvalues and eigenvectors of symmetric matrix
matrix | overwritten and contains n orthonormal eigenvectors |
n | |
m |
Definition at line 868 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
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 890 of file SGMatrix.cpp.
|
protectedvirtual |
|
protectedinherited |
copy refcount
Definition at line 55 of file SGReferencedData.cpp.
|
static |
create diagonal matrix
Definition at line 251 of file SGMatrix.cpp.
returns the identity matrix, scaled by a factor
size | size of square identity matrix |
scale | (optional) scaling factor |
Definition at line 616 of file SGMatrix.cpp.
Definition at line 623 of file SGMatrix.cpp.
Definition at line 636 of file SGMatrix.cpp.
Definition at line 649 of file SGMatrix.cpp.
Definition at line 662 of file SGMatrix.cpp.
Definition at line 675 of file SGMatrix.cpp.
Definition at line 688 of file SGMatrix.cpp.
Definition at line 701 of file SGMatrix.cpp.
Definition at line 714 of file SGMatrix.cpp.
Definition at line 727 of file SGMatrix.cpp.
Definition at line 740 of file SGMatrix.cpp.
Definition at line 753 of file SGMatrix.cpp.
SGMatrix< floatmax_t > create_identity_matrix | ( | index_t | size, |
floatmax_t | scale | ||
) |
Definition at line 766 of file SGMatrix.cpp.
SGMatrix< complex128_t > create_identity_matrix | ( | index_t | size, |
complex128_t | scale | ||
) |
Definition at line 779 of file SGMatrix.cpp.
void display_matrix | ( | const char * | name = "matrix" | ) | const |
display matrix
Definition at line 350 of file SGMatrix.cpp.
|
static |
display matrix (useful for debugging)
|
static |
display matrix
Definition at line 356 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 364 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 382 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 400 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 418 of file SGMatrix.cpp.
void display_matrix | ( | const int16_t * | matrix, |
int32_t | rows, | ||
int32_t | cols, | ||
const char * | name, | ||
const char * | prefix | ||
) |
Definition at line 436 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 454 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 473 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 491 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 508 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 526 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 544 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 562 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 580 of file SGMatrix.cpp.
void display_matrix | ( | const complex128_t * | matrix, |
int32_t | rows, | ||
int32_t | cols, | ||
const char * | name, | ||
const char * | prefix | ||
) |
Definition at line 598 of file SGMatrix.cpp.
bool equals | ( | SGMatrix< T > & | other | ) |
operator overload for element-wise matrix comparison. Note that only numerical data is compared
other | matrix to compare with |
Definition at line 74 of file SGMatrix.cpp.
|
protectedvirtual |
SGMatrix<T> get | ( | ) |
get the matrix (no copying is done here)
Definition at line 111 of file SGMatrix.h.
|
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.
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 |
Definition at line 953 of file SGMatrix.cpp.
|
static |
sums up all columns of a matrix and returns the resulting columnvector
Definition at line 289 of file SGMatrix.cpp.
T* get_column_vector | ( | index_t | col | ) | const |
SGVector< T > get_diagonal_vector | ( | ) | const |
get a main diagonal vector. Matrix is not required to be square.
Definition at line 1055 of file SGMatrix.cpp.
|
static |
sums up all rows of a matrix and returns the resulting rowvector
Definition at line 276 of file SGMatrix.cpp.
get a row vector
row | row index |
Definition at line 1044 of file SGMatrix.cpp.
|
protectedvirtual |
overridden to initialize empty data
Implements SGReferencedData.
Definition at line 991 of file SGMatrix.cpp.
inverses square matrix in-place
inverses square matrix in-place
Definition at line 841 of file SGMatrix.cpp.
bool is_symmetric | ( | ) |
Definition at line 126 of file SGMatrix.cpp.
bool is_symmetric | ( | ) |
Checks whether the matrix is symmetric or not. The equality check is performed using '==' operators for discrete types (int, char, bool) and using CMath::fequals method for floating types (float, double, long double, std::complex<double>) with default espilon values from std::numeric_limits
Definition at line 110 of file SGMatrix.cpp.
bool is_symmetric | ( | ) |
Definition at line 143 of file SGMatrix.cpp.
bool is_symmetric | ( | ) |
Definition at line 160 of file SGMatrix.cpp.
bool is_symmetric | ( | ) |
Definition at line 177 of file SGMatrix.cpp.
void load | ( | CFile * | loader | ) |
load matrix from file
loader | File object via which to load data |
Definition at line 1008 of file SGMatrix.cpp.
void load | ( | CFile * | loader | ) |
Definition at line 1023 of file SGMatrix.cpp.
|
static |
Computes scale* A*B, where A and B may be transposed. Asserts for matching inner dimensions.
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 903 of file SGMatrix.cpp.
T max_single | ( | ) |
returns the maximum single element of the matrix
Definition at line 196 of file SGMatrix.cpp.
complex128_t max_single | ( | ) |
Definition at line 209 of file SGMatrix.cpp.
operator overload for matrix read only access
i_row | |
i_col |
Definition at line 74 of file SGMatrix.h.
operator overload for matrix r/w access
i_row | |
i_col |
Definition at line 92 of file SGMatrix.h.
bool operator== | ( | SGMatrix< T > & | other | ) |
check for pointer identity
Definition at line 62 of file SGMatrix.cpp.
const T& operator[] | ( | index_t | index | ) | const |
operator overload for matrix read only access
index | to access |
Definition at line 83 of file SGMatrix.h.
T& operator[] | ( | index_t | index | ) |
operator overload for matrix r/w access
index | to access |
Definition at line 101 of file SGMatrix.h.
|
static |
return the pseudo inverse for matrix when matrix has shape (rows, cols) the pseudo inverse has (cols, rows)
Definition at line 802 of file SGMatrix.cpp.
|
protectedinherited |
increase reference counter
Definition at line 64 of file SGReferencedData.cpp.
|
inherited |
display reference counter
Definition at line 41 of file SGReferencedData.cpp.
void remove_column_mean | ( | ) |
remove column mean
Definition at line 333 of file SGMatrix.cpp.
void save | ( | CFile * | saver | ) |
save matrix to file
saver | File object via which to save data |
Definition at line 1029 of file SGMatrix.cpp.
void save | ( | CFile * | saver | ) |
Definition at line 1038 of file SGMatrix.cpp.
void set_const | ( | T | const_elem | ) |
set matrix to a constant
Definition at line 89 of file SGMatrix.cpp.
compute trace
Definition at line 266 of file SGMatrix.cpp.
|
static |
transpose matrix
Definition at line 233 of file SGMatrix.cpp.
|
protectedinherited |
decrement reference counter and deallocate object if refcount is zero before or after decrementing it
Definition at line 84 of file SGReferencedData.cpp.
void zero | ( | ) |
Definition at line 103 of file SGMatrix.cpp.
void zero | ( | ) |
fill matrix with zeros
Definition at line 96 of file SGMatrix.cpp.
T* matrix |
matrix
Definition at line 296 of file SGMatrix.h.
index_t num_cols |
number of columns of matrix
Definition at line 300 of file SGMatrix.h.
index_t num_rows |
number of rows of matrix
Definition at line 298 of file SGMatrix.h.