Modify MLPACK methods to work with DHrectBound API change
This commit is contained in:
@@ -173,7 +173,9 @@ class AllkNN {
|
||||
double MinPointNodeDistSq_ (const Vector& query_point, TreeType* reference_node) {
|
||||
// node->bound() gives us the DHrectBound class for the node
|
||||
// It has a function MinDistanceSq which takes another DHrectBound
|
||||
return reference_node->bound().MinDistanceSq(query_point);
|
||||
arma::vec tmp;
|
||||
arma_compat::vectorToVec(query_point, tmp);
|
||||
return reference_node->bound().MinDistanceSq(tmp);
|
||||
}
|
||||
|
||||
|
||||
@@ -408,8 +410,10 @@ class AllkNN {
|
||||
*min_dist_so_far=neighbor_distances_[ind+knns_-1];
|
||||
} else {
|
||||
// We'll order the computation by distance
|
||||
double left_distance = reference_node->left()->bound().MinDistanceSq(point);
|
||||
double right_distance = reference_node->right()->bound().MinDistanceSq(point);
|
||||
arma::vec tmp;
|
||||
arma_compat::vectorToVec(point, tmp);
|
||||
double left_distance = reference_node->left()->bound().MinDistanceSq(tmp);
|
||||
double right_distance = reference_node->right()->bound().MinDistanceSq(tmp);
|
||||
|
||||
if (left_distance < right_distance) {
|
||||
ComputeSingleNeighborsRecursion_(point_id, point, reference_node->left(),
|
||||
|
||||
@@ -260,8 +260,10 @@ class AllNN {
|
||||
// These are easy to search for, though for some reason, Garry
|
||||
// was more partial to "where's WALDO". More memorable, maybe?
|
||||
|
||||
arma::vec tmp;
|
||||
arma_compat::vectorToVec(query_point, tmp);
|
||||
double distance_to_hrect =
|
||||
reference_node->bound().MinDistanceSq(query_point);
|
||||
reference_node->bound().MinDistanceSq(tmp);
|
||||
|
||||
/* Try to prune one last time */
|
||||
if (distance_to_hrect < neighbor_distances_[query_index]) {
|
||||
|
||||
@@ -12,6 +12,9 @@
|
||||
|
||||
#include <fastlib/fastlib.h>
|
||||
|
||||
#include <armadillo>
|
||||
#include <fastlib/base/arma_compat.h>
|
||||
|
||||
/** @brief A static class providing utilities for scaling the query
|
||||
* and the reference datasets.
|
||||
*
|
||||
@@ -37,26 +40,28 @@ class DatasetScaler {
|
||||
bool queries_equal_references) {
|
||||
|
||||
int num_dims = rset.n_rows();
|
||||
DHrectBound<2> qset_bound;
|
||||
DHrectBound<2> rset_bound;
|
||||
qset_bound.Init(qset.n_rows());
|
||||
rset_bound.Init(qset.n_rows());
|
||||
DHrectBound<2> qset_bound(qset.n_rows());
|
||||
DHrectBound<2> rset_bound(qset.n_rows());
|
||||
|
||||
// go through each query/reference point to find out the bounds
|
||||
for(index_t r = 0; r < rset.n_cols(); r++) {
|
||||
Vector ref_vector;
|
||||
rset.MakeColumnVector(r, &ref_vector);
|
||||
rset_bound |= ref_vector;
|
||||
arma::vec tmp;
|
||||
arma_compat::vectorToVec(ref_vector, tmp);
|
||||
rset_bound |= tmp;
|
||||
}
|
||||
for(index_t q = 0; q < qset.n_cols(); q++) {
|
||||
Vector query_vector;
|
||||
qset.MakeColumnVector(q, &query_vector);
|
||||
qset_bound |= query_vector;
|
||||
arma::vec tmp;
|
||||
arma_compat::vectorToVec(query_vector, tmp);
|
||||
qset_bound |= tmp;
|
||||
}
|
||||
|
||||
for(index_t i = 0; i < num_dims; i++) {
|
||||
DRange qset_range = qset_bound.get(i);
|
||||
DRange rset_range = rset_bound.get(i);
|
||||
DRange qset_range = qset_bound[i];
|
||||
DRange rset_range = rset_bound[i];
|
||||
double min_coord = min(qset_range.lo, rset_range.lo);
|
||||
double max_coord = max(qset_range.hi, rset_range.hi);
|
||||
|
||||
@@ -87,25 +92,28 @@ class DatasetScaler {
|
||||
bool queries_equal_references) {
|
||||
|
||||
index_t num_dims = qset.n_rows();
|
||||
DHrectBound<2> total_bound;
|
||||
total_bound.Init(qset.n_rows());
|
||||
DHrectBound<2> total_bound(qset.n_rows());
|
||||
|
||||
// go through each query/reference point to find out the bounds
|
||||
for(index_t r = 0; r < rset.n_cols(); r++) {
|
||||
Vector ref_vector;
|
||||
rset.MakeColumnVector(r, &ref_vector);
|
||||
total_bound |= ref_vector;
|
||||
arma::vec tmp;
|
||||
arma_compat::vectorToVec(ref_vector, tmp);
|
||||
total_bound |= tmp;
|
||||
}
|
||||
if(!queries_equal_references) {
|
||||
for(index_t q = 0; q < qset.n_cols(); q++) {
|
||||
Vector query_vector;
|
||||
qset.MakeColumnVector(q, &query_vector);
|
||||
total_bound |= query_vector;
|
||||
arma::vec tmp;
|
||||
arma_compat::vectorToVec(query_vector, tmp);
|
||||
total_bound |= tmp;
|
||||
}
|
||||
}
|
||||
|
||||
for(index_t i = 0; i < num_dims; i++) {
|
||||
DRange total_range = total_bound.get(i);
|
||||
DRange total_range = total_bound[i];
|
||||
double min_coord = total_range.lo;
|
||||
double max_coord = total_range.hi;
|
||||
double width = max_coord - min_coord;
|
||||
|
||||
Reference in New Issue
Block a user