kde_stat.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_METHODS_KDE_STAT_HPP
13 #define MLPACK_METHODS_KDE_STAT_HPP
14 
15 #include <mlpack/prereqs.hpp>
16 
17 namespace mlpack {
18 namespace kde {
19 
24 class KDEStat
25 {
26  public:
28  KDEStat() : validCentroid(false) { }
29 
31  template<typename TreeType>
32  KDEStat(TreeType& node)
33  {
34  // Calculate centroid if necessary.
36  {
37  node.Center(centroid);
38  validCentroid = true;
39  }
40  else
41  {
42  validCentroid = false;
43  }
44  }
45 
47  inline const arma::vec& Centroid() const
48  {
49  if (validCentroid)
50  return centroid;
51  throw std::logic_error("Centroid must be assigned before requesting its "
52  "value");
53  }
54 
56  void SetCentroid(arma::vec newCentroid)
57  {
58  validCentroid = true;
59  centroid = std::move(newCentroid);
60  }
61 
63  inline bool ValidCentroid() const { return validCentroid; }
64 
66  template<typename Archive>
67  void serialize(Archive& ar, const unsigned int /* version */)
68  {
69  ar & BOOST_SERIALIZATION_NVP(centroid);
70  ar & BOOST_SERIALIZATION_NVP(validCentroid);
71  }
72 
73  private:
75  arma::vec centroid;
76 
78  bool validCentroid;
79 };
80 
81 } // namespace kde
82 } // namespace mlpack
83 
84 #endif
bool ValidCentroid() const
Get whether the centroid is valid.
Definition: kde_stat.hpp:63
.hpp
Definition: add_to_po.hpp:21
const arma::vec & Centroid() const
Get the centroid of the node.
Definition: kde_stat.hpp:47
The core includes that mlpack expects; standard C++ includes and Armadillo.
Extra data for each node in the tree for the task of kernel density estimation.
Definition: kde_stat.hpp:24
KDEStat(TreeType &node)
Initialization for a fully initialized node.
Definition: kde_stat.hpp:32
The TreeTraits class provides compile-time information on the characteristics of a given tree type...
Definition: tree_traits.hpp:77
void serialize(Archive &ar, const unsigned int)
Serialize the statistic to/from an archive.
Definition: kde_stat.hpp:67
void SetCentroid(arma::vec newCentroid)
Modify the centroid of the node.
Definition: kde_stat.hpp:56
KDEStat()
Initialize the statistic.
Definition: kde_stat.hpp:28