mlpack: src/mlpack/methods/fastmks/fastmks_stat.hpp Source File
fastmks_stat.hpp
Go to the documentation of this file.
1 
14 #ifndef mlpack_METHODS_FASTMKS_FASTMKS_STAT_HPP
15 #define mlpack_METHODS_FASTMKS_FASTMKS_STAT_HPP
16 
17 #include <mlpack/core.hpp>
19 
20 namespace mlpack {
21 namespace fastmks {
22 
28 {
29  public:
34  bound(-DBL_MAX),
35  selfKernel(0.0),
36  lastKernel(0.0),
37  lastKernelNode(NULL)
38  { }
39 
47  template<typename TreeType>
48  FastMKSStat(const TreeType& node) :
49  bound(-DBL_MAX),
50  lastKernel(0.0),
51  lastKernelNode(NULL)
52  {
53  // Do we have to calculate the centroid?
55  {
56  // If this type of tree has self-children, then maybe the evaluation is
57  // already done. These statistics are built bottom-up, so the child stat
58  // should already be done.
60  (node.NumChildren() > 0) &&
61  (node.Point(0) == node.Child(0).Point(0)))
62  {
63  selfKernel = node.Child(0).Stat().SelfKernel();
64  }
65  else
66  {
67  selfKernel = sqrt(node.Metric().Kernel().Evaluate(
68  node.Dataset().col(node.Point(0)),
69  node.Dataset().col(node.Point(0))));
70  }
71  }
72  else
73  {
74  // Calculate the centroid.
75  arma::vec center;
76  node.Center(center);
77 
78  selfKernel = sqrt(node.Metric().Kernel().Evaluate(center, center));
79  }
80  }
81 
83  double SelfKernel() const { return selfKernel; }
85  double& SelfKernel() { return selfKernel; }
86 
88  double Bound() const { return bound; }
90  double& Bound() { return bound; }
91 
93  double LastKernel() const { return lastKernel; }
95  double& LastKernel() { return lastKernel; }
96 
98  void* LastKernelNode() const { return lastKernelNode; }
101  void*& LastKernelNode() { return lastKernelNode; }
102 
104  template<typename Archive>
105  void Serialize(Archive& ar, const unsigned int /* version */)
106  {
107  ar & data::CreateNVP(bound, "bound");
108  ar & data::CreateNVP(selfKernel, "selfKernel");
109 
110  // Void out last kernel information on load.
111  if (Archive::is_loading::value)
112  {
113  lastKernel = 0.0;
114  lastKernelNode = NULL;
115  }
116  }
117 
118  private:
120  double bound;
121 
123  double selfKernel;
124 
126  double lastKernel;
127 
131 };
132 
133 } // namespace fastmks
134 } // namespace mlpack
135 
136 #endif
void * lastKernelNode
The node corresponding to the last kernel evaluation.
double lastKernel
The last kernel evaluation.
double LastKernel() const
Get the last kernel evaluation.
double & LastKernel()
Modify the last kernel evaluation.
FastMKSStat(const TreeType &node)
Initialize this statistic for the given tree node.
Linear algebra utility functions, generally performed on matrices or vectors.
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.
double & Bound()
Modify the bound.
double selfKernel
The self-kernel evaluation: sqrt(K(centroid, centroid)).
double bound
The bound for pruning.
double & SelfKernel()
Modify the self-kernel.
FastMKSStat()
Default initialization.
double Bound() const
Get the bound.
double SelfKernel() const
Get the self-kernel.
Include all of the base components required to write mlpack methods, and the main mlpack Doxygen docu...
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:79
The statistic used in trees with FastMKS.
void Serialize(Archive &ar, const unsigned int)
Serialize the statistic.
void * LastKernelNode() const
Get the address of the node corresponding to the last distance evaluation.