Update FirstBound correctly. Trivial speedup.

This commit is contained in:
Ryan Curtin
2015-03-12 15:42:44 -04:00
parent ee7eb43f01
commit dea4b29b71
2 changed files with 11 additions and 4 deletions
@@ -58,7 +58,8 @@ class DualTreeKMeans
//! Track distance calculations.
size_t distanceCalculations;
void ClusterTreeUpdate(TreeType* node);
void ClusterTreeUpdate(TreeType* node,
const arma::mat& distances);
void TreeUpdate(TreeType* node,
const size_t clusters,
@@ -81,7 +81,7 @@ double DualTreeKMeans<MetricType, MatType, TreeType>::Iterate(
distanceCalculations += nns.Scores();
// Update FirstBound().
ClusterTreeUpdate(centroidTree);
ClusterTreeUpdate(centroidTree, interclusterDistances);
// Now run the dual-tree algorithm.
typedef DualTreeKMeansRules<MetricType, TreeType> RulesType;
@@ -133,16 +133,22 @@ double DualTreeKMeans<MetricType, MatType, TreeType>::Iterate(
template<typename MetricType, typename MatType, typename TreeType>
void DualTreeKMeans<MetricType, MatType, TreeType>::ClusterTreeUpdate(
TreeType* node)
TreeType* node,
const arma::mat& distances)
{
// Just update the first bound, after recursing to the bottom.
double firstBound = 0.0;
for (size_t i = 0; i < node->NumChildren(); ++i)
{
ClusterTreeUpdate(&node->Child(i));
ClusterTreeUpdate(&node->Child(i), distances);
if (node->Child(i).Stat().FirstBound() >= firstBound)
firstBound = node->Child(i).Stat().FirstBound();
}
for (size_t i = 0; i < node->NumPoints(); ++i)
{
if (distances(1, node->Point(i)) > firstBound)
firstBound = distances(1, node->Point(i));
}
node->Stat().FirstBound() = firstBound;
}