#include <matrix.h>
Public Member Functions | |
Matrix (int rowDim=0, int colDim=0) | |
Matrix::Matrix Default constructor - creates a Matrix of given dimension (0x0) Use resize(m,n) or zeromatrix(m,n) to resize it. More... | |
Matrix (const Matrix &b) | |
Matrix::Matrix Copy constructor. Creates a Matrix identical to Matrix b Allows Matrix a=b declaration Every MatrixRow object holds max_int=32762. More... | |
~Matrix () | |
Matrix::~Matrix Destructor. More... | |
void | clear () |
Clears data. More... | |
void | resize (const int m, const int n) |
Resizes this matrix to m x n Called before every operation on new matrices. Every MatrixRow object holds max_int=32762. More... | |
qreal | item (int r, int c) |
Returns the (r,c) matrix element. More... | |
void | setItem (const int r, const int c, const qreal elem) |
Sets the (r,c) matrix element calling the setColumn method. More... | |
qreal | operator() (const int r, const int c) |
MatrixRow & | operator[] (const int &r) |
void | clearItem (int r, int c) |
Clears the (r,c) matrix element. More... | |
int | cols () |
int | rows () |
int | size () |
void | findMinMaxValues (qreal &min, qreal &max, bool &hasRealNumbers) |
finds Min-Max values in current Matrix More... | |
void | NeighboursNearestFarthest (qreal &min, qreal &max, int &imin, int &jmin, int &imax, int &jmax) |
Like Matrix::findMinMaxValues only it skips r==c. More... | |
void | deleteRowColumn (int i) |
Deletes row and column and shifts rows and cols accordingly. More... | |
void | identityMatrix (int dim) |
Makes this square matrix the identity square matrix I. More... | |
void | zeroMatrix (const int m, const int n) |
Makes this matrix the zero matrix of size mxn. More... | |
void | fillMatrix (qreal value) |
Fills a matrix with a given value. More... | |
Matrix & | subtractFromI () |
Subtracts this matrix from I and returns. More... | |
Matrix & | operator= (Matrix &a) |
Matrix equality/assignment , operator = Allows copying a matrix onto another using b=a where b,a matrices Equals two matrices. More... | |
void | sum (Matrix &a, Matrix &b) |
Matrix addition Takes two (nxn) matrices and returns their sum as a reference to this Same algorithm as operator +, just different interface. In this case, you use something like: c.sum(a,b) More... | |
void | operator+= (Matrix &b) |
Matrix::operator += Matrix add another matrix: += Adds to this matrix another matrix B of the same dim and returns to this Allows A+=B. More... | |
Matrix & | operator+ (Matrix &b) |
Matrix addition, operator + Adds this matrix and B of the same dim and returns the sum S Allows S = A+B. More... | |
Matrix & | operator- (Matrix &b) |
Matrix subtraction, operator - Subtract this matrix - B of the same dim and returns the result S Allows S = A-B. More... | |
Matrix & | operator* (Matrix &b) |
Matrix multiplication, operator * Multiplies (right) this matrix with given matrix b. Allows P = A * B where A,B of same dimension and returns product as a reference to the calling object. More... | |
void | operator*= (Matrix &b) |
Multiplies (right) this m x n matrix with given n x p matrix b and returns the product in the calling matrix which becomes an m x p matrix. This convenience operator *= allows A *= B. More... | |
void | product (Matrix &A, Matrix &B, bool symmetry=false) |
Matrix Multiplication. Given two matrices A (mxn) and B (nxp) computes their product and stores it to the calling matrix which becomes an m x p matrix Allows P.product(A, B) More... | |
Matrix & | productSym (Matrix &a, Matrix &b) |
Takes two ( N x N ) matrices (symmetric) and outputs an upper triangular matrix. More... | |
void | swapRows (int rowA, int rowB) |
Swaps row A with row B of this matrix. More... | |
void | multiplyScalar (const qreal &f) |
Scalar Multiplication. Multiplies this by qreal f and returns the product matrix of the same dim Allows to use P.multiplyScalar(f) More... | |
void | multiplyRow (int row, qreal value) |
Multiply every element of row by value. More... | |
void | productByVector (qreal in[], qreal out[], const bool &leftMultiply=false) |
Calculates the matrix-by-vector product Ax of this matrix Default product: Ax if leftMultiply=true then it returns the left product xA. More... | |
Matrix & | pow (int n, bool symmetry=false) |
Returns the n-nth power of this matrix. More... | |
Matrix & | expBySquaring2 (Matrix &Y, Matrix &X, int n, bool symmetry=false) |
Recursive algorithm implementing "Exponentiation by squaring". Also known as Fast Modulo Multiplication, this algorithm allows fast computation of a large power n of square matrix X. More... | |
qreal | distanceManhattan (qreal x[], qreal y[], int n) |
Helper function, takes to vectors and returns their Manhattan distance (also known as l1 norm, Taxicab or L1 distance) which is the sum of the absolute differences of their coordinates. More... | |
qreal | distanceEuclidean (qreal x[], int n) |
Helper function, computes the Euclideian length (also known as L2 distance) of a vector: if x = (x1 x2 ... xn), then ||x|| = square_root(x1*x1 + x2*x2 + ... + xn*xn) More... | |
void | powerIteration (qreal x[], qreal &xsum, qreal &xmax, int &xmaxi, qreal &xmin, int &xmini, const qreal eps, const int &maxIter) |
Implementation of the Power method which computes the leading eigenvector x of this matrix, that is the eigenvector corresponding to the largest positive eigenvalue. In the process, it also computes min and max values. Used by Eigenvector Centrality (EVC). We use C arrays instead of std::vectors or anything else, as we know from start the size (n) of vectors x and tmp This approach is faster than using std::vector when n > 1000. More... | |
Matrix & | degreeMatrix () |
Returns the Degree Matrix of this matrix. The Degree Matrix is diagonal matrix which contains information about the degree of each graph vertex (row of the adjacency matrix) Allows S = A.degreeMatrix() More... | |
Matrix & | laplacianMatrix () |
Returns the Laplacian of this matrix. The Laplacian is a NxN matrix L = D - A where D is the degree matrix of A Allows S = A.laplacianMatrix() More... | |
Matrix & | transpose () |
Returns the Transpose of this matrix Allows T = A.transpose() More... | |
Matrix & | cocitationMatrix () |
Returns the Cocitation Matrix of this matrix (C = A * A^T) Allows T = A.cocitationMatrix() More... | |
Matrix & | inverseByGaussJordanElimination (Matrix &a) |
Inverts given matrix A by Gauss Jordan elimination Input: matrix A Output: matrix A becomes unit matrix this becomes the invert of A and is returned back. More... | |
Matrix & | inverse (Matrix &a) |
Computes and returns the inverse of given matrix a Allows b.inverse(a) More... | |
bool | solve (qreal b[]) |
Computes and returns the solution of the set of n linear equations A·x = b Allows A.solve(b) More... | |
bool | ludcmp (Matrix &a, const int &n, int indx[], qreal &d) |
Given matrix a, it replaces a by the LU decomposition of a rowwise permutation of itself. Used in combination with lubksb to solve linear equations or invert a matrix. More... | |
void | lubksb (Matrix &a, const int &n, int indx[], qreal b[]) |
Solves the set of n linear equations A·X = b, where A nxn matrix decomposed as L·U (L lower triangular and U upper triangular) by forward substitution and backsubstitution. More... | |
Matrix & | distancesMatrix (const int &metric, const QString varLocation, const bool &diagonal, const bool &considerWeights) |
Computes the dissimilarities matrix of the variables (rows, columns, both) of this matrix using the user defined metric. More... | |
Matrix & | similarityMatrix (Matrix &AM, const int &measure, const QString varLocation="Rows", const bool &diagonal=false, const bool &considerWeights=true) |
Computes the pair-wise matching score of the rows, columns or both of the given matrix AM, based on the given matching measure and returns the similarity matrix. More... | |
Matrix & | pearsonCorrelationCoefficients (Matrix &AM, const QString &varLocation="Rows", const bool &diagonal=false) |
Computes the Pearson Correlation Coefficient of the rows or the columns of the given matrix AM. More... | |
bool | printHTMLTable (QTextStream &os, const bool markDiag=false, const bool &plain=false, const bool &printInfinity=true) |
Prints this matrix as HTML table This has the problem that the real actorNumber != elementLabel i.e. when we have deleted a node/vertex. More... | |
bool | printMatrixConsole (bool debug=true) |
Prints this matrix to stderr or stdout. More... | |
bool | illDefined () |
Checks if matrix is ill-defined (contains at least an inf element) More... | |
Private Attributes | |
MatrixRow * | row |
int | m_rows |
int | m_cols |
Friends | |
QTextStream & | operator<< (QTextStream &os, Matrix &m) |
Prints matrix m to given textstream. More... | |
Constructor & Destructor Documentation
◆ Matrix() [1/2]
Matrix::Matrix | ( | int | rowDim = 0 , |
int | colDim = 0 |
||
) |
Matrix::Matrix Default constructor - creates a Matrix of given dimension (0x0) Use resize(m,n) or zeromatrix(m,n) to resize it.
default constructor - default rows = cols = 0
- Parameters
-
Actors
◆ Matrix() [2/2]
Matrix::Matrix | ( | const Matrix & | b | ) |
Matrix::Matrix Copy constructor. Creates a Matrix identical to Matrix b Allows Matrix a=b declaration Every MatrixRow object holds max_int=32762.
- Parameters
-
b
◆ ~Matrix()
Matrix::~Matrix | ( | ) |
Matrix::~Matrix Destructor.
Member Function Documentation
◆ clear()
void Matrix::clear | ( | ) |
Clears data.
◆ clearItem()
void Matrix::clearItem | ( | int | r, |
int | c | ||
) |
Clears the (r,c) matrix element.
- Parameters
-
r c
◆ cocitationMatrix()
Matrix & Matrix::cocitationMatrix | ( | ) |
◆ cols()
|
inline |
◆ degreeMatrix()
Matrix & Matrix::degreeMatrix | ( | ) |
◆ deleteRowColumn()
void Matrix::deleteRowColumn | ( | int | erased | ) |
Deletes row and column and shifts rows and cols accordingly.
- Parameters
-
erased row/col to delete
◆ distanceEuclidean()
qreal Matrix::distanceEuclidean | ( | qreal | x[], |
int | n | ||
) |
Helper function, computes the Euclideian length (also known as L2 distance) of a vector: if x = (x1 x2 ... xn), then ||x|| = square_root(x1*x1 + x2*x2 + ... + xn*xn)
- Parameters
-
x n
- Returns
◆ distanceManhattan()
qreal Matrix::distanceManhattan | ( | qreal | x[], |
qreal | y[], | ||
int | n | ||
) |
Helper function, takes to vectors and returns their Manhattan distance (also known as l1 norm, Taxicab or L1 distance) which is the sum of the absolute differences of their coordinates.
- Parameters
-
x y
- Returns
◆ distancesMatrix()
Matrix & Matrix::distancesMatrix | ( | const int & | metric, |
const QString | varLocation, | ||
const bool & | diagonal, | ||
const bool & | considerWeights | ||
) |
Computes the dissimilarities matrix of the variables (rows, columns, both) of this matrix using the user defined metric.
- Parameters
-
metric varLocation diagonal considerWeights
- Returns
◆ expBySquaring2()
Recursive algorithm implementing "Exponentiation by squaring". Also known as Fast Modulo Multiplication, this algorithm allows fast computation of a large power n of square matrix X.
- Parameters
-
Y must be the Identity matrix on first call X the matrix to be powered n the power symmetry
- Returns
- Matrix&
On first call, parameters must be: Y=I, X the orginal matrix to power and n the power. Returns the power of matrix X to this object. For n > 4 it is more efficient than naively multiplying the base with itself repeatedly.
◆ fillMatrix()
void Matrix::fillMatrix | ( | qreal | value | ) |
Fills a matrix with a given value.
- Parameters
-
value
◆ findMinMaxValues()
void Matrix::findMinMaxValues | ( | qreal & | min, |
qreal & | max, | ||
bool & | hasRealNumbers | ||
) |
finds Min-Max values in current Matrix
- Parameters
-
min value in the matrix max value Complexity: O(n^2)
◆ identityMatrix()
void Matrix::identityMatrix | ( | int | dim | ) |
Makes this square matrix the identity square matrix I.
- Parameters
-
dim
◆ illDefined()
bool Matrix::illDefined | ( | ) |
Checks if matrix is ill-defined (contains at least an inf element)
- Returns
◆ inverse()
Computes and returns the inverse of given matrix a Allows b.inverse(a)
- Parameters
-
a
- Returns
◆ inverseByGaussJordanElimination()
Inverts given matrix A by Gauss Jordan elimination Input: matrix A Output: matrix A becomes unit matrix this becomes the invert of A and is returned back.
- Parameters
-
A
- Returns
- inverse matrix of A
◆ item()
qreal Matrix::item | ( | int | r, |
int | c | ||
) |
Returns the (r,c) matrix element.
- Parameters
-
r c
- Returns
◆ laplacianMatrix()
Matrix & Matrix::laplacianMatrix | ( | ) |
Returns the Laplacian of this matrix. The Laplacian is a NxN matrix L = D - A where D is the degree matrix of A Allows S = A.laplacianMatrix()
- Parameters
-
b
- Returns
- Matrix S
◆ lubksb()
void Matrix::lubksb | ( | Matrix & | a, |
const int & | n, | ||
int | indx[], | ||
qreal | b[] | ||
) |
Solves the set of n linear equations A·X = b, where A nxn matrix decomposed as L·U (L lower triangular and U upper triangular) by forward substitution and backsubstitution.
Given A = L·U we have A · x = (L · U) · x = L · (U · x) = b So, this routine first solves L · y = b for the vector y by forward substitution and then solves U · x = y for the vector x using backsubstitution
- Parameters
-
a input matrix a as the LU decomposition of A, returned by the routine ludcmp n input size of matrix indx input vector, records the row permutation, returned by the routine ludcmp b input array as the right-hand side vector B, and output with the solution vector X
- Returns
- :
a, n, and indx are not modified by this routine and can be left in place for successive calls with different right-hand sides b. This routine takes into account the possibility that b will begin with many zero elements, so it is efficient for use in matrix inversion.
Code adapted from Knuth's Numerical Recipes in C, pp 47
◆ ludcmp()
bool Matrix::ludcmp | ( | Matrix & | a, |
const int & | n, | ||
int | indx[], | ||
qreal & | d | ||
) |
Given matrix a, it replaces a by the LU decomposition of a rowwise permutation of itself. Used in combination with lubksb to solve linear equations or invert a matrix.
- Parameters
-
a input matrix n x n and output arranged as in Knuth's equation (2.3.14) n input size of matrix indx output vector, records the row permutation effected by the partial pivoting d output as ±1 depending on whether the number of row interchanges was even or odd
- Returns
- :
Code adapted from Knuth's Numerical Recipes in C, pp 46
◆ multiplyRow()
void Matrix::multiplyRow | ( | int | row, |
qreal | value | ||
) |
Multiply every element of row by value.
- Parameters
-
row value
◆ multiplyScalar()
void Matrix::multiplyScalar | ( | const qreal & | f | ) |
Scalar Multiplication. Multiplies this by qreal f and returns the product matrix of the same dim Allows to use P.multiplyScalar(f)
- Parameters
-
f
◆ NeighboursNearestFarthest()
void Matrix::NeighboursNearestFarthest | ( | qreal & | min, |
qreal & | max, | ||
int & | imin, | ||
int & | jmin, | ||
int & | imax, | ||
int & | jmax | ||
) |
Like Matrix::findMinMaxValues only it skips r==c.
- Parameters
-
min value. If (r,c) = minimum, it mean that neighbors r and c are the nearest in the matrix/network max value Complexity: O(n^2)
◆ operator()()
|
inline |
◆ operator*()
Matrix multiplication, operator * Multiplies (right) this matrix with given matrix b. Allows P = A * B where A,B of same dimension and returns product as a reference to the calling object.
- Parameters
-
b symmetry
- Returns
◆ operator*=()
void Matrix::operator*= | ( | Matrix & | b | ) |
Multiplies (right) this m x n matrix with given n x p matrix b and returns the product in the calling matrix which becomes an m x p matrix. This convenience operator *= allows A *= B.
- Parameters
-
b symmetry
- Returns
◆ operator+()
◆ operator+=()
void Matrix::operator+= | ( | Matrix & | b | ) |
Matrix::operator += Matrix add another matrix: += Adds to this matrix another matrix B of the same dim and returns to this Allows A+=B.
- Parameters
-
b
- Returns
- this
◆ operator-()
◆ operator=()
Matrix equality/assignment , operator = Allows copying a matrix onto another using b=a where b,a matrices Equals two matrices.
- Parameters
-
a
- Returns
◆ operator[]()
|
inline |
◆ pearsonCorrelationCoefficients()
◆ pow()
Matrix & Matrix::pow | ( | int | n, |
bool | symmetry = false |
||
) |
◆ powerIteration()
void Matrix::powerIteration | ( | qreal | x[], |
qreal & | xsum, | ||
qreal & | xmax, | ||
int & | xmaxi, | ||
qreal & | xmin, | ||
int & | xmini, | ||
const qreal | eps, | ||
const int & | maxIter | ||
) |
Implementation of the Power method which computes the leading eigenvector x of this matrix, that is the eigenvector corresponding to the largest positive eigenvalue. In the process, it also computes min and max values. Used by Eigenvector Centrality (EVC). We use C arrays instead of std::vectors or anything else, as we know from start the size (n) of vectors x and tmp This approach is faster than using std::vector when n > 1000.
- Parameters
-
x xsum xmax xmaxi xmin xmini eps maxIter
◆ printHTMLTable()
bool Matrix::printHTMLTable | ( | QTextStream & | os, |
const bool | markDiag = false , |
||
const bool & | plain = false , |
||
const bool & | printInfinity = true |
||
) |
Prints this matrix as HTML table This has the problem that the real actorNumber != elementLabel i.e. when we have deleted a node/vertex.
- Parameters
-
os debug
- Returns
◆ printMatrixConsole()
bool Matrix::printMatrixConsole | ( | bool | debug = true | ) |
Prints this matrix to stderr or stdout.
- Returns
◆ product()
Matrix Multiplication. Given two matrices A (mxn) and B (nxp) computes their product and stores it to the calling matrix which becomes an m x p matrix Allows P.product(A, B)
- Parameters
-
A B symmetry
- Returns
- i x k matrix
◆ productByVector()
void Matrix::productByVector | ( | qreal | in[], |
qreal | out[], | ||
const bool & | leftMultiply = false |
||
) |
Calculates the matrix-by-vector product Ax of this matrix Default product: Ax if leftMultiply=true then it returns the left product xA.
- Parameters
-
in input array/vector out output array leftMultiply
◆ productSym()
Takes two ( N x N ) matrices (symmetric) and outputs an upper triangular matrix.
- Parameters
-
a b
- Returns
◆ resize()
void Matrix::resize | ( | const int | m, |
const int | n | ||
) |
Resizes this matrix to m x n Called before every operation on new matrices. Every MatrixRow object holds max_int=32762.
- Parameters
-
Actors
◆ rows()
|
inline |
◆ setItem()
void Matrix::setItem | ( | const int | r, |
const int | c, | ||
const qreal | elem | ||
) |
Sets the (r,c) matrix element calling the setColumn method.
- Parameters
-
r c elem
◆ similarityMatrix()
◆ size()
|
inline |
◆ solve()
bool Matrix::solve | ( | qreal | b[] | ) |
Computes and returns the solution of the set of n linear equations A·x = b Allows A.solve(b)
- Parameters
-
b vector
- Returns
◆ subtractFromI()
Matrix & Matrix::subtractFromI | ( | ) |
Subtracts this matrix from I and returns.
- Returns
- I-this to this matrix
◆ sum()
Matrix addition Takes two (nxn) matrices and returns their sum as a reference to this Same algorithm as operator +, just different interface. In this case, you use something like: c.sum(a,b)
- Parameters
-
a b
- Returns
◆ swapRows()
void Matrix::swapRows | ( | int | rowA, |
int | rowB | ||
) |
Swaps row A with row B of this matrix.
- Parameters
-
rowA rowB
◆ transpose()
Matrix & Matrix::transpose | ( | ) |
◆ zeroMatrix()
void Matrix::zeroMatrix | ( | const int | m, |
const int | n | ||
) |
Makes this matrix the zero matrix of size mxn.
- Parameters
-
m n
Friends And Related Function Documentation
◆ operator<<
|
friend |
Prints matrix m to given textstream.
- Parameters
-
os m
- Returns
Member Data Documentation
◆ m_cols
|
private |
◆ m_rows
|
private |
◆ row
|
private |
The documentation for this class was generated from the following files:
- app/src/matrix.h
- app/src/matrix.cpp