fastmks_stat.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_METHODS_FASTMKS_FASTMKS_STAT_HPP
13 #define MLPACK_METHODS_FASTMKS_FASTMKS_STAT_HPP
14 
15 #include <mlpack/prereqs.hpp>
17 
18 namespace mlpack {
19 namespace fastmks {
20 
26 {
27  public:
32  bound(-DBL_MAX),
33  selfKernel(0.0),
34  lastKernel(0.0),
35  lastKernelNode(NULL)
36  { }
37 
45  template<typename TreeType>
46  FastMKSStat(const TreeType& node) :
47  bound(-DBL_MAX),
48  lastKernel(0.0),
49  lastKernelNode(NULL)
50  {
51  // Do we have to calculate the centroid?
53  {
54  // If this type of tree has self-children, then maybe the evaluation is
55  // already done. These statistics are built bottom-up, so the child stat
56  // should already be done.
58  (node.NumChildren() > 0) &&
59  (node.Point(0) == node.Child(0).Point(0)))
60  {
61  selfKernel = node.Child(0).Stat().SelfKernel();
62  }
63  else
64  {
65  selfKernel = sqrt(node.Metric().Kernel().Evaluate(
66  node.Dataset().col(node.Point(0)),
67  node.Dataset().col(node.Point(0))));
68  }
69  }
70  else
71  {
72  // Calculate the centroid.
73  arma::vec center;
74  node.Center(center);
75 
76  selfKernel = sqrt(node.Metric().Kernel().Evaluate(center, center));
77  }
78  }
79 
81  double SelfKernel() const { return selfKernel; }
83  double& SelfKernel() { return selfKernel; }
84 
86  double Bound() const { return bound; }
88  double& Bound() { return bound; }
89 
91  double LastKernel() const { return lastKernel; }
93  double& LastKernel() { return lastKernel; }
94 
96  void* LastKernelNode() const { return lastKernelNode; }
99  void*& LastKernelNode() { return lastKernelNode; }
100 
102  template<typename Archive>
103  void serialize(Archive& ar, const uint32_t /* version */)
104  {
105  ar(CEREAL_NVP(bound));
106  ar(CEREAL_NVP(selfKernel));
107 
108  // Void out last kernel information on load.
109  if (cereal::is_loading<Archive>())
110  {
111  lastKernel = 0.0;
112  lastKernelNode = NULL;
113  }
114  }
115 
116  private:
118  double bound;
119 
121  double selfKernel;
122 
124  double lastKernel;
125 
128  void* lastKernelNode;
129 };
130 
131 } // namespace fastmks
132 } // namespace mlpack
133 
134 #endif
double Bound() const
Get the bound.
Linear algebra utility functions, generally performed on matrices or vectors.
FastMKSStat(const TreeType &node)
Initialize this statistic for the given tree node.
The core includes that mlpack expects; standard C++ includes and Armadillo.
void * LastKernelNode() const
Get the address of the node corresponding to the last distance evaluation.
double & SelfKernel()
Modify the self-kernel.
void serialize(Archive &ar, const uint32_t)
Serialize the statistic.
double & LastKernel()
Modify the last kernel evaluation.
double & Bound()
Modify the bound.
void *& LastKernelNode()
Modify the address of the node corresponding to the last distance evaluation.
The TreeTraits class provides compile-time information on the characteristics of a given tree type...
Definition: tree_traits.hpp:77
double LastKernel() const
Get the last kernel evaluation.
double SelfKernel() const
Get the self-kernel.
The statistic used in trees with FastMKS.
FastMKSStat()
Default initialization.