Devirtulaization of metrics.
This commit is contained in:
@@ -7,7 +7,6 @@
|
||||
#define CORE_GNP_DISTRIBUTED_DUALTREE_DFS_H
|
||||
|
||||
#include <boost/mpi/communicator.hpp>
|
||||
#include "core/metric_kernels/abstract_metric.h"
|
||||
#include "core/math/range.h"
|
||||
|
||||
namespace core {
|
||||
@@ -38,8 +37,9 @@ class DistributedDualtreeDfs {
|
||||
|
||||
private:
|
||||
|
||||
template<typename MetricType>
|
||||
void ReduceScatter_(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
typename DistributedProblemType::ResultType *query_results);
|
||||
|
||||
void ResetStatisticRecursion_(
|
||||
@@ -51,8 +51,9 @@ class DistributedDualtreeDfs {
|
||||
template<typename TemplateTreeType>
|
||||
void PreProcess_(TemplateTreeType *qnode);
|
||||
|
||||
template<typename MetricType>
|
||||
void PostProcess_(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
TreeType *qnode, ResultType *query_results);
|
||||
|
||||
public:
|
||||
@@ -68,8 +69,9 @@ class DistributedDualtreeDfs {
|
||||
void Init(
|
||||
boost::mpi::communicator *world, DistributedProblemType &problem_in);
|
||||
|
||||
template<typename MetricType>
|
||||
void Compute(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
typename DistributedProblemType::ResultType *query_results);
|
||||
};
|
||||
};
|
||||
|
||||
+6
-3
@@ -25,8 +25,9 @@ extern core::table::MemoryMappedFile *global_m_file_;
|
||||
};
|
||||
|
||||
template<typename DistributedProblemType>
|
||||
template<typename MetricType>
|
||||
void core::gnp::DistributedDualtreeDfs<DistributedProblemType>::ReduceScatter_(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
typename DistributedProblemType::ResultType *query_results) {
|
||||
|
||||
// The typedef of a sub table in use and its list.
|
||||
@@ -180,8 +181,9 @@ void core::gnp::DistributedDualtreeDfs<DistributedProblemType>::Init(
|
||||
}
|
||||
|
||||
template<typename DistributedProblemType>
|
||||
template<typename MetricType>
|
||||
void core::gnp::DistributedDualtreeDfs<DistributedProblemType>::Compute(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
typename DistributedProblemType::ResultType *query_results) {
|
||||
|
||||
// Allocate space for storing the final results.
|
||||
@@ -210,7 +212,8 @@ void core::gnp::DistributedDualtreeDfs<DistributedProblemType>::Compute(
|
||||
}
|
||||
|
||||
template<typename DistributedProblemType>
|
||||
void core::gnp::DistributedDualtreeDfs<DistributedProblemType>::ResetStatisticRecursion_(
|
||||
void core::gnp::DistributedDualtreeDfs <
|
||||
DistributedProblemType >::ResetStatisticRecursion_(
|
||||
typename DistributedProblemType::DistributedTableType::TreeType *node,
|
||||
typename DistributedProblemType::DistributedTableType * table) {
|
||||
node->stat().SetZero();
|
||||
|
||||
+6
-4
@@ -10,7 +10,6 @@
|
||||
#define CORE_GNP_DISTRIBUTED_TRIPLETREE_DFS_H
|
||||
|
||||
#include <boost/mpi/communicator.hpp>
|
||||
#include "core/metric_kernels/abstract_metric.h"
|
||||
#include "core/math/range.h"
|
||||
|
||||
namespace core {
|
||||
@@ -41,8 +40,9 @@ class DistributedTripletreeDfs {
|
||||
|
||||
private:
|
||||
|
||||
template<typename MetricType>
|
||||
void ReduceScatter_(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
typename DistributedProblemType::ResultType *query_results);
|
||||
|
||||
void ResetStatisticRecursion_(
|
||||
@@ -54,8 +54,9 @@ class DistributedTripletreeDfs {
|
||||
template<typename TemplateTreeType>
|
||||
void PreProcess_(TemplateTreeType *qnode);
|
||||
|
||||
template<typename MetricType>
|
||||
void PostProcess_(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
TreeType *qnode, ResultType *query_results);
|
||||
|
||||
public:
|
||||
@@ -71,8 +72,9 @@ class DistributedTripletreeDfs {
|
||||
void Init(
|
||||
boost::mpi::communicator *world, DistributedProblemType &problem_in);
|
||||
|
||||
template<typename MetricType>
|
||||
void Compute(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
typename DistributedProblemType::ResultType *query_results);
|
||||
};
|
||||
};
|
||||
|
||||
+4
-2
@@ -25,8 +25,9 @@ extern core::table::MemoryMappedFile *global_m_file_;
|
||||
};
|
||||
|
||||
template<typename DistributedProblemType>
|
||||
template<typename MetricType>
|
||||
void core::gnp::DistributedTripletreeDfs<DistributedProblemType>::ReduceScatter_(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
typename DistributedProblemType::ResultType *query_results) {
|
||||
|
||||
// The typedef of a sub table in use and its list.
|
||||
@@ -180,8 +181,9 @@ void core::gnp::DistributedTripletreeDfs<DistributedProblemType>::Init(
|
||||
}
|
||||
|
||||
template<typename DistributedProblemType>
|
||||
template<typename MetricType>
|
||||
void core::gnp::DistributedTripletreeDfs<DistributedProblemType>::Compute(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
typename DistributedProblemType::ResultType *query_results) {
|
||||
|
||||
// Allocate space for storing the final results.
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#define CORE_GNP_DUALTREE_DFS_H
|
||||
|
||||
#include <map>
|
||||
#include "core/metric_kernels/abstract_metric.h"
|
||||
#include "core/math/range.h"
|
||||
#include "core/gnp/dualtree_trace.h"
|
||||
|
||||
@@ -24,6 +23,7 @@ class DualtreeDfs {
|
||||
typedef typename ProblemType::ResultType ResultType;
|
||||
|
||||
public:
|
||||
template<typename IteratorMetricType>
|
||||
class iterator {
|
||||
private:
|
||||
class IteratorArgType {
|
||||
@@ -43,13 +43,13 @@ class DualtreeDfs {
|
||||
IteratorArgType(const IteratorArgType &arg_in);
|
||||
|
||||
IteratorArgType(
|
||||
const core::metric_kernels::AbstractMetric &metric_in,
|
||||
const IteratorMetricType &metric_in,
|
||||
TableType *query_table_in, TreeType *qnode_in,
|
||||
TableType *reference_table_in,
|
||||
TreeType *rnode_in);
|
||||
|
||||
IteratorArgType(
|
||||
const core::metric_kernels::AbstractMetric &metric_in,
|
||||
const IteratorMetricType &metric_in,
|
||||
TableType *query_table_in, TreeType *qnode_in,
|
||||
TableType *reference_table_in,
|
||||
TreeType *rnode_in,
|
||||
@@ -74,16 +74,15 @@ class DualtreeDfs {
|
||||
|
||||
DualtreeDfs<ProblemType> *engine_;
|
||||
|
||||
const core::metric_kernels::AbstractMetric &metric_;
|
||||
const IteratorMetricType &metric_;
|
||||
|
||||
ResultType *query_results_;
|
||||
|
||||
core::gnp::DualtreeTrace<IteratorArgType> trace_;
|
||||
|
||||
public:
|
||||
|
||||
iterator(
|
||||
const core::metric_kernels::AbstractMetric &metric_in,
|
||||
const IteratorMetricType &metric_in,
|
||||
DualtreeDfs<ProblemType> &engine_in,
|
||||
ResultType *query_results_in);
|
||||
|
||||
@@ -125,8 +124,9 @@ class DualtreeDfs {
|
||||
|
||||
void PreProcess_(TreeType *qnode);
|
||||
|
||||
template<typename MetricType>
|
||||
void DualtreeBase_(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
TreeType *qnode,
|
||||
TreeType *rnode,
|
||||
ResultType *result);
|
||||
@@ -142,8 +142,9 @@ class DualtreeDfs {
|
||||
const typename ProblemType::DeltaType &delta,
|
||||
typename ProblemType::ResultType *query_results);
|
||||
|
||||
template<typename MetricType>
|
||||
bool CanProbabilisticSummarize_(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
TreeType *qnode,
|
||||
TreeType *rnode,
|
||||
double failure_probability,
|
||||
@@ -157,8 +158,9 @@ class DualtreeDfs {
|
||||
const typename ProblemType::DeltaType &delta,
|
||||
typename ProblemType::ResultType *query_results);
|
||||
|
||||
template<typename MetricType>
|
||||
void Heuristic_(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
TreeType *node,
|
||||
TableType *node_table,
|
||||
TreeType *first_candidate,
|
||||
@@ -169,16 +171,18 @@ class DualtreeDfs {
|
||||
TreeType **second_partner,
|
||||
core::math::Range &second_squared_distance_range);
|
||||
|
||||
template<typename MetricType>
|
||||
bool DualtreeCanonical_(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
TreeType *qnode,
|
||||
TreeType *rnode,
|
||||
double failure_probability,
|
||||
const core::math::Range &squared_distance_range,
|
||||
ResultType *query_results);
|
||||
|
||||
template<typename MetricType>
|
||||
void PostProcess_(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
TreeType *qnode, ResultType *query_results);
|
||||
|
||||
public:
|
||||
@@ -205,16 +209,19 @@ class DualtreeDfs {
|
||||
|
||||
TableType *reference_table();
|
||||
|
||||
typename DualtreeDfs<ProblemType>::iterator get_iterator(
|
||||
const core::metric_kernels::AbstractMetric &metric_in,
|
||||
template<typename MetricType>
|
||||
typename DualtreeDfs<ProblemType>::template
|
||||
iterator<MetricType> get_iterator(
|
||||
const MetricType &metric_in,
|
||||
ResultType *query_results_in);
|
||||
|
||||
void ResetStatistic();
|
||||
|
||||
void Init(ProblemType &problem_in);
|
||||
|
||||
template<typename MetricType>
|
||||
void Compute(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
typename ProblemType::ResultType *query_results,
|
||||
bool do_initializations = true);
|
||||
};
|
||||
|
||||
@@ -96,8 +96,9 @@ void DualtreeDfs<ProblemType>::Init(ProblemType &problem_in) {
|
||||
}
|
||||
|
||||
template<typename ProblemType>
|
||||
template<typename MetricType>
|
||||
void DualtreeDfs<ProblemType>::Compute(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
typename ProblemType::ResultType *query_results,
|
||||
bool do_initializations) {
|
||||
|
||||
@@ -180,8 +181,9 @@ void DualtreeDfs<ProblemType>::PreProcess_(
|
||||
}
|
||||
|
||||
template<typename ProblemType>
|
||||
template<typename MetricType>
|
||||
void DualtreeDfs<ProblemType>::DualtreeBase_(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
typename ProblemType::TableType::TreeType *qnode,
|
||||
typename ProblemType::TableType::TreeType *rnode,
|
||||
typename ProblemType::ResultType *query_results) {
|
||||
@@ -246,8 +248,9 @@ void DualtreeDfs<ProblemType>::DualtreeBase_(
|
||||
}
|
||||
|
||||
template<typename ProblemType>
|
||||
template<typename MetricType>
|
||||
bool DualtreeDfs<ProblemType>::CanProbabilisticSummarize_(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
typename ProblemType::TableType::TreeType *qnode,
|
||||
typename ProblemType::TableType::TreeType *rnode,
|
||||
double failure_probability,
|
||||
@@ -303,8 +306,9 @@ void DualtreeDfs<ProblemType>::Summarize_(
|
||||
}
|
||||
|
||||
template<typename ProblemType>
|
||||
template<typename MetricType>
|
||||
void DualtreeDfs<ProblemType>::Heuristic_(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
typename ProblemType::TableType::TreeType *node,
|
||||
typename ProblemType::TableType *node_table,
|
||||
typename ProblemType::TableType::TreeType *first_candidate,
|
||||
@@ -338,8 +342,9 @@ void DualtreeDfs<ProblemType>::Heuristic_(
|
||||
}
|
||||
|
||||
template<typename ProblemType>
|
||||
template<typename MetricType>
|
||||
bool DualtreeDfs<ProblemType>::DualtreeCanonical_(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
typename ProblemType::TableType::TreeType *qnode,
|
||||
typename ProblemType::TableType::TreeType *rnode,
|
||||
double failure_probability,
|
||||
@@ -519,8 +524,9 @@ bool DualtreeDfs<ProblemType>::DualtreeCanonical_(
|
||||
}
|
||||
|
||||
template<typename ProblemType>
|
||||
template<typename MetricType>
|
||||
void DualtreeDfs<ProblemType>::PostProcess_(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
typename ProblemType::TableType::TreeType *qnode,
|
||||
typename ProblemType::ResultType *query_results) {
|
||||
|
||||
|
||||
+47
-27
@@ -6,12 +6,14 @@
|
||||
#ifndef CORE_GNP_DUALTREE_DFS_ITERATOR_DEV_H
|
||||
#define CORE_GNP_DUALTREE_DFS_ITERATOR_DEV_H
|
||||
|
||||
#include "dualtree_dfs.h"
|
||||
#include "core/gnp/dualtree_dfs.h"
|
||||
|
||||
namespace core {
|
||||
namespace gnp {
|
||||
template<typename ProblemType>
|
||||
DualtreeDfs<ProblemType>::iterator::IteratorArgType::IteratorArgType() {
|
||||
template<typename IteratorMetricType>
|
||||
DualtreeDfs<ProblemType>::iterator <
|
||||
IteratorMetricType >::IteratorArgType::IteratorArgType() {
|
||||
|
||||
// Initialize the members.
|
||||
qnode_ = NULL;
|
||||
@@ -22,7 +24,8 @@ DualtreeDfs<ProblemType>::iterator::IteratorArgType::IteratorArgType() {
|
||||
}
|
||||
|
||||
template<typename ProblemType>
|
||||
DualtreeDfs<ProblemType>::iterator::
|
||||
template<typename IteratorMetricType>
|
||||
DualtreeDfs<ProblemType>::iterator<IteratorMetricType>::
|
||||
IteratorArgType::IteratorArgType(const IteratorArgType &arg_in) {
|
||||
|
||||
// Initialize the members.
|
||||
@@ -34,38 +37,46 @@ IteratorArgType::IteratorArgType(const IteratorArgType &arg_in) {
|
||||
}
|
||||
|
||||
template<typename ProblemType>
|
||||
typename ProblemType::TableType::TreeType *DualtreeDfs<ProblemType>::iterator
|
||||
::IteratorArgType::qnode() {
|
||||
template<typename IteratorMetricType>
|
||||
typename ProblemType::TableType::TreeType *DualtreeDfs <
|
||||
ProblemType >::iterator<IteratorMetricType>::IteratorArgType::qnode() {
|
||||
return qnode_;
|
||||
}
|
||||
|
||||
template<typename ProblemType>
|
||||
typename ProblemType::TableType::TreeType *DualtreeDfs<ProblemType>::iterator
|
||||
::IteratorArgType::qnode() const {
|
||||
template<typename IteratorMetricType>
|
||||
typename ProblemType::TableType::TreeType *DualtreeDfs <
|
||||
ProblemType >::iterator<IteratorMetricType>::IteratorArgType::qnode() const {
|
||||
return qnode_;
|
||||
}
|
||||
|
||||
template<typename ProblemType>
|
||||
typename ProblemType::TableType::TreeType *DualtreeDfs<ProblemType>::iterator
|
||||
::IteratorArgType::rnode() {
|
||||
template<typename IteratorMetricType>
|
||||
typename ProblemType::TableType::TreeType *DualtreeDfs <
|
||||
ProblemType >::iterator<IteratorMetricType>::IteratorArgType::rnode() {
|
||||
return rnode_;
|
||||
}
|
||||
|
||||
template<typename ProblemType>
|
||||
typename ProblemType::TableType::TreeType *DualtreeDfs<ProblemType>::iterator
|
||||
::IteratorArgType::rnode() const {
|
||||
template<typename IteratorMetricType>
|
||||
typename ProblemType::TableType::TreeType *DualtreeDfs <
|
||||
ProblemType >::iterator<IteratorMetricType>::IteratorArgType::rnode() const {
|
||||
return rnode_;
|
||||
}
|
||||
|
||||
template<typename ProblemType>
|
||||
const core::math::Range &DualtreeDfs<ProblemType>::iterator
|
||||
template<typename IteratorMetricType>
|
||||
const core::math::Range &DualtreeDfs <
|
||||
ProblemType >::iterator<IteratorMetricType>
|
||||
::IteratorArgType::squared_distance_range() const {
|
||||
return squared_distance_range_;
|
||||
}
|
||||
|
||||
template<typename ProblemType>
|
||||
DualtreeDfs<ProblemType>::iterator::IteratorArgType::IteratorArgType(
|
||||
const core::metric_kernels::AbstractMetric &metric_in,
|
||||
template<typename IteratorMetricType>
|
||||
DualtreeDfs<ProblemType>::iterator <
|
||||
IteratorMetricType >::IteratorArgType::IteratorArgType(
|
||||
const IteratorMetricType &metric_in,
|
||||
typename DualtreeDfs<ProblemType>::TableType *query_table_in,
|
||||
typename DualtreeDfs<ProblemType>::TableType::TreeType *qnode_in,
|
||||
typename DualtreeDfs<ProblemType>::TableType *reference_table_in,
|
||||
@@ -79,8 +90,10 @@ DualtreeDfs<ProblemType>::iterator::IteratorArgType::IteratorArgType(
|
||||
}
|
||||
|
||||
template<typename ProblemType>
|
||||
DualtreeDfs<ProblemType>::iterator::IteratorArgType::IteratorArgType(
|
||||
const core::metric_kernels::AbstractMetric &metric_in,
|
||||
template<typename IteratorMetricType>
|
||||
DualtreeDfs<ProblemType>::iterator <
|
||||
IteratorMetricType >::IteratorArgType::IteratorArgType(
|
||||
const IteratorMetricType &metric_in,
|
||||
typename DualtreeDfs<ProblemType>::TableType *query_table_in,
|
||||
typename DualtreeDfs<ProblemType>::TableType::TreeType *qnode_in,
|
||||
typename DualtreeDfs<ProblemType>::TableType *reference_table_in,
|
||||
@@ -94,8 +107,9 @@ DualtreeDfs<ProblemType>::iterator::IteratorArgType::IteratorArgType(
|
||||
}
|
||||
|
||||
template<typename ProblemType>
|
||||
DualtreeDfs<ProblemType>::iterator::iterator(
|
||||
const core::metric_kernels::AbstractMetric &metric_in,
|
||||
template<typename IteratorMetricType>
|
||||
DualtreeDfs<ProblemType>::iterator<IteratorMetricType>::iterator(
|
||||
const IteratorMetricType &metric_in,
|
||||
DualtreeDfs<ProblemType> &engine_in,
|
||||
typename ProblemType::ResultType *query_results_in): metric_(metric_in) {
|
||||
|
||||
@@ -115,7 +129,8 @@ DualtreeDfs<ProblemType>::iterator::iterator(
|
||||
}
|
||||
|
||||
template<typename ProblemType>
|
||||
void DualtreeDfs<ProblemType>::iterator::operator++() {
|
||||
template<typename IteratorMetricType>
|
||||
void DualtreeDfs<ProblemType>::iterator<IteratorMetricType>::operator++() {
|
||||
|
||||
// Push a blank argument to the trace for making the exit phase.
|
||||
trace_.push_front(IteratorArgType());
|
||||
@@ -248,33 +263,38 @@ void DualtreeDfs<ProblemType>::iterator::operator++() {
|
||||
}
|
||||
|
||||
template<typename ProblemType>
|
||||
void DualtreeDfs<ProblemType>::iterator::Finalize() {
|
||||
template<typename IteratorMetricType>
|
||||
void DualtreeDfs<ProblemType>::iterator<IteratorMetricType>::Finalize() {
|
||||
return engine_->PostProcess_(
|
||||
metric_, query_table_->get_tree(), query_results_);
|
||||
}
|
||||
|
||||
template<typename ProblemType>
|
||||
typename ProblemType::ResultType &DualtreeDfs<ProblemType>::iterator
|
||||
::operator*() {
|
||||
template<typename IteratorMetricType>
|
||||
typename ProblemType::ResultType &DualtreeDfs <
|
||||
ProblemType >::iterator<IteratorMetricType>::operator*() {
|
||||
return *query_results_;
|
||||
}
|
||||
|
||||
template<typename ProblemType>
|
||||
const typename ProblemType::ResultType &DualtreeDfs<ProblemType>::iterator
|
||||
::operator*() const {
|
||||
template<typename IteratorMetricType>
|
||||
const typename ProblemType::ResultType &DualtreeDfs <
|
||||
ProblemType >::iterator<IteratorMetricType>::operator*() const {
|
||||
return *query_results_;
|
||||
}
|
||||
|
||||
template<typename ProblemType>
|
||||
typename DualtreeDfs<ProblemType>::iterator
|
||||
template<typename IteratorMetricType>
|
||||
typename DualtreeDfs<ProblemType>::template iterator<IteratorMetricType>
|
||||
DualtreeDfs<ProblemType>::get_iterator(
|
||||
const core::metric_kernels::AbstractMetric &metric_in,
|
||||
const IteratorMetricType &metric_in,
|
||||
typename ProblemType::ResultType *query_results_in) {
|
||||
|
||||
// Allocate space for storing the final results.
|
||||
query_results_in->Init(query_table_->n_entries());
|
||||
|
||||
return typename DualtreeDfs<ProblemType>::iterator(
|
||||
return typename DualtreeDfs<ProblemType>::template
|
||||
iterator<IteratorMetricType>(
|
||||
metric_in, *this, query_results_in);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#define CORE_GNP_TRIPLE_DISTANCE_SQ_H
|
||||
|
||||
#include <armadillo>
|
||||
#include "core/metric_kernels/abstract_metric.h"
|
||||
#include "core/table/table.h"
|
||||
#include "core/table/dense_point.h"
|
||||
|
||||
@@ -52,8 +51,9 @@ class TripleDistanceSq {
|
||||
return distance_sq_.at(first_pos, second_pos);
|
||||
}
|
||||
|
||||
template<typename MetricType>
|
||||
void ReplaceOnePoint(
|
||||
const core::metric_kernels::AbstractMetric &metric_in,
|
||||
const MetricType &metric_in,
|
||||
const core::table::DensePoint &new_point_in,
|
||||
int new_point_index_in,
|
||||
int point_pos_in) {
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
|
||||
#include <armadillo>
|
||||
#include "core/math/math_lib.h"
|
||||
#include "core/metric_kernels/abstract_metric.h"
|
||||
#include "core/table/table.h"
|
||||
|
||||
namespace core {
|
||||
@@ -128,8 +127,9 @@ class TripleRangeDistanceSq {
|
||||
nodes_ = ranges_in.nodes();
|
||||
}
|
||||
|
||||
template<typename MetricType>
|
||||
void ReplaceOneNodeBackward(
|
||||
const core::metric_kernels::AbstractMetric &metric_in,
|
||||
const MetricType &metric_in,
|
||||
const TableType &table_in,
|
||||
TreeType *new_node_in,
|
||||
int node_index_in) {
|
||||
@@ -152,8 +152,9 @@ class TripleRangeDistanceSq {
|
||||
ComputeNumTuples_(table_in);
|
||||
}
|
||||
|
||||
template<typename MetricType>
|
||||
void ReplaceOneNodeForward(
|
||||
const core::metric_kernels::AbstractMetric &metric_in,
|
||||
const MetricType &metric_in,
|
||||
const TableType &table_in,
|
||||
TreeType *new_node_in,
|
||||
int node_index_in) {
|
||||
@@ -176,8 +177,9 @@ class TripleRangeDistanceSq {
|
||||
ComputeNumTuples_(table_in);
|
||||
}
|
||||
|
||||
template<typename MetricType>
|
||||
void Init(
|
||||
const core::metric_kernels::AbstractMetric &metric_in,
|
||||
const MetricType &metric_in,
|
||||
const TableType &table,
|
||||
const std::vector< TreeType * > &nodes_in) {
|
||||
for(unsigned int j = 0; j < nodes_.size(); j++) {
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#ifndef CORE_GNP_TRIPLETREE_DFS_H
|
||||
#define CORE_GNP_TRIPLETREE_DFS_H
|
||||
|
||||
#include "core/metric_kernels/abstract_metric.h"
|
||||
#include "core/math/range.h"
|
||||
#include "core/gnp/triple_range_distance_sq.h"
|
||||
|
||||
@@ -50,8 +49,9 @@ class TripletreeDfs {
|
||||
|
||||
void ResetStatisticRecursion_(TreeType *node);
|
||||
|
||||
template<typename MetricType>
|
||||
void RecursionHelper_(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
core::gnp::TripleRangeDistanceSq<TableType> &triple_range_distance_sq,
|
||||
double relative_error,
|
||||
const std::vector<double> &failure_probabilities,
|
||||
@@ -65,21 +65,24 @@ class TripletreeDfs {
|
||||
|
||||
void PreProcess_(TreeType *node);
|
||||
|
||||
template<typename MetricType>
|
||||
void TripletreeBase_(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
const core::gnp::TripleRangeDistanceSq<TableType> &range_in,
|
||||
ResultType *result);
|
||||
|
||||
template<typename MetricType>
|
||||
bool CanProbabilisticSummarize_(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
const core::gnp::TripleRangeDistanceSq<TableType> &range_in,
|
||||
const std::vector<double> &failure_probabilities,
|
||||
int node_start_index,
|
||||
typename ProblemType::DeltaType &delta,
|
||||
typename ProblemType::ResultType *query_results);
|
||||
|
||||
template<typename MetricType>
|
||||
void ProbabilisticSummarize_(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
GlobalType &global,
|
||||
const core::gnp::TripleRangeDistanceSq<TableType> &range_in,
|
||||
const std::vector<double> &failure_probabilities,
|
||||
@@ -99,15 +102,17 @@ class TripletreeDfs {
|
||||
const typename ProblemType::DeltaType &delta,
|
||||
typename ProblemType::ResultType *query_results);
|
||||
|
||||
template<typename MetricType>
|
||||
bool TripletreeCanonical_(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
core::gnp::TripleRangeDistanceSq<TableType> &triple_range_distance_sq,
|
||||
double relative_error,
|
||||
const std::vector<double> &failure_probabilities,
|
||||
typename ProblemType::ResultType *query_results);
|
||||
|
||||
template<typename MetricType>
|
||||
void PostProcess_(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
TreeType *node, ResultType *query_results,
|
||||
bool do_query_results_postprocess);
|
||||
|
||||
@@ -125,12 +130,14 @@ class TripletreeDfs {
|
||||
|
||||
void Init(ProblemType &problem_in);
|
||||
|
||||
template<typename MetricType>
|
||||
void NaiveCompute(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
typename ProblemType::ResultType *naive_query_results);
|
||||
|
||||
template<typename MetricType>
|
||||
void Compute(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
typename ProblemType::ResultType *query_results);
|
||||
};
|
||||
};
|
||||
|
||||
@@ -52,8 +52,9 @@ void TripletreeDfs<ProblemType>::Init(ProblemType &problem_in) {
|
||||
}
|
||||
|
||||
template<typename ProblemType>
|
||||
template<typename MetricType>
|
||||
void TripletreeDfs<ProblemType>::NaiveCompute(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
typename ProblemType::ResultType *naive_query_results) {
|
||||
|
||||
// Preprocess the tree.
|
||||
@@ -72,8 +73,9 @@ void TripletreeDfs<ProblemType>::NaiveCompute(
|
||||
}
|
||||
|
||||
template<typename ProblemType>
|
||||
template<typename MetricType>
|
||||
void TripletreeDfs<ProblemType>::Compute(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
typename ProblemType::ResultType *query_results) {
|
||||
|
||||
// Preprocess the tree.
|
||||
@@ -155,8 +157,9 @@ TripletreeDfs<ProblemType>::GetNextNodeIterator_(
|
||||
}
|
||||
|
||||
template<typename ProblemType>
|
||||
template<typename MetricType>
|
||||
void TripletreeDfs<ProblemType>::TripletreeBase_(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
const TripleRangeDistanceSq<TableType> &range_sq_in,
|
||||
typename ProblemType::ResultType *query_results) {
|
||||
|
||||
@@ -267,8 +270,9 @@ void TripletreeDfs<ProblemType>::TripletreeBase_(
|
||||
}
|
||||
|
||||
template<typename ProblemType>
|
||||
template<typename MetricType>
|
||||
bool TripletreeDfs<ProblemType>::CanProbabilisticSummarize_(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
const TripleRangeDistanceSq<TableType> &range_in,
|
||||
const std::vector<double> &failure_probabilities,
|
||||
int node_start_index,
|
||||
@@ -350,8 +354,9 @@ bool TripletreeDfs<ProblemType>::CanProbabilisticSummarize_(
|
||||
}
|
||||
|
||||
template<typename ProblemType>
|
||||
template<typename MetricType>
|
||||
void TripletreeDfs<ProblemType>::ProbabilisticSummarize_(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
GlobalType &global,
|
||||
const TripleRangeDistanceSq<TableType> &range_in,
|
||||
const std::vector<double> &failure_probabilities,
|
||||
@@ -472,8 +477,9 @@ bool TripletreeDfs<ProblemType>::NodeIsAgreeable_(
|
||||
}
|
||||
|
||||
template<typename ProblemType>
|
||||
template<typename MetricType>
|
||||
void TripletreeDfs<ProblemType>::RecursionHelper_(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
TripleRangeDistanceSq<TableType> &triple_range_distance_sq,
|
||||
double relative_error,
|
||||
const std::vector<double> &failure_probabilities,
|
||||
@@ -642,8 +648,9 @@ void TripletreeDfs<ProblemType>::RecursionHelper_(
|
||||
}
|
||||
|
||||
template<typename ProblemType>
|
||||
template<typename MetricType>
|
||||
bool TripletreeDfs<ProblemType>::TripletreeCanonical_(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
TripleRangeDistanceSq<TableType> &triple_range_distance_sq,
|
||||
double relative_error,
|
||||
const std::vector<double> &failure_probabilities,
|
||||
@@ -695,8 +702,9 @@ bool TripletreeDfs<ProblemType>::TripletreeCanonical_(
|
||||
}
|
||||
|
||||
template<typename ProblemType>
|
||||
template<typename MetricType>
|
||||
void TripletreeDfs<ProblemType>::PostProcess_(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
typename ProblemType::TableType::TreeType *qnode,
|
||||
typename ProblemType::ResultType *query_results,
|
||||
bool do_query_results_postprocess) {
|
||||
|
||||
@@ -2,7 +2,6 @@ cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
set(SOURCES
|
||||
abstract_kernel.h
|
||||
abstract_metric.h
|
||||
kernel.h
|
||||
lmetric.h
|
||||
)
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
/** @file abstract_metric.h
|
||||
*
|
||||
* A prototype for an abstract metric.
|
||||
*
|
||||
* @author Dongryeol Lee (dongryel@cc.gatech.edu)
|
||||
*/
|
||||
|
||||
#ifndef CORE_METRIC_KERNELS_ABSTRACT_METRIC_H
|
||||
#define CORE_METRIC_KERNELS_ABSTRACT_METRIC_H
|
||||
|
||||
#include "core/table/dense_point.h"
|
||||
|
||||
namespace core {
|
||||
namespace metric_kernels {
|
||||
class AbstractMetric {
|
||||
|
||||
public:
|
||||
|
||||
virtual ~AbstractMetric() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the distance metric between two points.
|
||||
*/
|
||||
virtual double Distance(
|
||||
const core::table::DensePoint& a,
|
||||
const core::table::DensePoint& b) const = 0;
|
||||
|
||||
virtual double DistanceIneq(
|
||||
const core::table::DensePoint& a,
|
||||
const core::table::DensePoint& b) const = 0;
|
||||
|
||||
/**
|
||||
* Computes the distance metric between two points, raised to a
|
||||
* particular power.
|
||||
*
|
||||
* This might be faster so that you could get, for instance, squared
|
||||
* L2 distance.
|
||||
*/
|
||||
virtual double DistanceSq(
|
||||
const core::table::DensePoint &a,
|
||||
const core::table::DensePoint &b) const = 0;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -9,75 +9,74 @@
|
||||
#define CORE_METRIC_KERNELS_LMETRIC_H
|
||||
|
||||
#include "core/math/math_lib.h"
|
||||
#include "core/metric_kernels/abstract_metric.h"
|
||||
|
||||
namespace core {
|
||||
namespace metric_kernels {
|
||||
|
||||
/** @brief A trait class for computing a squared distance.
|
||||
*/
|
||||
template<int t_pow>
|
||||
class LMetricDistanceSqTrait {
|
||||
public:
|
||||
template<typename LMetricType, typename PointType>
|
||||
static double Compute(
|
||||
const core::metric_kernels::AbstractMetric &metric_in,
|
||||
const core::table::DensePoint &a,
|
||||
const core::table::DensePoint &b) {
|
||||
|
||||
const LMetricType &metric_in,
|
||||
const PointType &a, const PointType &b) {
|
||||
return core::math::Pow<2, t_pow>(metric_in.DistanceIneq(a, b));
|
||||
}
|
||||
};
|
||||
|
||||
/** @brief Template specialization for computing a squared distance
|
||||
* under L2 metric, which avoids a square root operation.
|
||||
*/
|
||||
template<>
|
||||
class LMetricDistanceSqTrait<2> {
|
||||
public:
|
||||
template<typename LMetricType, typename PointType>
|
||||
static double Compute(
|
||||
const core::metric_kernels::AbstractMetric &metric_in,
|
||||
const core::table::DensePoint &a,
|
||||
const core::table::DensePoint &b) {
|
||||
|
||||
const LMetricType &metric_in,
|
||||
const PointType &a, const PointType &b) {
|
||||
return metric_in.DistanceIneq(a, b);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* An L_p metric for vector spaces.
|
||||
/** @brief An L_p metric for vector spaces.
|
||||
*
|
||||
* A generic Metric class should simply compute the distance between
|
||||
* two points. An LMetric operates for integer powers on arma::vec spaces.
|
||||
*/
|
||||
template<int t_pow>
|
||||
class LMetric: public core::metric_kernels::AbstractMetric {
|
||||
class LMetric {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Computes the distance metric between two points.
|
||||
/** @brief Computes the distance metric between two points.
|
||||
*/
|
||||
template<typename PointType>
|
||||
double Distance(
|
||||
const core::table::DensePoint& a,
|
||||
const core::table::DensePoint& b) const {
|
||||
const PointType &a, const PointType &b) const {
|
||||
return core::math::Pow<1, t_pow>(DistanceIneq(a, b));
|
||||
}
|
||||
|
||||
template<typename PointType>
|
||||
double DistanceIneq(
|
||||
const core::table::DensePoint &a,
|
||||
const core::table::DensePoint &b) const {
|
||||
|
||||
const PointType &a, const PointType &b) const {
|
||||
double distance_ineq = 0;
|
||||
for(int i = 0; i < a.length(); i++) {
|
||||
int length = core::table::LengthTrait<PointType>::length(a);
|
||||
for(int i = 0; i < length; i++) {
|
||||
distance_ineq += core::math::Pow<t_pow, 1>(a[i] - b[i]);
|
||||
}
|
||||
return distance_ineq;
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the distance metric between two points, raised to a
|
||||
* particular power.
|
||||
/** @brief Computes the distance metric between two points, raised
|
||||
* to a particular power.
|
||||
*
|
||||
* This might be faster so that you could get, for instance, squared
|
||||
* L2 distance.
|
||||
*/
|
||||
template<typename PointType>
|
||||
double DistanceSq(
|
||||
const core::table::DensePoint &a,
|
||||
const core::table::DensePoint &b) const {
|
||||
const PointType &a, const PointType &b) const {
|
||||
|
||||
return core::metric_kernels::LMetricDistanceSqTrait<t_pow>::Compute(
|
||||
*this, a, b);
|
||||
|
||||
+2
-2
@@ -194,10 +194,10 @@ class DistributedLocalKMeans {
|
||||
|
||||
public:
|
||||
|
||||
template<typename TableType>
|
||||
template<typename MetricType, typename TableType>
|
||||
void Compute(
|
||||
boost::mpi::communicator &comm,
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
TableType &local_table_in,
|
||||
int neighbor_radius, int num_outer_loop_iterations,
|
||||
core::table::DensePoint &starting_centroid,
|
||||
|
||||
+44
-9
@@ -11,7 +11,6 @@
|
||||
#include <algorithm>
|
||||
#include <numeric>
|
||||
#include <boost/mpi.hpp>
|
||||
#include "core/metric_kernels/abstract_metric.h"
|
||||
#include "core/parallel/parallel_sample_sort.h"
|
||||
#include "core/table/offset_dense_matrix.h"
|
||||
#include "core/table/memory_mapped_file.h"
|
||||
@@ -97,8 +96,9 @@ class DistributedTreeBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
template<typename MetricType>
|
||||
void GetLeafNodeMembershipCounts_(
|
||||
const core::metric_kernels::AbstractMetric &metric_in,
|
||||
const MetricType &metric_in,
|
||||
const std::vector<TreeType *> &top_leaf_nodes,
|
||||
std::vector< std::vector<int> > *assigned_point_indices,
|
||||
std::vector<int> *membership_counts_per_node) {
|
||||
@@ -137,8 +137,9 @@ class DistributedTreeBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
template<typename MetricType>
|
||||
void ReshufflePoints_(
|
||||
const core::metric_kernels::AbstractMetric &metric_in,
|
||||
const MetricType &metric_in,
|
||||
boost::mpi::communicator &world,
|
||||
const std::vector<TreeType *> &top_leaf_nodes) {
|
||||
|
||||
@@ -185,8 +186,9 @@ class DistributedTreeBuilder {
|
||||
distributed_table_->set_local_table(new_local_table);
|
||||
}
|
||||
|
||||
template<typename MetricType>
|
||||
void BuildSampleTree_(
|
||||
const core::metric_kernels::AbstractMetric &metric_in,
|
||||
const MetricType &metric_in,
|
||||
boost::mpi::communicator &world,
|
||||
std::vector<TreeType *> *top_leaf_nodes_out) {
|
||||
|
||||
@@ -242,6 +244,35 @@ class DistributedTreeBuilder {
|
||||
boost::mpi::broadcast(world, *top_leaf_nodes_out, 0);
|
||||
}
|
||||
|
||||
template<typename MetricType>
|
||||
void RankPointsFromItsCentroid_(
|
||||
const MetricType &metric_in,
|
||||
std::vector<int> *sorted_indices_increasing) {
|
||||
|
||||
// First compute the centroid.
|
||||
arma::vec centroid;
|
||||
centroid.zeros(distributed_table_->n_attributes());
|
||||
for(int i = 0; i < distributed_table_->local_table()->n_entries(); i++) {
|
||||
arma::vec point;
|
||||
distributed_table_->local_table()->get(i, &point);
|
||||
centroid += point;
|
||||
}
|
||||
centroid /=
|
||||
static_cast<double>(distributed_table_->local_table()->n_entries());
|
||||
|
||||
// Pairs of point id and its squared distance from the centroid.
|
||||
std::vector< std::pair<int, double> > point_id_distance_pairs;
|
||||
point_id_distance_pairs.resize(
|
||||
distributed_table_->local_table()->n_enries());
|
||||
for(int i = 0; i < distributed_table_->local_table()->n_entries(); i++) {
|
||||
arma::vec point;
|
||||
distributed_table_->local_table()->get(i, &point);
|
||||
point_id_distance_pairs[i].first = i;
|
||||
point_id_distance_pairs[i].second =
|
||||
metric_in.DistanceSq(point, centroid);
|
||||
}
|
||||
}
|
||||
|
||||
void SelectSubset_(
|
||||
std::vector<int> *sampled_indices_out) {
|
||||
|
||||
@@ -270,8 +301,9 @@ class DistributedTreeBuilder {
|
||||
sampling_rate_ = sampling_rate_in;
|
||||
}
|
||||
|
||||
template<typename MetricType>
|
||||
void Build(
|
||||
const core::metric_kernels::AbstractMetric &metric_in,
|
||||
const MetricType &metric_in,
|
||||
boost::mpi::communicator &world) {
|
||||
|
||||
// Build the initial sample tree.
|
||||
@@ -283,11 +315,14 @@ class DistributedTreeBuilder {
|
||||
// reshuffle.
|
||||
ReshufflePoints_(metric_in, world, top_leaf_nodes);
|
||||
|
||||
// Recompute the centroids of each machine.
|
||||
// Recompute the centroids of each process and sort each point
|
||||
// according to its distance from its centroid.
|
||||
std::vector<int> sorted_indices_increasing;
|
||||
RankPointsFromItsCentroid_(metric_in, &sorted_indices_increasing);
|
||||
|
||||
|
||||
// Compute two prefix sums to do a re-distribution. This works
|
||||
// assuming that the centroids are roughly in Morton order.
|
||||
// Compute two prefix sums to do a re-distribution so that each
|
||||
// process has a equal number of points. This works assuming
|
||||
// that the centroids are roughly in Morton order.
|
||||
|
||||
// Recompute the centroids and repeat.
|
||||
|
||||
|
||||
@@ -164,6 +164,28 @@ class DensePoint {
|
||||
}
|
||||
};
|
||||
|
||||
template<typename PointType>
|
||||
class LengthTrait {
|
||||
public:
|
||||
static int length(const PointType &p);
|
||||
};
|
||||
|
||||
template<>
|
||||
class LengthTrait<arma::vec> {
|
||||
public:
|
||||
static int Length(const arma::vec &p) {
|
||||
return p.n_elem;
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
class LengthTrait<core::table::DensePoint> {
|
||||
public:
|
||||
static int length(const core::table::DensePoint &p) {
|
||||
return p.length();
|
||||
}
|
||||
};
|
||||
|
||||
static void DoublePtrToArmaVec(
|
||||
const double *point_in, int length, arma::vec *vec_out) {
|
||||
|
||||
|
||||
@@ -179,9 +179,10 @@ class DistributedTable: public boost::noncopyable {
|
||||
}
|
||||
}
|
||||
|
||||
template<typename MetricType>
|
||||
void ReadjustCentroids_(
|
||||
boost::mpi::communicator &world,
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
const std::vector<TreeType *> &top_leaf_nodes,
|
||||
int leaf_node_assignment_index) {
|
||||
|
||||
@@ -313,8 +314,9 @@ class DistributedTable: public boost::noncopyable {
|
||||
}
|
||||
}
|
||||
|
||||
template<typename MetricType>
|
||||
void GetLeafNodeMembershipCounts_(
|
||||
const core::metric_kernels::AbstractMetric &metric_in,
|
||||
const MetricType &metric_in,
|
||||
const std::vector<TreeType *> &top_leaf_nodes,
|
||||
std::vector<double> &points_assigned_to_node) {
|
||||
|
||||
@@ -506,8 +508,9 @@ class DistributedTable: public boost::noncopyable {
|
||||
return global_table_->get_tree() != NULL;
|
||||
}
|
||||
|
||||
template<typename MetricType>
|
||||
void IndexData(
|
||||
const core::metric_kernels::AbstractMetric & metric_in,
|
||||
const MetricType & metric_in,
|
||||
boost::mpi::communicator &world,
|
||||
int leaf_size, double sample_probability_in) {
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
#include <boost/interprocess/offset_ptr.hpp>
|
||||
#include <boost/utility.hpp>
|
||||
#include "core/csv_parser/dataset_reader.h"
|
||||
#include "core/metric_kernels/abstract_metric.h"
|
||||
#include "core/tree/general_spacetree.h"
|
||||
#include "core/tree/gen_metric_tree.h"
|
||||
#include "core/tree/statistic.h"
|
||||
@@ -376,8 +375,9 @@ class Table {
|
||||
fclose(foutput);
|
||||
}
|
||||
|
||||
template<typename MetricType>
|
||||
void IndexData(
|
||||
const core::metric_kernels::AbstractMetric &metric_in, int leaf_size,
|
||||
const MetricType &metric_in, int leaf_size,
|
||||
int max_num_leaf_nodes = std::numeric_limits<int>::max()) {
|
||||
int num_nodes;
|
||||
tree_ = TreeType::MakeTree(
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
#include <boost/serialization/string.hpp>
|
||||
#include "core/math/math_lib.h"
|
||||
#include "core/math/range.h"
|
||||
#include "core/metric_kernels/abstract_metric.h"
|
||||
#include "core/table/dense_point.h"
|
||||
|
||||
namespace core {
|
||||
@@ -107,8 +106,9 @@ class BallBound {
|
||||
/**
|
||||
* Determines if a point is within this bound.
|
||||
*/
|
||||
template<typename MetricType>
|
||||
bool Contains(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
const core::table::DensePoint& point) const {
|
||||
return MidDistance(metric, point) <= radius_;
|
||||
}
|
||||
@@ -116,15 +116,17 @@ class BallBound {
|
||||
/**
|
||||
* Calculates minimum bound-to-point squared distance.
|
||||
*/
|
||||
template<typename MetricType>
|
||||
double MinDistance(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
const core::table::DensePoint& point) const {
|
||||
|
||||
return std::max(MidDistance(metric, point) - radius_, 0.0);
|
||||
}
|
||||
|
||||
template<typename MetricType>
|
||||
double MinDistanceSq(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
const core::table::DensePoint& point) const {
|
||||
|
||||
return core::math::Pow<2, 1>(MinDistance(metric, point));
|
||||
@@ -133,16 +135,18 @@ class BallBound {
|
||||
/**
|
||||
* Calculates minimum bound-to-bound squared distance.
|
||||
*/
|
||||
template<typename MetricType>
|
||||
double MinDistance(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
const BallBound& other) const {
|
||||
double delta =
|
||||
MidDistance(metric, other.center_) - radius_ - other.radius_;
|
||||
return std::max(delta, 0.0);
|
||||
}
|
||||
|
||||
template<typename MetricType>
|
||||
double MinDistanceSq(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
const BallBound& other) const {
|
||||
return core::math::Pow<2, 1>(MinDistance(metric, other));
|
||||
}
|
||||
@@ -150,14 +154,16 @@ class BallBound {
|
||||
/**
|
||||
* Computes maximum distance.
|
||||
*/
|
||||
template<typename MetricType>
|
||||
double MaxDistance(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
const core::table::DensePoint& point) const {
|
||||
return MidDistance(metric, point) + radius_;
|
||||
}
|
||||
|
||||
template<typename MetricType>
|
||||
double MaxDistanceSq(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
const core::table::DensePoint& point) const {
|
||||
return core::math::Pow<2, 1>(MaxDistance(metric, point));
|
||||
}
|
||||
@@ -165,14 +171,16 @@ class BallBound {
|
||||
/**
|
||||
* Computes maximum distance.
|
||||
*/
|
||||
template<typename MetricType>
|
||||
double MaxDistance(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
const BallBound& other) const {
|
||||
return MidDistance(metric, other.center_) + radius_ + other.radius_;
|
||||
}
|
||||
|
||||
template<typename MetricType>
|
||||
double MaxDistanceSq(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
const BallBound& other) const {
|
||||
return core::math::Pow<2, 1>(MaxDistance(metric, other));
|
||||
}
|
||||
@@ -182,8 +190,9 @@ class BallBound {
|
||||
*
|
||||
* Example: bound1.MinDistanceSq(other) for minimum squared distance.
|
||||
*/
|
||||
template<typename MetricType>
|
||||
core::math::Range RangeDistance(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
const BallBound& other) const {
|
||||
|
||||
double delta = MidDistance(metric, other.center_);
|
||||
@@ -193,8 +202,9 @@ class BallBound {
|
||||
delta + sumradius);
|
||||
}
|
||||
|
||||
template<typename MetricType>
|
||||
core::math::Range RangeDistanceSq(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
const BallBound& other) const {
|
||||
|
||||
double delta = MidDistance(metric, other.center_);
|
||||
@@ -215,15 +225,17 @@ class BallBound {
|
||||
* return MinDistanceSqToPoint(other_midpoint)
|
||||
* </code>
|
||||
*/
|
||||
template<typename MetricType>
|
||||
double MinToMid(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
const BallBound& other) const {
|
||||
double delta = MidDistance(metric, other.center_) - radius_;
|
||||
return std::max(delta, 0.0);
|
||||
}
|
||||
|
||||
template<typename MetricType>
|
||||
double MinToMidSq(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
const BallBound& other) const {
|
||||
return core::math::Pow<2, 1>(MinToMid(metric, other));
|
||||
}
|
||||
@@ -231,16 +243,18 @@ class BallBound {
|
||||
/**
|
||||
* Computes minimax distance, where the other node is trying to avoid me.
|
||||
*/
|
||||
template<typename MetricType>
|
||||
double MinimaxDistance(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
const BallBound& other) const {
|
||||
double delta =
|
||||
MidDistance(metric, other.center_) + other.radius_ - radius_;
|
||||
return std::max(delta, 0.0);
|
||||
}
|
||||
|
||||
template<typename MetricType>
|
||||
double MinimaxDistanceSq(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
const BallBound& other) const {
|
||||
return core::math::Pow<2, 1>(MinimaxDistance(metric, other));
|
||||
}
|
||||
@@ -248,26 +262,30 @@ class BallBound {
|
||||
/**
|
||||
* Calculates midpoint-to-midpoint bounding box distance.
|
||||
*/
|
||||
template<typename MetricType>
|
||||
double MidDistance(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
const BallBound& other) const {
|
||||
return MidDistance(metric, other.center_);
|
||||
}
|
||||
|
||||
template<typename MetricType>
|
||||
double MidDistanceSq(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
const BallBound& other) const {
|
||||
return core::math::Pow<2, 1>(MidDistance(metric, other));
|
||||
}
|
||||
|
||||
template<typename MetricType>
|
||||
double MidDistance(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
const core::table::DensePoint& point) const {
|
||||
return metric.Distance(center_, point);
|
||||
}
|
||||
|
||||
template<typename MetricType>
|
||||
double MidDistanceSq(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
const core::table::DensePoint& point) const {
|
||||
return metric.DistanceSq(center_, point);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
#include "core/tree/general_spacetree.h"
|
||||
#include "core/tree/hrect_bound.h"
|
||||
|
||||
|
||||
namespace core {
|
||||
namespace tree {
|
||||
|
||||
@@ -33,8 +32,9 @@ class GenKdTree {
|
||||
|
||||
typedef IncomingStatisticType StatisticType;
|
||||
|
||||
template<typename MetricType>
|
||||
static void FindBoundFromMatrix(
|
||||
const core::metric_kernels::AbstractMetric &metric_in,
|
||||
const MetricType &metric_in,
|
||||
const core::table::DenseMatrix &matrix,
|
||||
int first, int count, BoundType *bounds) {
|
||||
|
||||
@@ -46,24 +46,26 @@ class GenKdTree {
|
||||
}
|
||||
}
|
||||
|
||||
template<typename MetricType>
|
||||
static void MakeLeafNode(
|
||||
const core::metric_kernels::AbstractMetric &metric_in,
|
||||
const MetricType &metric_in,
|
||||
const core::table::DenseMatrix& matrix,
|
||||
int begin, int count, BoundType *bounds) {
|
||||
|
||||
FindBoundFromMatrix(metric_in, matrix, begin, count, bounds);
|
||||
}
|
||||
|
||||
template<typename TreeType>
|
||||
template<typename MetricType, typename TreeType>
|
||||
static void CombineBounds(
|
||||
const core::metric_kernels::AbstractMetric &metric_in,
|
||||
const MetricType &metric_in,
|
||||
core::table::DenseMatrix &matrix,
|
||||
TreeType *node, TreeType *left, TreeType *right) {
|
||||
|
||||
}
|
||||
|
||||
template<typename MetricType>
|
||||
static void ComputeMemberships(
|
||||
const core::metric_kernels::AbstractMetric &metric_in,
|
||||
const MetricType &metric_in,
|
||||
const core::table::DenseMatrix &matrix,
|
||||
int first, int end,
|
||||
BoundType &left_bound, BoundType &right_bound,
|
||||
@@ -96,9 +98,9 @@ class GenKdTree {
|
||||
}
|
||||
}
|
||||
|
||||
template<typename TreeType, typename IndexType>
|
||||
template<typename MetricType, typename TreeType, typename IndexType>
|
||||
static bool AttemptSplitting(
|
||||
const core::metric_kernels::AbstractMetric &metric_in,
|
||||
const MetricType &metric_in,
|
||||
core::table::DenseMatrix& matrix, TreeType *node, TreeType **left,
|
||||
TreeType **right, int leaf_size,
|
||||
IndexType *old_from_new,
|
||||
@@ -148,7 +150,6 @@ class GenKdTree {
|
||||
(*right)->Init(
|
||||
node->begin() + left_count, node->count() - left_count);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
#include <vector>
|
||||
#include "ball_bound.h"
|
||||
#include "general_spacetree.h"
|
||||
#include "core/metric_kernels/abstract_metric.h"
|
||||
#include "core/table/dense_matrix.h"
|
||||
#include "core/table/memory_mapped_file.h"
|
||||
|
||||
@@ -26,8 +25,9 @@ class GenMetricTree {
|
||||
typedef IncomingStatisticType StatisticType;
|
||||
|
||||
private:
|
||||
template<typename MetricType>
|
||||
static int FurthestColumnIndex_(
|
||||
const core::metric_kernels::AbstractMetric &metric_in,
|
||||
const MetricType &metric_in,
|
||||
const core::table::DensePoint &pivot,
|
||||
const core::table::DenseMatrix &matrix,
|
||||
int begin, int count,
|
||||
@@ -54,16 +54,18 @@ class GenMetricTree {
|
||||
|
||||
public:
|
||||
|
||||
template<typename MetricType>
|
||||
static void FindBoundFromMatrix(
|
||||
const core::metric_kernels::AbstractMetric &metric_in,
|
||||
const MetricType &metric_in,
|
||||
const core::table::DenseMatrix &matrix,
|
||||
int first, int count, BoundType *bounds) {
|
||||
|
||||
MakeLeafNode(metric_in, matrix, first, count, bounds);
|
||||
}
|
||||
|
||||
template<typename MetricType>
|
||||
static void MakeLeafNode(
|
||||
const core::metric_kernels::AbstractMetric &metric_in,
|
||||
const MetricType &metric_in,
|
||||
const core::table::DenseMatrix& matrix,
|
||||
int begin, int count, BoundType *bounds) {
|
||||
|
||||
@@ -87,9 +89,9 @@ class GenMetricTree {
|
||||
bounds->set_radius(furthest_distance);
|
||||
}
|
||||
|
||||
template<typename TreeType>
|
||||
template<typename MetricType, typename TreeType>
|
||||
static void CombineBounds(
|
||||
const core::metric_kernels::AbstractMetric &metric_in,
|
||||
const MetricType &metric_in,
|
||||
core::table::DenseMatrix &matrix,
|
||||
TreeType *node, TreeType *left, TreeType *right) {
|
||||
|
||||
@@ -116,8 +118,9 @@ class GenMetricTree {
|
||||
node->bound().set_radius(std::max(left_max_dist, right_max_dist));
|
||||
}
|
||||
|
||||
template<typename MetricType>
|
||||
static void ComputeMemberships(
|
||||
const core::metric_kernels::AbstractMetric &metric_in,
|
||||
const MetricType &metric_in,
|
||||
const core::table::DenseMatrix &matrix,
|
||||
int first, int end,
|
||||
BoundType &left_bound, BoundType &right_bound,
|
||||
@@ -146,9 +149,9 @@ class GenMetricTree {
|
||||
}
|
||||
}
|
||||
|
||||
template<typename TreeType, typename IndexType>
|
||||
template<typename MetricType, typename TreeType, typename IndexType>
|
||||
static bool AttemptSplitting(
|
||||
const core::metric_kernels::AbstractMetric &metric_in,
|
||||
const MetricType &metric_in,
|
||||
core::table::DenseMatrix& matrix, TreeType *node, TreeType **left,
|
||||
TreeType **right, int leaf_size, IndexType *old_from_new,
|
||||
core::table::MemoryMappedFile *m_file_in) {
|
||||
|
||||
@@ -353,9 +353,9 @@ class GeneralBinarySpaceTree {
|
||||
}
|
||||
}
|
||||
|
||||
template<typename IndexType>
|
||||
template<typename MetricType, typename IndexType>
|
||||
static void SplitTree(
|
||||
const core::metric_kernels::AbstractMetric &metric_in,
|
||||
const MetricType &metric_in,
|
||||
core::table::DenseMatrix& matrix,
|
||||
TreeType *node,
|
||||
int leaf_size,
|
||||
@@ -420,9 +420,9 @@ class GeneralBinarySpaceTree {
|
||||
* original indexes to new indices
|
||||
* @param num_nodes the number of nodes constructed in total.
|
||||
*/
|
||||
template<typename IndexType>
|
||||
template<typename MetricType, typename IndexType>
|
||||
static TreeType *MakeTree(
|
||||
const core::metric_kernels::AbstractMetric &metric_in,
|
||||
const MetricType &metric_in,
|
||||
core::table::DenseMatrix& matrix, int leaf_size,
|
||||
IndexType *old_from_new,
|
||||
int *new_from_old,
|
||||
@@ -458,9 +458,9 @@ class GeneralBinarySpaceTree {
|
||||
return node;
|
||||
}
|
||||
|
||||
template<typename IndexType>
|
||||
template<typename MetricType, typename IndexType>
|
||||
static int MatrixPartition(
|
||||
const core::metric_kernels::AbstractMetric &metric_in,
|
||||
const MetricType &metric_in,
|
||||
core::table::DenseMatrix& matrix, int first, int count,
|
||||
BoundType &left_bound, BoundType &right_bound,
|
||||
IndexType *old_from_new) {
|
||||
|
||||
@@ -88,8 +88,9 @@ class HrectBound {
|
||||
/**
|
||||
* Determines if a point is within this bound.
|
||||
*/
|
||||
template<typename MetricType>
|
||||
bool Contains(
|
||||
const core::metric_kernels::AbstractMetric &metric_in,
|
||||
const MetricType &metric_in,
|
||||
const core::table::DensePoint &point) const {
|
||||
for(int i = 0; i < point.length(); i++) {
|
||||
if(!bounds_[i].Contains(point[i])) {
|
||||
@@ -119,8 +120,9 @@ class HrectBound {
|
||||
/**
|
||||
* Calculates minimum bound-to-point squared distance.
|
||||
*/
|
||||
template<typename MetricType>
|
||||
double MinDistanceSq(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
const core::table::DensePoint& point) const {
|
||||
|
||||
double sum = 0;
|
||||
@@ -144,8 +146,9 @@ class HrectBound {
|
||||
*
|
||||
* Example: bound1.MinDistanceSq(other) for minimum squared distance.
|
||||
*/
|
||||
template<typename MetricType>
|
||||
double MinDistanceSq(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
const HrectBound& other) const {
|
||||
|
||||
double sum = 0;
|
||||
@@ -170,8 +173,9 @@ class HrectBound {
|
||||
/**
|
||||
* Calculates maximum bound-to-point squared distance.
|
||||
*/
|
||||
template<typename MetricType>
|
||||
double MaxDistanceSq(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
const core::table::DensePoint& point) const {
|
||||
double sum = 0;
|
||||
|
||||
@@ -186,8 +190,9 @@ class HrectBound {
|
||||
/**
|
||||
* Computes maximum distance.
|
||||
*/
|
||||
template<typename MetricType>
|
||||
double MaxDistanceSq(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
const HrectBound& other) const {
|
||||
double sum = 0;
|
||||
const core::math::Range *a = this->bounds_;
|
||||
@@ -204,8 +209,9 @@ class HrectBound {
|
||||
/**
|
||||
* Calculates minimum and maximum bound-to-bound squared distance.
|
||||
*/
|
||||
template<typename MetricType>
|
||||
core::math::Range RangeDistanceSq(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
const HrectBound &other) const {
|
||||
double sum_lo = 0;
|
||||
double sum_hi = 0;
|
||||
@@ -233,8 +239,9 @@ class HrectBound {
|
||||
/**
|
||||
* Calculates minimum and maximum bound-to-point squared distance.
|
||||
*/
|
||||
template<typename MetricType>
|
||||
core::math::Range RangeDistanceSq(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
const core::table::DensePoint& point) const {
|
||||
|
||||
double sum_lo = 0;
|
||||
@@ -266,8 +273,9 @@ class HrectBound {
|
||||
* return MinDistanceSqToPoint(other_midpoint)
|
||||
* </code>
|
||||
*/
|
||||
template<typename MetricType>
|
||||
double MinToMidSq(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
const HrectBound &other) const {
|
||||
|
||||
double sum = 0;
|
||||
@@ -293,8 +301,9 @@ class HrectBound {
|
||||
/**
|
||||
* Computes minimax distance, where the other node is trying to avoid me.
|
||||
*/
|
||||
template<typename MetricType>
|
||||
double MinimaxDistanceSq(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
const HrectBound &other) const {
|
||||
|
||||
double sum = 0;
|
||||
@@ -315,8 +324,9 @@ class HrectBound {
|
||||
/**
|
||||
* Calculates midpoint-to-midpoint bounding box distance.
|
||||
*/
|
||||
template<typename MetricType>
|
||||
double MidDistanceSq(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
const HrectBound &other) const {
|
||||
double sum = 0;
|
||||
const core::math::Range *a = this->bounds_;
|
||||
|
||||
+2
-1
@@ -157,8 +157,9 @@ class TestDistributed_Kde {
|
||||
return achieved_error <= relative_error;
|
||||
}
|
||||
|
||||
template<typename MetricType>
|
||||
void UltraNaive_(
|
||||
const core::metric_kernels::AbstractMetric &metric_in,
|
||||
const MetricType &metric_in,
|
||||
TableType &query_table, TableType &reference_table,
|
||||
const core::metric_kernels::AbstractKernel &kernel,
|
||||
std::vector<double> &ultra_naive_query_results) {
|
||||
|
||||
+1
-2
@@ -8,7 +8,6 @@
|
||||
|
||||
#include <boost/interprocess/offset_ptr.hpp>
|
||||
#include "core/table/table.h"
|
||||
#include "core/metric_kernels/abstract_metric.h"
|
||||
|
||||
namespace core {
|
||||
namespace table {
|
||||
@@ -40,7 +39,7 @@ class DistributedKdeArguments {
|
||||
|
||||
std::string kernel_;
|
||||
|
||||
core::metric_kernels::AbstractMetric *metric_;
|
||||
core::metric_kernels::LMetric<2> *metric_;
|
||||
|
||||
public:
|
||||
DistributedKdeArguments() {
|
||||
|
||||
@@ -68,8 +68,9 @@ class TestKde {
|
||||
}
|
||||
}
|
||||
|
||||
template<typename MetricType>
|
||||
void UltraNaive_(
|
||||
const core::metric_kernels::AbstractMetric &metric_in,
|
||||
const MetricType &metric_in,
|
||||
TableType &query_table, TableType &reference_table,
|
||||
const core::metric_kernels::AbstractKernel &kernel,
|
||||
std::vector<double> &ultra_naive_query_results) {
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#define MLPACK_KDE_KDE_ARGUMENTS_H
|
||||
|
||||
#include "core/table/table.h"
|
||||
#include "core/metric_kernels/abstract_metric.h"
|
||||
#include "core/metric_kernels/lmetric.h"
|
||||
|
||||
namespace mlpack {
|
||||
namespace kde {
|
||||
@@ -33,7 +33,7 @@ class KdeArguments {
|
||||
|
||||
std::string kernel_;
|
||||
|
||||
core::metric_kernels::AbstractMetric *metric_;
|
||||
core::metric_kernels::LMetric<2> *metric_;
|
||||
|
||||
bool tables_are_aliased_;
|
||||
|
||||
|
||||
@@ -78,10 +78,10 @@ class KdePostponed {
|
||||
/** @brief Called from an exact pairwise evaluation method
|
||||
* (i.e. the base case) which incurs no error.
|
||||
*/
|
||||
template<typename GlobalType, typename PointType>
|
||||
template<typename GlobalType, typename MetricType, typename PointType>
|
||||
void ApplyContribution(
|
||||
const GlobalType &global,
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
const PointType &query_point, const PointType &reference_point) {
|
||||
|
||||
double distsq = metric.DistanceSq(query_point, reference_point);
|
||||
@@ -300,9 +300,9 @@ class KdeResult {
|
||||
}
|
||||
}
|
||||
|
||||
template<typename GlobalType>
|
||||
template<typename MetricType, typename GlobalType>
|
||||
void PostProcess(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
int q_index, const GlobalType &global,
|
||||
const bool is_monochromatic) {
|
||||
|
||||
@@ -409,9 +409,9 @@ class KdeDelta {
|
||||
mean_variance_pair_ = NULL;
|
||||
}
|
||||
|
||||
template<typename GlobalType, typename TreeType>
|
||||
template<typename MetricType, typename GlobalType, typename TreeType>
|
||||
void DeterministicCompute(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
const GlobalType &global, TreeType *qnode, TreeType *rnode,
|
||||
const core::math::Range &squared_distance_range) {
|
||||
|
||||
@@ -464,10 +464,10 @@ class KdeSummary {
|
||||
used_error_u_ = summary_in.used_error_u_;
|
||||
}
|
||||
|
||||
template < typename GlobalType, typename DeltaType,
|
||||
template < typename MetricType, typename GlobalType, typename DeltaType,
|
||||
typename TreeType, typename ResultType >
|
||||
bool CanProbabilisticSummarize(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
GlobalType &global, DeltaType &delta, TreeType *qnode, TreeType *rnode,
|
||||
double failure_probability, ResultType *query_results) const {
|
||||
|
||||
|
||||
+1
-2
@@ -7,7 +7,6 @@
|
||||
#define PHYSPACK_NBODY_SIMULATOR_NBODY_SIMULATOR_ARGUMENTS_H
|
||||
|
||||
#include "core/table/table.h"
|
||||
#include "core/metric_kernels/abstract_metric.h"
|
||||
|
||||
namespace physpack {
|
||||
namespace nbody_simulator {
|
||||
@@ -25,7 +24,7 @@ class NbodySimulatorArguments {
|
||||
|
||||
double probability_;
|
||||
|
||||
core::metric_kernels::AbstractMetric *metric_;
|
||||
core::metric_kernels::LMetric<2> *metric_;
|
||||
|
||||
double summary_compute_quantile_;
|
||||
|
||||
|
||||
+9
-8
@@ -132,9 +132,9 @@ class NbodySimulatorDelta {
|
||||
mean_variance_pair_ = NULL;
|
||||
}
|
||||
|
||||
template<typename GlobalType>
|
||||
template<typename MetricType, typename GlobalType>
|
||||
void DeterministicCompute(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
const GlobalType &global,
|
||||
const core::gnp::TripleRangeDistanceSq <
|
||||
typename GlobalType::TableType > &triple_range_distance_sq) {
|
||||
@@ -172,9 +172,9 @@ class NbodySimulatorResult {
|
||||
int num_deterministic_prunes_;
|
||||
int num_monte_carlo_prunes_;
|
||||
|
||||
template<typename GlobalType>
|
||||
template<typename MetricType, typename GlobalType>
|
||||
void PostProcess(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
int q_index, const GlobalType &global) {
|
||||
potential_e_[q_index] = (
|
||||
negative_potential_[q_index].mid() +
|
||||
@@ -410,10 +410,10 @@ class NbodySimulatorSummary {
|
||||
used_error_ = 0;
|
||||
}
|
||||
|
||||
template<typename TableType>
|
||||
template<typename TableType, typename MetricType>
|
||||
void ReplacePoints_(
|
||||
const TableType &table,
|
||||
const core::metric_kernels::AbstractMetric &metric_in,
|
||||
const MetricType &metric_in,
|
||||
const std::vector<int> &random_combination,
|
||||
int node_index_fix,
|
||||
core::gnp::TripleDistanceSq *distance_sq_out) const {
|
||||
@@ -544,9 +544,10 @@ class NbodySimulatorSummary {
|
||||
used_error_ = summary_in.used_error_;
|
||||
}
|
||||
|
||||
template < typename GlobalType, typename DeltaType, typename ResultType >
|
||||
template < typename MetricType, typename GlobalType,
|
||||
typename DeltaType, typename ResultType >
|
||||
bool CanProbabilisticSummarize(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const MetricType &metric,
|
||||
GlobalType &global, DeltaType &delta,
|
||||
const core::gnp::TripleRangeDistanceSq <
|
||||
typename GlobalType::TableType > &range_sq_in,
|
||||
|
||||
Reference in New Issue
Block a user