Skip to content

Commit

Permalink
Merge pull request #1189 from lambday/feature/log_determinant
Browse files Browse the repository at this point in the history
params registered, sample modified (log-det), gitignore modified
  • Loading branch information
karlnapf committed Jun 26, 2013
2 parents 384185f + 5bcdd54 commit 2aa7804
Show file tree
Hide file tree
Showing 25 changed files with 371 additions and 101 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -117,3 +117,6 @@ examples/undocumented/python_modular/*

# /tests
/tests/unit/shogun-unit-test
/tests/unit/*.txt
/tests/unit/*.xml
/tests/unit/*.hdf5
Expand Up @@ -40,7 +40,9 @@ class CIndependentComputationEngine : public CSGObject
SG_GCDEBUG("%s destroyed (%p)\n", this->get_name(), this)
}

/** abstract method that submits the jobs to the engine
/**
* abstract method that submits the jobs to the engine
*
* @param job the job to be computed
*/
virtual void submit_job(CIndependentJob* job) = 0;
Expand Down
3 changes: 3 additions & 0 deletions src/shogun/lib/computation/engine/SerialComputationEngine.cpp
Expand Up @@ -28,7 +28,10 @@ CSerialComputationEngine::~CSerialComputationEngine()
void CSerialComputationEngine::submit_job(CIndependentJob* job)
{
SG_DEBUG("Entering. The job is being computed!\n");

REQUIRE(job, "Job to be computed is NULL\n");
job->compute();

SG_DEBUG("The job is computed. Leaving!\n");
}

Expand Down
7 changes: 5 additions & 2 deletions src/shogun/lib/computation/engine/SerialComputationEngine.h
Expand Up @@ -28,13 +28,16 @@ class CSerialComputationEngine : public CIndependentComputationEngine
/** destructor */
virtual ~CSerialComputationEngine();

/** method that calls the job's compute method in each call, therefore
/**
* method that calls the job's compute method in each call, therefore
* blocks until the its computation is done
*
* @param job the job to be computed
*/
virtual void submit_job(CIndependentJob* job);

/** method that returns when all the jobs computed, in this case it does
/**
* method that returns when all the jobs computed, in this case it does
* nothing
*/
virtual void wait_for_all();
Expand Down
32 changes: 27 additions & 5 deletions src/shogun/lib/computation/job/DenseExactLogJob.cpp
Expand Up @@ -7,7 +7,7 @@
* Written (W) 2013 Soumyajit De
*/

#include <shogun/lib/common.h>
#include <shogun/lib/config.h>

#ifdef HAVE_EIGEN3
#include <shogun/lib/SGVector.h>
Expand All @@ -23,31 +23,52 @@ namespace shogun
{

CDenseExactLogJob::CDenseExactLogJob()
: CIndependentJob(), m_log_operator(NULL)
: CIndependentJob()
{
init();

SG_GCDEBUG("%s created (%p)\n", this->get_name(), this)
}

CDenseExactLogJob::CDenseExactLogJob(CJobResultAggregator* aggregator,
CDenseMatrixOperator<float64_t>* log_operator, SGVector<float64_t> vector)
: CIndependentJob(aggregator),
m_log_operator(log_operator),
m_vector(vector)
: CIndependentJob(aggregator)
{
init();

m_log_operator=log_operator;
SG_REF(m_log_operator);

m_vector=vector;

SG_GCDEBUG("%s created (%p)\n", this->get_name(), this)
}

void CDenseExactLogJob::init()
{
m_log_operator=NULL;

SG_ADD((CSGObject**)&m_log_operator, "log_operator",
"Log of linear operator", MS_NOT_AVAILABLE);

SG_ADD((SGVector<float64_t>*)&m_vector, "trace_sample",
"Sample vector to apply linear operator on", MS_NOT_AVAILABLE);
}

CDenseExactLogJob::~CDenseExactLogJob()
{
SG_UNREF(m_log_operator);

SG_GCDEBUG("%s destroyed (%p)\n", this->get_name(), this)
}

void CDenseExactLogJob::compute()
{
SG_DEBUG("Entering...\n")

REQUIRE(m_log_operator, "Log operator function is NULL\n");
REQUIRE(m_aggregator, "Job result aggregator is NULL\n");

// apply the log to m_vector
SGVector<float64_t> vec=m_log_operator->apply(m_vector);

Expand All @@ -57,6 +78,7 @@ void CDenseExactLogJob::compute()

CScalarResult<float64_t>* result=new CScalarResult<float64_t>(s.dot(v));
SG_REF(result);

m_aggregator->submit_result(result);
SG_UNREF(result);

Expand Down
8 changes: 7 additions & 1 deletion src/shogun/lib/computation/job/DenseExactLogJob.h
Expand Up @@ -29,7 +29,9 @@ class CDenseExactLogJob : public CIndependentJob
/** default constructor */
CDenseExactLogJob();

/** constructor
/**
* constructor
*
* @param aggregator the job result aggregator for this job
* @param log_operator the dense matrix operator to be applied to the vector
* @param vector the sample vector to which operator is to be applied
Expand Down Expand Up @@ -61,6 +63,10 @@ class CDenseExactLogJob : public CIndependentJob

/** the trace-sample */
SGVector<float64_t> m_vector;

private:
/** initialize with default values and register params */
void init();
};

}
Expand Down
27 changes: 24 additions & 3 deletions src/shogun/lib/computation/job/IndependentJob.h
Expand Up @@ -12,6 +12,7 @@

#include <shogun/lib/config.h>
#include <shogun/base/SGObject.h>
#include <shogun/base/Parameter.h>
#include <shogun/lib/computation/job/JobResultAggregator.h>

namespace shogun
Expand All @@ -27,29 +28,39 @@ class CIndependentJob : public CSGObject
public:
/** default constructor*/
CIndependentJob()
: CSGObject(), m_aggregator(NULL)
: CSGObject()
{
init();

SG_GCDEBUG("%s created (%p)\n", this->get_name(), this)
}

/** constructor
/**
* constructor
*
* @param aggregator the job result aggregator for the current job
*/
CIndependentJob(CJobResultAggregator* aggregator)
: CSGObject(), m_aggregator(aggregator)
{
init();

m_aggregator=aggregator;
SG_REF(m_aggregator);

SG_GCDEBUG("%s created (%p)\n", this->get_name(), this)
}

/** destructor */
virtual ~CIndependentJob()
{
SG_UNREF(m_aggregator);

SG_GCDEBUG("%s destroyed (%p)\n", this->get_name(), this)
}

/** abstract compute method that computes the job, creates a CJobResult,
/**
* abstract compute method that computes the job, creates a CJobResult,
* submits the result to the job result aggregator
*/
virtual void compute() = 0;
Expand All @@ -62,6 +73,16 @@ class CIndependentJob : public CSGObject
protected:
/** the job result aggregator for the current job */
CJobResultAggregator* m_aggregator;

private:
/** initialize with default values and register params */
void init()
{
m_aggregator=NULL;

SG_ADD((CSGObject**)&m_aggregator, "job_result_aggregator",
"Job result aggregator for current job", MS_NOT_AVAILABLE);
}
};

}
Expand Down
23 changes: 20 additions & 3 deletions src/shogun/lib/computation/job/JobResultAggregator.h
Expand Up @@ -13,6 +13,7 @@
#include <shogun/lib/config.h>
#include <shogun/base/SGObject.h>
#include <shogun/lib/computation/job/JobResult.h>
#include <shogun/base/Parameter.h>

namespace shogun
{
Expand All @@ -26,25 +27,31 @@ class CJobResultAggregator : public CSGObject
public:
/** default constructor */
CJobResultAggregator()
: CSGObject(), m_result(NULL)
: CSGObject()
{
init();

SG_GCDEBUG("%s created (%p)\n", this->get_name(), this)
}

/** destructor */
virtual ~CJobResultAggregator()
{
SG_UNREF(m_result);

SG_GCDEBUG("%s destroyed (%p)\n", this->get_name(), this)
}

/** abstract method that submits the result of an independent job, and
/**
* abstract method that submits the result of an independent job, and
* computes the aggregation with the previously submitted result
*
* @param result the result of an independent job
*/
virtual void submit_result(CJobResult* result) = 0;

/** abstract method that finalizes the aggregation and computes the result,
/**
* abstract method that finalizes the aggregation and computes the result,
* its necessary to call finalize before getting the final result
*/
virtual void finalize() = 0;
Expand All @@ -63,6 +70,16 @@ class CJobResultAggregator : public CSGObject
protected:
/** the final job result */
CJobResult* m_result;

private:
/** initialize with default values and register params */
void init()
{
m_result=NULL;

SG_ADD((CSGObject**)&m_result, "final_result",
"Aggregation of computation job results", MS_NOT_AVAILABLE);
}
};

}
Expand Down
27 changes: 23 additions & 4 deletions src/shogun/lib/computation/job/ScalarResult.h
Expand Up @@ -12,6 +12,7 @@

#include <shogun/lib/config.h>
#include <shogun/lib/computation/job/JobResult.h>
#include <shogun/base/Parameter.h>

namespace shogun
{
Expand All @@ -22,19 +23,27 @@ namespace shogun
template<class T> class CScalarResult : public CJobResult
{
public:
/** default constructor, no args */
/** default constructor */
CScalarResult()
: CJobResult(), m_result(static_cast<T>(0))
: CJobResult()
{
init();

SG_GCDEBUG("%s created (%p)\n", this->get_name(), this)
}

/** constructor
/**
* constructor
*
* @param result the scalar result
*/
CScalarResult(const T& result)
: CJobResult(), m_result(result)
: CJobResult()
{
init();

m_result=result;

SG_GCDEBUG("%s created (%p)\n", this->get_name(), this)
}

Expand All @@ -59,6 +68,16 @@ template<class T> class CScalarResult : public CJobResult
protected:
/** the scalar result */
T m_result;

private:
/** initialize with default values and register params */
void init()
{
m_result=static_cast<T>(0);

SG_ADD(&m_result, "scalar_result", "Scalar result of a computation job",
MS_NOT_AVAILABLE);
}
};

template class CScalarResult<bool>;
Expand Down
16 changes: 13 additions & 3 deletions src/shogun/lib/computation/job/StoreScalarAggregator.cpp
Expand Up @@ -7,19 +7,30 @@
* Written (W) 2013 Soumyajit De
*/

#include <shogun/lib/common.h>
#include <shogun/lib/config.h>
#include <shogun/lib/computation/job/ScalarResult.h>
#include <shogun/lib/computation/job/StoreScalarAggregator.h>

namespace shogun
{
template<class T>
CStoreScalarAggregator<T>::CStoreScalarAggregator()
: CJobResultAggregator(), m_aggregate(static_cast<T>(0))
: CJobResultAggregator()
{
init();

SG_GCDEBUG("%s created (%p)\n", this->get_name(), this)
}

template<class T>
void CStoreScalarAggregator<T>::init()
{
m_aggregate=static_cast<T>(0);

SG_ADD(&m_aggregate, "current_aggregate",
"Aggregation of computation job results", MS_NOT_AVAILABLE);
}

template<class T>
CStoreScalarAggregator<T>::~CStoreScalarAggregator()
{
Expand All @@ -32,7 +43,6 @@ void CStoreScalarAggregator<T>::submit_result(CJobResult* result)
SG_GCDEBUG("Entering ...\n")

// check for proper typecast
// DEBUG COMMENT : the following does NOT increase refcount of result
CScalarResult<T>* new_result=dynamic_cast<CScalarResult<T>*>(result);
if (!new_result)
SG_ERROR("result is not of CScalarResult type!\n");
Expand Down
10 changes: 8 additions & 2 deletions src/shogun/lib/computation/job/StoreScalarAggregator.h
Expand Up @@ -31,13 +31,16 @@ template<class T> class CStoreScalarAggregator : public CJobResultAggregator
/** destructor */
virtual ~CStoreScalarAggregator();

/** method that submits the result (scalar) of an independent job, and
/**
* method that submits the result (scalar) of an independent job, and
* computes the aggregation with the previously submitted result
*
* @param result the result of an independent job
*/
virtual void submit_result(CJobResult* result);

/** method that finalizes the aggregation and computes the result (scalar),
/**
* method that finalizes the aggregation and computes the result (scalar),
* its necessary to call finalize before getting the final result
*/
virtual void finalize();
Expand All @@ -50,6 +53,9 @@ template<class T> class CStoreScalarAggregator : public CJobResultAggregator
private:
/** the aggregation */
T m_aggregate;

/** initialize with default values and register params */
void init();
};

}
Expand Down

0 comments on commit 2aa7804

Please sign in to comment.