SHOGUN
v3.0.0
Main Page
Related Pages
Modules
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
src
shogun
mathematics
linalg
ratapprox
logdet
computation
job
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
#ifdef HAVE_EIGEN3
13
#include <
shogun/lib/SGVector.h
>
14
#include <
shogun/lib/SGMatrix.h
>
15
#include <
shogun/lib/computation/jobresult/ScalarResult.h
>
16
#include <
shogun/mathematics/eigen3.h
>
17
#include <
shogun/mathematics/linalg/linop/DenseMatrixOperator.h
>
18
#include <
shogun/mathematics/linalg/ratapprox/logdet/computation/job/DenseExactLogJob.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
33
CDenseExactLogJob::CDenseExactLogJob
(
CJobResultAggregator
* aggregator,
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
59
CDenseExactLogJob::~CDenseExactLogJob
()
60
{
61
SG_UNREF
(m_log_operator);
62
63
SG_GCDEBUG
(
"%s destroyed (%p)\n"
, this->
get_name
(),
this
)
64
}
65
66
void
CDenseExactLogJob::compute
()
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
80
CScalarResult<float64_t>
* result=
new
CScalarResult<float64_t>
(s.dot(v));
81
SG_REF
(result);
82
83
m_aggregator
->
submit_result
(result);
84
SG_UNREF
(result);
85
86
SG_DEBUG
(
"Leaving...\n"
)
87
}
88
89
SGVector<float64_t>
CDenseExactLogJob::get_vector
()
const
90
{
91
return
m_vector;
92
}
93
94
CDenseMatrixOperator<float64_t>
*
CDenseExactLogJob::get_operator
()
const
95
{
96
return
m_log_operator;
97
}
98
99
}
100
#endif // HAVE_EIGEN3
SHOGUN
Machine Learning Toolbox - Documentation