ʻOhana
Population structure, admixture history, and selection using learning methods.
|
A template class for a matrix. More...
#include <jade.matrix.hpp>
Public Types | |
typedef TValue | value_type |
The value type. More... | |
typedef basic_blas< value_type > | blas_type |
The BLAS type. More... | |
typedef basic_lapack< value_type > | lapack_type |
The LAPACK type. More... | |
typedef std::initializer_list< std::initializer_list< value_type > > | initializer_list_type |
The initializer list type. More... | |
Public Member Functions | |
basic_matrix () | |
Initializes a new instance of the class with no size. More... | |
basic_matrix (const size_t cy, const size_t cx) | |
Initializes a new instance of the class based on the specified width and height. More... | |
basic_matrix (const char *const path) | |
Initializes a new instance of the class based on values from the specified file. More... | |
basic_matrix (const std::string &path) | |
Initializes a new instance of the class based on values from the specified file. More... | |
basic_matrix (std::istream &in) | |
Initializes a new instance of the class based on values from the specified input stream. More... | |
basic_matrix (const initializer_list_type &values) | |
Initializes a new instance of the class based on the specified values. More... | |
template<typename TPredicate > | |
bool | all_of (const TPredicate predicate) const |
template<typename TPredicate > | |
bool | any_of (const TPredicate predicate) const |
void | clamp (const value_type min, const value_type max) |
Clamps all values in the matrix to the specified range. More... | |
void | clamp_column (const size_t column, const value_type min, const value_type max) |
Clamps all values in a column to the specified range. More... | |
void | clamp_row (const size_t row, const value_type min, const value_type max) |
Clamps all values in a row to the specified range. More... | |
bool | contains_inf () const |
bool | contains_nan () const |
basic_matrix | copy_column (const size_t column) const |
void | copy_column (const size_t column, basic_matrix &out) const |
Copies a column into the specified vector. More... | |
void | copy_lower_to_upper () |
Copies the elements in the lower triangle of the square matrix to the corresponding upper triangle elements. More... | |
basic_matrix | copy_row (const size_t row) const |
void | copy_row (const size_t row, basic_matrix &out) const |
Copies a row into the specified matrix. More... | |
void | copy_upper_to_lower () |
Copies the elements in the upper triangle of the square matrix to the corresponding lower triangle elements. More... | |
basic_matrix | create_transpose () const |
void | create_transpose (basic_matrix &out) const |
Stores the transpose of the matrix. More... | |
bool | gesv () |
Computes the solution to the system of linear equations with a square coefficient matrix A and multiple right-hand sides. Specifically, this method solves for X the system of linear equations A*X = B, where A is an n-by-n matrix, the columns of matrix B are individual right-hand sides, and the columns of X are the corresponding solutions. More... | |
value_type | get_column_sum (const size_t column) const |
const value_type * | get_data () const |
value_type * | get_data () |
const value_type * | get_data (const size_t index) const |
value_type * | get_data (const size_t index) |
const value_type * | get_data (const size_t row, const size_t column) const |
value_type * | get_data (const size_t row, const size_t column) |
size_t | get_height () const |
size_t | get_index (const size_t row, const size_t column) const |
size_t | get_length () const |
value_type | get_max_value () const |
Returns the maximum element value. This method should not be called if the matrix is empty. More... | |
value_type | get_min_value () const |
Returns the minimum element value. This method should not be called if the matrix is empty. More... | |
bool | get_min_max (value_type &min, value_type &max) const |
Returns the minimum and maximum elements in the matrix. If the matrix is empty, this method returns false. Otherwise, this method stores the results in the specified arguments and returns true. More... | |
bool | get_min_max_column (const size_t column, value_type &min, value_type &max) const |
Returns the minimum and maximum elements in a column. If the matrix is empty, this method returns false. Otherwise, this method stores the results in the specified arguments and returns true. More... | |
value_type | get_row_sum (const size_t row) const |
std::string | get_size_str () const |
value_type | get_sum () const |
size_t | get_width () const |
value_type | get_value (const size_t index) const |
value_type | get_value (const size_t row, const size_t column) const |
bool | invert (value_type &log_det) |
Computes and stores the inverse of this matrix using the Cholesky square root method. Only the lower-left triangle is used to perform the calculation. If this method fails, indicating this matrix is not positive semidefinite, then the contents of this instance and the parameter are left undefined, and the method returns false. Otherwise, the lower triangle is copied to the upper triangle, the parameter is assigned the log of the determinant of the original matrix values, and the method returns true. More... | |
bool | invert () |
Computes and stores the inverse of this matrix using the Cholesky square root method. Only the lower-left triangle is used to perform the calculation. If this method fails, indicating this matrix is not positive semidefinite, then the contents of this instance is left undefined, and the method returns false. Otherwise, the lower triangle is copied to the upper triangle, and the method returns true. More... | |
bool | is_column_vector () const |
bool | is_empty () const |
bool | is_row_vector () const |
bool | is_length (const basic_matrix &other) const |
bool | is_length (const size_t length) const |
bool | is_size (const basic_matrix &other) const |
bool | is_size (const size_t height, const size_t width) const |
bool | is_square () const |
bool | is_vector () const |
void | multiply_column (const size_t column, const value_type value) |
Multiplies a column by a specified value. More... | |
value_type | multiply_column (const size_t column, const basic_matrix &vector) |
void | multiply_row (const size_t row, const value_type value) |
Multiplies a row by a specified value. More... | |
value_type | multiply_row (const size_t row, const basic_matrix &vector) const |
bool | potrf_lower () |
Forms the Cholesky factorization of a symmetric positive-definite matrix: [A = L * L^T] where L is the lower triangular portion of the matrix. More... | |
bool | potri_lower () |
Computes the inverse inv(A) of a symmetric positive definite matrix A. Before calling this routine, call dpotrf to factorize A. More... | |
void | read (const std::string &path) |
Reads the matrix values from the specified file. More... | |
void | read (const char *const path) |
Reads the matrix values from the specified file. More... | |
void | read (std::istream &in) |
Reads the matrix values from the specified stream. More... | |
void | resize (const size_t height, const size_t width) |
Resizes the matrix to the specified dimensions. The values of the matrix are not reset. More... | |
void | set_value (const size_t index, const value_type &value) |
Sets a single value of the vector. More... | |
void | set_value (const size_t row, const size_t column, const value_type &value) |
Sets a single value of the matrix. More... | |
void | set_values (const value_type value) |
Sets all values of the matrix to the specified value. More... | |
std::string | str () const |
void | swap (basic_matrix &other) |
Swaps this matrix and another matrix. More... | |
void | transpose () |
Transposes this matrix. More... | |
void | write (const std::string &path) const |
Writes this matrix to the specified file. More... | |
void | write (const char *const path) const |
Writes this matrix to the specified file. More... | |
void | write (std::ostream &out) const |
Writes this matrix to the specified output stream. More... | |
const value_type & | operator[] (const size_t rhs) const |
value_type & | operator[] (const size_t rhs) |
const value_type & | operator() (const size_t rhs_1, const size_t rhs_2) const |
value_type & | operator() (const size_t rhs_1, const size_t rhs_2) |
basic_matrix & | operator+= (const basic_matrix &rhs) |
Adds the specified matrix to this instance. More... | |
basic_matrix & | operator+= (const value_type rhs) |
Adds the specified scalar to this instance. More... | |
basic_matrix & | operator-= (const basic_matrix &rhs) |
Subtracts the specified matrix from this instance. More... | |
basic_matrix & | operator-= (const value_type rhs) |
Subtracts the specified scalar from this instance. More... | |
basic_matrix & | operator*= (const basic_matrix &rhs) |
Multiplies this matrix and the specified matrix and assigns the product to this instance. More... | |
basic_matrix & | operator*= (const value_type rhs) |
Multiplies this matrix and the specified scalar and assigns the product to this instance. More... | |
basic_matrix & | operator/= (const value_type rhs) |
Divides this matrix by the specified scalar and assigns the quotient to this instance. More... | |
basic_matrix | operator+ (const basic_matrix &rhs) const |
Adds a matrix. More... | |
basic_matrix | operator+ (const value_type rhs) const |
Adds a value. More... | |
basic_matrix | operator- (const basic_matrix &rhs) const |
Subtracts a matrix. More... | |
basic_matrix | operator- (const value_type rhs) const |
Subtracts a value. More... | |
basic_matrix | operator- () const |
basic_matrix | operator* (const basic_matrix &rhs) const |
Multiplies a matrix. More... | |
basic_matrix | operator* (const value_type rhs) const |
Multiplies a scalar. More... | |
basic_matrix | operator/ (const value_type rhs) const |
Divides a scalar. More... | |
Static Public Member Functions | |
static void | gemm (const basic_matrix &lhs, const basic_matrix &rhs, basic_matrix &dst, const value_type alpha=value_type(1), const value_type beta=value_type(0)) |
Multiplies a left matrix by a right matrix and stores the result into a destination matrix. If the beta parameter is provided, the initial values of the destination matrix are scaled by beta, and the product of the left and right matrices is added to the destination matrix. If the alpha parameter is provided, the product of the left and right matrices is scaled by alpha. More... | |
static void | set_high_precision (std::ostream &out) |
Sets the specified stream to scientific notation with a high precision. More... | |
A template class for a matrix.
Definition at line 20 of file jade.matrix.hpp.
typedef basic_blas<value_type> jade::basic_matrix< TValue >::blas_type |
The BLAS type.
Definition at line 27 of file jade.matrix.hpp.
typedef std::initializer_list< std::initializer_list<value_type> > jade::basic_matrix< TValue >::initializer_list_type |
The initializer list type.
Definition at line 35 of file jade.matrix.hpp.
typedef basic_lapack<value_type> jade::basic_matrix< TValue >::lapack_type |
The LAPACK type.
Definition at line 30 of file jade.matrix.hpp.
typedef TValue jade::basic_matrix< TValue >::value_type |
The value type.
Definition at line 24 of file jade.matrix.hpp.
|
inline |
Initializes a new instance of the class with no size.
Definition at line 40 of file jade.matrix.hpp.
|
inline |
Initializes a new instance of the class based on the specified width and height.
cy | The height. |
cx | The width. |
Definition at line 49 of file jade.matrix.hpp.
|
inlineexplicit |
Initializes a new instance of the class based on values from the specified file.
path | The path to the file. |
Definition at line 64 of file jade.matrix.hpp.
|
inlineexplicit |
Initializes a new instance of the class based on values from the specified file.
path | The path to the file. |
Definition at line 75 of file jade.matrix.hpp.
|
inlineexplicit |
Initializes a new instance of the class based on values from the specified input stream.
in | The input stream. |
Definition at line 85 of file jade.matrix.hpp.
|
inlineexplicit |
Initializes a new instance of the class based on the specified values.
values | The two-dimensional values. |
Definition at line 98 of file jade.matrix.hpp.
|
inline |
predicate | The predicate function. |
Definition at line 117 of file jade.matrix.hpp.
|
inline |
predicate | The predicate function. |
Definition at line 128 of file jade.matrix.hpp.
|
inline |
Clamps all values in the matrix to the specified range.
min | The minimum value. |
max | The maximum value. |
Definition at line 138 of file jade.matrix.hpp.
|
inline |
Clamps all values in a column to the specified range.
column | The column to clamp. |
min | The minimum value. |
max | The maximum value. |
Definition at line 157 of file jade.matrix.hpp.
|
inline |
Clamps all values in a row to the specified range.
row | The row to clamp. |
min | The minimum value. |
max | The maximum value. |
Definition at line 178 of file jade.matrix.hpp.
|
inline |
Definition at line 199 of file jade.matrix.hpp.
|
inline |
Definition at line 214 of file jade.matrix.hpp.
|
inline |
column | The column to copy. |
Definition at line 230 of file jade.matrix.hpp.
|
inline |
Copies a column into the specified vector.
column | The column to copy. |
out | The output vector. |
Definition at line 242 of file jade.matrix.hpp.
|
inline |
Copies the elements in the lower triangle of the square matrix to the corresponding upper triangle elements.
Definition at line 266 of file jade.matrix.hpp.
|
inline |
row | The row to copy. |
Definition at line 312 of file jade.matrix.hpp.
|
inline |
Copies a row into the specified matrix.
row | The row to copy. |
out | The output vector. |
Definition at line 324 of file jade.matrix.hpp.
|
inline |
Copies the elements in the upper triangle of the square matrix to the corresponding lower triangle elements.
Definition at line 345 of file jade.matrix.hpp.
|
inline |
Definition at line 391 of file jade.matrix.hpp.
|
inline |
Stores the transpose of the matrix.
out | The matrix receiving the transpose. |
Definition at line 401 of file jade.matrix.hpp.
|
inlinestatic |
Multiplies a left matrix by a right matrix and stores the result into a destination matrix. If the beta parameter is provided, the initial values of the destination matrix are scaled by beta, and the product of the left and right matrices is added to the destination matrix. If the alpha parameter is provided, the product of the left and right matrices is scaled by alpha.
lhs | The matrix left of the operator. |
rhs | The matrix right of the operator. |
dst | The matrix receiving the product. |
alpha | The scalar applied to the left matrix. |
beta | The scalar applied to the right matrix. |
Definition at line 459 of file jade.matrix.hpp.
|
inline |
Computes the solution to the system of linear equations with a square coefficient matrix A and multiple right-hand sides. Specifically, this method solves for X the system of linear equations A*X = B, where A is an n-by-n matrix, the columns of matrix B are individual right-hand sides, and the columns of X are the corresponding solutions.
Definition at line 496 of file jade.matrix.hpp.
|
inline |
column | The column to sum. |
Definition at line 520 of file jade.matrix.hpp.
|
inline |
Definition at line 551 of file jade.matrix.hpp.
|
inline |
Definition at line 542 of file jade.matrix.hpp.
|
inline |
index | The index of the element. |
Definition at line 572 of file jade.matrix.hpp.
|
inline |
index | The index of the element. |
Definition at line 560 of file jade.matrix.hpp.
|
inline |
row | The row of the element. |
column | The column of the element. |
Definition at line 593 of file jade.matrix.hpp.
|
inline |
row | The row. |
column | The column. |
Definition at line 582 of file jade.matrix.hpp.
|
inline |
Definition at line 603 of file jade.matrix.hpp.
|
inline |
row | The row. |
column | The column. |
Definition at line 611 of file jade.matrix.hpp.
|
inline |
Definition at line 624 of file jade.matrix.hpp.
|
inline |
Returns the maximum element value. This method should not be called if the matrix is empty.
Definition at line 635 of file jade.matrix.hpp.
|
inline |
Returns the minimum and maximum elements in the matrix. If the matrix is empty, this method returns false. Otherwise, this method stores the results in the specified arguments and returns true.
min | The minimum value (output). |
max | The maximum value (output). |
Definition at line 663 of file jade.matrix.hpp.
|
inline |
Returns the minimum and maximum elements in a column. If the matrix is empty, this method returns false. Otherwise, this method stores the results in the specified arguments and returns true.
column | The column index. |
min | The minimum value (output). |
max | The maximum value (output). |
column | The column index. |
min | The minimum column element. |
max | The maximum column element. |
Definition at line 686 of file jade.matrix.hpp.
|
inline |
Returns the minimum element value. This method should not be called if the matrix is empty.
Definition at line 647 of file jade.matrix.hpp.
|
inline |
row | The row to sum. |
Definition at line 716 of file jade.matrix.hpp.
|
inline |
Definition at line 735 of file jade.matrix.hpp.
|
inline |
|
inline |
index | The index in the vector data. |
Definition at line 765 of file jade.matrix.hpp.
|
inline |
row | The row index. |
column | The column index. |
Definition at line 776 of file jade.matrix.hpp.
|
inline |
Definition at line 757 of file jade.matrix.hpp.
|
inline |
Computes and stores the inverse of this matrix using the Cholesky square root method. Only the lower-left triangle is used to perform the calculation. If this method fails, indicating this matrix is not positive semidefinite, then the contents of this instance is left undefined, and the method returns false. Otherwise, the lower triangle is copied to the upper triangle, and the method returns true.
Definition at line 843 of file jade.matrix.hpp.
|
inline |
Computes and stores the inverse of this matrix using the Cholesky square root method. Only the lower-left triangle is used to perform the calculation. If this method fails, indicating this matrix is not positive semidefinite, then the contents of this instance and the parameter are left undefined, and the method returns false. Otherwise, the lower triangle is copied to the upper triangle, the parameter is assigned the log of the determinant of the original matrix values, and the method returns true.
log_det | The log of the determinant. |
Definition at line 796 of file jade.matrix.hpp.
|
inline |
Definition at line 852 of file jade.matrix.hpp.
|
inline |
Definition at line 860 of file jade.matrix.hpp.
|
inline |
other | The other matrix. |
Definition at line 876 of file jade.matrix.hpp.
|
inline |
length | The length to compare. |
Definition at line 886 of file jade.matrix.hpp.
|
inline |
Definition at line 868 of file jade.matrix.hpp.
|
inline |
other | The other matrix. |
Definition at line 896 of file jade.matrix.hpp.
|
inline |
height | The height of the matrix. |
width | The width of the matrix. |
Definition at line 906 of file jade.matrix.hpp.
|
inline |
Definition at line 917 of file jade.matrix.hpp.
|
inline |
Definition at line 925 of file jade.matrix.hpp.
|
inline |
column | The column to multiply. |
vector | The vector to multiply. |
Definition at line 952 of file jade.matrix.hpp.
|
inline |
Multiplies a column by a specified value.
column | The column to multiply. |
value | The value to multiply. |
Definition at line 933 of file jade.matrix.hpp.
|
inline |
row | The row to multiply. |
vector | The vector to multiply. |
Definition at line 992 of file jade.matrix.hpp.
|
inline |
Multiplies a row by a specified value.
row | The row to multiply. |
value | The value to multiply. |
Definition at line 976 of file jade.matrix.hpp.
|
inline |
rhs_1 | The row. |
rhs_2 | The column. |
Definition at line 1317 of file jade.matrix.hpp.
|
inline |
rhs_1 | The row. |
rhs_2 | The column. |
Definition at line 1305 of file jade.matrix.hpp.
|
inline |
Multiplies a matrix.
rhs | The matrix to multiply. |
Definition at line 1519 of file jade.matrix.hpp.
|
inline |
Multiplies a scalar.
rhs | The scalar to multiply. |
Definition at line 1532 of file jade.matrix.hpp.
|
inline |
Multiplies this matrix and the specified matrix and assigns the product to this instance.
rhs | The matrix to multiply. |
Definition at line 1408 of file jade.matrix.hpp.
|
inline |
Multiplies this matrix and the specified scalar and assigns the product to this instance.
rhs | The scalar to multiply. |
Definition at line 1423 of file jade.matrix.hpp.
|
inline |
Adds a matrix.
rhs | The matrix to add. |
Definition at line 1458 of file jade.matrix.hpp.
|
inline |
Adds a value.
rhs | The value to add. |
Definition at line 1469 of file jade.matrix.hpp.
|
inline |
Adds the specified matrix to this instance.
rhs | The matrix to add. |
Definition at line 1331 of file jade.matrix.hpp.
|
inline |
Adds the specified scalar to this instance.
rhs | The scalar to add. |
Definition at line 1352 of file jade.matrix.hpp.
|
inline |
|
inline |
Subtracts a matrix.
rhs | The matrix to subtract. |
Definition at line 1480 of file jade.matrix.hpp.
|
inline |
Subtracts a value.
rhs | The value to subtract. |
Definition at line 1491 of file jade.matrix.hpp.
|
inline |
Subtracts the specified matrix from this instance.
rhs | The matrix to subtract. |
Definition at line 1369 of file jade.matrix.hpp.
|
inline |
Subtracts the specified scalar from this instance.
rhs | The scalar to subtract. |
Definition at line 1390 of file jade.matrix.hpp.
|
inline |
Divides a scalar.
rhs | The scalar to divides. |
Definition at line 1543 of file jade.matrix.hpp.
|
inline |
Divides this matrix by the specified scalar and assigns the quotient to this instance.
rhs | The scalar to multiply. |
Definition at line 1441 of file jade.matrix.hpp.
|
inline |
rhs | The element index. |
Definition at line 1295 of file jade.matrix.hpp.
|
inline |
rhs | The element index. |
Definition at line 1284 of file jade.matrix.hpp.
|
inline |
Forms the Cholesky factorization of a symmetric positive-definite matrix: [A = L * L^T] where L is the lower triangular portion of the matrix.
Definition at line 1018 of file jade.matrix.hpp.
|
inline |
Computes the inverse inv(A) of a symmetric positive definite matrix A. Before calling this routine, call dpotrf to factorize A.
Definition at line 1039 of file jade.matrix.hpp.
|
inline |
Reads the matrix values from the specified file.
An | exception if there is an error reading the file. |
path | The path to the file. |
Definition at line 1070 of file jade.matrix.hpp.
|
inline |
Reads the matrix values from the specified file.
An | exception if there is an error reading the file. |
path | The path to the file. |
Definition at line 1059 of file jade.matrix.hpp.
|
inline |
Reads the matrix values from the specified stream.
An | exception if there is an error reading the stream. |
in | The input stream. |
Definition at line 1096 of file jade.matrix.hpp.
|
inline |
Resizes the matrix to the specified dimensions. The values of the matrix are not reset.
height | The new height. |
width | The new width. |
Definition at line 1135 of file jade.matrix.hpp.
|
inlinestatic |
Sets the specified stream to scientific notation with a high precision.
out | The output stream. |
Definition at line 1154 of file jade.matrix.hpp.
|
inline |
Sets a single value of the vector.
index | The index of the value. |
value | The new value. |
Definition at line 1166 of file jade.matrix.hpp.
|
inline |
Sets a single value of the matrix.
row | The row to assign. |
column | The colum to assign. |
value | The value to assign. |
Definition at line 1177 of file jade.matrix.hpp.
|
inline |
Sets all values of the matrix to the specified value.
value | The value to assign. |
Definition at line 1189 of file jade.matrix.hpp.
|
inline |
Definition at line 1199 of file jade.matrix.hpp.
|
inline |
Swaps this matrix and another matrix.
other | The matrix to swap. |
Definition at line 1209 of file jade.matrix.hpp.
|
inline |
Transposes this matrix.
Definition at line 1220 of file jade.matrix.hpp.
|
inline |
Writes this matrix to the specified file.
An | exception if there is an error writing to the file. |
path | The path to the file. |
Definition at line 1242 of file jade.matrix.hpp.
|
inline |
Writes this matrix to the specified file.
An | exception if there is an error writing to the file. |
path | The path to the file. |
Definition at line 1230 of file jade.matrix.hpp.
|
inline |
Writes this matrix to the specified output stream.
out | The output stream. |
Definition at line 1259 of file jade.matrix.hpp.