Ocean
|
This class implements a sparse matrix using a float type for its elements that is specified by T. More...
Data Structures | |
class | Entry |
This class implements a triple object for matrix entries. More... | |
Public Types | |
typedef std::vector< Entry > | Entries |
Definition of a vector holding entries. More... | |
Public Member Functions | |
SparseMatrixT () | |
Creates an empty sparse matrix object. More... | |
SparseMatrixT (const SparseMatrixT< T > &matrix) | |
Copy constructor. More... | |
SparseMatrixT (SparseMatrixT< T > &&matrix) noexcept | |
Move constructor. More... | |
SparseMatrixT (const size_t rows, const size_t columns) | |
Creates a new spare matrix with given dimensions. More... | |
SparseMatrixT (const size_t rows, const size_t columns, const size_t nonZeroElements) | |
Creates a new spare matrix with given dimensions. More... | |
SparseMatrixT (const size_t rows, const size_t columns, const Entries &entries) | |
Creates a new spare matrix with given dimensions. More... | |
SparseMatrixT (const size_t rows, const size_t columns, const MatrixT< T > &diagonal, const bool forceNonZeros=false) | |
Creates a new sparse matrix with defined rows and columns and initializes the diagonal with small sub matrices. More... | |
SparseMatrixT (const MatrixT< T > &denseMatrix) | |
Creates a new sparse matrix with defined rows and columns and copies all non-zero values from a dense matrix. More... | |
~SparseMatrixT () | |
Destructs a sparse matrix object. More... | |
size_t | rows () const |
Returns the number of rows this matrix has. More... | |
size_t | columns () const |
Returns the number of columns this matrix has. More... | |
size_t | nonZeroElements () const |
Returns the number of non zero elements stored in this matrix. More... | |
MatrixT< T > | diagonal () const |
Returns a vector containing the values of the diagonal. More... | |
void | reserve (const size_t elements) |
Reserves memory for a specified number of non zero elements. More... | |
bool | isZero (const size_t row, const size_t column) const |
Returns whether a specified elements is zero. More... | |
bool | isEqual (const SparseMatrixT< T > &matrix, const T eps) const |
Returns whether two matrices are almost identical up to a specified epsilon. More... | |
bool | isEqual (const MatrixT< T > &matrix, const T eps) const |
Returns whether two matrices are almost identical up to a specified epsilon. More... | |
void | setEntries (const Entries &entries) |
(Re-)sets the non-zero entries of this sparse matrix. More... | |
SparseMatrixT< T > | submatrix (const size_t row, const size_t column, const size_t rows, const size_t columns) const |
Returns a submatrix of this matrix. More... | |
SparseMatrixT< T > | transposed () const |
Returns the transposes matrix of this matrix. More... | |
void | transpose () |
Transposes this matrix. More... | |
bool | solve (const MatrixT< T > &b, MatrixT< T > &x) const |
Solves the given linear system. More... | |
size_t | rank () const |
Computes the rank of this matrix. More... | |
T | sum () const |
Determines the sum of all elements of this matrix. More... | |
bool | invertDiagonal () |
Inverts this square diagonal matrix. More... | |
bool | invertBlockDiagonal3 () |
Inverts this square block diagonal matrix with 3x3 block size. More... | |
bool | invertBlockDiagonal (const size_t size) |
Inverts this square block diagonal matrix with size x size block size. More... | |
MatrixT< T > | denseMatrix () const |
Returns the dense matrix of this matrix. More... | |
bool | nonNegativeMatrixFactorization (MatrixT< T > &subcomponents, MatrixT< T > &weights, const unsigned int components=0u, const unsigned int iterations=100u, const T convergenceThreshold=T(0.0001)) const |
Performs a non-negative matrix factorization with multiplicative update rules V = W * H, V is a matrix containing non-negative values This matrix is V, and will be factorized into two matrices W (weights) and H (subcomponents). More... | |
SparseMatrixT< T > & | operator= (const SparseMatrixT< T > &matrix) |
Assign operator. More... | |
SparseMatrixT< T > & | operator= (SparseMatrixT< T > &&matrix) noexcept |
Move operator. More... | |
SparseMatrixT< T > | operator* (const SparseMatrixT< T > &matrix) const |
Multiplies two sparse matrix objects and returns the matrix result. More... | |
SparseMatrixT< T > & | operator*= (const SparseMatrixT< T > &matrix) |
Multiplies a second sparse matrix object to this matrix object. More... | |
SparseMatrixT< T > | operator+ (const SparseMatrixT< T > &matrix) const |
Adds two sparse matrix objects and returns the matrix result. More... | |
SparseMatrixT< T > & | operator+= (const SparseMatrixT< T > &matrix) |
Adds a second sparse matrix object to this matrix. More... | |
SparseMatrixT< T > | operator- (const SparseMatrixT< T > &matrix) const |
Subtracts two sparse matrix objects and returns the matrix result. More... | |
SparseMatrixT< T > & | operator-= (const SparseMatrixT< T > &matrix) |
Subtracts a second sparse matrix object from this matrix. More... | |
MatrixT< T > | operator* (const MatrixT< T > &matrix) const |
Multiplies a dense matrix object on this sparse matrix object and returns the dense matrix result. More... | |
bool | operator== (const SparseMatrixT< T > &matrix) const |
Returns whether this matrix is equal to an other one up to an epsilon value. More... | |
bool | operator== (const MatrixT< T > &matrix) const |
Returns whether this matrix is equal to an other one up to an epsilon value. More... | |
T | operator() (const size_t row, const size_t column) const |
Returns a specific element of the sparse matrix. More... | |
T & | operator() (const size_t row, const size_t column) |
Returns the reference to a specific element of the sparse matrix. More... | |
Private Member Functions | |
SparseMatrixT (void *matrix) | |
Creates a new sparse matrix object by the internal matrix object data directly. More... | |
Private Attributes | |
void * | internalMatrix |
Abstract pointer to the internal matrix object. More... | |
This class implements a sparse matrix using a float type for its elements that is specified by T.
T | Data type of matrix elements |
typedef std::vector<Entry> Ocean::SparseMatrixT< T >::Entries |
Definition of a vector holding entries.
Ocean::SparseMatrixT< T >::SparseMatrixT | ( | ) |
Creates an empty sparse matrix object.
Ocean::SparseMatrixT< T >::SparseMatrixT | ( | const SparseMatrixT< T > & | matrix | ) |
Copy constructor.
matrix | Sparse matrix to be copied |
|
noexcept |
Move constructor.
matrix | Sparse matrix to be movied |
Ocean::SparseMatrixT< T >::SparseMatrixT | ( | const size_t | rows, |
const size_t | columns | ||
) |
Creates a new spare matrix with given dimensions.
rows | Number of rows to create a sparse matrix for |
columns | Number of columns to create a sparse matrix for |
Ocean::SparseMatrixT< T >::SparseMatrixT | ( | const size_t | rows, |
const size_t | columns, | ||
const size_t | nonZeroElements | ||
) |
Creates a new spare matrix with given dimensions.
rows | Number of rows to create a sparse matrix for |
columns | Number of columns to create a sparse matrix for |
nonZeroElements | Number of expected non zero elements to reserve memory for |
Ocean::SparseMatrixT< T >::SparseMatrixT | ( | const size_t | rows, |
const size_t | columns, | ||
const Entries & | entries | ||
) |
Creates a new spare matrix with given dimensions.
rows | Number of rows to create a sparse matrix for |
columns | Number of columns to create a sparse matrix for |
entries | All non-zero entries of the new matrix |
Ocean::SparseMatrixT< T >::SparseMatrixT | ( | const size_t | rows, |
const size_t | columns, | ||
const MatrixT< T > & | diagonal, | ||
const bool | forceNonZeros = false |
||
) |
Creates a new sparse matrix with defined rows and columns and initializes the diagonal with small sub matrices.
The number of columns of the given diagonal vector matrix defines the size of the small sub matrices.
The number of rows of the diagonal vector matrix must be a multiple of the number of rows.
rows | Rows of the new matrix |
columns | Columns of the new matrix |
diagonal | Diagonal vector matrix holding the new diagonal sub matrices |
forceNonZeros | True, to force all diagonal elements to be an epsilon larger than zero (if the given element is zero) |
|
explicit |
Creates a new sparse matrix with defined rows and columns and copies all non-zero values from a dense matrix.
denseMatrix | Dense matrix from that the non-zero values are copied |
Ocean::SparseMatrixT< T >::~SparseMatrixT | ( | ) |
Destructs a sparse matrix object.
|
explicitprivate |
Creates a new sparse matrix object by the internal matrix object data directly.
matrix | Internal matrix object |
size_t Ocean::SparseMatrixT< T >::columns | ( | ) | const |
Returns the number of columns this matrix has.
MatrixT<T> Ocean::SparseMatrixT< T >::denseMatrix | ( | ) | const |
Returns the dense matrix of this matrix.
MatrixT<T> Ocean::SparseMatrixT< T >::diagonal | ( | ) | const |
Returns a vector containing the values of the diagonal.
bool Ocean::SparseMatrixT< T >::invertBlockDiagonal | ( | const size_t | size | ) |
Inverts this square block diagonal matrix with size x size block size.
The size of the matrix must be a multiple of size.
Each of the size x size block is inverted individually.
size | The size of the block (size x size) with range (2, infinity) |
bool Ocean::SparseMatrixT< T >::invertBlockDiagonal3 | ( | ) |
Inverts this square block diagonal matrix with 3x3 block size.
The size of the matrix must be a multiple of three.
Each of the 3x3 block is inverted individually.
bool Ocean::SparseMatrixT< T >::invertDiagonal | ( | ) |
Inverts this square diagonal matrix.
bool Ocean::SparseMatrixT< T >::isEqual | ( | const MatrixT< T > & | matrix, |
const T | eps | ||
) | const |
Returns whether two matrices are almost identical up to a specified epsilon.
matrix | Second matrix that will be checked |
eps | Epsilon to be used |
bool Ocean::SparseMatrixT< T >::isEqual | ( | const SparseMatrixT< T > & | matrix, |
const T | eps | ||
) | const |
Returns whether two matrices are almost identical up to a specified epsilon.
matrix | Second matrix that will be checked |
eps | Epsilon to be used |
bool Ocean::SparseMatrixT< T >::isZero | ( | const size_t | row, |
const size_t | column | ||
) | const |
Returns whether a specified elements is zero.
row | The row of the element to be checked |
column | The column of the element to be checked |
bool Ocean::SparseMatrixT< T >::nonNegativeMatrixFactorization | ( | MatrixT< T > & | subcomponents, |
MatrixT< T > & | weights, | ||
const unsigned int | components = 0u , |
||
const unsigned int | iterations = 100u , |
||
const T | convergenceThreshold = T(0.0001) |
||
) | const |
Performs a non-negative matrix factorization with multiplicative update rules V = W * H, V is a matrix containing non-negative values
This matrix is V, and will be factorized into two matrices W (weights) and H (subcomponents).
subcomponents | Solution matrix containing base component vectors |
weights | Solution matrix containing weights to the component vectors |
components | Number of base component vectors (Number of components is usally much smaller than its rank). If set to 0, the rank of matrix is used [0, rank] |
iterations | Number of iterations maximal performed [1, infinity) |
convergenceThreshold | Differential threshold as convergence criterion (0, infinity) |
size_t Ocean::SparseMatrixT< T >::nonZeroElements | ( | ) | const |
Returns the number of non zero elements stored in this matrix.
T& Ocean::SparseMatrixT< T >::operator() | ( | const size_t | row, |
const size_t | column | ||
) |
Returns the reference to a specific element of the sparse matrix.
Beware: The element must be non zero, thus the element must have been inserted before!
row | Element row to be returned |
column | Element column to be returned |
T Ocean::SparseMatrixT< T >::operator() | ( | const size_t | row, |
const size_t | column | ||
) | const |
Returns a specific element of the sparse matrix.
row | Element row to be returned |
column | Element column to be returned |
MatrixT<T> Ocean::SparseMatrixT< T >::operator* | ( | const MatrixT< T > & | matrix | ) | const |
Multiplies a dense matrix object on this sparse matrix object and returns the dense matrix result.
matrix | Right matrix to multiply |
SparseMatrixT<T> Ocean::SparseMatrixT< T >::operator* | ( | const SparseMatrixT< T > & | matrix | ) | const |
Multiplies two sparse matrix objects and returns the matrix result.
matrix | Right sparse matrix to multiply |
|
inline |
Multiplies a second sparse matrix object to this matrix object.
matrix | Right sparse matrix to multiply |
SparseMatrixT<T> Ocean::SparseMatrixT< T >::operator+ | ( | const SparseMatrixT< T > & | matrix | ) | const |
Adds two sparse matrix objects and returns the matrix result.
matrix | Right sparse matrix to add |
SparseMatrixT<T>& Ocean::SparseMatrixT< T >::operator+= | ( | const SparseMatrixT< T > & | matrix | ) |
Adds a second sparse matrix object to this matrix.
matrix | Right sparse matrix to add |
SparseMatrixT<T> Ocean::SparseMatrixT< T >::operator- | ( | const SparseMatrixT< T > & | matrix | ) | const |
Subtracts two sparse matrix objects and returns the matrix result.
matrix | Right sparse matrix to subtract |
SparseMatrixT<T>& Ocean::SparseMatrixT< T >::operator-= | ( | const SparseMatrixT< T > & | matrix | ) |
Subtracts a second sparse matrix object from this matrix.
matrix | Right sparse matrix to subtract |
SparseMatrixT<T>& Ocean::SparseMatrixT< T >::operator= | ( | const SparseMatrixT< T > & | matrix | ) |
Assign operator.
matrix | Sparse matrix to be assigned to this matrix |
|
noexcept |
Move operator.
matrix | Sparse matrix to be move to this matrix |
|
inline |
Returns whether this matrix is equal to an other one up to an epsilon value.
matrix | Second matrix to compare |
|
inline |
Returns whether this matrix is equal to an other one up to an epsilon value.
matrix | Second matrix to compare |
size_t Ocean::SparseMatrixT< T >::rank | ( | ) | const |
void Ocean::SparseMatrixT< T >::reserve | ( | const size_t | elements | ) |
Reserves memory for a specified number of non zero elements.
elements | Number of non zero elements. |
size_t Ocean::SparseMatrixT< T >::rows | ( | ) | const |
Returns the number of rows this matrix has.
void Ocean::SparseMatrixT< T >::setEntries | ( | const Entries & | entries | ) |
(Re-)sets the non-zero entries of this sparse matrix.
All previous non-zero entries will be removed.
If the given set of entries contains zero-values these zero values will be skipped.
entries | The entries to set |
bool Ocean::SparseMatrixT< T >::solve | ( | const MatrixT< T > & | b, |
MatrixT< T > & | x | ||
) | const |
Solves the given linear system.
M * x = b, with M and b known.
This matrix is M, the given vector is b and the result will be x.
b | Vector defining the linear system |
x | Solution vector receiving the solution if existing |
SparseMatrixT<T> Ocean::SparseMatrixT< T >::submatrix | ( | const size_t | row, |
const size_t | column, | ||
const size_t | rows, | ||
const size_t | columns | ||
) | const |
Returns a submatrix of this matrix.
row | The index of the row which will be the first row of the new submatrix, with range [0, rows()) |
column | The index of the column which will be the first column of the new sub-matrix, with range [0, colums()) |
rows | The number of rows of the new sub-matrix, with range [1, rows() - row] |
columns | The number of columns of the new sub-matrix, with range [1, columns() - column] |
|
inline |
Determines the sum of all elements of this matrix.
void Ocean::SparseMatrixT< T >::transpose | ( | ) |
Transposes this matrix.
SparseMatrixT<T> Ocean::SparseMatrixT< T >::transposed | ( | ) | const |
Returns the transposes matrix of this matrix.
|
private |
Abstract pointer to the internal matrix object.