[mlpack-git] master: Fixed DiscreteHilbertOrderingTest. Added serialization. Minor style fixes. (7f8dbf5)

gitdub at mlpack.org gitdub at mlpack.org
Mon Jun 27 11:36:03 EDT 2016


Repository : https://github.com/mlpack/mlpack
On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/37fda23945b4f998cd5fa6ec011ae345236c8552...479eca0c625cc4255a3b1a354a4788dae10f1b01

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

commit 7f8dbf50f99d41d67aec20ee17ce0dc54bfbb081
Author: Mikhail Lozhnikov <lozhnikovma at gmail.com>
Date:   Sun Jun 5 10:02:00 2016 +0300

    Fixed DiscreteHilbertOrderingTest. Added serialization. Minor style fixes.


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

7f8dbf50f99d41d67aec20ee17ce0dc54bfbb081
 .../tree/rectangle_tree/discrete_hilbert_value.hpp |  4 ++++
 .../rectangle_tree/discrete_hilbert_value_impl.hpp | 26 ++++++++++++++++++----
 .../hilbert_r_tree_auxiliary_information_impl.hpp  |  3 +--
 .../rectangle_tree/hilbert_r_tree_split_impl.hpp   |  6 ++---
 .../rectangle_tree/recursive_hilbert_value.hpp     |  4 +++-
 .../recursive_hilbert_value_impl.hpp               | 18 ++++++++++++---
 src/mlpack/tests/rectangle_tree_test.cpp           |  2 +-
 7 files changed, 49 insertions(+), 14 deletions(-)

diff --git a/src/mlpack/core/tree/rectangle_tree/discrete_hilbert_value.hpp b/src/mlpack/core/tree/rectangle_tree/discrete_hilbert_value.hpp
index 07c16ec..6d85211 100644
--- a/src/mlpack/core/tree/rectangle_tree/discrete_hilbert_value.hpp
+++ b/src/mlpack/core/tree/rectangle_tree/discrete_hilbert_value.hpp
@@ -212,6 +212,10 @@ class DiscreteHilbertValue
    * Returns true if the node has the largest Hilbert value.
    */
   bool HasValue() const;
+
+ public:
+  template<typename Archive>
+  void Serialize(Archive& ar, const unsigned int /* version */);
 };
 } // namespace tree
 } // namespace mlpack
diff --git a/src/mlpack/core/tree/rectangle_tree/discrete_hilbert_value_impl.hpp b/src/mlpack/core/tree/rectangle_tree/discrete_hilbert_value_impl.hpp
index 4d19d13..ef2b313 100644
--- a/src/mlpack/core/tree/rectangle_tree/discrete_hilbert_value_impl.hpp
+++ b/src/mlpack/core/tree/rectangle_tree/discrete_hilbert_value_impl.hpp
@@ -270,17 +270,16 @@ InsertPoint(TreeType *node, const VecType& pt,
 
     localDataset->col(i) = *valueToInsert;
     numValues++;
-
     // Propogate changes of the largest Hilbert value downward
-    TreeType *root = node->Parent();
+    TreeType* root = node->Parent();
 
     while(root != NULL)
     {
-      root->AuxiliaryInfo().HilbertValue().LocalDataset() = localDataset;
-      root->AuxiliaryInfo().HilbertValue().NumValues() = numValues;
+      root->AuxiliaryInfo().HilbertValue().UpdateLargestValue(root);
 
       root = root->Parent();
     }
+
   }
 
   return i;
@@ -344,6 +343,11 @@ template<typename TreeElemType>
 template<typename TreeType>
 void DiscreteHilbertValue<TreeElemType>::Copy(TreeType* dst, TreeType* src)
 {
+  DiscreteHilbertValue<TreeElemType> &dstVal = dst->AuxiliaryInfo().HilbertValue();
+  DiscreteHilbertValue<TreeElemType> &srcVal = src->AuxiliaryInfo().HilbertValue();
+
+  dst.LocalDataset() = src.LocalDataset();
+  dst.NumValues() = src.NumValues();
 }
 
 template<typename TreeElemType>
@@ -420,6 +424,20 @@ bool DiscreteHilbertValue<TreeElemType>::HasValue() const
   return numValues > 0;
 }
 
+template<typename TreeElemType>
+template<typename Archive>
+void DiscreteHilbertValue<TreeElemType>::
+Serialize(Archive& ar, const unsigned int /* version */)
+{
+  using data::CreateNVP;
+
+  ar & CreateNVP(localDataset, "localDataset");
+  ar & CreateNVP(ownsLocalDataset, "ownsLocalDataset");
+  ar & CreateNVP(numValues, "numValues");
+  ar & CreateNVP(valueToInsert, "valueToInsert");
+  ar & CreateNVP(ownsValueToInsert, "ownsValueToInsert");
+}
+
 } // namespace tree
 } // namespace mlpack
 
diff --git a/src/mlpack/core/tree/rectangle_tree/hilbert_r_tree_auxiliary_information_impl.hpp b/src/mlpack/core/tree/rectangle_tree/hilbert_r_tree_auxiliary_information_impl.hpp
index 08549d0..b9924d3 100644
--- a/src/mlpack/core/tree/rectangle_tree/hilbert_r_tree_auxiliary_information_impl.hpp
+++ b/src/mlpack/core/tree/rectangle_tree/hilbert_r_tree_auxiliary_information_impl.hpp
@@ -188,8 +188,7 @@ UpdateAuxiliaryInfo(TreeType* node)
     return true;
 
   TreeType *child = node->Children()[node->NumChildren()-1];
-  if(HilbertValueType<ElemType>::CompareValues(hilbertValue,
-                            child->AuxiliaryInfo().hilbertValue()) < 0)
+  if(hilbertValue.CompareWith(child->AuxiliaryInfo().hilbertValue()) < 0)
   {
     hilbertValue.Copy(node,child);
 //    hilbertValue = child->AuxiliaryInfo().hilbertValue();
diff --git a/src/mlpack/core/tree/rectangle_tree/hilbert_r_tree_split_impl.hpp b/src/mlpack/core/tree/rectangle_tree/hilbert_r_tree_split_impl.hpp
index 5e066d3..d185409 100644
--- a/src/mlpack/core/tree/rectangle_tree/hilbert_r_tree_split_impl.hpp
+++ b/src/mlpack/core/tree/rectangle_tree/hilbert_r_tree_split_impl.hpp
@@ -34,7 +34,7 @@ SplitLeafNode(TreeType* tree, std::vector<bool>& relevels)
     return;
   }
 
-  TreeType *parent = tree->Parent();
+  TreeType* parent = tree->Parent();
   size_t iTree = 0;
   for(iTree = 0;parent->Children()[iTree] != tree; iTree++);
 
@@ -97,7 +97,7 @@ SplitNonLeafNode(TreeType* tree,std::vector<bool>& relevels)
     return true;
   }
 
-  TreeType *parent = tree->Parent();
+  TreeType* parent = tree->Parent();
 
   size_t iTree = 0;
   for(iTree = 0;parent->Children()[iTree] != tree; iTree++);
@@ -318,7 +318,7 @@ RedistributePointsEvenly(TreeType *parent,
   // Fix the largest Hilbert values of the siblings.
   parent->AuxiliaryInfo().HilbertValue().UpdateHilbertValues(parent, firstSibling, lastSibling);
 
-  TreeType *root = parent;
+  TreeType* root = parent;
 
   while(root != NULL)
   {
diff --git a/src/mlpack/core/tree/rectangle_tree/recursive_hilbert_value.hpp b/src/mlpack/core/tree/rectangle_tree/recursive_hilbert_value.hpp
index b46ab37..e8da3e1 100644
--- a/src/mlpack/core/tree/rectangle_tree/recursive_hilbert_value.hpp
+++ b/src/mlpack/core/tree/rectangle_tree/recursive_hilbert_value.hpp
@@ -206,7 +206,9 @@ class RecursiveHilbertValue
   static int ComparePoints(const VecType1& pt1, const VecType2& pt2,
        CompareStruct& comp, typename boost::enable_if<IsVector<VecType1>>* = 0,
                             typename boost::enable_if<IsVector<VecType2>>* = 0);
-
+ public:
+  template<typename Archive>
+  void Serialize(Archive& ar, const unsigned int /* version */);
 };
 } // namespace tree
 } // namespace mlpack
diff --git a/src/mlpack/core/tree/rectangle_tree/recursive_hilbert_value_impl.hpp b/src/mlpack/core/tree/rectangle_tree/recursive_hilbert_value_impl.hpp
index 49e00d7..4c4665c 100644
--- a/src/mlpack/core/tree/rectangle_tree/recursive_hilbert_value_impl.hpp
+++ b/src/mlpack/core/tree/rectangle_tree/recursive_hilbert_value_impl.hpp
@@ -223,7 +223,7 @@ InsertPoint(TreeType* node, const VecType& point,
     hasLargestValue = true;
 
     // Propogate changes of the largest Hilbert value downward
-    TreeType *root = node->Parent();
+    TreeType* root = node->Parent();
 
     while(root != NULL)
     {
@@ -285,8 +285,10 @@ template<typename TreeElemType>
 template<typename TreeType>
 void RecursiveHilbertValue<TreeElemType>::Copy(TreeType* dst, TreeType* src)
 {
-  dst->AuxiliaryInfo().LargestHilbertValue().LargestValue() =
-    src->AuxiliaryInfo().LargestHilbertValue().LargestValue();
+  dst->AuxiliaryInfo().HilbertValue().LargestValue() =
+    src->AuxiliaryInfo().HilbertValue().LargestValue();
+  dst->AuxiliaryInfo().HilbertValue().hasLargestValue =
+    src->AuxiliaryInfo().HilbertValue().hasLargestValue;
 }
 
 template<typename TreeElemType>
@@ -326,7 +328,17 @@ UpdateHilbertValues(TreeType* parent, size_t firstSibling,  size_t lastSibling)
 
 }
 
+template<typename TreeElemType>
+template<typename Archive>
+void RecursiveHilbertValue<TreeElemType>::
+Serialize(Archive& ar, const unsigned int /* version */)
+{
+  using data::CreateNVP;
 
+  ar & CreateNVP(largestValue, "largestValue");
+  ar & CreateNVP(ownsLargestValue, "ownsLargestValue");
+  ar & CreateNVP(hasLargestValue, "hasLargestValue");
+}
 
 } // namespace tree
 } // namespace mlpack
diff --git a/src/mlpack/tests/rectangle_tree_test.cpp b/src/mlpack/tests/rectangle_tree_test.cpp
index 8057840..d4a23ec 100644
--- a/src/mlpack/tests/rectangle_tree_test.cpp
+++ b/src/mlpack/tests/rectangle_tree_test.cpp
@@ -699,7 +699,7 @@ BOOST_AUTO_TEST_CASE(RecursiveHilbertRTreeTraverserTest)
 }
 
 template<typename TreeType>
-void CheckHilbertOrdering(TreeType *tree)
+void CheckHilbertOrdering(TreeType* tree)
 {
   if(tree->IsLeaf())
   {




More information about the mlpack-git mailing list