![]() |
Code Documentation 3.1
Social Network Visualizer
|
#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. | |
| 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. | |
| ~Matrix () | |
| Matrix::~Matrix Destructor. | |
| void | clear () |
| Clears data. | |
| 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. | |
| qreal | item (int r, int c) |
| Returns the (r,c) matrix element. | |
| void | setItem (const int r, const int c, const qreal elem) |
| Sets the (r,c) matrix element calling the setColumn method. | |
| 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. | |
| int | cols () |
| int | rows () |
| int | size () |
| void | findMinMaxValues (qreal &min, qreal &max, bool &hasRealNumbers) |
| finds Min-Max values in current Matrix | |
| void | NeighboursNearestFarthest (qreal &min, qreal &max, int &imin, int &jmin, int &imax, int &jmax) |
| Like Matrix::findMinMaxValues only it skips r==c. | |
| void | deleteRowColumn (int i) |
| Deletes row and column and shifts rows and cols accordingly. | |
| void | identityMatrix (int dim) |
| Makes this square matrix the identity square matrix I. | |
| void | zeroMatrix (const int m, const int n) |
| Makes this matrix the zero matrix of size mxn. | |
| void | fillMatrix (qreal value) |
| Fills a matrix with a given value. | |
| Matrix & | subtractFromI () |
| Subtracts this matrix from I and returns. | |
| Matrix & | operator= (Matrix &a) |
| Matrix equality/assignment , operator = Allows copying a matrix onto another using b=a where b,a matrices Equals two matrices. | |
| 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) | |
| 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. | |
| 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. | |
| Matrix & | operator- (Matrix &b) |
| Matrix subtraction, operator - Subtract this matrix - B of the same dim and returns the result S Allows S = A-B. | |
| 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. | |
| 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. | |
| 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) | |
| Matrix & | productSym (Matrix &a, Matrix &b) |
| Takes two ( N x N ) matrices (symmetric) and outputs an upper triangular matrix. | |
| void | swapRows (int rowA, int rowB) |
| Swaps row A with row B of this matrix. | |
| 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) | |
| void | multiplyRow (int row, qreal value) |
| Multiply every element of row by value. | |
| 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. | |
| Matrix & | pow (int n, bool symmetry=false) |
| Returns the n-nth power of this matrix. | |
| 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. | |
| 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. | |
| 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) | |
| 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. | |
| 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() | |
| 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() | |
| Matrix & | transpose () |
| Returns the Transpose of this matrix Allows T = A.transpose() | |
| Matrix & | cocitationMatrix () |
| Returns the Cocitation Matrix of this matrix (C = A * A^T) Allows T = A.cocitationMatrix() | |
| 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. | |
| Matrix & | inverse (Matrix &a) |
| Computes and returns the inverse of given matrix a Allows b.inverse(a) | |
| bool | solve (qreal b[]) |
| Computes and returns the solution of the set of n linear equations A·x = b Allows A.solve(b) | |
| 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. | |
| 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. | |
| 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. | |
| 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. | |
| 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. | |
| 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. | |
| bool | printMatrixConsole (bool debug=true) |
| Prints this matrix to stderr or stdout. | |
| bool | illDefined () |
| Checks if matrix is ill-defined (contains at least an inf element) | |
Private Attributes | |
| MatrixRow * | row |
| int | m_rows |
| int | m_cols |
Friends | |
| QTextStream & | operator<< (QTextStream &os, Matrix &m) |
| Prints matrix m to given textstream. | |
| 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
| Actors |
| 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.
| b |
| Matrix::~Matrix | ( | ) |
Matrix::~Matrix Destructor.
| void Matrix::clear | ( | ) |
Clears data.
| void Matrix::clearItem | ( | int | r, |
| int | c | ||
| ) |
Clears the (r,c) matrix element.
| r | |
| c |
| Matrix & Matrix::cocitationMatrix | ( | ) |
|
inline |
| Matrix & Matrix::degreeMatrix | ( | ) |
| void Matrix::deleteRowColumn | ( | int | erased | ) |
Deletes row and column and shifts rows and cols accordingly.
| erased | row/col to delete |
| 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)
| x | |
| n |
| 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.
| x | |
| y |
| 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.
| metric | |
| varLocation | |
| diagonal | |
| considerWeights |
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.
| Y | must be the Identity matrix on first call |
| X | the matrix to be powered |
| n | the power |
| symmetry |
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.
| void Matrix::fillMatrix | ( | qreal | value | ) |
Fills a matrix with a given value.
| value |
| void Matrix::findMinMaxValues | ( | qreal & | min, |
| qreal & | max, | ||
| bool & | hasRealNumbers | ||
| ) |
finds Min-Max values in current Matrix
| min | value in the matrix |
| max | value Complexity: O(n^2) |
| void Matrix::identityMatrix | ( | int | dim | ) |
Makes this square matrix the identity square matrix I.
| dim |
| bool Matrix::illDefined | ( | ) |
Checks if matrix is ill-defined (contains at least an inf element)
Computes and returns the inverse of given matrix a Allows b.inverse(a)
| 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.
| A |
| qreal Matrix::item | ( | int | r, |
| int | c | ||
| ) |
Returns the (r,c) matrix element.
| r | |
| c |
| 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()
| b |
| 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
| 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 |
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
| 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.
| 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 |
Code adapted from Knuth's Numerical Recipes in C, pp 46
| void Matrix::multiplyRow | ( | int | row, |
| qreal | value | ||
| ) |
Multiply every element of row by value.
| row | |
| value |
| 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)
| f |
| void Matrix::NeighboursNearestFarthest | ( | qreal & | min, |
| qreal & | max, | ||
| int & | imin, | ||
| int & | jmin, | ||
| int & | imax, | ||
| int & | jmax | ||
| ) |
Like Matrix::findMinMaxValues only it skips r==c.
| 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) |
|
inline |
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.
| b | |
| symmetry |
| 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.
| b | |
| symmetry |
| 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.
| b |
Matrix equality/assignment , operator = Allows copying a matrix onto another using b=a where b,a matrices Equals two matrices.
| a |
|
inline |
| Matrix & Matrix::pow | ( | int | n, |
| bool | symmetry = false |
||
| ) |
| 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.
| x | |
| xsum | |
| xmax | |
| xmaxi | |
| xmin | |
| xmini | |
| eps | |
| maxIter |
| 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.
| os | |
| debug |
| bool Matrix::printMatrixConsole | ( | bool | debug = true | ) |
Prints this matrix to stderr or stdout.
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)
| A | |
| B | |
| symmetry |
| 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.
| in | input array/vector |
| out | output array |
| leftMultiply |
Takes two ( N x N ) matrices (symmetric) and outputs an upper triangular matrix.
| a | |
| b |
| 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.
| Actors |
|
inline |
| void Matrix::setItem | ( | const int | r, |
| const int | c, | ||
| const qreal | elem | ||
| ) |
Sets the (r,c) matrix element calling the setColumn method.
| r | |
| c | |
| elem |
|
inline |
| bool Matrix::solve | ( | qreal | b[] | ) |
Computes and returns the solution of the set of n linear equations A·x = b Allows A.solve(b)
| b | vector |
| Matrix & Matrix::subtractFromI | ( | ) |
Subtracts this matrix from I and returns.
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)
| a | |
| b |
| void Matrix::swapRows | ( | int | rowA, |
| int | rowB | ||
| ) |
Swaps row A with row B of this matrix.
| rowA | |
| rowB |
| Matrix & Matrix::transpose | ( | ) |
| void Matrix::zeroMatrix | ( | const int | m, |
| const int | n | ||
| ) |
Makes this matrix the zero matrix of size mxn.
| m | |
| n |
|
friend |
Prints matrix m to given textstream.
| os | |
| m |
|
private |
|
private |
|
private |