libcrn  3.9.5
A document image processing library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CRNSquareMatrixDouble.h
Go to the documentation of this file.
1 /* Copyright 2008-2016 INSA-Lyon, ENS-Lyon
2  *
3  * This file is part of libcrn.
4  *
5  * libcrn is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * libcrn is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with libcrn. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * file: CRNSquareMatrixDouble.h
19  * \author Jean DUONG, Yann LEYDIER
20  */
21 
22 #ifndef CRNSQUAREMATRIXDOUBLE_HEADER
23 #define CRNSQUAREMATRIXDOUBLE_HEADER
24 
26 #include <map>
27 
28 namespace crn
29 {
30  /****************************************************************************/
41  {
42  public:
44  SquareMatrixDouble(size_t size, double value = 0.0) : MatrixDouble(size, size, value) {}
47  SquareMatrixDouble(const std::vector<std::vector<double>> &m);
48  SquareMatrixDouble(std::vector<std::vector<double>> &&m);
49  SquareMatrixDouble(const SquareMatrixDouble &) = default;
51 
53  virtual ~SquareMatrixDouble() override = default;
54 
57 
58  /*********************************************************************/
59  /* Special matrix constructors */
60  /*********************************************************************/
62  static SquareMatrixDouble NewGaussian(double sigma);
64  static SquareMatrixDouble NewGaussianSobelX(double sigma);
66  static SquareMatrixDouble NewGaussianSobelY(double sigma);
68  static SquareMatrixDouble NewIdentity(size_t n);
69 
71  bool IsUpperTriangular() const;
73  bool IsLowerTriangular() const;
75  bool IsUpperHessenberg() const;
77  bool IsDiagonal() const;
79  double Trace() const;
81  double DiagonalProduct() const;
83  virtual SquareMatrixDouble& Transpose() override;
85  SquareMatrixDouble MakeMinor(size_t r, size_t c) const;
87  double Cofactor(size_t r, size_t c) const;
89  double Determinant() const;
98 
100  std::multimap<double, MatrixDouble> MakeSpectralEigensystem() const;
102  std::multimap<double, MatrixDouble> MakeJacobiEigensystem(size_t MaxIteration = 100) const;
104  std::multimap<double, MatrixDouble> MakeTQLIEigensystem(size_t maxiter = 30) const;
106  std::vector<std::complex<double>> Eigenvalues(size_t max_iter = 30) const;
107 
108  private:
110  void tred2(SquareMatrixDouble &z, std::vector<double> &diag, std::vector<double> &offdiag) const;
111  virtual std::string getClassName() const override { return "SquareMatrixDouble"; }
112 
114  public:
115  SquareMatrixDouble(xml::Element &el):MatrixDouble(1, 1) { Deserialize(el); }
116  };
117  template<> struct IsSerializable<SquareMatrixDouble> : public std::true_type {};
118  template<> struct IsClonable<SquareMatrixDouble> : public std::true_type {};
119 
120  template<> struct TypeInfo<SquareMatrixDouble>
121  {
125  };
126 
127 }
128 
130 #endif
std::vector< std::complex< double > > Eigenvalues(size_t max_iter=30) const
Extract eigenvalues for matrix of real (eigenvalues may be complex)
static SquareMatrixDouble NewGaussianSobelX(double sigma)
Create Gaussian Sobel X derivation mask.
bool IsDiagonal() const
Check if matrix is diagonal.
bool IsUpperTriangular() const
Check if matrix is upper triangular.
SquareMatrixDouble MakeGaussJordanInverse() const
Invert using Gauss-Jordan elimination.
virtual ~SquareMatrixDouble() override=default
Destructor.
virtual SquareMatrixDouble & Transpose() override
Transposition.
SquareMatrixDouble(size_t size, double value=0.0)
Constructor.
SquareMatrixDouble MakeUpperHessenberg() const
Get the upper Hessenberg form of matrix.
SquareMatrixDouble & operator=(const SquareMatrixDouble &)=default
double Trace() const
Trace.
std::multimap< double, MatrixDouble > MakeJacobiEigensystem(size_t MaxIteration=100) const
Perform diagonalization for symmetric matrix.
static SquareMatrixDouble NewGaussian(double sigma)
Create Gaussian matrix.
static SquareMatrixDouble NewIdentity(size_t n)
Create identity matrix.
bool IsUpperHessenberg() const
Check if matrix is upper Hessenberg.
SquareMatrixDouble MakeInverse() const
Invert using determinants.
std::multimap< double, MatrixDouble > MakeTQLIEigensystem(size_t maxiter=30) const
Perform diagonalization for positive symmetric matrix.
virtual void Deserialize(xml::Element &el)
double matrix class
static SquareMatrixDouble NewGaussianSobelY(double sigma)
Create Gaussian Sobel Y derivation mask.
#define CRN_DECLARE_CLASS_CONSTRUCTOR(classname)
Declares a class constructor.
Definition: CRNObject.h:173
Square double matrix class.
bool IsLowerTriangular() const
Check if matrix is lower triangular.
std::multimap< double, MatrixDouble > MakeSpectralEigensystem() const
Perform diagonalization for 2x2 symmetric matrix.
SquareMatrixDouble MakeMinor(size_t r, size_t c) const
Minor matrix.
double Cofactor(size_t r, size_t c) const
Cofactor.
double Determinant() const
Determinant.
SquareMatrixDouble MakeCholesky() const
Get the lower triangular factor in Cholesky decomposition.
A class containing informations on a type.
Definition: CRNType.h:176
double DiagonalProduct() const
Diagonal product.