SHOGUN  4.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
LogRationalApproximationCGM.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/base/Parameter.h>
14 #include <shogun/lib/SGVector.h>
15 #include <shogun/lib/SGMatrix.h>
23 
24 using namespace Eigen;
25 
26 namespace shogun
27 {
28 
29 CLogRationalApproximationCGM::CLogRationalApproximationCGM()
30  : CRationalApproximation(NULL, NULL, NULL, 0, OF_LOG)
31 {
32  init();
33 }
34 
37  CIndependentComputationEngine* computation_engine,
38  CEigenSolver* eigen_solver,
39  CCGMShiftedFamilySolver* linear_solver,
40  float64_t desired_accuracy)
41  : CRationalApproximation(linear_operator, computation_engine,
42  eigen_solver, desired_accuracy, OF_LOG)
43 {
44  init();
45 
46  m_linear_solver=linear_solver;
47  SG_REF(m_linear_solver);
48 }
49 
50 void CLogRationalApproximationCGM::init()
51 {
52  m_linear_solver=NULL;
53 
54  SG_ADD((CSGObject**)&m_linear_solver, "linear_solver",
55  "Linear solver for complex systems", MS_NOT_AVAILABLE);
56 
57  SG_ADD(&m_negated_shifts, "negated_shifts",
58  "Negated shifts", MS_NOT_AVAILABLE);
59 }
60 
62 {
63  SG_UNREF(m_linear_solver);
64 }
65 
67  SGVector<float64_t> sample)
68 {
69  SG_DEBUG("Entering\n");
70  REQUIRE(sample.vector, "Sample is not initialized!\n");
71  REQUIRE(m_linear_operator, "Operator is not initialized!\n");
72  REQUIRE(m_computation_engine, "Computation engine is NULL\n");
73 
74  // create the scalar aggregator
76  // we don't want the aggregator to be destroyed when the job is unref-ed
77  SG_REF(agg);
78 
79  // we need to take the negation of the shifts for this case
80  if (m_negated_shifts.vector==NULL)
81  {
82  m_negated_shifts=SGVector<complex128_t>(m_shifts.vlen);
84  Map<VectorXcd> negated_shifts(m_negated_shifts.vector, m_negated_shifts.vlen);
85  negated_shifts=-shifts;
86  }
87 
88  // create one CG-M job for current sample vector which solves for all
89  // the shifts, and computes the final result and stores that in the aggregator
91  =new CRationalApproximationCGMJob(agg, m_linear_solver,
92  m_linear_operator, sample, m_negated_shifts, m_weights, m_constant_multiplier);
93  SG_REF(job);
94 
96 
97  // we can safely unref the job here, computation engine takes it from here
98  SG_UNREF(job);
99 
100  SG_DEBUG("Leaving\n");
101  return agg;
102 }
103 
104 }
105 #endif // HAVE_EIGEN3
CIndependentComputationEngine * m_computation_engine
CLinearOperator< SGVector< float64_t >, SGVector< float64_t > > * m_linear_operator
class that uses conjugate gradient method for solving a shifted linear system family where the linear...
Definition: SGMatrix.h:20
#define REQUIRE(x,...)
Definition: SGIO.h:206
SGVector< complex128_t > m_shifts
#define SG_REF(x)
Definition: SGObject.h:51
index_t vlen
Definition: SGVector.h:494
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:112
Template class that aggregates scalar job results in each submit_result call, finalize then transform...
double float64_t
Definition: common.h:50
Implementation of independent jobs that solves one whole family of shifted systems in rational approx...
Abstract base class of the rational approximation of a function of a linear operator (A) times vector...
virtual CJobResultAggregator * submit_jobs(SGVector< float64_t > sample)
Abstract base class that provides an interface for computing an aggeregation of the job results of in...
SGVector< complex128_t > m_weights
#define SG_UNREF(x)
Definition: SGObject.h:52
#define SG_DEBUG(...)
Definition: SGIO.h:107
Abstract base class that provides an abstract compute method for computing eigenvalues of a real valu...
Definition: EigenSolver.h:24
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
Abstract template base class that represents a linear operator, e.g. a matrix.
Abstract base class for solving multiple independent instances of CIndependentJob. It has one method, submit_job, which may add the job to an internal queue and might block if there is yet not space in the queue. After jobs are submitted, it might not yet be ready. wait_for_all waits until all jobs are completed, which must be called to guarantee that all jobs are finished.
#define SG_ADD(...)
Definition: SGObject.h:81
virtual void submit_job(CIndependentJob *job)=0

SHOGUN Machine Learning Toolbox - Documentation