SHOGUN  v3.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
DenseExactLogJob.cpp
Go to the documentation of this file.
00001 /*
00002  * This program is free software; you can redistribute it and/or modify
00003  * it under the terms of the GNU General Public License as published by
00004  * the Free Software Foundation; either version 3 of the License, or
00005  * (at your option) any later version.
00006  *
00007  * Written (W) 2013 Soumyajit De
00008  */
00009 
00010 #include <shogun/lib/config.h>
00011 
00012 #ifdef HAVE_EIGEN3
00013 #include <shogun/lib/SGVector.h>
00014 #include <shogun/lib/SGMatrix.h>
00015 #include <shogun/lib/computation/jobresult/ScalarResult.h>
00016 #include <shogun/mathematics/eigen3.h>
00017 #include <shogun/mathematics/linalg/linop/DenseMatrixOperator.h>
00018 #include <shogun/mathematics/linalg/ratapprox/logdet/computation/job/DenseExactLogJob.h>
00019 
00020 using namespace Eigen;
00021 
00022 namespace shogun
00023 {
00024 
00025 CDenseExactLogJob::CDenseExactLogJob()
00026     : CIndependentJob()
00027 {
00028     init();
00029 
00030     SG_GCDEBUG("%s created (%p)\n", this->get_name(), this)
00031 }
00032 
00033 CDenseExactLogJob::CDenseExactLogJob(CJobResultAggregator* aggregator,
00034     CDenseMatrixOperator<float64_t>* log_operator,
00035     SGVector<float64_t> vector)
00036     : CIndependentJob(aggregator)
00037 {
00038     init();
00039 
00040     m_log_operator=log_operator;
00041     SG_REF(m_log_operator);
00042 
00043     m_vector=vector;
00044 
00045     SG_GCDEBUG("%s created (%p)\n", this->get_name(), this)
00046 }
00047 
00048 void CDenseExactLogJob::init()
00049 {
00050     m_log_operator=NULL;
00051 
00052     SG_ADD((CSGObject**)&m_log_operator, "log_operator",
00053         "Log of linear operator", MS_NOT_AVAILABLE);
00054 
00055     SG_ADD(&m_vector, "trace_sample",
00056         "Sample vector to apply linear operator on", MS_NOT_AVAILABLE);
00057 }
00058 
00059 CDenseExactLogJob::~CDenseExactLogJob()
00060 {
00061     SG_UNREF(m_log_operator);
00062 
00063     SG_GCDEBUG("%s destroyed (%p)\n", this->get_name(), this)
00064 }
00065 
00066 void CDenseExactLogJob::compute()
00067 {
00068     SG_DEBUG("Entering...\n")
00069 
00070     REQUIRE(m_log_operator, "Log operator function is NULL\n");
00071     REQUIRE(m_aggregator, "Job result aggregator is NULL\n");
00072 
00073     // apply the log to m_vector
00074     SGVector<float64_t> vec=m_log_operator->apply(m_vector);
00075 
00076     // compute the vector-vector dot product using Eigen3
00077     Map<VectorXd> v(vec.vector, vec.vlen);
00078     Map<VectorXd> s(m_vector.vector, m_vector.vlen);
00079 
00080     CScalarResult<float64_t>* result=new CScalarResult<float64_t>(s.dot(v));
00081     SG_REF(result);
00082 
00083     m_aggregator->submit_result(result);
00084     SG_UNREF(result);
00085 
00086     SG_DEBUG("Leaving...\n")
00087 }
00088 
00089 SGVector<float64_t> CDenseExactLogJob::get_vector() const
00090 {
00091     return m_vector;
00092 }
00093 
00094 CDenseMatrixOperator<float64_t>* CDenseExactLogJob::get_operator() const
00095 {
00096     return m_log_operator;
00097 }
00098 
00099 }
00100 #endif // HAVE_EIGEN3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation