ballbound.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_CORE_TREE_BALLBOUND_HPP
13 #define MLPACK_CORE_TREE_BALLBOUND_HPP
14 
15 #include <mlpack/prereqs.hpp>
17 #include "bound_traits.hpp"
18 
19 namespace mlpack {
20 namespace bound {
21 
30 template<typename MetricType = metric::LMetric<2, true>,
31  typename VecType = arma::vec>
32 class BallBound
33 {
34  public:
36  typedef typename VecType::elem_type ElemType;
38  typedef VecType Vec;
39 
40  private:
42  ElemType radius;
44  VecType center;
46  MetricType* metric;
47 
54  bool ownsMetric;
55 
56  public:
58  BallBound();
59 
65  BallBound(const size_t dimension);
66 
73  BallBound(const ElemType radius, const VecType& center);
74 
76  BallBound(const BallBound& other);
77 
79  BallBound& operator=(const BallBound& other);
80 
82  BallBound(BallBound&& other);
83 
85  ~BallBound();
86 
88  ElemType Radius() const { return radius; }
90  ElemType& Radius() { return radius; }
91 
93  const VecType& Center() const { return center; }
95  VecType& Center() { return center; }
96 
98  size_t Dim() const { return center.n_elem; }
99 
104  ElemType MinWidth() const { return radius * 2.0; }
105 
107  math::RangeType<ElemType> operator[](const size_t i) const;
108 
114  bool Contains(const VecType& point) const;
115 
121  void Center(VecType& center) const { center = this->center; }
122 
128  template<typename OtherVecType>
129  ElemType MinDistance(
130  const OtherVecType& point,
131  typename std::enable_if_t<IsVector<OtherVecType>::value>* = 0) const;
132 
138  ElemType MinDistance(const BallBound& other) const;
139 
145  template<typename OtherVecType>
146  ElemType MaxDistance(
147  const OtherVecType& point,
148  typename std::enable_if_t<IsVector<OtherVecType>::value>* = 0) const;
149 
155  ElemType MaxDistance(const BallBound& other) const;
156 
163  template<typename OtherVecType>
165  const OtherVecType& other,
166  typename std::enable_if_t<IsVector<OtherVecType>::value>* = 0) const;
167 
177 
181  const BallBound& operator|=(const BallBound& other);
182 
191  template<typename MatType>
192  const BallBound& operator|=(const MatType& data);
193 
197  ElemType Diameter() const { return 2 * radius; }
198 
200  const MetricType& Metric() const { return *metric; }
202  MetricType& Metric() { return *metric; }
203 
205  template<typename Archive>
206  void serialize(Archive& ar, const unsigned int version);
207 };
208 
210 template<typename MetricType, typename VecType>
211 struct BoundTraits<BallBound<MetricType, VecType>>
212 {
214  const static bool HasTightBounds = false;
215 };
216 
217 } // namespace bound
218 } // namespace mlpack
219 
220 #include "ballbound_impl.hpp"
221 
222 #endif // MLPACK_CORE_TREE_DBALLBOUND_HPP
ElemType MinDistance(const OtherVecType &point, typename std::enable_if_t< IsVector< OtherVecType >::value > *=0) const
Calculates minimum bound-to-point squared distance.
math::RangeType< ElemType > RangeDistance(const OtherVecType &other, typename std::enable_if_t< IsVector< OtherVecType >::value > *=0) const
Calculates minimum and maximum bound-to-point distance.
BallBound()
Empty Constructor.
VecType Vec
A public version of the vector type.
Definition: ballbound.hpp:38
typename enable_if< B, T >::type enable_if_t
Definition: prereqs.hpp:58
strip_type.hpp
Definition: add_to_po.hpp:21
A class to obtain compile-time traits about BoundType classes.
ElemType & Radius()
Modify the radius of the ball.
Definition: ballbound.hpp:90
The core includes that mlpack expects; standard C++ includes and Armadillo.
VecType::elem_type ElemType
The underlying data type.
Definition: ballbound.hpp:36
Ball bound encloses a set of points at a specific distance (radius) from a specific point (center)...
Definition: ballbound.hpp:32
ElemType Radius() const
Get the radius of the ball.
Definition: ballbound.hpp:88
math::RangeType< ElemType > operator[](const size_t i) const
Get the range in a certain dimension.
size_t Dim() const
Get the dimensionality of the ball.
Definition: ballbound.hpp:98
ElemType Diameter() const
Returns the diameter of the ballbound.
Definition: ballbound.hpp:197
bool Contains(const VecType &point) const
Determines if a point is within this bound.
void serialize(Archive &ar, const unsigned int version)
Serialize the bound.
const BallBound & operator|=(const BallBound &other)
Expand the bound to include the given node.
ElemType MinWidth() const
Get the minimum width of the bound (this is same as the diameter).
Definition: ballbound.hpp:104
const VecType & Center() const
Get the center point of the ball.
Definition: ballbound.hpp:93
~BallBound()
Destructor to release allocated memory.
BallBound & operator=(const BallBound &other)
For the same reason as the copy constructor: to prevent memory leaks.
MetricType & Metric()
Modify the distance metric used in this bound.
Definition: ballbound.hpp:202
VecType & Center()
Modify the center point of the ball.
Definition: ballbound.hpp:95
void Center(VecType &center) const
Place the center of BallBound into the given vector.
Definition: ballbound.hpp:121
If value == true, then VecType is some sort of Armadillo vector or subview.
Definition: arma_traits.hpp:35
const MetricType & Metric() const
Returns the distance metric used in this bound.
Definition: ballbound.hpp:200
ElemType MaxDistance(const OtherVecType &point, typename std::enable_if_t< IsVector< OtherVecType >::value > *=0) const
Computes maximum distance.