From 0b30babbc2fdf098ea963993717e4f064c25e7ca Mon Sep 17 00:00:00 2001 From: Ryan Curtin Date: Wed, 12 May 2010 19:59:28 +0000 Subject: [PATCH] Modify MLPACK methods to work with DHrectBound API change --- .../fastlib-armadillo/mlpack/allknn/allknn.h | 10 ++++-- .../fastlib-armadillo/mlpack/allnn/allnn.h | 4 ++- .../mlpack/kde/dataset_scaler.h | 34 ++++++++++++------- 3 files changed, 31 insertions(+), 17 deletions(-) diff --git a/fastlib/branches/fastlib-armadillo/mlpack/allknn/allknn.h b/fastlib/branches/fastlib-armadillo/mlpack/allknn/allknn.h index e097181b85..c78a1b28d8 100644 --- a/fastlib/branches/fastlib-armadillo/mlpack/allknn/allknn.h +++ b/fastlib/branches/fastlib-armadillo/mlpack/allknn/allknn.h @@ -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(), diff --git a/fastlib/branches/fastlib-armadillo/mlpack/allnn/allnn.h b/fastlib/branches/fastlib-armadillo/mlpack/allnn/allnn.h index 18c8db7949..c957654a70 100644 --- a/fastlib/branches/fastlib-armadillo/mlpack/allnn/allnn.h +++ b/fastlib/branches/fastlib-armadillo/mlpack/allnn/allnn.h @@ -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]) { diff --git a/fastlib/branches/fastlib-armadillo/mlpack/kde/dataset_scaler.h b/fastlib/branches/fastlib-armadillo/mlpack/kde/dataset_scaler.h index dc6cbdccd2..df3de2ed2c 100644 --- a/fastlib/branches/fastlib-armadillo/mlpack/kde/dataset_scaler.h +++ b/fastlib/branches/fastlib-armadillo/mlpack/kde/dataset_scaler.h @@ -12,6 +12,9 @@ #include +#include +#include + /** @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;