SHOGUN  v3.2.0
DenseMatrixExactLog.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/common.h>
11 
12 #ifdef HAVE_EIGEN3
14 
15 #if EIGEN_VERSION_AT_LEAST(3,1,0)
16 #include <unsupported/Eigen/MatrixFunctions>
17 #endif // EIGEN_VERSION_AT_LEAST(3,1,0)
18 
19 #include <shogun/lib/SGVector.h>
20 #include <shogun/lib/SGMatrix.h>
26 
27 using namespace Eigen;
28 
29 namespace shogun
30 {
31 
32 CDenseMatrixExactLog::CDenseMatrixExactLog()
33  : COperatorFunction<float64_t>(NULL, NULL, OF_LOG)
34 {
35  SG_GCDEBUG("%s created (%p)\n", this->get_name(), this)
36 }
37 
42  (CLinearOperator<float64_t>*)op, engine, OF_LOG)
43 {
44  SG_GCDEBUG("%s created (%p)\n", this->get_name(), this)
45 }
46 
48 {
49  SG_GCDEBUG("%s destroyed (%p)\n", this->get_name(), this)
50 }
51 
52 #if EIGEN_VERSION_AT_LEAST(3,1,0)
54 {
55  SG_DEBUG("Entering...\n");
56 
57  // check for proper downcast
60  REQUIRE(op, "Operator not an instance of DenseMatrixOperator!\n");
62 
63  // compute log(C) using Eigen3
64  Map<MatrixXd> mat(m.matrix, m.num_rows, m.num_cols);
66  Map<MatrixXd> log_mat(log_m.matrix, log_m.num_rows, log_m.num_cols);
67 #if EIGEN_WITH_LOG_BUG_1229
68  MatrixXd tmp = mat;
69  log_mat=tmp.log();
70 #else
71  log_mat=mat.log();
72 #endif
73 
74  // the log(C) is also a linear operator here
75  // reset the operator of this function with log(C)
79 
80  SG_DEBUG("Leaving...\n");
81 }
82 #else
84 {
85  SG_WARNING("Eigen3.1.0 or later required!\n")
86 }
87 #endif // EIGEN_VERSION_AT_LEAST(3,1,0)
88 
90  sample)
91 {
92  SG_DEBUG("Entering...\n");
93 
95  // we don't want the aggregator to be destroyed when the job is unref-ed
96  SG_REF(agg);
98  dynamic_cast<CDenseMatrixOperator<float64_t>*>(m_linear_operator), sample);
99  SG_REF(job);
100  // sanity check
101  REQUIRE(m_computation_engine, "Computation engine is NULL\n");
103  // we can safely unref the job here, computation engine takes it from here
104  SG_UNREF(job);
105 
106  SG_DEBUG("Leaving...\n");
107  return agg;
108 }
109 
110 }
111 #endif // HAVE_EIGEN3
CLinearOperator< float64_t > * m_linear_operator
SGMatrix< T > get_matrix_operator() const
Class that represents the job of applying the log of a CDenseMatrixOperator on a real vector...
#define SG_UNREF(x)
Definition: SGRefObject.h:35
#define REQUIRE(x,...)
Definition: SGIO.h:208
#define SG_GCDEBUG(...)
Definition: SGIO.h:104
Template class that aggregates scalar job results in each submit_result call, finalize then transform...
Abstract template base class for computing for a linear operator C and a vector s. submit_jobs method creates a bunch of jobs needed to solve for this particular and attaches one unique job aggregator to each of them, then submits them all to the computation engine.
double float64_t
Definition: common.h:48
#define SG_REF(x)
Definition: SGRefObject.h:34
index_t num_rows
Definition: SGMatrix.h:301
index_t num_cols
Definition: SGMatrix.h:303
Abstract base class that provides an interface for computing an aggeregation of the job results of in...
virtual const char * get_name() const
Abstract template base class that represents a linear operator, e.g. a matrix.
#define SG_DEBUG(...)
Definition: SGIO.h:109
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:16
Abstract base class for solving multiple independent instances of CIndependentJob. It has one method, submit_job, which may add the job to an internal queue and might block if there is yet not space in the queue. After jobs are submitted, it might not yet be ready. wait_for_all waits until all jobs are completed, which must be called to guarantee that all jobs are finished.
#define SG_WARNING(...)
Definition: SGIO.h:130
virtual void submit_job(CIndependentJob *job)=0
virtual CJobResultAggregator * submit_jobs(SGVector< float64_t > sample)
CIndependentComputationEngine * m_computation_engine

SHOGUN Machine Learning Toolbox - Documentation