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& operator=(BallBound&& other);
86 
88  ~BallBound();
89 
91  ElemType Radius() const { return radius; }
93  ElemType& Radius() { return radius; }
94 
96  const VecType& Center() const { return center; }
98  VecType& Center() { return center; }
99 
101  size_t Dim() const { return center.n_elem; }
102 
107  ElemType MinWidth() const { return radius * 2.0; }
108 
110  math::RangeType<ElemType> operator[](const size_t i) const;
111 
117  bool Contains(const VecType& point) const;
118 
124  void Center(VecType& center) const { center = this->center; }
125 
131  template<typename OtherVecType>
132  ElemType MinDistance(
133  const OtherVecType& point,
134  typename std::enable_if_t<IsVector<OtherVecType>::value>* = 0) const;
135 
141  ElemType MinDistance(const BallBound& other) const;
142 
148  template<typename OtherVecType>
149  ElemType MaxDistance(
150  const OtherVecType& point,
151  typename std::enable_if_t<IsVector<OtherVecType>::value>* = 0) const;
152 
158  ElemType MaxDistance(const BallBound& other) const;
159 
166  template<typename OtherVecType>
168  const OtherVecType& other,
169  typename std::enable_if_t<IsVector<OtherVecType>::value>* = 0) const;
170 
180 
184  const BallBound& operator|=(const BallBound& other);
185 
194  template<typename MatType>
195  const BallBound& operator|=(const MatType& data);
196 
200  ElemType Diameter() const { return 2 * radius; }
201 
203  const MetricType& Metric() const { return *metric; }
205  MetricType& Metric() { return *metric; }
206 
208  template<typename Archive>
209  void serialize(Archive& ar, const uint32_t version);
210 };
211 
213 template<typename MetricType, typename VecType>
214 struct BoundTraits<BallBound<MetricType, VecType>>
215 {
217  const static bool HasTightBounds = false;
218 };
219 
220 } // namespace bound
221 } // namespace mlpack
222 
223 #include "ballbound_impl.hpp"
224 
225 #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:70
Linear algebra utility functions, generally performed on matrices or vectors.
A class to obtain compile-time traits about BoundType classes.
ElemType & Radius()
Modify the radius of the ball.
Definition: ballbound.hpp:93
The core includes that mlpack expects; standard C++ includes and Armadillo.
VecType::elem_type ElemType
The underlying data type.
Definition: ballbound.hpp:36
void serialize(Archive &ar, const uint32_t version)
Serialize the bound.
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:91
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:101
ElemType Diameter() const
Returns the diameter of the ballbound.
Definition: ballbound.hpp:200
bool Contains(const VecType &point) const
Determines if a point is within this 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:107
const VecType & Center() const
Get the center point of the ball.
Definition: ballbound.hpp:96
~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:205
VecType & Center()
Modify the center point of the ball.
Definition: ballbound.hpp:98
void Center(VecType &center) const
Place the center of BallBound into the given vector.
Definition: ballbound.hpp:124
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:203
ElemType MaxDistance(const OtherVecType &point, typename std::enable_if_t< IsVector< OtherVecType >::value > *=0) const
Computes maximum distance.