SHOGUN  4.1.0
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
DirectLinearSolverComplex.cpp
浏览该文件的文档.
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/SGVector.h>
14 #include <shogun/lib/SGMatrix.h>
15 #include <shogun/io/SGIO.h>
19 
20 using namespace Eigen;
21 
22 namespace shogun
23 {
24 
25 CDirectLinearSolverComplex::CDirectLinearSolverComplex()
27  m_type(DS_QR_NOPERM)
28 {
29  SG_GCDEBUG("%s created (%p)\n", this->get_name(), this)
30 }
31 
34  m_type(type)
35 {
36  SG_GCDEBUG("%s created (%p)\n", this->get_name(), this)
37 }
38 
40 {
41  SG_GCDEBUG("%s destroyed (%p)\n", this->get_name(), this)
42 }
43 
46 {
48 
49  REQUIRE(A, "Operator is NULL!\n");
50  REQUIRE(A->get_dimension()==b.vlen, "Dimension mismatch!\n");
51 
53  dynamic_cast<CDenseMatrixOperator<complex128_t>*>(A);
54  REQUIRE(op, "Operator is not CDenseMatrixOperator<complex128_t, float64_t> type!\n");
55 
56  SGMatrix<complex128_t> mat_A=op->get_matrix_operator();
57  Map<MatrixXcd> map_A(mat_A.matrix, mat_A.num_rows, mat_A.num_cols);
58  Map<VectorXd> map_b(b.vector, b.vlen);
59  Map<VectorXcd> map_x(x.vector, x.vlen);
60 
61  switch (m_type)
62  {
63  case DS_LLT:
64  {
65  LLT<MatrixXcd> llt(map_A);
66  map_x=llt.solve(map_b.cast<complex128_t>());
67 
68  // checking for success
69  if (llt.info()==NumericalIssue)
70  SG_WARNING("Matrix is not Hermitian positive definite!\n");
71  }
72  break;
73  case DS_QR_NOPERM:
74  map_x=map_A.householderQr().solve(map_b.cast<complex128_t>());
75  break;
76  case DS_QR_COLPERM:
77  map_x=map_A.colPivHouseholderQr().solve(map_b.cast<complex128_t>());
78  break;
79  case DS_QR_FULLPERM:
80  map_x=map_A.fullPivHouseholderQr().solve(map_b.cast<complex128_t>());
81  break;
82  case DS_SVD:
83  map_x=map_A.jacobiSvd(ComputeThinU|ComputeThinV).solve(map_b.cast<complex128_t>());
84  break;
85  }
86 
87  return x;
88 }
89 
90 }
91 #endif // HAVE_EIGEN3
std::complex< float64_t > complex128_t
Definition: common.h:67
const index_t get_dimension() const
Definition: SGMatrix.h:20
#define REQUIRE(x,...)
Definition: SGIO.h:206
index_t num_cols
Definition: SGMatrix.h:378
index_t num_rows
Definition: SGMatrix.h:376
shogun matrix
index_t vlen
Definition: SGVector.h:494
#define SG_GCDEBUG(...)
Definition: SGIO.h:102
virtual const char * get_name() const
virtual SGVector< complex128_t > solve(CLinearOperator< complex128_t > *A, SGVector< float64_t > b)
double float64_t
Definition: common.h:50
Class that represents a dense-matrix linear operator. It computes matrix-vector product in its apply...
Abstract template base class that provides an abstract solve method for linear systems, that takes a linear operator , a vector , solves the system and returns the vector .
Definition: LinearSolver.h:25
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
#define SG_WARNING(...)
Definition: SGIO.h:128

SHOGUN 机器学习工具包 - 项目文档