[mlpack-git] master: More accurate counting of calculations. (8d30f34)
gitdub at big.cc.gt.atl.ga.us
gitdub at big.cc.gt.atl.ga.us
Thu Mar 12 16:04:25 EDT 2015
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/eddd7167d69b6c88b271ef2e51d1c20e13f1acd8...70342dd8e5c17e0c164cfb8189748671e9c0dd44
>---------------------------------------------------------------
commit 8d30f34835fd259d897afe7960b601f703db6aa6
Author: Ryan Curtin <ryan at ratml.org>
Date: Fri Feb 27 10:53:00 2015 -0500
More accurate counting of calculations.
>---------------------------------------------------------------
8d30f34835fd259d897afe7960b601f703db6aa6
src/mlpack/methods/kmeans/dtnn_rules_impl.hpp | 30 +++++++++++++++------------
1 file changed, 17 insertions(+), 13 deletions(-)
diff --git a/src/mlpack/methods/kmeans/dtnn_rules_impl.hpp b/src/mlpack/methods/kmeans/dtnn_rules_impl.hpp
index 6eb714d..1ef3c14 100644
--- a/src/mlpack/methods/kmeans/dtnn_rules_impl.hpp
+++ b/src/mlpack/methods/kmeans/dtnn_rules_impl.hpp
@@ -230,11 +230,7 @@ inline double DTNNKMeansRules<MetricType, TreeType>::Score(
if (score != DBL_MAX)
{
// Get minimum and maximum distances.
-// math::Range distances = queryNode.RangeDistance(&referenceNode);
- math::Range distances;
- distances.Lo() = queryNode.MinDistance(&referenceNode);
- distances.Hi() =
- queryNode.MaxDistance(centroids.col(referenceNode.Descendant(0)));
+ const math::Range distances = queryNode.RangeDistance(&referenceNode);
score = distances.Lo();
++scores;
@@ -252,14 +248,22 @@ inline double DTNNKMeansRules<MetricType, TreeType>::Score(
}
else if (distances.Hi() < queryNode.Stat().UpperBound())
{
- // We can improve the best estimate.
- queryNode.Stat().UpperBound() = distances.Hi();
- // If this node has only one descendant, then it may be the owner.
- if (referenceNode.NumDescendants() == 1)
- queryNode.Stat().Owner() =
- (tree::TreeTraits<TreeType>::RearrangesDataset) ?
- oldFromNewCentroids[referenceNode.Descendant(0)] :
- referenceNode.Descendant(0);
+ // Tighten upper bound.
+ const double tighterBound =
+ queryNode.MaxDistance(centroids.col(referenceNode.Descendant(0)));
+ ++scores; // Count extra distance calculation.
+
+ if (tighterBound <= queryNode.Stat().UpperBound())
+ {
+ // We can improve the best estimate.
+ queryNode.Stat().UpperBound() = tighterBound;
+ // If this node has only one descendant, then it may be the owner.
+ if (referenceNode.NumDescendants() == 1)
+ queryNode.Stat().Owner() =
+ (tree::TreeTraits<TreeType>::RearrangesDataset) ?
+ oldFromNewCentroids[referenceNode.Descendant(0)] :
+ referenceNode.Descendant(0);
+ }
}
}
More information about the mlpack-git
mailing list