Update FirstBound correctly. Trivial speedup.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user