SHOGUN  v3.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
IndividualJobResultAggregator.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/computation/jobresult/ScalarResult.h>
00015 #include <shogun/base/Parameter.h>
00016 #include <shogun/mathematics/eigen3.h>
00017 #include <shogun/mathematics/linalg/linop/LinearOperator.h>
00018 #include <shogun/mathematics/linalg/ratapprox/logdet/computation/aggregator/IndividualJobResultAggregator.h>
00019 
00020 using namespace Eigen;
00021 
00022 namespace shogun
00023 {
00024 CIndividualJobResultAggregator::CIndividualJobResultAggregator()
00025     : CStoreVectorAggregator<complex128_t>(),
00026       m_const_multiplier(0.0)
00027 {
00028     init();
00029 
00030     SG_GCDEBUG("%s created (%p)\n", this->get_name(), this)
00031 }
00032 
00033 CIndividualJobResultAggregator::CIndividualJobResultAggregator(
00034     CLinearOperator<float64_t>* linear_operator,
00035     SGVector<float64_t> vector,
00036     const float64_t& const_multiplier)
00037     : CStoreVectorAggregator<complex128_t>(vector.vlen),
00038       m_const_multiplier(const_multiplier)
00039 {
00040     init();
00041 
00042     m_vector=vector;
00043 
00044     m_linear_operator=linear_operator;
00045     SG_REF(m_linear_operator);
00046 
00047     SG_GCDEBUG("%s created (%p)\n", this->get_name(), this)
00048 }
00049 
00050 void CIndividualJobResultAggregator::init()
00051 {
00052     m_linear_operator=NULL;
00053 
00054     SG_ADD(&m_vector, "sample_vector",
00055         "The sample vector to perform final dot product", MS_NOT_AVAILABLE);
00056 
00057     SG_ADD((CSGObject**)&m_linear_operator, "linear_operator",
00058         "The linear operator to apply on the aggregation", MS_NOT_AVAILABLE);
00059 }
00060 
00061 CIndividualJobResultAggregator::~CIndividualJobResultAggregator()
00062 {
00063     SG_UNREF(m_linear_operator);
00064 
00065     SG_GCDEBUG("%s destroyed (%p)\n", this->get_name(), this)
00066 }
00067 
00068 void CIndividualJobResultAggregator::finalize()
00069 {
00070     // take out the imaginary part of the aggegation before
00071     // applying linear operator
00072     SGVector<float64_t> imag_agg=m_aggregate.get_imag();
00073     SGVector<float64_t> agg=m_linear_operator->apply(imag_agg);
00074 
00075     // perform dot product
00076     Map<VectorXd> map_agg(agg.vector, agg.vlen);
00077     Map<VectorXd> map_vector(m_vector.vector, m_vector.vlen);
00078     float64_t result=map_vector.dot(map_agg);
00079 
00080     result*=m_const_multiplier;
00081 
00082     // form the final result into a scalar result
00083     m_result=new CScalarResult<float64_t>(result);
00084     SG_REF(m_result);
00085 }
00086 
00087 }
00088 #endif // HAVE_EIGEN3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation