SHOGUN  v3.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
LogRationalApproximationCGM.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/base/Parameter.h>
00014 #include <shogun/lib/SGVector.h>
00015 #include <shogun/lib/SGMatrix.h>
00016 #include <shogun/mathematics/eigen3.h>
00017 #include <shogun/mathematics/linalg/linsolver/CGMShiftedFamilySolver.h>
00018 #include <shogun/mathematics/linalg/linop/LinearOperator.h>
00019 #include <shogun/mathematics/linalg/ratapprox/logdet/opfunc/LogRationalApproximationCGM.h>
00020 #include <shogun/mathematics/linalg/ratapprox/logdet/computation/job/RationalApproximationCGMJob.h>
00021 #include <shogun/lib/computation/aggregator/StoreScalarAggregator.h>
00022 #include <shogun/lib/computation/engine/IndependentComputationEngine.h>
00023 
00024 using namespace Eigen;
00025 
00026 namespace shogun
00027 {
00028 
00029 CLogRationalApproximationCGM::CLogRationalApproximationCGM()
00030     : CRationalApproximation(NULL, NULL, NULL, 0, OF_LOG)
00031 {
00032     init();
00033 }
00034 
00035 CLogRationalApproximationCGM::CLogRationalApproximationCGM(
00036     CLinearOperator<float64_t>* linear_operator,
00037     CIndependentComputationEngine* computation_engine,
00038     CEigenSolver* eigen_solver,
00039     CCGMShiftedFamilySolver* linear_solver,
00040     float64_t desired_accuracy)
00041     : CRationalApproximation(linear_operator, computation_engine,
00042       eigen_solver, desired_accuracy, OF_LOG)
00043 {
00044     init();
00045 
00046     m_linear_solver=linear_solver;
00047     SG_REF(m_linear_solver);
00048 }
00049 
00050 void CLogRationalApproximationCGM::init()
00051 {
00052     m_linear_solver=NULL;
00053 
00054     SG_ADD((CSGObject**)&m_linear_solver, "linear_solver",
00055         "Linear solver for complex systems", MS_NOT_AVAILABLE);
00056 
00057     SG_ADD(&m_negated_shifts, "negated_shifts",
00058         "Negated shifts", MS_NOT_AVAILABLE);
00059 }
00060 
00061 CLogRationalApproximationCGM::~CLogRationalApproximationCGM()
00062 {
00063     SG_UNREF(m_linear_solver);
00064 }
00065 
00066 CJobResultAggregator* CLogRationalApproximationCGM::submit_jobs(
00067     SGVector<float64_t> sample)
00068 {
00069     SG_DEBUG("Entering\n");
00070     REQUIRE(sample.vector, "Sample is not initialized!\n");
00071     REQUIRE(m_linear_operator, "Operator is not initialized!\n");
00072     REQUIRE(m_computation_engine, "Computation engine is NULL\n");
00073 
00074     // create the scalar aggregator
00075     CStoreScalarAggregator<float64_t>* agg=new CStoreScalarAggregator<float64_t>();
00076     // we don't want the aggregator to be destroyed when the job is unref-ed
00077     SG_REF(agg);
00078 
00079     // we need to take the negation of the shifts for this case
00080     if (m_negated_shifts.vector==NULL)
00081     {
00082         m_negated_shifts=SGVector<complex128_t>(m_shifts.vlen);
00083         Map<VectorXcd> shifts(m_shifts.vector, m_shifts.vlen);
00084         Map<VectorXcd> negated_shifts(m_negated_shifts.vector, m_negated_shifts.vlen);
00085         negated_shifts=-shifts;
00086     }
00087 
00088     // create one CG-M job for current sample vector which solves for all
00089     // the shifts, and computes the final result and stores that in the aggregator
00090     CRationalApproximationCGMJob* job
00091             =new CRationalApproximationCGMJob(agg, m_linear_solver,
00092             m_linear_operator, sample, m_negated_shifts, m_weights, m_constant_multiplier);
00093     SG_REF(job);
00094 
00095     m_computation_engine->submit_job(job);
00096 
00097     // we can safely unref the job here, computation engine takes it from here
00098     SG_UNREF(job);
00099 
00100     SG_DEBUG("Leaving\n");
00101     return agg;
00102 }
00103 
00104 }
00105 #endif // HAVE_EIGEN3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation