SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
DenseExactLogJob.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>
18 
19 using namespace Eigen;
20 
21 namespace shogun
22 {
23 
24 CDenseExactLogJob::CDenseExactLogJob()
25  : CIndependentJob()
26 {
27  init();
28 
29  SG_GCDEBUG("%s created (%p)\n", this->get_name(), this)
30 }
31 
33  CDenseMatrixOperator<float64_t>* log_operator,
34  SGVector<float64_t> vector)
35  : CIndependentJob(aggregator)
36 {
37  init();
38 
39  m_log_operator=log_operator;
40  SG_REF(m_log_operator);
41 
42  m_vector=vector;
43 
44  SG_GCDEBUG("%s created (%p)\n", this->get_name(), this)
45 }
46 
47 void CDenseExactLogJob::init()
48 {
49  m_log_operator=NULL;
50 
51  SG_ADD((CSGObject**)&m_log_operator, "log_operator",
52  "Log of linear operator", MS_NOT_AVAILABLE);
53 
54  SG_ADD(&m_vector, "trace_sample",
55  "Sample vector to apply linear operator on", MS_NOT_AVAILABLE);
56 }
57 
59 {
60  SG_UNREF(m_log_operator);
61 
62  SG_GCDEBUG("%s destroyed (%p)\n", this->get_name(), this)
63 }
64 
66 {
67  SG_DEBUG("Entering...\n")
68 
69  REQUIRE(m_log_operator, "Log operator function is NULL\n");
70  REQUIRE(m_aggregator, "Job result aggregator is NULL\n");
71 
72  // apply the log to m_vector
73  SGVector<float64_t> vec=m_log_operator->apply(m_vector);
74 
75  // compute the vector-vector dot product using Eigen3
76  Map<VectorXd> v(vec.vector, vec.vlen);
77  Map<VectorXd> s(m_vector.vector, m_vector.vlen);
78 
80  SG_REF(result);
81 
82  m_aggregator->submit_result(result);
83  SG_UNREF(result);
84 
85  SG_DEBUG("Leaving...\n")
86 }
87 
89 {
90  return m_vector;
91 }
92 
94 {
95  return m_log_operator;
96 }
97 
98 }
Base class that stores the result of an independent job when the result is a scalar.
Definition: ScalarResult.h:24
Definition: SGMatrix.h:20
#define REQUIRE(x,...)
Definition: SGIO.h:206
virtual SGVector< T > apply(SGVector< T > b) const
virtual void submit_result(CJobResult *result)=0
#define SG_REF(x)
Definition: SGObject.h:51
index_t vlen
Definition: SGVector.h:492
#define SG_GCDEBUG(...)
Definition: SGIO.h:102
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:112
Abstract base class that provides an interface for computing an aggeregation of the job results of in...
#define SG_UNREF(x)
Definition: SGObject.h:52
#define SG_DEBUG(...)
Definition: SGIO.h:107
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
virtual const char * get_name() const
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.
SGVector< float64_t > get_vector() const
CDenseMatrixOperator< float64_t > * get_operator() const
#define SG_ADD(...)
Definition: SGObject.h:81
CJobResultAggregator * m_aggregator

SHOGUN Machine Learning Toolbox - Documentation