math
-
class Matrix
-
Public Functions
-
explicit Matrix(int num_row = 0, int num_column = 0)
- Parameters:
num_row – [in] Number of rows.
num_column – [in] Number of columns.
-
Matrix(int num_row, int num_column, const std::vector<double> &vector)
- Parameters:
num_row – [in] Number of rows.
num_column – [in] Number of columns.
vector – [in] Diagonal elements.
-
inline int GetNumRow() const
- Returns:
Number of rows.
-
inline int GetNumColumn() const
- Returns:
Number of columns.
-
void Resize(int num_row, int num_column)
Resize matrix.
- Parameters:
num_row – [in] Number of rows.
num_column – [in] Number of columns.
-
inline double *operator[](int row)
- Parameters:
row – [in] Row.
-
inline const double *operator[](int row) const
- Parameters:
row – [in] Row.
-
double &At(int row, int column)
Get element.
- Parameters:
row – [in] i.
column – [in] j.
- Returns:
(i, j)-th element.
-
const double &At(int row, int column) const
Get element.
- Parameters:
row – [in] i.
column – [in] j.
- Returns:
(i, j)-th element.
-
Matrix &operator-=(const Matrix &matrix)
- Parameters:
matrix – [in] Subtrahend.
- Returns:
Difference.
-
Matrix operator-(const Matrix &matrix) const
- Parameters:
matrix – [in] Subtrahend.
- Returns:
Difference.
-
Matrix operator*(const Matrix &matrix) const
- Parameters:
matrix – [in] Multiplicand.
- Returns:
Product.
-
void Fill(double value)
Overwrite all elements with a value.
- Parameters:
value – [in] Value.
-
void FillDiagonal(double value)
Overwrite diagonal elements with a value.
- Parameters:
value – [in] Diagonal value.
-
void Negate()
Negate all elements of matrix.
-
bool Transpose(Matrix *transposed_matrix) const
Transpose matrix.
- Parameters:
transposed_matrix – [out] Transposed matrix.
- Returns:
True on success, false on failure.
-
bool GetSubmatrix(int row_offset, int num_row_of_submatrix, int column_offset, int num_column_of_submatrix, Matrix *submatrix) const
Get submatrix.
- Parameters:
row_offset – [in] Offset of row.
num_row_of_submatrix – [in] Number of rows of submatrix.
column_offset – [in] Offset of column.
num_column_of_submatrix – [in] Number of columns of submatrix.
submatrix – [out] Submatrix.
- Returns:
True on success, false on failure.
-
bool GetDeterminant(double *determinant) const
Compute determinant.
- Parameters:
determinant – [out] Determinant.
- Returns:
True on success, false on failure.
-
explicit Matrix(int num_row = 0, int num_column = 0)
-
class Matrix2D
2D matrix.
Public Functions
-
Matrix2D()
Make 2D matrix.
-
inline double *operator[](int row)
- Parameters:
row – [in] Row.
-
inline const double *operator[](int row) const
- Parameters:
row – [in] Row.
-
double &At(int row, int column)
Get element.
- Parameters:
row – [in] i.
column – [in] j.
- Returns:
(i, j)-th element.
-
const double &At(int row, int column) const
Get element.
- Parameters:
row – [in] i.
column – [in] j.
- Returns:
(i, j)-th element.
-
void Fill(double value)
Overwrite all elements with a value.
- Parameters:
value – [in] Value.
-
void FillDiagonal(double value)
Overwrite diagonal elements with a value.
- Parameters:
value – [in] Diagonal value.
-
void Negate()
Negate all elements of matrix.
Public Static Functions
-
static bool Add(const Matrix2D &matrix, Matrix2D *output)
Compute sum.
- Parameters:
matrix – [in] Addend.
output – [inout] Result.
- Returns:
True on success, false on failure.
-
static bool Add(const Matrix2D &first_matrix, const Matrix2D &second_matrix, Matrix2D *output)
Compute sum.
- Parameters:
first_matrix – [in] Augend.
second_matrix – [in] Addend.
output – [out] Result.
- Returns:
True on success, false on failure.
-
static bool Subtract(const Matrix2D &matrix, Matrix2D *output)
Compute difference.
- Parameters:
matrix – [in] Subtrahend.
output – [inout] Result.
- Returns:
True on success, false on failure.
-
static bool Subtract(const Matrix2D &first_matrix, const Matrix2D &second_matrix, Matrix2D *output)
Compute difference.
- Parameters:
first_matrix – [in] Minuend.
second_matrix – [in] Subtrahend.
output – [out] Result.
- Returns:
True on success, false on failure.
-
Matrix2D()
-
class SymmetricMatrix
Symmetric matrix.
Public Functions
-
explicit SymmetricMatrix(int num_dimension = 0)
- Parameters:
num_dimension – [in] Size of matrix.
-
SymmetricMatrix(const SymmetricMatrix &matrix)
- Parameters:
matrix – [in] Symmetric matrix.
-
SymmetricMatrix &operator=(const SymmetricMatrix &matrix)
- Parameters:
matrix – [in] Symmetric matrix.
-
inline int GetNumDimension() const
- Returns:
Number of dimensions.
-
void Resize(int num_dimension)
Resize matrix.
- Parameters:
num_dimension – [in] Number of dimensions.
-
double &At(int row, int column)
Get element.
- Parameters:
row – [in] i.
column – [in] j.
- Returns:
(i, j)-th element.
-
const double &At(int row, int column) const
Get element.
- Parameters:
row – [in] i.
column – [in] j.
- Returns:
(i, j)-th element.
-
void Fill(double value)
Overwrite all elements with a value.
- Parameters:
value – [in] Value.
-
bool GetDiagonal(std::vector<double> *diagonal_elements) const
Get diagonal elements.
- Parameters:
diagonal_elements – [out] Diagonal elements.
- Returns:
True on success, false on failure.
-
bool SetDiagonal(const std::vector<double> &diagonal_elements) const
Set diagonal elements.
- Parameters:
diagonal_elements – [in] Diagonal elements.
- Returns:
True on success, false on failure.
-
bool CholeskyDecomposition(SymmetricMatrix *lower_triangular_matrix, std::vector<double> *diagonal_elements) const
Perform Cholesky decomposition.
- Parameters:
lower_triangular_matrix – [out] Lower triangular matrix.
diagonal_elements – [out] Diagonal elements.
- Returns:
True on success, false on failure.
-
bool Invert(SymmetricMatrix *inverse_matrix) const
Compute inverse matrix.
- Parameters:
inverse_matrix – [out] Inverse matrix.
- Returns:
True on success, false on failure.
-
class Row
A row of symmetric matrix.a
Public Functions
-
inline Row(const SymmetricMatrix &matrix, int row)
- Parameters:
matrix – [in] Symmetric matrix.
row – [in] Row index.
-
double &operator[](int column)
- Parameters:
column – [in] Column index.
- Returns:
Element.
-
const double &operator[](int column) const
- Parameters:
column – [in] Column index.
- Returns:
Element.
-
inline Row(const SymmetricMatrix &matrix, int row)
-
explicit SymmetricMatrix(int num_dimension = 0)
-
class SymmetricSystemSolver
Solve the following symmetric system:
\[ \boldsymbol{A} \boldsymbol{x} = \boldsymbol{b}, \]where \(\boldsymbol{A}\) is a symmetric matrix.The inputs are \(\boldsymbol{A}\) and \(M\)-th order constant vector:
\[ \begin{array}{cccc} b(0), & b(1), & \ldots, & b(M). \end{array} \]The outputs are the unknown coefficients\[ \begin{array}{cccc} x(0), & x(1), & \ldots, & x(M). \end{array} \]Public Functions
-
explicit SymmetricSystemSolver(int num_order)
- Parameters:
num_order – [in] Order of vector, \(M\).
-
inline int GetNumOrder() const
- Returns:
Order of vector.
-
inline bool IsValid() const
- Returns:
True if this object is valid.
-
bool Run(const SymmetricMatrix &coefficient_matrix, const std::vector<double> &constant_vector, std::vector<double> *solution_vector, SymmetricSystemSolver::Buffer *buffer) const
- Parameters:
coefficient_matrix – [in] \((M+1, M+1)\) matrix \(\boldsymbol{A}\).
constant_vector – [in] \(M\)-th order vector \(\boldsymbol{b}\).
solution_vector – [out] \(M\)-th order vector \(\boldsymbol{x}\).
buffer – [out] Buffer.
- Returns:
True on success, false on failure.
-
class Buffer
Buffer for SymmetricSystemSolver class.
-
explicit SymmetricSystemSolver(int num_order)
-
class ToeplitzPlusHankelSystemSolver
Solve the following Toeplitz-plus-Hankel system:
\[ (\boldsymbol{T} + \boldsymbol{H}) \boldsymbol{x} = \boldsymbol{b}, \]where\[\begin{split}\begin{eqnarray} \boldsymbol{T} &=& \left[ \begin{array}{ccccc} t(0) & t(-1) & t(-2) & \cdots & t(-M) \\ t(1) & t(0) & t(-1) & \cdots & t(-M+1) \\ t(2) & t(1) & t(0) & \ddots & \vdots \\ \vdots & \vdots & \ddots & \ddots & t(-1) \\ t(M) & t(M-1) & \cdots & t(1) & t(0) \end{array} \right], \\ \boldsymbol{H} &=& \left[ \begin{array}{ccccc} h(0) & h(1) & h(2) & \cdots & h(M) \\ h(1) & h(2) & h(3) & \cdots & h(M+1) \\ h(2) & t(3) & h(4) & \ddots & \vdots \\ \vdots & \vdots & \ddots & \ddots & h(2M-1) \\ h(M) & h(M+1) & \cdots & h(2M-1)& h(2M) \end{array} \right], \\ \boldsymbol{b} &=& \left[ \begin{array}{cccc} b(0) & b(1) & \cdots & b(M) \end{array} \right]^\mathsf{T}. \\ \end{eqnarray}\end{split}\]The inputs are \((2M+1)\) Toeplitz coefficient vector:
\[ \begin{array}{cccc} t(-M), & t(-M+1), & \ldots, & t(M), \end{array} \]\((2M+1)\) Hankel coefficient vector:\[ \begin{array}{cccc} h(0), & h(1), & \ldots, & h(2M), \end{array} \]and \((M+1)\) constant vector:\[ \begin{array}{cccc} b(0), & b(1), & \ldots, & b(M). \end{array} \]The outputs are the unknown coefficients\[ \begin{array}{cccc} x(0), & x(1), & \ldots, & x(M). \end{array} \][1] G. Merchant and T. Parks, “Efficient solution of a Toeplitz-plus-Hankel coefficient matrix system of equations,” IEEE Transactions on Acoustics, Speech, and Signal Processing, vol. 30, no. 1, pp. 40-44, 1982.
Public Functions
-
explicit ToeplitzPlusHankelSystemSolver(int num_order, bool coefficients_modification = true)
- Parameters:
num_order – [in] Order of vector, \(M\).
coefficients_modification – [in] If true, perform coefficients modification.
-
inline int GetNumOrder() const
- Returns:
Order of vector.
-
inline bool GetCoefficientsModificationFlag()
- Returns:
Ture if coefficients modification is enabled.
-
inline bool IsValid() const
- Returns:
True if this object is valid.
-
bool Run(const std::vector<double> &toeplitz_coefficient_vector, const std::vector<double> &hankel_coefficient_vector, const std::vector<double> &constant_vector, std::vector<double> *solution_vector, ToeplitzPlusHankelSystemSolver::Buffer *buffer) const
- Parameters:
toeplitz_coefficient_vector – [in] \(2M\)-th order coefficient vector of Toeplitz matrix \(\boldsymbol{T}\).
hankel_coefficient_vector – [in] \(2M\)-th order coefficient vector of Hankel matrix \(\boldsymbol{H}\).
constant_vector – [in] \(M\)-th order constant vector \(\boldsymbol{b}\).
solution_vector – [out] \(M\)-th order solution vector \(\boldsymbol{x}\).
buffer – [out] Buffer.
- Returns:
True on success, false on failure.
-
class Buffer
Buffer for ToeplitzPlusHankelSystemSolver class.
-
explicit ToeplitzPlusHankelSystemSolver(int num_order, bool coefficients_modification = true)
-
class VandermondeSystemSolver
Solve the following Vandermonde system:
\[\begin{split} \left[ \begin{array}{cccc} 1 & 1 & \cdots & 1 \\ x(0) & x(1) & \cdots & x(M) \\ x^2(0) & x^2(1) & \cdots & x^2(M) \\ \vdots & \vdots & \ddots & \vdots \\ x^M(0) & x^M(1) & \cdots & x^M(M) \end{array} \right] \left[ \begin{array}{c} w(0) \\ w(1) \\ w(2) \\ \vdots \\ w(M) \end{array} \right] = \left[ \begin{array}{c} q(0) \\ q(1) \\ q(2) \\ \vdots \\ q(M) \end{array} \right]. \end{split}\]The inputs are
\[ \begin{array}{cccc} x(0), & x(1), & \ldots, & x(M), \end{array} \]and\[ \begin{array}{cccc} q(0), & q(1), & \ldots, & q(M). \end{array} \]The outputs are the unknown coefficients\[ \begin{array}{cccc} w(0), & w(1), & \ldots, & w(M). \end{array} \][1] W. H. Press, et al., “Numerical recipes in C: The art of scientific computing,” Cambridge University Press, pp. 90-92, 1992.
Public Functions
-
explicit VandermondeSystemSolver(int num_order)
- Parameters:
num_order – [in] Order of vector, \(M\).
-
inline int GetNumOrder() const
- Returns:
Order of vector.
-
inline bool IsValid() const
- Returns:
True if this object is valid.
-
bool Run(const std::vector<double> &coefficient_vector, const std::vector<double> &constant_vector, std::vector<double> *solution_vector, VandermondeSystemSolver::Buffer *buffer) const
- Parameters:
coefficient_vector – [in] \(M\)-th order vector \(\boldsymbol{x}\).
constant_vector – [in] \(M\)-th order vector \(\boldsymbol{q}\).
solution_vector – [out] \(M\)-th order vector \(\boldsymbol{w}\).
buffer – [out] Buffer.
- Returns:
True on success, false on failure.
-
class Buffer
Buffer for VandermondeSystemSolver class.
-
explicit VandermondeSystemSolver(int num_order)