Starting on the distributed kde driver.

This commit is contained in:
Dongryeol Lee
2010-12-04 04:03:10 +00:00
parent 5969f85215
commit 31465ac0c9
3 changed files with 56 additions and 50 deletions
@@ -12,6 +12,7 @@
#include "core/tree/gen_kdtree.h"
#include "core/tree/gen_metric_tree.h"
#include "mlpack/kde/kde_dualtree.h"
#include "mlpack/distributed_kde/distributed_kde_dev.h"
typedef core::tree::GenMetricTree<core::tree::AbstractStatistic> TreeSpecType;
typedef core::tree::GeneralBinarySpaceTree < TreeSpecType > TreeType;
@@ -22,12 +23,14 @@ void Compute(
// Each process does the work owned by itself.
// This is the exchange loop.
do {
// Each process grabs the necessary work. This is the exchange
// phase.
// Each process computes.
}
@@ -87,7 +90,7 @@ int main(int argc, char *argv[]) {
// Initialize the memory allocator.
core::table::global_m_file_ = new core::table::MemoryMappedFile();
core::table::global_m_file_->Init(
std::string("tmp_file"), world.rank(), world.rank(), 50000000);
std::string("tmp_file"), world.rank(), world.rank(), 5000000);
// Seed the random number.
srand(time(NULL) + world.rank());
@@ -6,31 +6,31 @@
#ifndef MLPACK_DISTRIBUTED_KDE_DISTRIBUTED_KDE_H
#define MLPACK_DISTRIBUTED_KDE_DISTRIBUTED_KDE_H
#include <armadillo>
#include "boost/program_options.hpp"
#include "core/table/table.h"
#include "kde_dualtree.h"
#include "kde_arguments.h"
#include <boost/program_options.hpp>
#include "core/table/distributed_table.h"
#include "mlpack/kde/kde_dualtree.h"
#include "mlpack/kde/kde_arguments.h"
namespace mlpack {
namespace kde {
template<typename IncomingTableType>
namespace distributed_kde {
template<typename TreeSpecType>
class DistributedKde {
public:
typedef IncomingTableType TableType;
typedef core::table::Table<TreeSpecType> TableType;
typedef ml::KdePostponed PostponedType;
typedef core::table::DistributedTable<TreeSpecType> DistributedTableType;
typedef ml::KdeGlobal<TableType> GlobalType;
typedef mlpack::kde::::KdePostponed PostponedType;
typedef ml::KdeResult< std::vector<double> > ResultType;
typedef mlpack::kde::KdeGlobal<TableType> GlobalType;
typedef ml::KdeDelta DeltaType;
typedef mlpack::kde::KdeResult< std::vector<double> > ResultType;
typedef ml::KdeSummary SummaryType;
typedef mlpack::kde::KdeDelta DeltaType;
typedef ml::KdeStatistic StatisticType;
typedef mlpack::kde::KdeSummary SummaryType;
typedef mlpack::kde::KdeStatistic StatisticType;
public:
@@ -42,12 +42,12 @@ class DistributedKde {
/**
* @brief returns a pointer to the query table
*/
TableType *query_table();
core::table::DistributedTable<TreeSpecType> *query_table();
/**
* @brief returns a pointer to the reference table
*/
TableType *reference_table();
core::table::DistributedTable<TreeSpecType> *reference_table();
/**
* @brief returns a GlobalType structure that has the normalization statistics
@@ -63,25 +63,25 @@ class DistributedKde {
/**
* @brief Initialize a Kde engine with the arguments.
*/
void Init(ml::KdeArguments<TableType> &arguments_in);
void Init(mlpack::kde::KdeArguments<TableType> &arguments_in);
void Compute(
const ml::KdeArguments<TableType> &arguments_in,
const mlpack::kde::KdeArguments<TableType> &arguments_in,
ResultType *result_out);
static void ParseArguments(
const std::vector<std::string> &args,
ml::KdeArguments<TableType> *arguments_out);
mlpack::kde::KdeArguments<TableType> *arguments_out);
static void ParseArguments(
int argc,
char *argv[],
ml::KdeArguments<TableType> *arguments_out);
mlpack::kde::KdeArguments<TableType> *arguments_out);
private:
TableType *query_table_;
TableType *reference_table_;
DistributedTableType *query_table_;
DistributedTableType *reference_table_;
GlobalType global_;
bool is_monochromatic_;
@@ -8,43 +8,45 @@
#include "core/gnp/dualtree_dfs_dev.h"
#include "core/metric_kernels/lmetric.h"
#include "distributed_kde.h"
#include "mlpack/distributed_kde/distributed_kde.h"
template<typename TableType>
TableType *mlpack::DistributedKde<TableType>::query_table() {
template<typename TreeSpecType>
TableType *mlpack::distributed_kde::DistributedKde<TableType>::query_table() {
return query_table_;
}
template<typename TableType>
TableType *mlpack::DistributedKde<TableType>::reference_table() {
template<typename TreeSpecType>
TableType *mlpack::distributed_kde::DistributedKde<TableType>::reference_table() {
return reference_table_;
}
template<typename TableType>
typename mlpack::DistributedKde<TableType>::GlobalType &mlpack::DistributedKde<TableType>::global() {
template<typename TreeSpecType>
typename mlpack::distributed_kde::DistributedKde<TableType>::GlobalType &
mlpack::distributed_kde::DistributedKde<TableType>::global() {
return global_;
}
template<typename TableType>
bool mlpack::DistributedKde<TableType>::is_monochromatic() const {
template<typename TreeSpecType>
bool mlpack::distributed_kde::DistributedKde<TableType>::is_monochromatic() const {
return is_monochromatic_;
}
template<typename TableType>
void mlpack::DistributedKde<TableType>::Compute(
const mlpack::DistributedKdeArguments<TableType> &arguments_in,
mlpack::DistributedKdeResult< std::vector<double> > *result_out) {
template<typename TreeSpecType>
void mlpack::distributed_kde::DistributedKde<TableType>::Compute(
const mlpack::distributed_kde::DistributedKdeArguments<TableType> &arguments_in,
mlpack::distributed_kde::DistributedKdeResult< std::vector<double> > *result_out) {
// Instantiate a dual-tree algorithm of the KDE.
core::gnp::DualtreeDfs<mlpack::DistributedKde<TableType> > dualtree_dfs;
core::gnp::DualtreeDfs<mlpack::distributed_kde::DistributedKde<TableType> > dualtree_dfs;
dualtree_dfs.Init(*this);
// Compute the result.
dualtree_dfs.Compute(* arguments_in.metric_, result_out);
}
template<typename TableType>
void mlpack::DistributedKde<TableType>::Init(mlpack::DistributedKdeArguments<TableType> &arguments_in) {
template<typename TreeSpecType>
void mlpack::distributed_kde::DistributedKde<TableType>::Init(
mlpack::distributed_kde::DistributedKdeArguments<TableType> &arguments_in) {
reference_table_ = arguments_in.reference_table_;
if(arguments_in.query_table_ == NULL) {
@@ -63,13 +65,14 @@ void mlpack::DistributedKde<TableType>::Init(mlpack::DistributedKdeArguments<Tab
arguments_in.kernel_);
}
template<typename TableType>
void mlpack::DistributedKde<TableType>::set_bandwidth(double bandwidth_in) {
template<typename TreeSpecType>
void mlpack::distributed_kde::DistributedKde<TableType>::set_bandwidth(
double bandwidth_in) {
global_.set_bandwidth(bandwidth_in);
}
template<typename TableType>
bool mlpack::DistributedKde<TableType>::ConstructBoostVariableMap_(
template<typename TreeSpecType>
bool mlpack::distributed_kde::DistributedKde<TableType>::ConstructBoostVariableMap_(
const std::vector<std::string> &args,
boost::program_options::variables_map *vm) {
@@ -175,10 +178,10 @@ bool mlpack::DistributedKde<TableType>::ConstructBoostVariableMap_(
return false;
}
template<typename TableType>
void mlpack::DistributedKde<TableType>::ParseArguments(
template<typename TreeSpecType>
void mlpack::distributed_kde::DistributedKde<TableType>::ParseArguments(
const std::vector<std::string> &args,
mlpack::DistributedKdeArguments<TableType> *arguments_out) {
mlpack::distributed_kde::DistributedKdeArguments<TableType> *arguments_out) {
// A L2 metric to index the table to use.
arguments_out->metric_ = new core::metric_kernels::LMetric<2>();
@@ -238,11 +241,11 @@ void mlpack::DistributedKde<TableType>::ParseArguments(
std::cout << "Using the kernel: " << arguments_out->kernel_ << "\n";
}
template<typename TableType>
void mlpack::DistributedKde<TableType>::ParseArguments(
template<typename TreeSpecType>
void mlpack::distributed_kde::DistributedKde<TableType>::ParseArguments(
int argc,
char *argv[],
mlpack::DistributedKdeArguments<TableType> *arguments_out) {
mlpack::distributed_kde::DistributedKdeArguments<TableType> *arguments_out) {
// Convert C input to C++; skip executable name for Boost.
std::vector<std::string> args(argv + 1, argv + argc);