[mlpack-git] master: Last changes for a little while. (ca7b1a3)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Thu Mar 12 16:02:43 EDT 2015


Repository : https://github.com/mlpack/mlpack

On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/eddd7167d69b6c88b271ef2e51d1c20e13f1acd8...70342dd8e5c17e0c164cfb8189748671e9c0dd44

>---------------------------------------------------------------

commit ca7b1a38ff5d780657d5d1a6ed15a88f2e36cd01
Author: Ryan Curtin <ryan at ratml.org>
Date:   Wed Jan 28 10:20:45 2015 -0500

    Last changes for a little while.


>---------------------------------------------------------------

ca7b1a38ff5d780657d5d1a6ed15a88f2e36cd01
 .../methods/kmeans/dual_tree_kmeans_impl.hpp       | 42 +++++++++------
 .../methods/kmeans/dual_tree_kmeans_rules_impl.hpp | 62 +++++++++++-----------
 2 files changed, 58 insertions(+), 46 deletions(-)

diff --git a/src/mlpack/methods/kmeans/dual_tree_kmeans_impl.hpp b/src/mlpack/methods/kmeans/dual_tree_kmeans_impl.hpp
index 6e61d73..f08b4e1 100644
--- a/src/mlpack/methods/kmeans/dual_tree_kmeans_impl.hpp
+++ b/src/mlpack/methods/kmeans/dual_tree_kmeans_impl.hpp
@@ -165,6 +165,8 @@ bool IsDescendantOf(
 {
   if (potentialChild.Parent() == &potentialParent)
     return true;
+  else if (&potentialChild == &potentialParent)
+    return true;
   else if (potentialChild.Parent() == NULL)
     return false;
   else
@@ -205,8 +207,8 @@ void DualTreeKMeans<MetricType, MatType, TreeType>::TreeUpdate(
   const bool prunedLastIteration = node->Stat().HamerlyPruned();
   node->Stat().HamerlyPruned() = false;
 
-  if (node->Begin() == 37408)
-    Log::Warn << "r37408c" << node->Count() << " has owner " <<
+  if (node->Begin() == 23058)
+    Log::Warn << "r23058c" << node->Count() << " has owner " <<
 node->Stat().Owner() << ".\n";
 
   // The easy case: this node had an owner.
@@ -229,8 +231,8 @@ node->Stat().Owner() << ".\n";
     if (node->Stat().SecondClosestBound() == DBL_MAX && node->Parent() == NULL)
       node->Stat().SecondClosestBound() = 0.0; // Don't prune the root.
 
-    if (node->Begin() == 37408)
-      Log::Warn << "r37408c" << node->Count() << " scb " <<
+    if (node->Begin() == 23058)
+      Log::Warn << "r23058c" << node->Count() << " scb " <<
 node->Stat().SecondClosestBound() << " and lscb " <<
 node->Stat().LastSecondClosestBound() << ".\n";
 
@@ -266,7 +268,7 @@ node->Stat().LastSecondClosestBound() << ".\n";
       // of the second closest query node of the parent.
       if (node->Stat().SecondClosestQueryNode() != NULL)
       {
-        if (node->Begin() == 37408)
+        if (node->Begin() == 23058)
         {
           Log::Warn << "Second closest query node is q" << ((TreeType*)
 node->Stat().SecondClosestQueryNode())->Begin() << "c" << ((TreeType*)
@@ -278,7 +280,7 @@ node->MinDistance((TreeType*) node->Stat().SecondClosestQueryNode()) << ".\n";
       }
 
       if (node->Stat().ClosestQueryNode() != NULL)
-        if (node->Begin() == 37408)
+        if (node->Begin() == 23058)
           Log::Warn << "Closest query node: q" << ((TreeType*)
 node->Stat().ClosestQueryNode())->Begin() << "c" << ((TreeType*)
 node->Stat().ClosestQueryNode())->Count() << ", with MQND " <<
@@ -325,7 +327,7 @@ node->Stat().MinQueryNodeDistance() << ".\n";
         if (secondClosestDistance < node->Stat().SecondClosestBound())
           node->Stat().SecondClosestBound() = secondClosestDistance;
 
-      if (node->Begin() == 37408)
+      if (node->Begin() == 23058)
         Log::Warn << "After recalculation, closest for r" << node->Begin() << "c" << node->Count()
 << " is " << closest << ", with mQND " << node->Stat().MinQueryNodeDistance() <<
 ", MQND" << node->Stat().MaxQueryNodeDistance() << ", and scb " <<
@@ -334,7 +336,7 @@ node->Stat().SecondClosestBound() << ", " << secondClosest << ".\n";
 
 //      if (node->Parent() != NULL &&
 //node->Parent()->Stat().SecondClosestQueryNode() != NULL)
-//        if (node->Begin() == 37408)
+//        if (node->Begin() == 23058)
 //          Log::Warn << "Parent's (r" << node->Parent()->Begin() << "c"
 //<< node->Parent()->Count() << ") second closest query node is q" << ((TreeType*)
 //node->Parent()->Stat().SecondClosestQueryNode())->Begin() << "c" << ((TreeType*)
@@ -353,20 +355,30 @@ node->Stat().SecondClosestBound() << ", " << secondClosest << ".\n";
           (TreeType*) parent->Stat().SecondClosestQueryNode();
       TreeType* parentCqn = (parent == NULL) ? NULL :
           (TreeType*) parent->Stat().ClosestQueryNode();
+      if (parentScqn != NULL && node->Begin() == 23058)
+        Log::Warn << "Parent (" << parent->Begin() << "c" << parent->Count() <<
+") SCB is " << parent->Stat().SecondClosestBound() << ", "
+            << "with q" << parentScqn->Begin() << "c" << parentScqn->Count() <<
+".\n";
       if (scqn != NULL && parentScqn != NULL &&
           !IsDescendantOf(*parentScqn, *scqn) &&
           !IsDescendantOf(*parentCqn, *scqn) &&
           (parent->Stat().SecondClosestBound() <
               node->Stat().SecondClosestBound()))
       {
+        if (node->Begin() == 23058)
+          Log::Warn << "Take parent's SCB of " <<
+parent->Stat().SecondClosestBound() << "; parent SCQN is " <<
+parentScqn->Begin() << "c" << parentScqn->Count() << ", parent CQN is " <<
+parentCqn->Begin() << "c" << parentCqn->Count() << ".\n";
         node->Stat().SecondClosestBound() = parent->Stat().SecondClosestBound();
         node->Stat().SecondClosestQueryNode() = parentScqn;
       }
     }
 
-    if (node->Begin() == 37408)
+    if (node->Begin() == 23058)
     {
-      Log::Warn << "Attempt Hamerly prune on r37408c" << node->Count() <<
+      Log::Warn << "Attempt Hamerly prune on r23058c" << node->Count() <<
           " with MQND " << node->Stat().MaxQueryNodeDistance() << ", scb "
           << node->Stat().SecondClosestBound() << ", owner " <<
 node->Stat().Owner() << ", and clusterDistances " << clusterDistances[clusters]
@@ -374,7 +386,7 @@ node->Stat().Owner() << ", and clusterDistances " << clusterDistances[clusters]
     }
 
     // Check the second bound.  (This is time-consuming...)
-/*    arma::vec minDistances(centroids.n_cols);
+    arma::vec minDistances(centroids.n_cols);
     for (size_t j = 0; j < node->NumDescendants(); ++j)
     {
       arma::vec distances(centroids.n_cols);
@@ -393,8 +405,8 @@ node->Stat().Owner() << ", and clusterDistances " << clusterDistances[clusters]
       }
 
       if (j == 0)
-        if (node->Begin() == 37408)
-          Log::Warn << "r37408c" << node->Count() << ": " << minDistances.t();
+        if (node->Begin() == 23058)
+          Log::Warn << "r23058c" << node->Count() << ": " << minDistances.t();
       if (secondClosestDist < node->Stat().SecondClosestBound() - 1e-15)
       {
         Log::Warn << "r" << node->Begin() << "c" << node->Count() << ":\n";
@@ -407,7 +419,7 @@ node->Stat().SecondClosestBound() << " is too loose! -- " << secondClosestDist
             << "! (" << node->Stat().SecondClosestBound() - secondClosestDist
 << ")\n";
       }
-    }*/
+    }
 
 
     if (node->Stat().MaxQueryNodeDistance() < node->Stat().SecondClosestBound()
@@ -416,7 +428,7 @@ node->Stat().SecondClosestBound() << " is too loose! -- " << secondClosestDist
       node->Stat().HamerlyPruned() = true;
       if (!node->Parent()->Stat().HamerlyPruned())
       {
-        if (node->Begin() == 37408)
+        if (node->Begin() == 23058)
           Log::Warn << "Mark r" << node->Begin() << "c" << node->Count() << " as "
             << "Hamerly pruned.\n";
         hamerlyPruned += node->NumDescendants();
diff --git a/src/mlpack/methods/kmeans/dual_tree_kmeans_rules_impl.hpp b/src/mlpack/methods/kmeans/dual_tree_kmeans_rules_impl.hpp
index 7e1b09a..28b6695 100644
--- a/src/mlpack/methods/kmeans/dual_tree_kmeans_rules_impl.hpp
+++ b/src/mlpack/methods/kmeans/dual_tree_kmeans_rules_impl.hpp
@@ -113,8 +113,8 @@ double DualTreeKMeansRules<MetricType, TreeType>::Score(
 
   traversalInfo.LastReferenceNode() = &referenceNode;
 
-  if (referenceNode.Begin() == 37408)
-    Log::Warn << "Visit r37408c" << referenceNode.Count() << ", q" <<
+  if (referenceNode.Begin() == 23058)
+    Log::Warn << "Visit r23058c" << referenceNode.Count() << ", q" <<
 queryNode.Begin() << "c" << queryNode.Count() << ".\n";
 
   // If there's no closest query node assigned, but the parent has one, take
@@ -123,8 +123,8 @@ queryNode.Begin() << "c" << queryNode.Count() << ".\n";
       referenceNode.Parent() != NULL &&
       referenceNode.Parent()->Stat().ClosestQueryNode() != NULL)
   {
-    if (referenceNode.Begin() == 37408)
-      Log::Warn << "Update closest query node for r37408c" <<
+    if (referenceNode.Begin() == 23058)
+      Log::Warn << "Update closest query node for r23058c" <<
 referenceNode.Count() << " to parent's, which is "
           << ((TreeType*)
 referenceNode.Parent()->Stat().ClosestQueryNode())->Begin() << "c" <<
@@ -139,8 +139,8 @@ referenceNode.Parent()->Stat().ClosestQueryNode())->Begin() << "c" <<
 //    referenceNode.Stat().SecondClosestBound() = std::min(
 //        referenceNode.Parent()->Stat().SecondClosestBound(),
 //        referenceNode.Stat().SecondClosestBound());
-//    if (referenceNode.Begin() == 37408)
-//      Log::Warn << "Update second closest bound for r37408c" <<
+//    if (referenceNode.Begin() == 23058)
+//      Log::Warn << "Update second closest bound for r23058c" <<
 //referenceNode.Count() << " to parent's, which "
 //          << "is " << referenceNode.Stat().SecondClosestBound() << ".\n";
   }
@@ -148,8 +148,8 @@ referenceNode.Parent()->Stat().ClosestQueryNode())->Begin() << "c" <<
   double score = HamerlyTypeScore(referenceNode);
   if (score == DBL_MAX)
   {
-    if (referenceNode.Begin() == 37408)
-      Log::Warn << "Hamerly prune for r37408c" << referenceNode.Count() << ", q" << queryNode.Begin() << "c" <<
+    if (referenceNode.Begin() == 23058)
+      Log::Warn << "Hamerly prune for r23058c" << referenceNode.Count() << ", q" << queryNode.Begin() << "c" <<
 queryNode.Count() << ".\n";
     if (origPruned == size_t(-1))
     {
@@ -175,8 +175,8 @@ queryNode.Count() << ".\n";
       const double minDistance = referenceNode.MinDistance(&queryNode);
       ++distanceCalculations;
       score = PellegMooreScore(queryNode, referenceNode, minDistance);
-      if (referenceNode.Begin() == 37408)
-        Log::Warn << "mQND for r37408c" << referenceNode.Count() << " is "
+      if (referenceNode.Begin() == 23058)
+        Log::Warn << "mQND for r23058c" << referenceNode.Count() << " is "
             << referenceNode.Stat().MinQueryNodeDistance() << "; minDistance "
             << minDistance << ", scb " <<
 referenceNode.Stat().SecondClosestBound() << ".\n";
@@ -195,8 +195,8 @@ referenceNode.Stat().SecondClosestBound() << ".\n";
               referenceNode.Stat().MinQueryNodeDistance();
           referenceNode.Stat().SecondClosestQueryNode() =
               referenceNode.Stat().ClosestQueryNode();
-          if (referenceNode.Begin() == 37408)
-            Log::Warn << "scb for r37408c" << referenceNode.Count() << " taken "
+          if (referenceNode.Begin() == 23058)
+            Log::Warn << "scb for r23058c" << referenceNode.Count() << " taken "
                 << "from minDistance, which is " <<
 referenceNode.Stat().MinQueryNodeDistance() << ".\n";
         }
@@ -207,8 +207,8 @@ referenceNode.Stat().MinQueryNodeDistance() << ".\n";
         {
           referenceNode.Stat().SecondClosestBound() = minDistance;
           referenceNode.Stat().SecondClosestQueryNode() = &queryNode;
-          if (referenceNode.Begin() == 37408)
-            Log::Warn << "scb for r37408c" << referenceNode.Count() << " taken "
+          if (referenceNode.Begin() == 23058)
+            Log::Warn << "scb for r23058c" << referenceNode.Count() << " taken "
                 << "from minDistance for pruned query node, which is " <<
 minDistance << ".\n";
         }
@@ -220,8 +220,8 @@ minDistance << ".\n";
           referenceNode.Stat().MinQueryNodeDistance() = minDistance;
           referenceNode.Stat().MaxQueryNodeDistance() = maxDistance;
 
-          if (referenceNode.Begin() == 37408)
-            Log::Warn << "mQND for r37408c" << referenceNode.Count() << " updated to " << minDistance << " and "
+          if (referenceNode.Begin() == 23058)
+            Log::Warn << "mQND for r23058c" << referenceNode.Count() << " updated to " << minDistance << " and "
               << "MQND to " << maxDistance << " with furthest query node " <<
               queryNode.Begin() << "c" << queryNode.Count() << ".\n";
         }
@@ -229,8 +229,8 @@ minDistance << ".\n";
       else if (IsDescendantOf(*((TreeType*)
           referenceNode.Stat().ClosestQueryNode()), queryNode))
       {
-        if (referenceNode.Begin() == 37408)
-          Log::Warn << "Old closest for r37408c" << referenceNode.Count() <<
+        if (referenceNode.Begin() == 23058)
+          Log::Warn << "Old closest for r23058c" << referenceNode.Count() <<
               " is q" << ((TreeType*)
 referenceNode.Stat().ClosestQueryNode())->Begin() << "c" << ((TreeType*)
 referenceNode.Stat().ClosestQueryNode())->Count() << " with mQND " <<
@@ -242,8 +242,8 @@ referenceNode.Stat().MaxQueryNodeDistance() << ".\n";
         referenceNode.Stat().MinQueryNodeDistance() = minDistance;
         referenceNode.Stat().MaxQueryNodeDistance() = maxDistance;
 
-        if (referenceNode.Begin() == 37408)
-          Log::Warn << "mQND for r37408c" << referenceNode.Count() << " updated to " << minDistance << " and "
+        if (referenceNode.Begin() == 23058)
+          Log::Warn << "mQND for r23058c" << referenceNode.Count() << " updated to " << minDistance << " and "
               << "MQND to " << maxDistance << " via descendant with fqn " <<
               queryNode.Begin() << "c" << queryNode.Count() << ".\n";
       }
@@ -251,8 +251,8 @@ referenceNode.Stat().MaxQueryNodeDistance() << ".\n";
       {
         referenceNode.Stat().SecondClosestBound() = minDistance;
         referenceNode.Stat().SecondClosestQueryNode() = &queryNode;
-        if (referenceNode.Begin() == 37408)
-          Log::Warn << "scb for r37408c" << referenceNode.Count() << " updated to " << minDistance << " via "
+        if (referenceNode.Begin() == 23058)
+          Log::Warn << "scb for r23058c" << referenceNode.Count() << " updated to " << minDistance << " via "
               << queryNode.Begin() << "c" << queryNode.Count() << ".\n";
       }
     }
@@ -264,7 +264,7 @@ referenceNode.Stat().MaxQueryNodeDistance() << ".\n";
       ++distanceCalculations;
       if (minDistance < referenceNode.Stat().SecondClosestBound())
       {
-        if (referenceNode.Begin() == 37408)
+        if (referenceNode.Begin() == 23058)
           Log::Warn << "After Elkan prune, update scb to " << minDistance <<
 ".\n";
 
@@ -285,8 +285,8 @@ referenceNode.Stat().MaxQueryNodeDistance() << ".\n";
   if (score == DBL_MAX)
   {
     referenceNode.Stat().ClustersPruned() += queryNode.NumDescendants();
-    if (referenceNode.Begin() == 37408)
-      Log::Warn << "For r37408c" << referenceNode.Count() << ", q" <<
+    if (referenceNode.Begin() == 23058)
+      Log::Warn << "For r23058c" << referenceNode.Count() << ", q" <<
 queryNode.Begin() << "c" << queryNode.Count() << " is pruned.  Min distance is"
     << " " << queryNode.MinDistance(&referenceNode) << " and scb is " <<
 referenceNode.Stat().SecondClosestBound() << ".\n";
@@ -344,7 +344,7 @@ double DualTreeKMeansRules<MetricType, TreeType>::HamerlyTypeScore(
 {
   if (referenceNode.Stat().HamerlyPruned())
   {
-//    if (referenceNode.Begin() == 37408)
+//    if (referenceNode.Begin() == 23058)
 //      Log::Warn << "Hamerly prune! r" << referenceNode.Begin() << "c" <<
 //referenceNode.Count() << ".\n";
     return DBL_MAX;
@@ -392,8 +392,8 @@ double DualTreeKMeansRules<MetricType, TreeType>::ElkanTypeScore(
           queryNode)) &&
       (&queryNode != (TreeType*) referenceNode.Stat().ClosestQueryNode()))
   {
-    if (referenceNode.Begin() == 37408)
-      Log::Warn << "Elkan prune r37408c" << referenceNode.Count() << ", q" <<
+    if (referenceNode.Begin() == 23058)
+      Log::Warn << "Elkan prune r23058c" << referenceNode.Count() << ", q" <<
 queryNode.Begin() << "c" << queryNode.Count() << "!\n";
     // Then we can conclude d_max(best(N_r), N_r) <= d_min(N_q, N_r) which
     // means that N_q cannot possibly hold any clusters that own any points in
@@ -413,14 +413,14 @@ double DualTreeKMeansRules<MetricType, TreeType>::PellegMooreScore(
   // If the minimum distance to the node is greater than the bound, then every
   // cluster in the query node cannot possibly be the nearest neighbor of any of
   // the points in the reference node.
-//  if (referenceNode.Begin() == 37408)
-//      Log::Warn << "Pelleg-Moore prune attempt r37408c" << referenceNode.Count() << ", "
+//  if (referenceNode.Begin() == 23058)
+//      Log::Warn << "Pelleg-Moore prune attempt r23058c" << referenceNode.Count() << ", "
 //          << "q" << queryNode.Begin() << "c" << queryNode.Count() << "; "
 //          << "minDistance " << minDistance << ", MQND " <<
 //referenceNode.Stat().MaxQueryNodeDistance() << ".\n";
   if (minDistance > referenceNode.Stat().MaxQueryNodeDistance())
   {
-//    if (referenceNode.Begin() == 37408)
+//    if (referenceNode.Begin() == 23058)
 //      Log::Warn << "Attempt successful!\n";
     return DBL_MAX;
   }



More information about the mlpack-git mailing list