[mlpack] 100/324: fix build
Barak A. Pearlmutter
barak+git at cs.nuim.ie
Sun Aug 17 08:22:00 UTC 2014
This is an automated email from the git hooks/post-receive script.
bap pushed a commit to branch svn-trunk
in repository mlpack.
commit 3e37bdb6f237cc423c438c9913f9a1e503e22f06
Author: andrewmw94 <andrewmw94 at 9d5b8971-822b-0410-80eb-d18c1038ef23>
Date: Wed Jul 2 17:50:26 2014 +0000
fix build
git-svn-id: http://svn.cc.gatech.edu/fastlab/mlpack/trunk@16738 9d5b8971-822b-0410-80eb-d18c1038ef23
---
...ree_traverser.hpp => single_tree_traverser.hpp} | 25 ++++++++++----
...ser_impl.hpp => single_tree_traverser_impl.hpp} | 39 +++++++++++-----------
2 files changed, 38 insertions(+), 26 deletions(-)
diff --git a/src/mlpack/core/tree/rectangle_tree/rectangle_tree_traverser.hpp b/src/mlpack/core/tree/rectangle_tree/single_tree_traverser.hpp
similarity index 68%
rename from src/mlpack/core/tree/rectangle_tree/rectangle_tree_traverser.hpp
rename to src/mlpack/core/tree/rectangle_tree/single_tree_traverser.hpp
index 1d570f6..e8620e4 100644
--- a/src/mlpack/core/tree/rectangle_tree/rectangle_tree_traverser.hpp
+++ b/src/mlpack/core/tree/rectangle_tree/single_tree_traverser.hpp
@@ -1,13 +1,13 @@
/**
- * @file rectangle_tree_traverser.hpp
+ * @file single_tree_traverser.hpp
* @author Andrew Wells
*
* A nested class of Rectangle Tree for traversing rectangle type trees
* with a given set of rules which indicate the branches to prune and the
* order in which to recurse. This is a depth-first traverser.
*/
-#ifndef __MLPACK_CORE_TREE_RECTANGLE_TREE_RECTANGLE_TREE_TRAVERSER_HPP
-#define __MLPACK_CORE_TREE_RECTANGLE_TREE_RECTANGLE_TREE_TRAVERSER_HPP
+#ifndef __MLPACK_CORE_TREE_RECTANGLE_TREE_SINGLE_TREE_TRAVERSER_HPP
+#define __MLPACK_CORE_TREE_RECTANGLE_TREE_SINGLE_TREE_TRAVERSER_HPP
#include <mlpack/core.hpp>
@@ -22,13 +22,13 @@ template<typename SplitType,
typename MatType>
template<typename RuleType>
class RectangleTree<SplitType, DescentType, StatisticType, MatType>::
- RectangleTreeTraverser
+ SingleTreeTraverser
{
public:
/**
* Instantiate the traverser with the given rule set.
*/
- RectangleTreeTraverser(RuleType& rule);
+ SingleTreeTraverser(RuleType& rule);
/**
* Traverse the tree with the given point.
@@ -44,6 +44,19 @@ class RectangleTree<SplitType, DescentType, StatisticType, MatType>::
//! Modify the number of prunes.
size_t& NumPrunes() { return numPrunes; }
+ //We use this struct and this function to make the sorting and scoring easy and efficient:
+ class NodeAndScore {
+ public:
+ RectangleTree<SplitType, DescentType, StatisticType, MatType>* node;
+ double score;
+ };
+
+ static bool nodeComparator(const NodeAndScore& obj1,
+ const NodeAndScore& obj2)
+ {
+ return obj1.score < obj2.score;
+ }
+
private:
//! Reference to the rules with which the tree will be traversed.
RuleType& rule;
@@ -56,6 +69,6 @@ class RectangleTree<SplitType, DescentType, StatisticType, MatType>::
}; // namespace mlpack
// Include implementation.
-#include "rectangle_tree_traverser_impl.hpp"
+#include "single_tree_traverser_impl.hpp"
#endif
diff --git a/src/mlpack/core/tree/rectangle_tree/rectangle_tree_traverser_impl.hpp b/src/mlpack/core/tree/rectangle_tree/single_tree_traverser_impl.hpp
similarity index 56%
rename from src/mlpack/core/tree/rectangle_tree/rectangle_tree_traverser_impl.hpp
rename to src/mlpack/core/tree/rectangle_tree/single_tree_traverser_impl.hpp
index 93319cf..f6adc20 100644
--- a/src/mlpack/core/tree/rectangle_tree/rectangle_tree_traverser_impl.hpp
+++ b/src/mlpack/core/tree/rectangle_tree/single_tree_traverser_impl.hpp
@@ -1,29 +1,29 @@
/**
- * @file rectangle_tree_traverser_impl.hpp
+ * @file single_tree_traverser_impl.hpp
* @author Andrew Wells
*
* A class for traversing rectangle type trees with a given set of rules
* 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_RECTANGLE_TREE_TRAVERSER_IMPL_HPP
-#define __MLPAC_CORE_TREE_RECTANGLE_TREE_RECTANGLE_TREE_TRAVERSER_IMPL_HPP
+#ifndef __MLPAC_CORE_TREE_RECTANGLE_TREE_SINGLE_TREE_TRAVERSER_IMPL_HPP
+#define __MLPAC_CORE_TREE_RECTANGLE_TREE_SINGLE_TREE_TRAVERSER_IMPL_HPP
-#include "rectangle_tree_traverser.hpp"
+#include "single_tree_traverser.hpp"
#include <algorithm>
#include <stack>
namespace mlpack {
namespace tree {
-
+
template<typename SplitType,
typename DescentType,
typename StatisticType,
typename MatType>
template<typename RuleType>
RectangleTree<SplitType, DescentType, StatisticType, MatType>::
-RectangleTreeTraverser<RuleType>::RectangleTreeTraverser(RuleType& rule) :
+SingleTreeTraverser<RuleType>::SingleTreeTraverser(RuleType& rule) :
rule(rule),
numPrunes(0)
{ /* Nothing to do */ }
@@ -34,7 +34,7 @@ template<typename SplitType,
typename MatType>
template<typename RuleType>
void RectangleTree<SplitType, DescentType, StatisticType, MatType>::
-RectangleTreeTraverser<RuleType>::Traverse(
+SingleTreeTraverser<RuleType>::Traverse(
const size_t queryIndex,
const RectangleTree<SplitType, DescentType, StatisticType, MatType>&
referenceNode)
@@ -42,28 +42,27 @@ RectangleTreeTraverser<RuleType>::Traverse(
// If we reach a leaf node, we need to run the base case.
if(referenceNode.IsLeaf()) {
for(size_t i = 0; i < referenceNode.Count(); i++) {
- rule.BaseCase(queryIndex, i);
+ rule.BaseCase(queryIndex, referenceNode.Points()[i]);
}
return;
}
- // This is not a leaf node so we:
- // Sort the children of this node by their scores.
- std::vector<RectangleTree*> nodes(referenceNode.NumChildren());
- std::vector<double> scores(referenceNode.NumChildren());
+ // This is not a leaf node so we sort the children of this node by their scores.
+ std::vector<NodeAndScore> nodesAndScores(referenceNode.NumChildren());
for(int i = 0; i < referenceNode.NumChildren(); i++) {
- nodes[i] = referenceNode.Children()[i];
- scores[i] = rule.Score(nodes[i]);
- }
- rule.sortNodesAndScores(&nodes, &scores);
+ nodesAndScores[i].node = referenceNode.Children()[i];
+ nodesAndScores[i].score = rule.Score(queryIndex, *nodesAndScores[i].node);
+ }
+
+ std::sort(nodesAndScores.begin(), nodesAndScores.end(), nodeComparator);
- // Iterate through them starting with the best and stopping when we reach
+ // Now iterate through them starting with the best and stopping when we reach
// one that isn't good enough.
for(int i = 0; i < referenceNode.NumChildren(); i++) {
- if(rule.Rescore(queryIndex, nodes[i], scores[i]) != DBL_MAX)
- Traverse(queryIndex, nodes[i]);
+ if(rule.Rescore(queryIndex, *nodesAndScores[i].node, nodesAndScores[i].score) != DBL_MAX)
+ Traverse(queryIndex, nodesAndScores[i].node);
else {
- numPrunes += referenceNode.NumChildren - i;
+ numPrunes += referenceNode.NumChildren() - i;
return;
}
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/mlpack.git
More information about the debian-science-commits
mailing list