SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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 #include <shogun/lib/SGVector.h>
13 #include <shogun/lib/SGMatrix.h>
19 #include <shogun/base/Parameter.h>
20 
21 using namespace Eigen;
22 
23 namespace shogun
24 {
25 
26 CRationalApproximationIndividualJob::CRationalApproximationIndividualJob()
27  : CIndependentJob()
28 {
29  init();
30 
31  SG_GCDEBUG("%s created (%p)\n", this->get_name(), this)
32 }
33 
35  CJobResultAggregator* aggregator,
37  CLinearOperator<complex128_t>* linear_operator,
38  SGVector<float64_t> vector,
39  complex128_t weight)
40  : CIndependentJob(aggregator)
41 {
42  init();
43 
44  m_linear_solver=linear_solver;
45  SG_REF(m_linear_solver);
46 
47  m_operator=linear_operator;
48  SG_REF(m_operator);
49 
50  m_vector=vector;
51 
52  m_weight=weight;
53 
54  SG_GCDEBUG("%s created (%p)\n", this->get_name(), this)
55 }
56 
57 void CRationalApproximationIndividualJob::init()
58 {
59  m_linear_solver=NULL;
60  m_operator=NULL;
61  m_weight=complex128_t(0.0);
62 
63  SG_ADD((CSGObject**)&m_linear_solver, "linear_solver",
64  "Linear solver for complex system", MS_NOT_AVAILABLE);
65 
66  SG_ADD((CSGObject**)&m_operator, "shifted_operator",
67  "Shifted linear operator", MS_NOT_AVAILABLE);
68 
69  SG_ADD(&m_vector, "trace_sample",
70  "Sample vector to apply linear operator on", MS_NOT_AVAILABLE);
71 
72  SG_ADD(&m_weight, "complex_weight",
73  "Weight to be multiplied to the solution vector", MS_NOT_AVAILABLE);
74 }
75 
77 {
78  SG_UNREF(m_linear_solver);
79  SG_UNREF(m_operator);
80 
81  SG_GCDEBUG("%s destroyed (%p)\n", this->get_name(), this)
82 }
83 
85 {
86  REQUIRE(m_aggregator, "Job result aggregator is not set!\n");
87  REQUIRE(m_operator, "Operator is not set!\n");
88  REQUIRE(m_vector.vector, "Vector is not set!\n");
89 
90  // solve the linear system with the sample vector
91  SGVector<complex128_t> vec=m_linear_solver->solve(m_operator, m_vector);
92 
93  // multiply with the weight using Eigen3 and take negative
94  // (see CRationalApproximation for the formula)
95  Map<VectorXcd> v(vec.vector, vec.vlen);
96  v*=m_weight;
97  v=-v;
98 
99  // set as a vector result and submit to the aggregator
101  SG_REF(result);
102 
103  m_aggregator->submit_result(result);
104 
105  SG_UNREF(result);
106 }
107 
108 }
std::complex< float64_t > complex128_t
Definition: common.h:67
Definition: SGMatrix.h:20
#define REQUIRE(x,...)
Definition: SGIO.h:206
virtual void submit_result(CJobResult *result)=0
#define SG_REF(x)
Definition: SGObject.h:54
index_t vlen
Definition: SGVector.h:494
#define SG_GCDEBUG(...)
Definition: SGIO.h:102
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:115
Abstract base class that provides an interface for computing an aggeregation of the job results of in...
virtual SGVector< T > solve(CLinearOperator< T > *A, SGVector< ST > b)=0
#define SG_UNREF(x)
Definition: SGObject.h:55
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
Abstract base for general computation jobs to be registered in CIndependentComputationEngine. compute method produces a job result and submits it to the internal JobResultAggregator. Each set of jobs that form a result will share the same job result aggregator.
#define SG_ADD(...)
Definition: SGObject.h:84
Base class that stores the result of an independent job when the result is a vector.
CJobResultAggregator * m_aggregator

SHOGUN Machine Learning Toolbox - Documentation