SHOGUN  4.1.0
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
DenseExactLogJob.cpp
浏览该文件的文档.
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>
19 
20 using namespace Eigen;
21 
22 namespace shogun
23 {
24 
25 CDenseExactLogJob::CDenseExactLogJob()
26  : CIndependentJob()
27 {
28  init();
29 
30  SG_GCDEBUG("%s created (%p)\n", this->get_name(), this)
31 }
32 
34  CDenseMatrixOperator<float64_t>* log_operator,
35  SGVector<float64_t> vector)
36  : CIndependentJob(aggregator)
37 {
38  init();
39 
40  m_log_operator=log_operator;
41  SG_REF(m_log_operator);
42 
43  m_vector=vector;
44 
45  SG_GCDEBUG("%s created (%p)\n", this->get_name(), this)
46 }
47 
48 void CDenseExactLogJob::init()
49 {
50  m_log_operator=NULL;
51 
52  SG_ADD((CSGObject**)&m_log_operator, "log_operator",
53  "Log of linear operator", MS_NOT_AVAILABLE);
54 
55  SG_ADD(&m_vector, "trace_sample",
56  "Sample vector to apply linear operator on", MS_NOT_AVAILABLE);
57 }
58 
60 {
61  SG_UNREF(m_log_operator);
62 
63  SG_GCDEBUG("%s destroyed (%p)\n", this->get_name(), this)
64 }
65 
67 {
68  SG_DEBUG("Entering...\n")
69 
70  REQUIRE(m_log_operator, "Log operator function is NULL\n");
71  REQUIRE(m_aggregator, "Job result aggregator is NULL\n");
72 
73  // apply the log to m_vector
74  SGVector<float64_t> vec=m_log_operator->apply(m_vector);
75 
76  // compute the vector-vector dot product using Eigen3
77  Map<VectorXd> v(vec.vector, vec.vlen);
78  Map<VectorXd> s(m_vector.vector, m_vector.vlen);
79 
81  SG_REF(result);
82 
83  m_aggregator->submit_result(result);
84  SG_UNREF(result);
85 
86  SG_DEBUG("Leaving...\n")
87 }
88 
90 {
91  return m_vector;
92 }
93 
95 {
96  return m_log_operator;
97 }
98 
99 }
100 #endif // HAVE_EIGEN3
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:494
#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 机器学习工具包 - 项目文档