[mlpack-svn] r12811 - mlpack/trunk/src/mlpack/core/tree
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Sun May 27 18:36:29 EDT 2012
Author: rcurtin
Date: 2012-05-27 18:36:29 -0400 (Sun, 27 May 2012)
New Revision: 12811
Modified:
mlpack/trunk/src/mlpack/core/tree/cover_tree_impl.hpp
Log:
Fix a couple bugs in furthest child and descendant determination.
Modified: mlpack/trunk/src/mlpack/core/tree/cover_tree_impl.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/tree/cover_tree_impl.hpp 2012-05-27 22:11:23 UTC (rev 12810)
+++ mlpack/trunk/src/mlpack/core/tree/cover_tree_impl.hpp 2012-05-27 22:36:29 UTC (rev 12811)
@@ -20,7 +20,9 @@
const double expansionConstant) :
dataset(dataset),
point(RootPointPolicy::ChooseRoot(dataset)),
- expansionConstant(expansionConstant)
+ expansionConstant(expansionConstant),
+ furthestChildDistance(0),
+ furthestDescendantDistance(0)
{
// Kick off the building. Create the indices array and the distances array.
arma::Col<size_t> indices = arma::linspace<arma::Col<size_t> >(1,
@@ -50,6 +52,8 @@
children.push_back(new CoverTree(dataset, expansionConstant, point, scale - 1,
indices, distances, childNearSetSize, childFarSetSize, usedSetSize));
+ furthestDescendantDistance = children[0]->FurthestDescendantDistance();
+
// If we created an implicit node, take its self-child instead (this could
// happen multiple times).
while (children[children.size() - 1]->NumChildren() == 1)
@@ -90,15 +94,18 @@
distances[0] = tempDist;
}
+ if (distances[0] > furthestChildDistance)
+ furthestChildDistance = distances[0];
+
size_t childUsedSetSize = 0;
// If there's only one point left, we don't need this crap.
- if (nearSetSize == 1)
+ if ((nearSetSize == 1) && (farSetSize == 0))
{
size_t childNearSetSize = 0;
children.push_back(new CoverTree(dataset, expansionConstant,
indices[0], scale - 1, indices, distances, childNearSetSize,
- childFarSetSize, usedSetSize));
+ farSetSize, usedSetSize));
// And we're done.
break;
@@ -291,6 +298,8 @@
// Will this be a new furthest child?
if (distances[0] > furthestChildDistance)
furthestChildDistance = distances[0];
+ if (distances[0] > furthestDescendantDistance)
+ furthestDescendantDistance = distances[0];
// If there's only one point left, we don't need this crap.
if ((nearSetSize == 1) && (farSetSize == 0))
@@ -656,8 +665,8 @@
// We have found a point to swap.
// Check if this point is a new furthest descendant.
- if (distances[i] > furthestDescendantDistance)
- furthestDescendantDistance = distances[i];
+ if (distances[i + nearSetSize] > furthestDescendantDistance)
+ furthestDescendantDistance = distances[i + nearSetSize];
// Perform the swap.
size_t tempIndex = indices[nearSetSize + farSetSize - 1];
More information about the mlpack-svn
mailing list