SHOGUN
v3.0.0
Main Page
Related Pages
Modules
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
src
shogun
mathematics
linalg
eigsolver
DirectEigenSolver.cpp
Go to the documentation of this file.
1
/*
2
* This program is free software; you can redistribute it and/or modify
3
* it under the terms of the GNU General Public License as published by
4
* the Free Software Foundation; either version 3 of the License, or
5
* (at your option) any later version.
6
*
7
* Written (W) 2013 Soumyajit De
8
*/
9
10
#include <
shogun/lib/config.h
>
11
12
#ifdef HAVE_EIGEN3
13
#include <
shogun/lib/SGMatrix.h
>
14
#include <
shogun/mathematics/eigen3.h
>
15
#include <
shogun/mathematics/linalg/linop/DenseMatrixOperator.h
>
16
#include <
shogun/mathematics/linalg/eigsolver/DirectEigenSolver.h
>
17
18
using namespace
Eigen;
19
20
namespace
shogun
21
{
22
23
CDirectEigenSolver::CDirectEigenSolver()
24
:
CEigenSolver
()
25
{
26
SG_GCDEBUG
(
"%s created (%p)\n"
, this->
get_name
(),
this
)
27
}
28
29
CDirectEigenSolver::CDirectEigenSolver
(
30
CDenseMatrixOperator<float64_t>
* linear_operator)
31
:
CEigenSolver
((
CLinearOperator
<
float64_t
>*)linear_operator)
32
{
33
SG_GCDEBUG
(
"%s created (%p)\n"
, this->
get_name
(),
this
)
34
}
35
36
CDirectEigenSolver::~CDirectEigenSolver
()
37
{
38
SG_GCDEBUG
(
"%s destroyed (%p)\n"
, this->
get_name
(),
this
)
39
}
40
41
void
CDirectEigenSolver::compute
()
42
{
43
if
(
m_is_computed_min
&&
m_is_computed_max
)
44
{
45
SG_DEBUG
(
"Minimum/maximum eigenvalues are already computed, exiting\n"
);
46
return
;
47
}
48
49
CDenseMatrixOperator<float64_t>
* op
50
=
dynamic_cast<
CDenseMatrixOperator<float64_t>
*
>
(
m_linear_operator
);
51
REQUIRE
(op,
"Linear operator is not of CDenseMatrixOperator type!\n"
);
52
53
SGMatrix<float64_t>
m=op->
get_matrix_operator
();
54
Map<MatrixXd> map_m(m.
matrix
, m.
num_rows
, m.
num_cols
);
55
56
// compute the eigenvalues with Eigen3
57
SelfAdjointEigenSolver<MatrixXd> eig_solver(map_m);
58
m_min_eigenvalue
=eig_solver.eigenvalues()[0];
59
m_max_eigenvalue
=eig_solver.eigenvalues()[op->
get_dimension
()-1];
60
61
m_is_computed_min
=
true
;
62
m_is_computed_max
=
false
;
63
}
64
65
}
66
#endif // HAVE_EIGEN3
SHOGUN
Machine Learning Toolbox - Documentation