mlpack 3.4.2
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
18namespace mlpack {
19namespace 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 unsigned int /* version */)
104 {
105 ar & BOOST_SERIALIZATION_NVP(bound);
106 ar & BOOST_SERIALIZATION_NVP(selfKernel);
107
108 // Void out last kernel information on load.
109 if (Archive::is_loading::value)
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
The statistic used in trees with FastMKS.
void * LastKernelNode() const
Get the address of the node corresponding to the last distance evaluation.
double LastKernel() const
Get the last kernel evaluation.
double & SelfKernel()
Modify the self-kernel.
double & Bound()
Modify the bound.
double SelfKernel() const
Get the self-kernel.
void *& LastKernelNode()
Modify the address of the node corresponding to the last distance evaluation.
FastMKSStat()
Default initialization.
double & LastKernel()
Modify the last kernel evaluation.
FastMKSStat(const TreeType &node)
Initialize this statistic for the given tree node.
double Bound() const
Get the bound.
void serialize(Archive &ar, const unsigned int)
Serialize the statistic.
The TreeTraits class provides compile-time information on the characteristics of a given tree type.
Definition: tree_traits.hpp:78
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
The core includes that mlpack expects; standard C++ includes and Armadillo.