mlpack  master
discrete_hilbert_value.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_CORE_TREE_RECTANGLE_TREE_DISCRETE_HILBERT_VALUE_HPP
14 #define MLPACK_CORE_TREE_RECTANGLE_TREE_DISCRETE_HILBERT_VALUE_HPP
15 
16 #include <mlpack/prereqs.hpp>
17 
18 namespace mlpack {
19 namespace tree {
20 
28 template<typename TreeElemType>
30 {
31  public:
34  typedef typename std::conditional<sizeof(TreeElemType) * CHAR_BIT <= 32,
35  uint32_t,
36  uint64_t>::type HilbertElemType;
37 
40 
47  template<typename TreeType>
48  DiscreteHilbertValue(const TreeType* tree);
49 
57  template<typename TreeType>
58  DiscreteHilbertValue(const DiscreteHilbertValue& other,
59  TreeType* tree,
60  bool deepCopy);
61 
67  DiscreteHilbertValue(DiscreteHilbertValue&& other);
68 
70  ~DiscreteHilbertValue();
71 
81  template<typename VecType1, typename VecType2>
82  static int ComparePoints(
83  const VecType1& pt1,
84  const VecType2& pt2,
87 
96  static int CompareValues(const DiscreteHilbertValue& val1,
97  const DiscreteHilbertValue& val2);
98 
107  int CompareWith(const DiscreteHilbertValue& val) const;
108 
118  template<typename VecType>
119  int CompareWith(
120  const VecType& pt,
121  typename std::enable_if_t<IsVector<VecType>::value>* = 0) const;
122 
133  template<typename VecType>
134  int CompareWithCachedPoint(
135  const VecType& pt,
136  typename std::enable_if_t<IsVector<VecType>::value>* = 0) const;
137 
145  template<typename TreeType, typename VecType>
146  size_t InsertPoint(TreeType *node,
147  const VecType& pt,
149 
155  template<typename TreeType>
156  void InsertNode(TreeType* node);
157 
165  template<typename TreeType>
166  void DeletePoint(TreeType* node, const size_t localIndex);
167 
174  template<typename TreeType>
175  void RemoveNode(TreeType* node, const size_t nodeIndex);
176 
183  DiscreteHilbertValue& operator=(const DiscreteHilbertValue& val);
184 
188  void NullifyData();
189 
197  template<typename TreeType>
198  void UpdateLargestValue(TreeType* node);
199 
209  template<typename TreeType>
210  void RedistributeHilbertValues(TreeType* parent,
211  const size_t firstSibling,
212  const size_t lastSibling);
213 
219  template<typename VecType>
220  static arma::Col<HilbertElemType> CalculateValue(
221  const VecType& pt,
223 
232  static int CompareValues(const arma::Col<HilbertElemType>& value1,
233  const arma::Col<HilbertElemType>& value2);
234 
236  size_t NumValues() const { return numValues; }
238  size_t& NumValues() { return numValues; }
239 
241  const arma::Mat<HilbertElemType>* LocalHilbertValues() const
242  { return localHilbertValues; }
244  arma::Mat<HilbertElemType>*& LocalHilbertValues()
245  { return localHilbertValues; }
246 
248  bool OwnsLocalHilbertValues() const { return ownsLocalHilbertValues; }
250  bool& OwnsLocalHilbertValues() { return ownsLocalHilbertValues; }
251 
253  const arma::Col<HilbertElemType>* ValueToInsert() const
254  { return valueToInsert; }
256  arma::Col<HilbertElemType>* ValueToInsert() { return valueToInsert; }
257 
259  bool OwnsValueToInsert() const { return ownsValueToInsert; }
261  bool& OwnsValueToInsert() { return ownsValueToInsert; }
262  private:
264  static constexpr size_t order = sizeof(HilbertElemType) * CHAR_BIT;
266  arma::Mat<HilbertElemType>* localHilbertValues;
268  bool ownsLocalHilbertValues;
270  size_t numValues;
277  arma::Col<HilbertElemType>* valueToInsert;
279  bool ownsValueToInsert;
280 
281  public:
282  template<typename Archive>
283  void Serialize(Archive& ar, const unsigned int /* version */);
284 };
285 
286 } // namespace tree
287 } // namespace mlpack
288 
289 // Include implementation.
290 #include "discrete_hilbert_value_impl.hpp"
291 
292 #endif // MLPACK_CORE_TREE_RECTANGLE_TREE_DISCRETE_HILBERT_VALUE_HPP
The DiscreteHilbertValue class stores Hilbert values for all of the points in a RectangleTree node...
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: binarize.hpp:18
The core includes that mlpack expects; standard C++ includes and Armadillo.
If value == true, then VecType is some sort of Armadillo vector or subview.
Definition: arma_traits.hpp:35
typename enable_if< B, T >::type enable_if_t
Definition: prereqs.hpp:59