SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
IndividualJobResultAggregator.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>
14 #include <shogun/base/Parameter.h>
18 
19 using namespace Eigen;
20 
21 namespace shogun
22 {
23 CIndividualJobResultAggregator::CIndividualJobResultAggregator()
25  m_const_multiplier(0.0)
26 {
27  init();
28 
29  SG_GCDEBUG("%s created (%p)\n", this->get_name(), this)
30 }
31 
33  CLinearOperator<float64_t>* linear_operator,
34  SGVector<float64_t> vector,
35  const float64_t& const_multiplier)
36  : CStoreVectorAggregator<complex128_t>(vector.vlen),
37  m_const_multiplier(const_multiplier)
38 {
39  init();
40 
41  m_vector=vector;
42 
43  m_linear_operator=linear_operator;
44  SG_REF(m_linear_operator);
45 
46  SG_GCDEBUG("%s created (%p)\n", this->get_name(), this)
47 }
48 
49 void CIndividualJobResultAggregator::init()
50 {
51  m_linear_operator=NULL;
52 
53  SG_ADD(&m_vector, "sample_vector",
54  "The sample vector to perform final dot product", MS_NOT_AVAILABLE);
55 
56  SG_ADD((CSGObject**)&m_linear_operator, "linear_operator",
57  "The linear operator to apply on the aggregation", MS_NOT_AVAILABLE);
58 }
59 
61 {
62  SG_UNREF(m_linear_operator);
63 
64  SG_GCDEBUG("%s destroyed (%p)\n", this->get_name(), this)
65 }
66 
68 {
69  // take out the imaginary part of the aggegation before
70  // applying linear operator
72  SGVector<float64_t> agg=m_linear_operator->apply(imag_agg);
73 
74  // perform dot product
75  Map<VectorXd> map_agg(agg.vector, agg.vlen);
76  Map<VectorXd> map_vector(m_vector.vector, m_vector.vlen);
77  float64_t result=map_vector.dot(map_agg);
78 
79  result*=m_const_multiplier;
80 
81  // form the final result into a scalar result
84 }
85 
86 }
Base class that stores the result of an independent job when the result is a scalar.
Definition: ScalarResult.h:24
std::complex< float64_t > complex128_t
Definition: common.h:67
Abstract template class that aggregates vector job results in each submit_result call, finalize is abstract.
SGVector< float64_t > get_imag()
Definition: SGVector.cpp:889
Definition: SGMatrix.h:20
#define SG_REF(x)
Definition: SGObject.h:54
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:115
double float64_t
Definition: common.h:50
virtual SGVector< T > apply(SGVector< T > b) const =0
#define SG_UNREF(x)
Definition: SGObject.h:55
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
#define SG_ADD(...)
Definition: SGObject.h:84

SHOGUN Machine Learning Toolbox - Documentation