32static const QString
infinity =
"\u221E" ;
34static const QString
infinity = QString(
"\xE2\x88\x9E") ;
74 Matrix (
int rowDim=0,
int colDim=0) ;
82 void resize (
const int m,
const int n) ;
88 void setItem(
const int r,
const int c,
const qreal elem ) {
m_rowPtr[r][c] = elem; }
105 int &imin,
int &jmin,
106 int &imax,
int &jmax);
144 const bool &leftMultiply=
false);
146 Matrix &
pow (
int n,
bool symmetry=
false) ;
164 const qreal eps,
const int &maxIter,
165 std::function<
bool()> cancelCheck =
nullptr,
166 qreal *lambdaMax =
nullptr);
179 bool inverse(
Matrix &a, std::function<
bool()> cancelCheck =
nullptr);
181 bool solve(qreal b[]);
183 bool ludcmp (
Matrix &a,
const int &n,
int indx[], qreal &d, std::function<
bool()> cancelCheck =
nullptr) ;
185 void lubksb (
Matrix &a,
const int &n,
int indx[], qreal b[]);
189 const QString varLocation,
190 const bool &diagonal,
191 const bool &considerWeights,
192 std::function<
bool()> cancelCheck =
nullptr);
196 const QString varLocation=
"Rows",
197 const bool &diagonal=
false,
198 const bool &considerWeights=
true,
199 std::function<
bool()> cancelCheck =
nullptr);
203 const QString &varLocation=
"Rows",
204 const bool &diagonal=
false,
205 std::function<
bool()> cancelCheck =
nullptr);
210 const bool markDiag=
false,
211 const bool &plain=
false,
212 const bool &printInfinity=
true);
239 for (
int i=0; i<
m_rows; i++) {
General-purpose dense matrix (adjacency, distance, similarity, sociomatrix, etc.),...
Definition matrix.h:71
void operator*=(Matrix &b)
Multiplies (right) this m x n matrix with given n x p matrix b, replacing this matrix's own contents ...
Definition matrix.cpp:483
friend QTextStream & operator<<(QTextStream &os, Matrix &m)
Prints matrix m to given textstream.
Definition matrix.cpp:2487
Matrix & expBySquaring2(Matrix &Y, Matrix &X, int n, bool symmetry=false)
Recursive algorithm implementing "Exponentiation by squaring". Also known as Fast Modulo Multiplicati...
Definition matrix.cpp:635
qreal * m_data
Definition matrix.h:244
void sum(Matrix &a, Matrix &b)
Matrix addition: sets this matrix to a + b, cell by cell. Same result as operator+(),...
Definition matrix.cpp:388
bool printHTMLTable(QTextStream &os, const bool markDiag=false, const bool &plain=false, const bool &printInfinity=true)
Writes this matrix as an HTML table to os, one row of table cells per matrix row.
Definition matrix.cpp:2615
void NeighboursNearestFarthest(qreal &min, qreal &max, int &imin, int &jmin, int &imax, int &jmax)
Like findMinMaxValues(), but skips the diagonal (r==c) and also reports which pair of distinct vertic...
Definition matrix.cpp:158
void multiplyRow(int row, qreal value)
Multiplies every element of the given row by value, in place. Complexity: O(cols()).
Definition matrix.cpp:337
Matrix & operator*(Matrix &b)
Matrix multiplication, operator *. Allows P = A * B, where A is this (m x n) and B is b (n x p); retu...
Definition matrix.cpp:451
void fillMatrix(qreal value)
Fills every cell of this matrix with the given value. Complexity: O(rows()*cols()).
Definition matrix.cpp:266
int cols()
Definition matrix.h:96
Matrix & cocitationMatrix()
Returns the cocitation matrix of this matrix (C = A * A^T). Allows T = A.cocitationMatrix()....
Definition matrix.cpp:934
void resize(const int m, const int n)
Resizes this matrix to m x n, discarding any previous contents. All cells start zero-initialized.
Definition matrix.cpp:101
Matrix & laplacianMatrix()
Returns the Laplacian of this matrix: an N x N matrix L = D - A, where D is this matrix's degreeMatri...
Definition matrix.cpp:973
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 triangula...
Definition matrix.cpp:1249
void identityMatrix(int dim)
Makes this square matrix the identity square matrix I.
Definition matrix.cpp:184
qreal * operator[](const int &r)
Definition matrix.h:92
int m_rows
Definition matrix.h:246
int m_cols
Definition matrix.h:247
Matrix & distancesMatrix(const int &metric, const QString varLocation, const bool &diagonal, const bool &considerWeights, std::function< bool()> cancelCheck=nullptr)
Computes a dissimilarities matrix T: T(i,k) is how different variable i and variable k are,...
Definition matrix.cpp:1427
void setItem(const int r, const int c, const qreal elem)
Definition matrix.h:88
bool ludcmp(Matrix &a, const int &n, int indx[], qreal &d, std::function< bool()> cancelCheck=nullptr)
Given matrix a, it replaces a by the LU decomposition of a rowwise permutation of itself....
Definition matrix.cpp:1101
bool illDefined()
Checks whether this matrix is "ill-defined": whether any cell holds RAND_MAX, the sentinel value used...
Definition matrix.cpp:2791
qreal distanceEuclidean(qreal x[], int n)
Helper function, computes the Euclideian length (also known as L2 distance) of a vector: if x = (x1 x...
Definition matrix.cpp:733
qreal distanceManhattan(qreal x[], qreal y[], int n)
Helper function, takes to vectors and returns their Manhattan distance (also known as l1 norm,...
Definition matrix.cpp:713
Matrix & productSym(Matrix &a, Matrix &b)
OBSOLETE - no caller found anywhere in the codebase. Was intended to take two (N x N) symmetric matri...
Definition matrix.cpp:567
int size()
Definition matrix.h:100
Matrix & pow(int n, bool symmetry=false)
Returns the n-th power of this matrix (X^n), via exponentiation by squaring (see expBySquaring2())....
Definition matrix.cpp:601
Matrix & pearsonCorrelationCoefficients(Matrix &AM, const QString &varLocation="Rows", const bool &diagonal=false, std::function< bool()> cancelCheck=nullptr)
Computes the Pearson product-moment correlation coefficient between every pair of variables (AM's row...
Definition matrix.cpp:2193
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 i...
Definition matrix.cpp:524
void rebuildRowPtr()
Definition matrix.h:236
Matrix & operator-(Matrix &b)
Matrix subtraction, operator -. Subtracts b (same dimensions) from this matrix and returns the result...
Definition matrix.cpp:433
void powerIteration(qreal x[], qreal &xsum, qreal &xmax, int &xmaxi, qreal &xmin, int &xmini, const qreal eps, const int &maxIter, std::function< bool()> cancelCheck=nullptr, qreal *lambdaMax=nullptr)
Implementation of the Power method which computes the leading eigenvector x of this matrix,...
Definition matrix.cpp:788
~Matrix()
Destructor: frees the data buffer and the row-pointer index.
Definition matrix.cpp:71
Matrix(int rowDim=0, int colDim=0)
Constructs a rowDim x colDim matrix, all cells zero-initialized. Defaults to 0x0 (an empty matrix) - ...
Definition matrix.cpp:41
bool solve(qreal b[])
Solves the linear system A*x = b, where A is this matrix, in place: b is overwritten with the solutio...
Definition matrix.cpp:1372
Matrix & similarityMatrix(Matrix &AM, const int &measure, const QString varLocation="Rows", const bool &diagonal=false, const bool &considerWeights=true, std::function< bool()> cancelCheck=nullptr)
Computes a pairwise similarity matrix SCM: SCM(i,k) is how alike variable i and variable k are,...
Definition matrix.cpp:1823
bool inverse(Matrix &a, std::function< bool()> cancelCheck=nullptr)
Computes and returns the inverse of matrix a, into this matrix. Allows b.inverse(a)....
Definition matrix.cpp:1304
Matrix & subtractFromI()
Replaces this matrix with I - this (the identity matrix minus this matrix), in place....
Definition matrix.cpp:279
qreal ** m_rowPtr
Definition matrix.h:245
Matrix & inverseByGaussJordanElimination(Matrix &a)
Inverts matrix A by Gauss-Jordan elimination with partial pivoting: starts this matrix as the identit...
Definition matrix.cpp:1000
Matrix & degreeMatrix()
Returns the degree matrix of this matrix: a diagonal matrix where S(i,i) is the sum of row i (i....
Definition matrix.cpp:951
void findMinMaxValues(qreal &min, qreal &max, bool &hasRealNumbers)
Scans every cell of this matrix (including the diagonal) and reports the smallest and largest values ...
Definition matrix.cpp:124
void clearItem(int r, int c)
Definition matrix.h:94
void operator+=(Matrix &b)
Adds matrix b to this matrix, in place, cell by cell. Allows A += B. Complexity: O(rows()*cols()).
Definition matrix.cpp:403
void clear()
Frees this matrix's data buffer and row-pointer index and resets it to 0x0. Called at the start of re...
Definition matrix.cpp:84
void swapRows(int rowA, int rowB)
Swaps row rowA with row rowB of this matrix, element by element. Used by inverseByGaussJordanEliminat...
Definition matrix.cpp:301
void zeroMatrix(const int m, const int n)
Makes this matrix the zero matrix of size mxn.
Definition matrix.cpp:204
qreal item(int r, int c)
Definition matrix.h:86
void deleteRowColumn(int i)
Deletes row erased and column erased from this (square) matrix, shifting every later row/column back ...
Definition matrix.cpp:229
Matrix & transpose()
Returns the transpose of this matrix (T(i,j) = this(j,i)). Allows T = A.transpose()....
Definition matrix.cpp:908
bool printMatrixConsole(bool debug=true)
Prints this matrix as plain text, one line per row, cells right-aligned to a fixed width....
Definition matrix.cpp:2757
int rows()
Definition matrix.h:98
Matrix & operator+(Matrix &b)
Matrix addition, operator +. Adds this matrix and b (same dimensions) and returns the sum S....
Definition matrix.cpp:417
Matrix & operator=(Matrix &a)
Matrix equality/assignment , operator = Allows copying a matrix onto another using b=a where b,...
Definition matrix.cpp:359
void multiplyScalar(const qreal &f)
Multiplies every cell of this matrix, in place, by scalar f. Allows P.multiplyScalar(f)....
Definition matrix.cpp:322
void productByVector(qreal in[], qreal out[], const bool &leftMultiply=false)
Calculates the matrix-by-vector product Ax of this matrix (or the left product xA,...
Definition matrix.cpp:679
static const int METRIC_EUCLIDEAN_DISTANCE
Definition matrix.h:43
static const int METRIC_HAMMING_DISTANCE
Definition matrix.h:41
static const int METRIC_NONE
Definition matrix.h:38
static const int METRIC_CHEBYSHEV_MAXIMUM
Definition matrix.h:46
static const QString infinity
Definition matrix.h:34
static const int METRIC_MANHATTAN_DISTANCE
Definition matrix.h:44
static const int METRIC_COSINE_SIMILARITY
Definition matrix.h:42
static const int METRIC_PEARSON_COEFFICIENT
Definition matrix.h:45
static const int METRIC_JACCARD_INDEX
Definition matrix.h:40
static const int METRIC_SIMPLE_MATCHING
Definition matrix.h:39