SHOGUN  6.1.3
Namespaces | Classes | Enumerations | Functions
shogun::linalg Namespace Reference

Namespaces

 ocl
 
 operations
 
 util
 

Classes

struct  Block
 Generic class Block which wraps a matrix class and contains block specific information, providing a uniform way to deal with matrix blocks for all supported backend matrices. More...
 

Enumerations

enum  SVDAlgorithm { BidiagonalDivideConquer, Jacobi }
 

Functions

template<class Matrix >
Block< Matrix > block (Matrix matrix, index_t row_begin, index_t col_begin, index_t row_size, index_t col_size)
 
template<typename T , template< typename > class Container>
LinalgBackendBaseinfer_backend (const Container< T > &a)
 
template<typename T , template< typename > class Container>
LinalgBackendBaseinfer_backend (const Container< T > &a, const Container< T > &b)
 
template<typename T >
void to_gpu (SGVector< T > &a, SGVector< T > &b)
 
template<typename T >
void to_gpu (SGMatrix< T > &a, SGMatrix< T > &b)
 
template<typename T , template< typename > class Container>
void to_gpu (Container< T > &a)
 
template<typename T >
void from_gpu (SGVector< T > &a, SGVector< T > &b)
 
template<typename T >
void from_gpu (SGMatrix< T > &a, SGMatrix< T > &b)
 
template<typename T , template< typename > class Container>
void from_gpu (Container< T > &a)
 
template<typename T >
void add (SGVector< T > &a, SGVector< T > &b, SGVector< T > &result, T alpha=1, T beta=1)
 
template<typename T >
void add (SGMatrix< T > &a, SGMatrix< T > &b, SGMatrix< T > &result, T alpha=1, T beta=1)
 
template<typename T , template< typename > class Container>
Container< T > add (Container< T > &a, Container< T > &b, T alpha=1, T beta=1)
 
template<typename T >
void add_col_vec (const SGMatrix< T > &A, index_t i, const SGVector< T > &b, SGMatrix< T > &result, T alpha=1, T beta=1)
 
template<typename T >
void add_col_vec (const SGMatrix< T > &A, index_t i, const SGVector< T > &b, SGVector< T > &result, T alpha=1, T beta=1)
 
template<typename T >
void add_vector (const SGMatrix< T > &A, const SGVector< T > &b, SGMatrix< T > &result, T alpha=1, T beta=1)
 
template<typename T , template< typename > class Container>
void add_scalar (Container< T > &a, T b)
 
template<typename T >
void center_matrix (SGMatrix< T > &A)
 
template<typename T >
void dger (T alpha, const SGVector< T > x, const SGVector< T > y, SGMatrix< T > &A)
 
template<typename T >
SGMatrix< T > cholesky_factor (const SGMatrix< T > &A, const bool lower=true)
 
template<typename T >
SGVector< T > cholesky_solver (const SGMatrix< T > &L, const SGVector< T > &b, const bool lower=true)
 
template<typename T >
dot (const SGVector< T > &a, const SGVector< T > &b)
 
template<typename T >
void eigen_solver (const SGMatrix< T > &A, SGVector< T > &eigenvalues, SGMatrix< T > &eigenvectors)
 
template<typename T >
void eigen_solver_symmetric (const SGMatrix< T > &A, SGVector< T > &eigenvalues, SGMatrix< T > &eigenvectors, index_t k=0)
 
template<typename T >
void element_prod (Block< SGMatrix< T >> &a, Block< SGMatrix< T >> &b, SGMatrix< T > &result)
 
template<typename T >
SGMatrix< T > element_prod (Block< SGMatrix< T >> &a, Block< SGMatrix< T >> &b)
 
template<typename T >
void element_prod (SGMatrix< T > &a, SGMatrix< T > &b, SGMatrix< T > &result)
 
template<typename T >
SGMatrix< T > element_prod (SGMatrix< T > &a, SGMatrix< T > &b)
 
template<typename T , template< typename > class Container>
Container< T > exponent (const Container< T > &a)
 
template<typename T >
void identity (SGMatrix< T > &identity_matrix)
 
template<typename T >
void matrix_prod (SGMatrix< T > &A, SGVector< T > &b, SGVector< T > &result, bool transpose=false)
 
template<typename T >
SGVector< T > matrix_prod (SGMatrix< T > &A, SGVector< T > &b, bool transpose=false)
 
template<typename T >
void matrix_prod (SGMatrix< T > &A, SGMatrix< T > &B, SGMatrix< T > &result, bool transpose_A=false, bool transpose_B=false)
 
template<typename T >
SGMatrix< T > matrix_prod (SGMatrix< T > &A, SGMatrix< T > &B, bool transpose_A=false, bool transpose_B=false)
 
template<typename T >
void dgemv (T alpha, SGMatrix< T > a, bool transpose, SGVector< T > x, T beta, SGVector< T > &y)
 
template<typename T >
void dgemm (T alpha, SGMatrix< T > a, SGMatrix< T > b, bool transpose_a, bool transpose_b, T beta, SGMatrix< T > &c)
 
template<typename T , template< typename > class Container>
max (const Container< T > &a)
 
template<typename T , template< typename > class Container>
std::enable_if<!std::is_same< T, complex128_t >::value, float64_t >::type mean (const Container< T > &a)
 
template<template< typename > class Container>
complex128_t mean (const Container< complex128_t > &a)
 
template<typename T >
norm (const SGVector< T > &a)
 
template<typename T , template< typename > class Container>
Container< T > qr_solver (const SGMatrix< T > &A, const Container< T > &b)
 
template<typename T , template< typename > class Container>
void range_fill (Container< T > &a, const T start=0)
 
template<typename T >
void scale (SGVector< T > &a, SGVector< T > &result, T alpha=1)
 
template<typename T >
void scale (SGMatrix< T > &A, SGMatrix< T > &result, T alpha=1)
 
template<typename T , template< typename > class Container>
Container< T > scale (Container< T > &a, T alpha=1)
 
template<typename T , template< typename > class Container>
void set_const (Container< T > &a, T value)
 
template<typename T , template< typename > class Container>
sum (const Container< T > &a, bool no_diag=false)
 
template<typename T >
sum (const Block< SGMatrix< T >> &a, bool no_diag=false)
 
template<typename T >
sum_symmetric (const SGMatrix< T > &a, bool no_diag=false)
 
template<typename T >
sum_symmetric (const Block< SGMatrix< T >> &a, bool no_diag=false)
 
template<typename T >
SGVector< T > colwise_sum (const SGMatrix< T > &mat, bool no_diag=false)
 
template<typename T >
SGVector< T > colwise_sum (const Block< SGMatrix< T >> &a, bool no_diag=false)
 
template<typename T >
SGVector< T > rowwise_sum (const SGMatrix< T > &mat, bool no_diag=false)
 
template<typename T >
SGVector< T > rowwise_sum (const Block< SGMatrix< T >> &a, bool no_diag=false)
 
template<typename T >
void svd (const SGMatrix< T > &A, SGVector< T > &s, SGMatrix< T > &U, bool thin_U=true, SVDAlgorithm alg=SVDAlgorithm::BidiagonalDivideConquer)
 
template<typename T >
trace (const SGMatrix< T > &A)
 
template<typename T >
SGMatrix< T > transpose_matrix (const SGMatrix< T > &A)
 
template<typename T , template< typename > class Container>
Container< T > triangular_solver (const SGMatrix< T > &L, const Container< T > &b, const bool lower=true)
 
template<typename T , template< typename > class Container>
void zero (Container< T > &a)
 
template<typename T >
void logistic (SGMatrix< T > &a, SGMatrix< T > &result)
 
template<typename T >
void multiply_by_logistic_derivative (SGMatrix< T > &a, SGMatrix< T > &result)
 
template<typename T >
void multiply_by_rectified_linear_derivative (SGMatrix< T > &a, SGMatrix< T > &result)
 
template<typename T >
void rectified_linear (SGMatrix< T > &a, SGMatrix< T > &result)
 
template<typename T >
void softmax (SGMatrix< T > &a)
 
template<typename T >
cross_entropy (const SGMatrix< T > p, const SGMatrix< T > q)
 
template<typename T >
squared_error (const SGMatrix< T > p, const SGMatrix< T > q)
 

Enumeration Type Documentation

◆ SVDAlgorithm

enum SVDAlgorithm
strong

Enum for choosing the algorithm used to calculate SVD. The bidiagonal divide and conquer algorithm is faster on large matrices but it's available with Eigen >= 3.3, furthermore it may produce inaccurate results when compiled with unsafe math optimization. For more details see: https://eigen.tuxfamily.org/dox/classEigen_1_1BDCSVD.html https://eigen.tuxfamily.org/dox/classEigen_1_1JacobiSVD.html

Enumerator
BidiagonalDivideConquer 
Jacobi 

Definition at line 51 of file LinalgEnums.h.

Function Documentation

◆ add() [1/3]

void shogun::linalg::add ( SGVector< T > &  a,
SGVector< T > &  b,
SGVector< T > &  result,
alpha = 1,
beta = 1 
)

Performs the operation result = alpha * a + beta * b on vectors. This version returns the result in-place. User should pass an appropriately pre-allocated memory matrix Or pass one of the operands arguments (A or B) as a result

Parameters
aFirst vector
bSecond vector
resultThe vector that saves the result
alphaConstant to be multiplied by the first vector
betaConstant to be multiplied by the second vector

Definition at line 298 of file LinalgNamespace.h.

◆ add() [2/3]

void shogun::linalg::add ( SGMatrix< T > &  a,
SGMatrix< T > &  b,
SGMatrix< T > &  result,
alpha = 1,
beta = 1 
)

Performs the operation result = alpha * a + beta * b on matrices. This version returns the result in-place. User should pass an appropriately pre-allocated memory matrix Or pass one of the operands arguments (A or B) as a result

Parameters
aFirst matrix
bSecond matrix
resultThe matrix that saves the result
alphaConstant to be multiplied by the first matrix
betaConstant to be multiplied by the second matrix

Definition at line 338 of file LinalgNamespace.h.

◆ add() [3/3]

Container<T> shogun::linalg::add ( Container< T > &  a,
Container< T > &  b,
alpha = 1,
beta = 1 
)

Performs the operation C = alpha * A + beta * B. This version returns the result in a newly created vector or matrix.

Parameters
aFirst vector or matrix
bSecond vector or matrix
alphaConstant to be multiplied by the first vector or matrix
betaConstant to be multiplied by the second vector or matrix
Returns
The result vector or matrix

Definition at line 376 of file LinalgNamespace.h.

◆ add_col_vec() [1/2]

void shogun::linalg::add_col_vec ( const SGMatrix< T > &  A,
index_t  i,
const SGVector< T > &  b,
SGMatrix< T > &  result,
alpha = 1,
beta = 1 
)

Performs the operation result.col(i) = alpha * A.col(i) + beta * b. User should pass an appropriately pre-allocated memory matrix Or pass the operand argument A as a result.

Parameters
AThe matrix
bThe vector
resultThe matrix that saves the result
alphaConstant to be multiplied by the matrix
betaConstant to be multiplied by the vector

Definition at line 395 of file LinalgNamespace.h.

◆ add_col_vec() [2/2]

void shogun::linalg::add_col_vec ( const SGMatrix< T > &  A,
index_t  i,
const SGVector< T > &  b,
SGVector< T > &  result,
alpha = 1,
beta = 1 
)

Performs the operation result = alpha * A.col(i) + beta * b. User should pass an appropriately pre-allocated vector Or pass the operand argument b as a result.

Parameters
AThe matrix
bThe vector
resultThe vector that saves the result
alphaConstant to be multiplied by the matrix
betaConstant to be multiplied by the vector

Definition at line 427 of file LinalgNamespace.h.

◆ add_scalar()

void shogun::linalg::add_scalar ( Container< T > &  a,
b 
)

Adds a scalar to each element of a vector or a matrix in-place.

Parameters
aVector or matrix
bScalar to be added

Definition at line 484 of file LinalgNamespace.h.

◆ add_vector()

void shogun::linalg::add_vector ( const SGMatrix< T > &  A,
const SGVector< T > &  b,
SGMatrix< T > &  result,
alpha = 1,
beta = 1 
)

Performs the operation result = alpha * A.col(i) + beta * b, for each column of A. User should pass an appropriately pre-allocated memory matrix or pass the operand argument A as a result.

Parameters
AThe matrix
bThe vector
resultThe matrix that saves the result
alphaConstant to be multiplied by the matrix
betaConstant to be multiplied by the vector

Definition at line 460 of file LinalgNamespace.h.

◆ block()

Block<Matrix> shogun::linalg::block ( Matrix  matrix,
index_t  row_begin,
index_t  col_begin,
index_t  row_size,
index_t  col_size 
)

Method that returns a block object. Suited for Eigen3/SGMatrix

Parameters
matrixthe matrix on which the block is defined
row_beginthe row index at which the block starts
col_beginthe col index at which the block starts
row_sizethe number of rows in the block
col_sizethe number of cols in the block
Returns
a block object on this matrix

Definition at line 105 of file mathematics/linalg/internal/Block.h.

◆ center_matrix()

void shogun::linalg::center_matrix ( SGMatrix< T > &  A)

Centers a square matrix in-place, i.e. removes column/row mean from columns/rows. In particular it computes A = A - 1N*A - A*1N + 1N*A*1N where 1N denotes the matrix of the same size as A for which each element takes value 1/n, where n is the number of columns and rows of A.

Parameters
AThe matrix to be centered

Definition at line 500 of file LinalgNamespace.h.

◆ cholesky_factor()

SGMatrix<T> shogun::linalg::cholesky_factor ( const SGMatrix< T > &  A,
const bool  lower = true 
)

Compute the cholesky decomposition \(A = L L^{*}\) or \(A = U^{*} U\) of a Hermitian positive definite matrix

Parameters
AThe matrix whose cholesky decomposition is to be computed
lowerWhether to compute the upper or lower triangular Cholesky factorization (default: lower)
Returns
The upper or lower triangular Cholesky factorization

Definition at line 542 of file LinalgNamespace.h.

◆ cholesky_solver()

SGVector<T> shogun::linalg::cholesky_solver ( const SGMatrix< T > &  L,
const SGVector< T > &  b,
const bool  lower = true 
)

Solve the linear equations \(Ax=b\), given the Cholesky factorization of A, where \(A\) is a Hermitian positive definite matrix

Parameters
LTriangular matrix, Cholesky factorization of A
bRight-hand side array
lowerWhether to use L as the upper or lower triangular Cholesky factorization (default:lower)
Returns
\(\x\)

Definition at line 559 of file LinalgNamespace.h.

◆ colwise_sum() [1/2]

SGVector<T> shogun::linalg::colwise_sum ( const SGMatrix< T > &  mat,
bool  no_diag = false 
)

Method that computes colwise sum of co-efficients of a dense matrix

Parameters
Mata matrix whose colwise sum has to be computed
no_diagIf true, diagonal entries are excluded from the sum. Default: false
Returns
The colwise sum of co-efficients computed as \(s_j=\sum_{i}b_{i,j}\)

Definition at line 1370 of file LinalgNamespace.h.

◆ colwise_sum() [2/2]

SGVector<T> shogun::linalg::colwise_sum ( const Block< SGMatrix< T >> &  a,
bool  no_diag = false 
)

Method that computes the colwise sum of matrix blocks This operation works with CPU backends only.

Parameters
athe matrix-block whose colwise sum of co-efficients has to be computed
no_diagIf true, diagonal entries are excluded from the sum. Default: false
Returns
the colwise sum of co-efficients computed as \(s_j=\sum_{i}b_{i,j}\)

Definition at line 1388 of file LinalgNamespace.h.

◆ cross_entropy()

T shogun::linalg::cross_entropy ( const SGMatrix< T >  p,
const SGMatrix< T >  q 
)

Returns the cross entropy between P and Q. The cross entropy is defined as \( H(P,Q) = - \sum_{ij} P[i,j]log(Q[i,j]) \)

Parameters
pInput matrix 1
qInput matrix 2

Definition at line 165 of file LinalgSpecialPurposes.h.

◆ dgemm()

void shogun::linalg::dgemm ( alpha,
SGMatrix< T >  a,
SGMatrix< T >  b,
bool  transpose_a,
bool  transpose_b,
beta,
SGMatrix< T > &  c 
)

This function multiplies a * b and multiplies the resulting matrix by alpha. It then multiplies matrix c by beta. It stores the sum of these two products in matrix c.

Parameters
alphascaling factor for matrix a*b
amatrix
bmatrix
transpose_aWhether to transpose matrix a
transpose_bWhether to transpose matrix b
betascaling factor for matrix c
cmatrix

Definition at line 1127 of file LinalgNamespace.h.

◆ dgemv()

void shogun::linalg::dgemv ( alpha,
SGMatrix< T >  a,
bool  transpose,
SGVector< T >  x,
beta,
SGVector< T > &  y 
)

Performs the operation y = ax + y This function multiplies a * x (after transposing a, if needed) and multiplies the resulting matrix by alpha. It then multiplies vector y by beta. It stores the sum of these two products in vector y

Parameters
alphascaling factor for vector ax
amatrix
transposeWhether to transpose matrix a
xvector
betascaling factor for vector y
yvector

Definition at line 1103 of file LinalgNamespace.h.

◆ dger()

void shogun::linalg::dger ( alpha,
const SGVector< T >  x,
const SGVector< T >  y,
SGMatrix< T > &  A 
)

Performs the operation A = alpha * x * y' + A

Parameters
alphascaling factor for vector x
xvector
yvector
Am artix

Definition at line 518 of file LinalgNamespace.h.

◆ dot()

T shogun::linalg::dot ( const SGVector< T > &  a,
const SGVector< T > &  b 
)

Vector dot-product that works with generic vectors.

Parameters
aFirst vector
bSecond vector
Returns
The dot product of \(\mathbf{a}\) and \(\mathbf{b}\), represented as \(\sum_i a_i b_i\)

Definition at line 576 of file LinalgNamespace.h.

◆ eigen_solver()

void shogun::linalg::eigen_solver ( const SGMatrix< T > &  A,
SGVector< T > &  eigenvalues,
SGMatrix< T > &  eigenvectors 
)

Compute the eigenvalues and eigenvectors of a matrix. Note that the type of the computed values is the same as the matrix's type, i.e. for real matrices it returns only the real part of the eigenvalues/vectors.

User should pass an appropriately pre-allocated memory vector to store the eigenvalues and an appropriately pre-allocated memory matrix to store the eigenvectors.

Parameters
AThe matrix whose eigenvalues and eigenvectors are to be computed
eigenvaluesEigenvalues result vector
eigenvectorsEigenvectors result matrix

Definition at line 601 of file LinalgNamespace.h.

◆ eigen_solver_symmetric()

void shogun::linalg::eigen_solver_symmetric ( const SGMatrix< T > &  A,
SGVector< T > &  eigenvalues,
SGMatrix< T > &  eigenvectors,
index_t  k = 0 
)

Compute the top-k eigenvalues and eigenvectors of a symmetric matrix.

User should pass an appropriately pre-allocated memory vector to store the eigenvalues and an appropriately pre-allocated memory matrix to store the eigenvectors.

Parameters
AThe matrix whose eigenvalues and eigenvectors are to be computed
eigenvaluesEigenvalues result vector in ascending order
eigenvectorsEigenvectors result matrix
knumber of top eigenvalues to be computed [default = 0: all eigenvalues]

Definition at line 640 of file LinalgNamespace.h.

◆ element_prod() [1/4]

void shogun::linalg::element_prod ( Block< SGMatrix< T >> &  a,
Block< SGMatrix< T >> &  b,
SGMatrix< T > &  result 
)

Performs the operation C = A .* B where ".*" denotes elementwise multiplication on matrix blocks.

This version returns the result in-place. User should pass an appropriately pre-allocated memory matrix.

This operation works with CPU backends only.

Parameters
aFirst matrix block
bSecond matrix block
resultResult matrix

Definition at line 689 of file LinalgNamespace.h.

◆ element_prod() [2/4]

SGMatrix<T> shogun::linalg::element_prod ( Block< SGMatrix< T >> &  a,
Block< SGMatrix< T >> &  b 
)

Performs the operation C = A .* B where ".*" denotes elementwise multiplication on matrix blocks.

This version returns the result in a newly created matrix.

Parameters
AFirst matrix block
BSecond matrix block
Returns
The result of the operation

Definition at line 722 of file LinalgNamespace.h.

◆ element_prod() [3/4]

void shogun::linalg::element_prod ( SGMatrix< T > &  a,
SGMatrix< T > &  b,
SGMatrix< T > &  result 
)

Performs the operation C = A .* B where ".*" denotes elementwise multiplication.

This version returns the result in-place. User should pass an appropriately pre-allocated memory matrix Or pass one of the operands arguments (A or B) as a result

Parameters
aFirst matrix
bSecond matrix
resultResult matrix

Definition at line 749 of file LinalgNamespace.h.

◆ element_prod() [4/4]

SGMatrix<T> shogun::linalg::element_prod ( SGMatrix< T > &  a,
SGMatrix< T > &  b 
)

Performs the operation C = A .* B where ".*" denotes elementwise multiplication.

This version returns the result in a newly created matrix.

Parameters
aFirst matrix
bSecond matrix
Returns
The result of the operation

Definition at line 784 of file LinalgNamespace.h.

◆ exponent()

Container<T> shogun::linalg::exponent ( const Container< T > &  a)

Performs the operation B = exp(A)

This version returns the result in a newly created vector or matrix.

Parameters
aExponent vector or matrix
Returns
The result of the operation

Definition at line 807 of file LinalgNamespace.h.

◆ from_gpu() [1/3]

void shogun::linalg::from_gpu ( SGVector< T > &  a,
SGVector< T > &  b 
)

Fetches data from GPU memory. Transfer vectors to CPU if GPU backend is still available.

Parameters
aSGVector to be transferred
bSGVector to be set

Definition at line 201 of file LinalgNamespace.h.

◆ from_gpu() [2/3]

void shogun::linalg::from_gpu ( SGMatrix< T > &  a,
SGMatrix< T > &  b 
)

Fetches data from GPU memory. Transfer matrices to CPU if GPU backend is still available.

Parameters
aSGMatrix to be transferred
bSGMatrix to be set

Definition at line 240 of file LinalgNamespace.h.

◆ from_gpu() [3/3]

void shogun::linalg::from_gpu ( Container< T > &  a)

Fetches data from GPU memory. Transfer vector or matrix to CPU if GPU backend is still available.

Parameters
aSGVector or SGMatrix to be transferred

Definition at line 279 of file LinalgNamespace.h.

◆ identity()

void shogun::linalg::identity ( SGMatrix< T > &  identity_matrix)

Method that writes the identity into a square matrix.

Parameters
aThe square matrix to be set

Definition at line 823 of file LinalgNamespace.h.

◆ infer_backend() [1/2]

LinalgBackendBase* shogun::linalg::infer_backend ( const Container< T > &  a)

Infer the appropriate backend for linalg operations from the input SGVector or SGMatrix (Container).

Parameters
aSGVector or SGMatrix
Returns
See also
LinalgBackendBase pointer

Definition at line 53 of file LinalgNamespace.h.

◆ infer_backend() [2/2]

LinalgBackendBase* shogun::linalg::infer_backend ( const Container< T > &  a,
const Container< T > &  b 
)

Infer the appropriate backend for linalg operations from the input SGVector or SGMatrix (Container). Raise error if the backends of the two Containers conflict.

Parameters
aThe first SGVector/SGMatrix
bThe second SGVector/SGMatrix
Returns
See also
LinalgBackendBase pointer

Definition at line 82 of file LinalgNamespace.h.

◆ logistic()

void shogun::linalg::logistic ( SGMatrix< T > &  a,
SGMatrix< T > &  result 
)

Applies the elementwise logistic function f(x) = 1/(1+exp(-x)) to a matrix This method returns the result in-place.

Parameters
aThe input matrix
resultThe output matrix

Definition at line 52 of file LinalgSpecialPurposes.h.

◆ matrix_prod() [1/4]

void shogun::linalg::matrix_prod ( SGMatrix< T > &  A,
SGVector< T > &  b,
SGVector< T > &  result,
bool  transpose = false 
)

Performs the operation of a matrix multiplies a vector \(x = Ab\).

This version returns the result in-place. User should pass an appropriately allocated memory matrix.

Parameters
AThe matrix
bThe vector
transposeWhether to transpose the matrix. Default false
resultResult vector

Definition at line 840 of file LinalgNamespace.h.

◆ matrix_prod() [2/4]

SGVector<T> shogun::linalg::matrix_prod ( SGMatrix< T > &  A,
SGVector< T > &  b,
bool  transpose = false 
)

Performs the operation of matrix multiply a vector \(x = Ab\). This version returns the result in a newly created vector.

Parameters
AThe matrix
bThe vector
transposeWhether to transpose a matrix. Default:false
Returns
result Result vector

Definition at line 896 of file LinalgNamespace.h.

◆ matrix_prod() [3/4]

void shogun::linalg::matrix_prod ( SGMatrix< T > &  A,
SGMatrix< T > &  B,
SGMatrix< T > &  result,
bool  transpose_A = false,
bool  transpose_B = false 
)

Performs the operation C = A * B where "*" denotes matrix multiplication.

This version returns the result in-place. User should pass an appropriately allocated memory matrix

Parameters
AFirst matrix
BSecond matrix
resultResult matrix
transpose_Awhether to transpose matrix A
transpose_Bwhether to transpose matrix B

Definition at line 938 of file LinalgNamespace.h.

◆ matrix_prod() [4/4]

SGMatrix<T> shogun::linalg::matrix_prod ( SGMatrix< T > &  A,
SGMatrix< T > &  B,
bool  transpose_A = false,
bool  transpose_B = false 
)

Performs the operation C = A * B where "*" denotes matrix multiplication.

This version returns the result in a newly created matrix.

Parameters
AFirst matrix
BSecond matrix
transpose_Awhether to transpose matrix A
transpose_Bwhether to transpose matrix B
Returns
The result of the operation

Definition at line 1039 of file LinalgNamespace.h.

◆ max()

T shogun::linalg::max ( const Container< T > &  a)

Returns the largest element in a vector or matrix

Parameters
aInput vector or matrix
Returns
The largest value in the vector or matrix

Definition at line 1142 of file LinalgNamespace.h.

◆ mean() [1/2]

std::enable_if<!std::is_same<T, complex128_t>::value, float64_t>::type shogun::linalg::mean ( const Container< T > &  a)

Method that computes the mean of vectors or matrices composed of real numbers.

Parameters
aSGVector or SGMatrix
Returns
The vector mean \(\bar{a}_i\) or matrix mean \(\bar{m}_{i,j}\)

Definition at line 1158 of file LinalgNamespace.h.

◆ mean() [2/2]

complex128_t shogun::linalg::mean ( const Container< complex128_t > &  a)

Method that computes the mean of vectors or matrices composed of complex numbers.

Parameters
aSGVector or SGMatrix
Returns
The vector mean \(\bar{a}_i\) or matrix mean \(\bar{m}_{i,j}\)

Definition at line 1173 of file LinalgNamespace.h.

◆ multiply_by_logistic_derivative()

void shogun::linalg::multiply_by_logistic_derivative ( SGMatrix< T > &  a,
SGMatrix< T > &  result 
)

Performs the operation C(i,j) = C(i,j) * A(i,j) * (1.0-A(i,j)) for all i and j This method returns the result in-place.

Parameters
aThe input matrix
resultThe output matrix

Definition at line 78 of file LinalgSpecialPurposes.h.

◆ multiply_by_rectified_linear_derivative()

void shogun::linalg::multiply_by_rectified_linear_derivative ( SGMatrix< T > &  a,
SGMatrix< T > &  result 
)

Performs the operation C(i,j) = C(i,j) * (A(i,j)!=0) for all i and j This method returns the result in-place.

Parameters
aThe input matrix
resultThe output matrix

Definition at line 102 of file LinalgSpecialPurposes.h.

◆ norm()

T shogun::linalg::norm ( const SGVector< T > &  a)

Method that computes the euclidean norm of a vector.

Parameters
aSGVector
Returns
The vector norm

Definition at line 1186 of file LinalgNamespace.h.

◆ qr_solver()

Container<T> shogun::linalg::qr_solver ( const SGMatrix< T > &  A,
const Container< T > &  b 
)

Solve the linear equations \(Ax=b\) through the QR decomposition of A.

Parameters
AThe matrix
bRight-hand side vector or matrix
Returns
\(\x\)

Definition at line 1201 of file LinalgNamespace.h.

◆ range_fill()

void shogun::linalg::range_fill ( Container< T > &  a,
const T  start = 0 
)

Range fill a vector or matrix with start...start+len-1

Parameters
aThe vector or matrix to be filled
startValue to be assigned to the first element of vector or matrix

Definition at line 1218 of file LinalgNamespace.h.

◆ rectified_linear()

void shogun::linalg::rectified_linear ( SGMatrix< T > &  a,
SGMatrix< T > &  result 
)

Applies the elementwise rectified linear function f(x) = max(0,x) to a matrix

Parameters
aThe input matrix
resultThe output matrix

Definition at line 128 of file LinalgSpecialPurposes.h.

◆ rowwise_sum() [1/2]

SGVector<T> shogun::linalg::rowwise_sum ( const SGMatrix< T > &  mat,
bool  no_diag = false 
)

Method that computes rowwise sum of co-efficients of a dense matrix

Parameters
mata matrix whose rowwise sum has to be computed
no_diagIf true, diagonal entries are excluded from the sum. Default: false
Returns
the rowwise sum of co-efficients computed as \(s_i=\sum_{j}m_{i,j}\)

Definition at line 1403 of file LinalgNamespace.h.

◆ rowwise_sum() [2/2]

SGVector<T> shogun::linalg::rowwise_sum ( const Block< SGMatrix< T >> &  a,
bool  no_diag = false 
)

Method that computes the rowwise sum of matrix blocks This operation works with CPU backends only.

Parameters
athe matrix-block whose rowwise sum of co-efficients has to be computed
no_diagIf true, diagonal entries are excluded from the sum. Default: false
Returns
the rowwise sum of co-efficients computed as \(s_i=\sum_{j}m_{i,j}\)

Definition at line 1421 of file LinalgNamespace.h.

◆ scale() [1/3]

void shogun::linalg::scale ( SGVector< T > &  a,
SGVector< T > &  result,
alpha = 1 
)

Performs the operation result = alpha * a on vectors This version returns the result in-place. User should pass an appropriately pre-allocated memory matrix Or pass the operands argument a as a result

Parameters
aFirst vector
alphaScale factor
resultThe vector of alpha * a

Definition at line 1234 of file LinalgNamespace.h.

◆ scale() [2/3]

void shogun::linalg::scale ( SGMatrix< T > &  A,
SGMatrix< T > &  result,
alpha = 1 
)

Performs the operation result = alpha * A on matrices This version returns the result in-place. User should pass an appropriately pre-allocated memory matrix Or pass the operands argument A as a result

Parameters
AFirst matrix
alphaScale factor
resultThe matrix of alpha * A

Definition at line 1254 of file LinalgNamespace.h.

◆ scale() [3/3]

Container<T> shogun::linalg::scale ( Container< T > &  a,
alpha = 1 
)

Performs the operation B = alpha * A on vectors or matrices This version returns the result in a newly created vector or matrix.

Parameters
aFirst vector/matrix
alphaScale factor
Returns
Vector or matrix of alpha * A

Definition at line 1278 of file LinalgNamespace.h.

◆ set_const()

void shogun::linalg::set_const ( Container< T > &  a,
value 
)

Set const value to vectors or matrices

Parameters
aVector or matrix to be set
valueThe value to set the vector or matrix

Definition at line 1292 of file LinalgNamespace.h.

◆ softmax()

void shogun::linalg::softmax ( SGMatrix< T > &  a)

Applies the softmax function inplace to a matrix. The softmax function is defined as \( f(A[i,j]) = \frac{exp(A[i,j])}{\sum_i exp(A[i,j])} \) This method returns the result in-place.

Parameters
aThe input matrix

Definition at line 152 of file LinalgSpecialPurposes.h.

◆ squared_error()

T shogun::linalg::squared_error ( const SGMatrix< T >  p,
const SGMatrix< T >  q 
)

Returns the squared error between P and Q. The squared error is defined as \( E(P,Q) = \frac{1}{2} \sum_{ij} (P[i,j]-Q[i,j])^2 \)

Parameters
pInput matrix 1
qInput matrix 2

Definition at line 187 of file LinalgSpecialPurposes.h.

◆ sum() [1/2]

T shogun::linalg::sum ( const Container< T > &  a,
bool  no_diag = false 
)

Method that computes the sum of vectors or matrices

Parameters
aThe vector or matrix whose sum has to be computed
no_diagIf true, diagonal entries are excluded from the sum. Default: false
Returns
The vector sum \(\sum_i a_i\) or matrix sum \(\sum_{i,j}b_{i,j}\)

Definition at line 1307 of file LinalgNamespace.h.

◆ sum() [2/2]

T shogun::linalg::sum ( const Block< SGMatrix< T >> &  a,
bool  no_diag = false 
)

Method that computes the sum of matrix blocks This operation works with CPU backends only.

Parameters
aThe matrix-block whose sum of co-efficients has to be computed
no_diagIf true, diagonal entries are excluded from the sum. Default: false
Returns
Matrix-block sum \(\sum_{i,j}b_{i,j}\)

Definition at line 1323 of file LinalgNamespace.h.

◆ sum_symmetric() [1/2]

T shogun::linalg::sum_symmetric ( const SGMatrix< T > &  a,
bool  no_diag = false 
)

Method that computes the sum of symmetric matrices

Parameters
aThe symmetric matrix whose sum has to be computed
no_diagIf true, diagonal entries are excluded from the sum. Default: false
Returns
The matrix sum \(\sum_{i,j}b_{i,j}\)

Definition at line 1337 of file LinalgNamespace.h.

◆ sum_symmetric() [2/2]

T shogun::linalg::sum_symmetric ( const Block< SGMatrix< T >> &  a,
bool  no_diag = false 
)

Method that computes the sum of symmetric matrix blocks This operation works with CPU backends only.

Parameters
aThe symmetric matrix-block whose sum has to be computed
no_diagIf true, diagonal entries are excluded from the sum. Default: false
Returns
Symmetric matrix-block sum \(\sum_{i,j}b_{i,j}\)

Definition at line 1353 of file LinalgNamespace.h.

◆ svd()

void shogun::linalg::svd ( const SGMatrix< T > &  A,
SGVector< T > &  s,
SGMatrix< T > &  U,
bool  thin_U = true,
SVDAlgorithm  alg = SVDAlgorithm::BidiagonalDivideConquer 
)

Compute the singular value decomposition \(A = U S V^{*}\) of a matrix. Given the \(m \times n\) matrix A with \(r = min(m,n)\), user should pass an appropriately pre-allocated vector of length r and a pre-allocated matrix of size \(m \times r\) for thin U or \(m \times m\) otherwise.

Parameters
AThe matrix whose svd is to be computed
sThe vector that stores the resulting singular values
UThe matrix that stores the resulting unitary matrix U
thin_UWhether to compute the full or thin matrix U (default:thin)
algWhether to compute the svd through bidiagonal divide and conquer algorithm or Jacobi's algorithm (
See also
SVDAlgorithm) (default: bidiagonal divide and conquer)

Definition at line 1446 of file LinalgNamespace.h.

◆ to_gpu() [1/3]

void shogun::linalg::to_gpu ( SGVector< T > &  a,
SGVector< T > &  b 
)

Transfers data to GPU memory. Shallow-copy of SGVector with vector on CPU if GPU backend not available

Parameters
aSGVector to be transferred
bSGVector to be set

Definition at line 118 of file LinalgNamespace.h.

◆ to_gpu() [2/3]

void shogun::linalg::to_gpu ( SGMatrix< T > &  a,
SGMatrix< T > &  b 
)

Transfers data to GPU memory. Does nothing if no GPU backend registered. Shallow-copy SGMatrix on CPU if GPU backend not available

Parameters
aSGMatrix to be transferred
bSGMatrix to be set

Definition at line 154 of file LinalgNamespace.h.

◆ to_gpu() [3/3]

void shogun::linalg::to_gpu ( Container< T > &  a)

Transfers data to GPU memory in-place.

Parameters
aSGVector or SGMatrix to be transferred

Definition at line 188 of file LinalgNamespace.h.

◆ trace()

T shogun::linalg::trace ( const SGMatrix< T > &  A)

Method that computes the trace of square matrix.

Parameters
AThe matrix whose trace has to be computed
Returns
The trace of the matrix

Definition at line 1486 of file LinalgNamespace.h.

◆ transpose_matrix()

SGMatrix<T> shogun::linalg::transpose_matrix ( const SGMatrix< T > &  A)

Method that computes the transpose of a matrix.

Parameters
AThe matrix
Returns
The transposed matrix

Definition at line 1499 of file LinalgNamespace.h.

◆ triangular_solver()

Container<T> shogun::linalg::triangular_solver ( const SGMatrix< T > &  L,
const Container< T > &  b,
const bool  lower = true 
)

Solve the linear equations \(Lx=b\), where \(L\) is a triangular matrix.

Parameters
LTriangular matrix
bRight-hand side array
lowerWhether L is upper or lower triangular (default:lower)
Returns
\(\x\)

Definition at line 1514 of file LinalgNamespace.h.

◆ zero()

void shogun::linalg::zero ( Container< T > &  a)

Method that fills with zero a vector or a matrix.

Parameters
aThe vector or the matrix to be set

Definition at line 1528 of file LinalgNamespace.h.


SHOGUN Machine Learning Toolbox - Documentation