SHOGUN  v3.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 
36  CLinearOperator<float64_t>* linear_operator,
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);
83  Map<VectorXcd> shifts(m_shifts.vector, 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

SHOGUN Machine Learning Toolbox - Documentation