Loading...
Searching...
No Matches
MatrixProperties.cpp
Go to the documentation of this file.
1//
2// MatrixProperties.cpp
3// gpr_dimer
4//
5// Created by Maxim Masterov on 18/01/2021.
6//
7
8#include "MatrixProperties.h"
9
10namespace math {
11
13{
14 bool res = true;
15
16 for (long i = 0; i < Matrix.rows(); ++i) {
17 double off_diag = 0.;
18 double diag = 0.;
19 for (long j = 0; j < Matrix.cols(); ++j) {
20 double coeff = Matrix(i, j);
21 if (j != i)
22 off_diag += fabs(coeff);
23 else
24 diag = fabs(coeff);
25 }
26
27 /*
28 * If absolute value of diagonal element is smaller than a sum of
29 * absolute values of off-diagonal elements matrix is not DD
30 */
31 if (fabs(diag) < fabs(off_diag)) {
32 res = false;
33 break;
34 }
35 }
36
37 return res;
38}
39
41{
42 return xTAx(Matrix) > 0 ? true : false;
43}
44
46{
47 return xTAx(Matrix) >= 0 ? true : false;
48}
49
50double MatrixProperties::xTAx(const gpr::EigenMatrix& Matrix)
51{
52 Eigen::VectorXd z(Matrix.rows());
53
54 z.setOnes();
55
56 // Just add some zeros at some positions
57 for (int i = 0; i < z.rows(); i += 4) {
58 z(i) = 0.;
59 }
60
61 return z.dot(Matrix * z);
62}
63} // namespace math
@ z
Definition Enums.h:28
bool isPD(const gpr::EigenMatrix &Matrix)
Return true if the given matrix is Positive Definite (PD).
bool isDD(const gpr::EigenMatrix &Matrix)
Return true if the given matrix is Diagonally Dominant (DD).
bool isPSD(const gpr::EigenMatrix &Matrix)
Return true if the given matrix is Positive Semi-Definite (PSD).
Eigen::Matrix< double, EigenDynamic, EigenDynamic, EigenMatrixStorage > EigenMatrix
Definition Macros.h:20