x_tree_auxiliary_information.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_CORE_TREE_RECTANGLE_TREE_X_TREE_AUXILIARY_INFORMATION_HPP
14 #define MLPACK_CORE_TREE_RECTANGLE_TREE_X_TREE_AUXILIARY_INFORMATION_HPP
15 
16 namespace mlpack {
17 namespace tree {
18 
23 template<typename TreeType>
25 {
26  public:
29  normalNodeMaxNumChildren(0),
30  splitHistory(0)
31  { };
32 
38  XTreeAuxiliaryInformation(const TreeType* node) :
39  normalNodeMaxNumChildren(node->Parent() ?
40  node->Parent()->AuxiliaryInfo().NormalNodeMaxNumChildren() :
41  node->MaxNumChildren()),
42  splitHistory(node->Bound().Dim())
43  { };
44 
55  TreeType* /* tree */ = NULL,
56  bool /* deepCopy */ = true) :
57  normalNodeMaxNumChildren(other.NormalNodeMaxNumChildren()),
58  splitHistory(other.SplitHistory())
59  { };
60 
67  {
68  normalNodeMaxNumChildren = other.NormalNodeMaxNumChildren();
69  splitHistory = other.SplitHistory();
70 
71  return *this;
72  }
73 
80  normalNodeMaxNumChildren(other.NormalNodeMaxNumChildren()),
81  splitHistory(std::move(other.splitHistory))
82  {
83  other.normalNodeMaxNumChildren = 0;
84  };
85 
96  bool HandlePointInsertion(TreeType* /* node */, const size_t /* point */)
97  {
98  return false;
99  }
100 
113  bool HandleNodeInsertion(TreeType* /* node */,
114  TreeType* /* nodeToInsert */,
115  bool /* insertionLevel */)
116  {
117  return false;
118  }
119 
129  bool HandlePointDeletion(TreeType* /* node */ , const size_t /* localIndex */)
130  {
131  return false;
132  }
133 
143  bool HandleNodeRemoval(TreeType* /* node */ , const size_t /* nodeIndex */)
144  {
145  return false;
146  }
147 
154  bool UpdateAuxiliaryInfo(TreeType* /* node */)
155  {
156  return false;
157  }
158 
162  void NullifyData()
163  { }
164 
169  typedef struct SplitHistoryStruct
170  {
172  std::vector<bool> history;
173 
174  SplitHistoryStruct(int dim) : lastDimension(0), history(dim)
175  {
176  for (int i = 0; i < dim; ++i)
177  history[i] = false;
178  }
179 
181  lastDimension(other.lastDimension),
182  history(other.history)
183  { }
184 
186  {
187  lastDimension = other.lastDimension;
188  history = other.history;
189  return *this;
190  }
191 
193  lastDimension(other.lastDimension),
194  history(std::move(other.history))
195  {
196  other.lastDimension = 0;
197  }
198 
199  template<typename Archive>
200  void serialize(Archive& ar, const uint32_t /* version */)
201  {
202  ar(CEREAL_NVP(lastDimension));
203  ar(CEREAL_NVP(history));
204  }
206 
207  private:
209  size_t normalNodeMaxNumChildren;
211  SplitHistoryStruct splitHistory;
212 
213  public:
215  size_t NormalNodeMaxNumChildren() const { return normalNodeMaxNumChildren; }
217  size_t& NormalNodeMaxNumChildren() { return normalNodeMaxNumChildren; }
219  const SplitHistoryStruct& SplitHistory() const { return splitHistory; }
221  SplitHistoryStruct& SplitHistory() { return splitHistory; }
222 
226  template<typename Archive>
227  void serialize(Archive& ar, const uint32_t /* version */)
228  {
229  ar(CEREAL_NVP(normalNodeMaxNumChildren));
230  ar(CEREAL_NVP(splitHistory));
231  }
232 };
233 
234 } // namespace tree
235 } // namespace mlpack
236 
237 #endif // MLPACK_CORE_TREE_RECTANGLE_TREE_X_TREE_AUXILIARY_INFORMATION_HPP
XTreeAuxiliaryInformation(const XTreeAuxiliaryInformation &other, TreeType *=NULL, bool=true)
Create an auxiliary information object by copying from another object.
Linear algebra utility functions, generally performed on matrices or vectors.
XTreeAuxiliaryInformation(const TreeType *node)
Construct this with the specified node.
const SplitHistoryStruct & SplitHistory() const
Return the split history of the node associated with this object.
SplitHistoryStruct & operator=(const SplitHistoryStruct &other)
bool UpdateAuxiliaryInfo(TreeType *)
Some tree types require to propagate the information upward.
bool HandleNodeInsertion(TreeType *, TreeType *, bool)
Some tree types require to save some properties at the insertion process.
XTreeAuxiliaryInformation & operator=(const XTreeAuxiliaryInformation &other)
Copy the auxiliary information object.
The X tree requires that the tree records it&#39;s "split history".
void serialize(Archive &ar, const uint32_t)
Serialize the information.
SplitHistoryStruct & SplitHistory()
Modify the split history of the node associated with this object.
void NullifyData()
Nullify the auxiliary information in order to prevent an invalid free.
bool HandlePointDeletion(TreeType *, const size_t)
Some tree types require to save some properties at the deletion process.
size_t & NormalNodeMaxNumChildren()
Modify the maximum number of a normal node&#39;s children.
The XTreeAuxiliaryInformation class provides information specific to X trees for each node in a Recta...
bool HandleNodeRemoval(TreeType *, const size_t)
Some tree types require to save some properties at the deletion process.
size_t NormalNodeMaxNumChildren() const
Return the maximum number of a normal node&#39;s children.
XTreeAuxiliaryInformation(XTreeAuxiliaryInformation &&other)
Create an auxiliary information object by moving from the other node.
bool HandlePointInsertion(TreeType *, const size_t)
Some tree types require to save some properties at the insertion process.