[mlpack-git] master: This is a more correct implementation. But it isn't efficient and it may fail on corner cases. (e839902)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Wed Dec 9 14:37:24 EST 2015


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

On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/cec4ac427536cbd9738a33e0c6facabeeadd31b0...4a39d474593067343b4972d4a5217bcfae84ca5d

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

commit e8399020bf15b23be5d11d07475dcc08ae9328ba
Author: ryan <ryan at ratml.org>
Date:   Wed Dec 9 10:14:44 2015 -0500

    This is a more correct implementation.
    But it isn't efficient and it may fail on corner cases.
    
    That can be a problem for another day... (are you reading this from the future?
    Sorry...!)


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

e8399020bf15b23be5d11d07475dcc08ae9328ba
 .../core/tree/rectangle_tree/rectangle_tree_impl.hpp | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/src/mlpack/core/tree/rectangle_tree/rectangle_tree_impl.hpp b/src/mlpack/core/tree/rectangle_tree/rectangle_tree_impl.hpp
index 8e4fa4d..d693249 100644
--- a/src/mlpack/core/tree/rectangle_tree/rectangle_tree_impl.hpp
+++ b/src/mlpack/core/tree/rectangle_tree/rectangle_tree_impl.hpp
@@ -604,7 +604,25 @@ template<typename MetricType,
 inline size_t RectangleTree<MetricType, StatisticType, MatType, SplitType,
                             DescentType>::Descendant(const size_t index) const
 {
-  return (points[index]);
+  // I think this may be inefficient...
+  if (numChildren == 0)
+  {
+    return (points[index]);
+  }
+  else
+  {
+    size_t n = 0;
+    for (size_t i = 0; i < numChildren; ++i)
+    {
+      const size_t nd = children[i]->NumDescendants();
+      if (index - n < nd)
+        return children[i]->Descendant(index - n);
+      n += nd;
+    }
+
+    // I don't think this is valid.
+    return children[numChildren - 1]->Descendant(index - n);
+  }
 }
 
 /**



More information about the mlpack-git mailing list