template<typename T = double>
SparseMatrix class
High-performance sparse matrix for game analytics.
| Template parameters | |
|---|---|
| T | Element type (default: double) |
Uses boost::numeric::ublas::compressed_matrix for efficient storage of sparse data like player interaction patterns and game statistics.
Public types
- using value_type = T
- using matrix_type = ublas::compressed_matrix<T>
- using size_type = typename matrix_type::size_type
Constructors, destructors, conversion operators
-
SparseMatrix(size_
type rows, size_ type cols, size_ type non_zeros = 0) - Construct sparse matrix with dimensions.
Public functions
-
void set(size_
type row, size_ type col, const T& value) - Set element value.
-
auto get(size_
type row, size_ type col) const -> T - Get element value.
-
void increment(size_
type row, size_ type col, const T& delta = T{1}) - Increment element value.
-
auto get_row(size_
type row) const -> std::vector<T> - Get row as dense vector.
-
auto get_column(size_
type col) const -> std::vector<T> - Get column as dense vector.
- auto row_sums() const -> std::vector<T>
- Calculate row sums.
- auto column_sums() const -> std::vector<T>
- Calculate column sums.
-
template<typename Func>void for_each_non_zero(Func func) const
- Apply function to all non-zero elements.
-
auto find_top_n(size_
type n) const -> std::vector<std::tuple<size_ type, size_ type, T>> - Find top N elements by value.
- auto normalize_rows() const -> SparseMatrix
- Normalize matrix rows to sum to 1.
- auto operator*(const SparseMatrix& other) const -> SparseMatrix
- Matrix multiplication.
-
auto rows() const -> size_
type -
auto cols() const -> size_
type -
auto non_zeros() const -> size_
type - auto sparsity() const -> double
- void clear()
-
auto data() const -> const matrix_
type& -
auto data() -> matrix_
type&
Function documentation
template<typename T>
liarsdice:: data_structures:: SparseMatrix<T>:: SparseMatrix(size_ type rows,
size_ type cols,
size_ type non_zeros = 0)
Construct sparse matrix with dimensions.
| Parameters | |
|---|---|
| rows | Number of rows |
| cols | Number of columns |
| non_zeros | Expected number of non-zero elements (hint) |
template<typename T>
std::vector<T> liarsdice:: data_structures:: SparseMatrix<T>:: get_column(size_ type col) const
Get column as dense vector.
| Parameters | |
|---|---|
| col | Column index |
| Returns | Vector containing column values |
template<typename T>
std::vector<T> liarsdice:: data_structures:: SparseMatrix<T>:: row_sums() const
Calculate row sums.
| Returns | Vector of row sums |
|---|
template<typename T>
std::vector<T> liarsdice:: data_structures:: SparseMatrix<T>:: column_sums() const
Calculate column sums.
| Returns | Vector of column sums |
|---|
template<typename T>
template<typename Func>
void liarsdice:: data_structures:: SparseMatrix<T>:: for_each_non_zero(Func func) const
Apply function to all non-zero elements.
| Template parameters | |
|---|---|
| Func | Function type |
| Parameters | |
| func | Function to apply (row, col, value) |
template<typename T>
std::vector<std::tuple<size_ type, size_ type, T>> liarsdice:: data_structures:: SparseMatrix<T>:: find_top_n(size_ type n) const
Find top N elements by value.
| Parameters | |
|---|---|
| n | Number of elements to find |
| Returns | Vector of (row, col, value) tuples |
template<typename T>
SparseMatrix liarsdice:: data_structures:: SparseMatrix<T>:: normalize_rows() const
Normalize matrix rows to sum to 1.
| Returns | New normalized matrix |
|---|
template<typename T>
SparseMatrix liarsdice:: data_structures:: SparseMatrix<T>:: operator*(const SparseMatrix& other) const
Matrix multiplication.
| Parameters | |
|---|---|
| other | Other sparse matrix |
| Returns | Result of matrix multiplication |