[mlpack-svn] r16671 - in mlpack/trunk/src/mlpack: core/tree methods/neighbor_search
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Fri Jun 6 11:45:33 EDT 2014
Author: andrewmw94
Date: Fri Jun 6 11:45:32 2014
New Revision: 16671
Log:
change a comment to be more accurate. Add on --r_tree option to the knn_all program. Doesn't do anything yet.
Modified:
mlpack/trunk/src/mlpack/core/tree/CMakeLists.txt
mlpack/trunk/src/mlpack/methods/neighbor_search/allknn_main.cpp
Modified: mlpack/trunk/src/mlpack/core/tree/CMakeLists.txt
==============================================================================
--- mlpack/trunk/src/mlpack/core/tree/CMakeLists.txt (original)
+++ mlpack/trunk/src/mlpack/core/tree/CMakeLists.txt Fri Jun 6 11:45:32 2014
@@ -34,6 +34,8 @@
rectangle_tree.hpp
rectangle_tree/rectangle_tree.hpp
rectangle_tree/rectangle_tree_impl.hpp
+ rectangle_tree/rectangle_tree_traverser.hpp
+ rectangle_tree/rectangle_tree_traverser_impl.hpp
rectangle_tree/r_tree_split.hpp
rectangle_tree/r_tree_split_impl.hpp
rectangle_tree/r_tree_descent_heuristic.hpp
Modified: mlpack/trunk/src/mlpack/methods/neighbor_search/allknn_main.cpp
==============================================================================
--- mlpack/trunk/src/mlpack/methods/neighbor_search/allknn_main.cpp (original)
+++ mlpack/trunk/src/mlpack/methods/neighbor_search/allknn_main.cpp Fri Jun 6 11:45:32 2014
@@ -24,7 +24,7 @@
PROGRAM_INFO("All K-Nearest-Neighbors",
"This program will calculate the all k-nearest-neighbors of a set of "
"points using kd-trees or cover trees (cover tree support is experimental "
- "and may not be optimally fast). You may specify a separate set of "
+ "and may be slow). You may specify a separate set of "
"reference points and query points, or just a reference set which will be "
"used as both the reference and query set."
"\n\n"
@@ -57,6 +57,8 @@
"dual-tree search).", "S");
PARAM_FLAG("cover_tree", "If true, use cover trees to perform the search "
"(experimental, may be slow).", "c");
+PARAM_FLAG("r_tree", "If true, use an R-Tree to perform the search "
+ "(experimental, may be slow. Currently automatically sets single_mode.).", "R");
PARAM_FLAG("random_basis", "Before tree-building, project the data onto a "
"random orthogonal basis.", "R");
PARAM_INT("seed", "Random seed (if 0, std::time(NULL) is used).", "s", 0);
@@ -122,7 +124,16 @@
{
Log::Warn << "--single_mode ignored because --naive is present." << endl;
}
-
+
+ // cover_tree overrides r_tree.
+ if (CLI::HasParam("cover_tree") && CLI::HasParam("r_tree"))
+ {
+ Log::Warn << "--cover_tree overrides --r_tree." << endl;
+ } else if (!singleMode && CLI::HasParam("r_tree")) // R_tree requires single mode.
+ {
+ Log::Warn << "--single_mode assumed because --r_tree is present." << endl;
+ }
+
if (naive)
leafSize = referenceData.n_cols;
@@ -168,90 +179,96 @@
if (!CLI::HasParam("cover_tree"))
{
- // Because we may construct it differently, we need a pointer.
- AllkNN* allknn = NULL;
-
- // Mappings for when we build the tree.
- std::vector<size_t> oldFromNewRefs;
-
- // Build trees by hand, so we can save memory: if we pass a tree to
- // NeighborSearch, it does not copy the matrix.
- Log::Info << "Building reference tree..." << endl;
- Timer::Start("tree_building");
-
- BinarySpaceTree<bound::HRectBound<2>,
- NeighborSearchStat<NearestNeighborSort> >
- refTree(referenceData, oldFromNewRefs, leafSize);
- BinarySpaceTree<bound::HRectBound<2>,
- NeighborSearchStat<NearestNeighborSort> >*
- queryTree = NULL; // Empty for now.
+ if(!CLI::HasParam("r_tree"))
+ {
+ // Because we may construct it differently, we need a pointer.
+ AllkNN* allknn = NULL;
- Timer::Stop("tree_building");
+ // Mappings for when we build the tree.
+ std::vector<size_t> oldFromNewRefs;
- std::vector<size_t> oldFromNewQueries;
+ // Build trees by hand, so we can save memory: if we pass a tree to
+ // NeighborSearch, it does not copy the matrix.
+ Log::Info << "Building reference tree..." << endl;
+ Timer::Start("tree_building");
- if (CLI::GetParam<string>("query_file") != "")
- {
- if (naive && leafSize < queryData.n_cols)
- leafSize = queryData.n_cols;
+ BinarySpaceTree<bound::HRectBound<2>,
+ NeighborSearchStat<NearestNeighborSort> >
+ refTree(referenceData, oldFromNewRefs, leafSize);
+ BinarySpaceTree<bound::HRectBound<2>,
+ NeighborSearchStat<NearestNeighborSort> >*
+ queryTree = NULL; // Empty for now.
- Log::Info << "Loaded query data from '" << queryFile << "' ("
- << queryData.n_rows << " x " << queryData.n_cols << ")." << endl;
+ Timer::Stop("tree_building");
- Log::Info << "Building query tree..." << endl;
+ std::vector<size_t> oldFromNewQueries;
- // Build trees by hand, so we can save memory: if we pass a tree to
- // NeighborSearch, it does not copy the matrix.
- if (!singleMode)
+ if (CLI::GetParam<string>("query_file") != "")
{
- Timer::Start("tree_building");
+ if (naive && leafSize < queryData.n_cols)
+ leafSize = queryData.n_cols;
- queryTree = new BinarySpaceTree<bound::HRectBound<2>,
- NeighborSearchStat<NearestNeighborSort> >(queryData,
- oldFromNewQueries, leafSize);
+ Log::Info << "Loaded query data from '" << queryFile << "' ("
+ << queryData.n_rows << " x " << queryData.n_cols << ")." << endl;
- Timer::Stop("tree_building");
- }
+ Log::Info << "Building query tree..." << endl;
- allknn = new AllkNN(&refTree, queryTree, referenceData, queryData,
- singleMode);
+ // Build trees by hand, so we can save memory: if we pass a tree to
+ // NeighborSearch, it does not copy the matrix.
+ if (!singleMode)
+ {
+ Timer::Start("tree_building");
- Log::Info << "Tree built." << endl;
- }
- else
- {
- allknn = new AllkNN(&refTree, referenceData, singleMode);
+ queryTree = new BinarySpaceTree<bound::HRectBound<2>,
+ NeighborSearchStat<NearestNeighborSort> >(queryData,
+ oldFromNewQueries, leafSize);
- Log::Info << "Trees built." << endl;
- }
+ Timer::Stop("tree_building");
+ }
- arma::mat distancesOut;
- arma::Mat<size_t> neighborsOut;
+ allknn = new AllkNN(&refTree, queryTree, referenceData, queryData,
+ singleMode);
- Log::Info << "Computing " << k << " nearest neighbors..." << endl;
- allknn->Search(k, neighborsOut, distancesOut);
+ Log::Info << "Tree built." << endl;
+ }
+ else
+ {
+ allknn = new AllkNN(&refTree, referenceData, singleMode);
- Log::Info << "Neighbors computed." << endl;
+ Log::Info << "Trees built." << endl;
+ }
- // We have to map back to the original indices from before the tree
- // construction.
- Log::Info << "Re-mapping indices..." << endl;
-
- // Map the results back to the correct places.
- if ((CLI::GetParam<string>("query_file") != "") && !singleMode)
- Unmap(neighborsOut, distancesOut, oldFromNewRefs, oldFromNewQueries,
- neighbors, distances);
- else if ((CLI::GetParam<string>("query_file") != "") && singleMode)
- Unmap(neighborsOut, distancesOut, oldFromNewRefs, neighbors, distances);
- else
- Unmap(neighborsOut, distancesOut, oldFromNewRefs, oldFromNewRefs,
- neighbors, distances);
+ arma::mat distancesOut;
+ arma::Mat<size_t> neighborsOut;
- // Clean up.
- if (queryTree)
- delete queryTree;
+ Log::Info << "Computing " << k << " nearest neighbors..." << endl;
+ allknn->Search(k, neighborsOut, distancesOut);
- delete allknn;
+ Log::Info << "Neighbors computed." << endl;
+
+ // We have to map back to the original indices from before the tree
+ // construction.
+ Log::Info << "Re-mapping indices..." << endl;
+
+ // Map the results back to the correct places.
+ if ((CLI::GetParam<string>("query_file") != "") && !singleMode)
+ Unmap(neighborsOut, distancesOut, oldFromNewRefs, oldFromNewQueries,
+ neighbors, distances);
+ else if ((CLI::GetParam<string>("query_file") != "") && singleMode)
+ Unmap(neighborsOut, distancesOut, oldFromNewRefs, neighbors, distances);
+ else
+ Unmap(neighborsOut, distancesOut, oldFromNewRefs, oldFromNewRefs,
+ neighbors, distances);
+
+ // Clean up.
+ if (queryTree)
+ delete queryTree;
+
+ delete allknn;
+ } else { // R tree.
+
+
+ }
}
else // Cover trees.
{
More information about the mlpack-svn
mailing list