mlpack  2.2.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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* , 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 
175  {
176  for (int i = 0; i < dim; i++)
177  history[i] = false;
178  }
179 
182  history(other.history)
183  { }
184 
186  {
188  history = other.history;
189  return *this;
190  }
191 
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:
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 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
XTreeAuxiliaryInformation(const XTreeAuxiliaryInformation &other, TreeType *=NULL, bool=true)
Create an auxiliary information object by copying from another object.
const SplitHistoryStruct & SplitHistory() const
Return the split history of the node associated with this object.
FirstShim< T > CreateNVP(T &t, const std::string &name, typename boost::enable_if< HasSerialize< T >>::type *=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.
XTreeAuxiliaryInformation(const TreeType *node)
Construct this with the specified node.
void Serialize(Archive &ar, const unsigned int)
Serialize the information.
size_t NormalNodeMaxNumChildren() const
Return the maximum number of a normal node&#39;s children.
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 &quot;split history&quot;.
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.
struct mlpack::tree::XTreeAuxiliaryInformation::SplitHistoryStruct SplitHistoryStruct
The X tree requires that the tree records it&#39;s &quot;split history&quot;.
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.