SHOGUN  v3.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RationalApproximationIndividualJob.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/SGVector.h>
14 #include <shogun/lib/SGMatrix.h>
20 #include <shogun/base/Parameter.h>
21 
22 using namespace Eigen;
23 
24 namespace shogun
25 {
26 
27 CRationalApproximationIndividualJob::CRationalApproximationIndividualJob()
28  : CIndependentJob()
29 {
30  init();
31 
32  SG_GCDEBUG("%s created (%p)\n", this->get_name(), this)
33 }
34 
36  CJobResultAggregator* aggregator,
38  CLinearOperator<complex128_t>* linear_operator,
39  SGVector<float64_t> vector,
40  complex128_t weight)
41  : CIndependentJob(aggregator)
42 {
43  init();
44 
45  m_linear_solver=linear_solver;
46  SG_REF(m_linear_solver);
47 
48  m_operator=linear_operator;
49  SG_REF(m_operator);
50 
51  m_vector=vector;
52 
53  m_weight=weight;
54 
55  SG_GCDEBUG("%s created (%p)\n", this->get_name(), this)
56 }
57 
58 void CRationalApproximationIndividualJob::init()
59 {
60  m_linear_solver=NULL;
61  m_operator=NULL;
62  m_weight=complex128_t(0.0);
63 
64  SG_ADD((CSGObject**)&m_linear_solver, "linear_solver",
65  "Linear solver for complex system", MS_NOT_AVAILABLE);
66 
67  SG_ADD((CSGObject**)&m_operator, "shifted_operator",
68  "Shifted linear operator", MS_NOT_AVAILABLE);
69 
70  SG_ADD(&m_vector, "trace_sample",
71  "Sample vector to apply linear operator on", MS_NOT_AVAILABLE);
72 
73  SG_ADD(&m_weight, "complex_weight",
74  "Weight to be multiplied to the solution vector", MS_NOT_AVAILABLE);
75 }
76 
78 {
79  SG_UNREF(m_linear_solver);
80  SG_UNREF(m_operator);
81 
82  SG_GCDEBUG("%s destroyed (%p)\n", this->get_name(), this)
83 }
84 
86 {
87  REQUIRE(m_aggregator, "Job result aggregator is not set!\n");
88  REQUIRE(m_operator, "Operator is not set!\n");
89  REQUIRE(m_vector.vector, "Vector is not set!\n");
90 
91  // solve the linear system with the sample vector
92  SGVector<complex128_t> vec=m_linear_solver->solve(m_operator, m_vector);
93 
94  // multiply with the weight using Eigen3 and take negative
95  // (see CRationalApproximation for the formula)
96  Map<VectorXcd> v(vec.vector, vec.vlen);
97  v*=m_weight;
98  v=-v;
99 
100  // set as a vector result and submit to the aggregator
102  SG_REF(result);
103 
104  m_aggregator->submit_result(result);
105 
106  SG_UNREF(result);
107 }
108 
109 }
110 #endif // HAVE_EIGEN3

SHOGUN Machine Learning Toolbox - Documentation