mlpack  master
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:
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) :
58  splitHistory(other.SplitHistory())
59  { };
60 
67  {
69  splitHistory = other.SplitHistory();
70 
71  return *this;
72  }
73 
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* , const size_t)
130  {
131  return false;
132  }
133 
143  bool HandleNodeRemoval(TreeType* , const size_t)
144  {
145  return false;
146  }
147 
154  bool UpdateAuxiliaryInfo(TreeType* )
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 unsigned int /* version */)
201  {
202  ar & data::CreateNVP(lastDimension, "lastDimension");
203  ar & data::CreateNVP(history, "history");
204  }
206 
207  private:
212 
213  public:
219  const SplitHistoryStruct& SplitHistory() const { return splitHistory; }
222 
226  template<typename Archive>
227  void Serialize(Archive& ar, const unsigned int /* version */)
228  {
229  using data::CreateNVP;
230 
231  ar & CreateNVP(normalNodeMaxNumChildren, "normalNodeMaxNumChildren");
232  ar & CreateNVP(splitHistory, "splitHistory");
233  }
234 
235 };
236 
237 } // namespace tree
238 } // namespace mlpack
239 
240 #endif // MLPACK_CORE_TREE_RECTANGLE_TREE_X_TREE_AUXILIARY_INFORMATION_HPP
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.
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: binarize.hpp:18
bool UpdateAuxiliaryInfo(TreeType *)
Some tree types require to propagate the information upward.
FirstShim< T > CreateNVP(T &t, const std::string &name, typename std::enable_if_t< HasSerialize< T >::value > *=0)
Call this function to produce a name-value pair; this is similar to BOOST_SERIALIZATION_NVP(), but should be used for types that have a Serialize() function (or contain a type that has a Serialize() function) instead of a serialize() function.
Definition: prereqs.hpp:56
bool HandlePointDeletion(TreeType *, const size_t)
Some tree types require to save some properties at the deletion process.
bool HandleNodeInsertion(TreeType *, TreeType *, bool)
Some tree types require to save some properties at the insertion process.
XTreeAuxiliaryInformation(const TreeType *node)
Construct this with the specified node.
size_t NormalNodeMaxNumChildren() const
Return the maximum number of a normal node&#39;s children.
SplitHistoryStruct & operator=(const SplitHistoryStruct &other)
The X tree requires that the tree records it&#39;s "split history".
size_t & NormalNodeMaxNumChildren()
Modify the maximum number of a normal node&#39;s children.
size_t normalNodeMaxNumChildren
The max number of child nodes a non-leaf normal node can have.
The XTreeAuxiliaryInformation class provides information specific to X trees for each node in a Recta...
XTreeAuxiliaryInformation & operator=(const XTreeAuxiliaryInformation &other)
Copy the auxiliary information object.
const SplitHistoryStruct & SplitHistory() const
Return the split history of the node associated with this object.
void Serialize(Archive &ar, const unsigned int)
Serialize the information.
bool HandleNodeRemoval(TreeType *, const size_t)
Some tree types require to save some properties at the deletion process.
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.
XTreeAuxiliaryInformation(const XTreeAuxiliaryInformation &other, TreeType *=NULL, bool=true)
Create an auxiliary information object by copying from another object.
SplitHistoryStruct splitHistory
A struct to store the "split history" for X trees.