[mlpack-svn] r16773 - in mlpack/trunk/src/mlpack: core/tree/binary_space_tree core/tree/rectangle_tree methods/neighbor_search tests
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Mon Jul 7 10:32:15 EDT 2014
Author: andrewmw94
Date: Mon Jul 7 10:32:14 2014
New Revision: 16773
Log:
tree traversal
Modified:
mlpack/trunk/src/mlpack/core/tree/binary_space_tree/binary_space_tree.hpp
mlpack/trunk/src/mlpack/core/tree/rectangle_tree/rectangle_tree_impl.hpp
mlpack/trunk/src/mlpack/core/tree/rectangle_tree/single_tree_traverser_impl.hpp
mlpack/trunk/src/mlpack/methods/neighbor_search/allknn_main.cpp
mlpack/trunk/src/mlpack/methods/neighbor_search/neighbor_search_impl.hpp
mlpack/trunk/src/mlpack/tests/rectangle_tree_test.cpp
Modified: mlpack/trunk/src/mlpack/core/tree/binary_space_tree/binary_space_tree.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/core/tree/binary_space_tree/binary_space_tree.hpp (original)
+++ mlpack/trunk/src/mlpack/core/tree/binary_space_tree/binary_space_tree.hpp Mon Jul 7 10:32:14 2014
@@ -66,7 +66,7 @@
size_t splitDimension;
//! The distance from the centroid of this node to the centroid of the parent.
double parentDistance;
- //! The distance to the furthest descendant, cached to speed things up.
+ //! The worst possible distance to the furthest descendant, cached to speed things up.
double furthestDescendantDistance;
//! The dataset.
MatType& dataset;
Modified: mlpack/trunk/src/mlpack/core/tree/rectangle_tree/rectangle_tree_impl.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/core/tree/rectangle_tree/rectangle_tree_impl.hpp (original)
+++ mlpack/trunk/src/mlpack/core/tree/rectangle_tree/rectangle_tree_impl.hpp Mon Jul 7 10:32:14 2014
@@ -268,7 +268,6 @@
return numChildren == 0;
}
-
/**
* Return a bound on the furthest point in the node form the centroid.
* This returns 0 unless the node is a leaf.
@@ -301,7 +300,8 @@
inline double RectangleTree<SplitType, DescentType, StatisticType, MatType>::
FurthestDescendantDistance() const
{
- return furthestDescendantDistance;
+ //return the distance from the centroid to a corner of the bound.
+ return 0.5 * bound.Diameter();
}
/**
@@ -342,7 +342,7 @@
}
/**
- * Return the index of a particular descendant contained in this node. SEE OTHER WARNINGS
+ * Return the index of a particular descendant contained in this node.
*/
template<typename SplitType,
typename DescentType,
@@ -351,11 +351,11 @@
inline size_t RectangleTree<SplitType, DescentType, StatisticType, MatType>::
Descendant(const size_t index) const
{
- return (begin + index);
+ return (points[index]);
}
/**
- * Return the index of a particular point contained in this node. SEE OTHER WARNINGS
+ * Return the index of a particular point contained in this node.
*/
template<typename SplitType,
typename DescentType,
@@ -368,8 +368,8 @@
}
/**
- * Return the last point in the tree. SINCE THE TREE STORES DATA SEPARATELY IN EACH LEAF
- * THIS IS CURRENTLY MEANINGLESS.
+ * Return the last point in the tree. WARNING: POINTS ARE NOT MOVED IN THE ORIGINAL DATASET,
+ * SO THIS IS RATHER POINTLESS.
*/
template<typename SplitType,
typename DescentType,
Modified: mlpack/trunk/src/mlpack/core/tree/rectangle_tree/single_tree_traverser_impl.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/core/tree/rectangle_tree/single_tree_traverser_impl.hpp (original)
+++ mlpack/trunk/src/mlpack/core/tree/rectangle_tree/single_tree_traverser_impl.hpp Mon Jul 7 10:32:14 2014
@@ -6,8 +6,8 @@
* which indicate the branches to prune and the order in which to recurse.
* This is a depth-first traverser.
*/
-#ifndef __MLPAC_CORE_TREE_RECTANGLE_TREE_SINGLE_TREE_TRAVERSER_IMPL_HPP
-#define __MLPAC_CORE_TREE_RECTANGLE_TREE_SINGLE_TREE_TRAVERSER_IMPL_HPP
+#ifndef __MLPACK_CORE_TREE_RECTANGLE_TREE_SINGLE_TREE_TRAVERSER_IMPL_HPP
+#define __MLPACK_CORE_TREE_RECTANGLE_TREE_SINGLE_TREE_TRAVERSER_IMPL_HPP
#include "single_tree_traverser.hpp"
@@ -42,7 +42,6 @@
// If we reach a leaf node, we need to run the base case.
if(referenceNode.IsLeaf()) {
- std::cout << "we reached a leaf" << std::endl;
for(size_t i = 0; i < referenceNode.Count(); i++) {
rule.BaseCase(queryIndex, referenceNode.Points()[i]);
}
@@ -62,9 +61,8 @@
// one that isn't good enough.
for(int i = 0; i < referenceNode.NumChildren(); i++) {
if(rule.Rescore(queryIndex, *nodesAndScores[i].node, nodesAndScores[i].score) != DBL_MAX)
- Traverse(queryIndex, nodesAndScores[i].node);
+ Traverse(queryIndex, *nodesAndScores[i].node);
else {
- std::cout << "we are pruning: " << referenceNode.NumChildren() - i << " nodes." << std::endl;
numPrunes += referenceNode.NumChildren() - i;
return;
}
@@ -76,4 +74,4 @@
}; // namespace tree
}; // namespace mlpack
-#endif
\ No newline at end of file
+#endif
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 Mon Jul 7 10:32:14 2014
@@ -318,15 +318,16 @@
}
Log::Info << "Tree built." << endl;
- arma::mat distancesOut;
- arma::Mat<size_t> neighborsOut;
+ //arma::mat distancesOut;
+ //arma::Mat<size_t> neighborsOut;
Log::Info << "Computing " << k << " nearest neighbors..." << endl;
- allknn->Search(k, neighborsOut, distancesOut);
+ allknn->Search(k, neighbors, distances);
Log::Info << "Neighbors computed." << endl;
+
delete allknn;
}
}
@@ -387,7 +388,7 @@
delete queryTree;
}
- // Save output.
+ // Save put.
data::Save(distancesFile, distances);
data::Save(neighborsFile, neighbors);
}
Modified: mlpack/trunk/src/mlpack/methods/neighbor_search/neighbor_search_impl.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/methods/neighbor_search/neighbor_search_impl.hpp (original)
+++ mlpack/trunk/src/mlpack/methods/neighbor_search/neighbor_search_impl.hpp Mon Jul 7 10:32:14 2014
@@ -252,18 +252,14 @@
}
else if (singleMode)
{
-
- std::cout << " we are in NeighborSearchImpl" << std::endl;
+
// The search doesn't work if the root node is also a leaf node.
// if this is the case, it is suggested that you use the naive method.
assert(!(referenceTree->IsLeaf()));
// Create the traverser.
typename TreeType::template SingleTreeTraverser<RuleType> traverser(rules);
-
- std::cout << " n_cols = " << querySet.n_cols << std::endl;
-
// Now have it traverse for each point.
for (size_t i = 0; i < querySet.n_cols; ++i)
traverser.Traverse(i, *referenceTree);
Modified: mlpack/trunk/src/mlpack/tests/rectangle_tree_test.cpp
==============================================================================
--- mlpack/trunk/src/mlpack/tests/rectangle_tree_test.cpp (original)
+++ mlpack/trunk/src/mlpack/tests/rectangle_tree_test.cpp Mon Jul 7 10:32:14 2014
@@ -47,7 +47,7 @@
BOOST_AUTO_TEST_CASE(RectangleTreeConstructionCountTest)
{
arma::mat dataset;
- dataset.randu(8, 1000); // 1000 points in 3 dimensions.
+ dataset.randu(3, 1000); // 1000 points in 3 dimensions.
RectangleTree<tree::RTreeSplit<tree::RTreeDescentHeuristic, NeighborSearchStat<NearestNeighborSort>, arma::mat>,
tree::RTreeDescentHeuristic,
@@ -80,7 +80,7 @@
BOOST_AUTO_TEST_CASE(RectangleTreeConstructionRepeatTest)
{
arma::mat dataset;
- dataset.randu(8, 15); // 1000 points in 8 dimensions.
+ dataset.randu(8, 1000); // 1000 points in 8 dimensions.
RectangleTree<tree::RTreeSplit<tree::RTreeDescentHeuristic, NeighborSearchStat<NearestNeighborSort>, arma::mat>,
tree::RTreeDescentHeuristic,
@@ -130,7 +130,7 @@
BOOST_AUTO_TEST_CASE(RectangleTreeContainmentTest)
{
arma::mat dataset;
- dataset.randu(8, 15); // 1000 points in 8 dimensions.
+ dataset.randu(8, 1000); // 1000 points in 8 dimensions.
RectangleTree<tree::RTreeSplit<tree::RTreeDescentHeuristic, NeighborSearchStat<NearestNeighborSort>, arma::mat>,
tree::RTreeDescentHeuristic,
More information about the mlpack-svn
mailing list