mlpack  master
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:
57 
59  BallBound();
60 
66  BallBound(const size_t dimension);
67 
74  BallBound(const ElemType radius, const VecType& center);
75 
77  BallBound(const BallBound& other);
78 
80  BallBound& operator=(const BallBound& other);
81 
83  BallBound(BallBound&& other);
84 
86  ~BallBound();
87 
89  ElemType Radius() const { return radius; }
91  ElemType& Radius() { return radius; }
92 
94  const VecType& Center() const { return center; }
96  VecType& Center() { return center; }
97 
99  size_t Dim() const { return center.n_elem; }
100 
105  ElemType MinWidth() const { return radius * 2.0; }
106 
108  math::RangeType<ElemType> operator[](const size_t i) const;
109 
113  bool Contains(const VecType& point) const;
114 
120  void Center(VecType& center) const { center = this->center; }
121 
125  template<typename OtherVecType>
126  ElemType MinDistance(
127  const OtherVecType& point,
128  typename std::enable_if_t<IsVector<OtherVecType>::value>* = 0) const;
129 
133  ElemType MinDistance(const BallBound& other) const;
134 
138  template<typename OtherVecType>
139  ElemType MaxDistance(
140  const OtherVecType& point,
141  typename std::enable_if_t<IsVector<OtherVecType>::value>* = 0) const;
142 
146  ElemType MaxDistance(const BallBound& other) const;
147 
151  template<typename OtherVecType>
153  const OtherVecType& other,
154  typename std::enable_if_t<IsVector<OtherVecType>::value>* = 0) const;
155 
162 
166  const BallBound& operator|=(const BallBound& other);
167 
176  template<typename MatType>
177  const BallBound& operator|=(const MatType& data);
178 
182  ElemType Diameter() const { return 2 * radius; }
183 
185  const MetricType& Metric() const { return *metric; }
187  MetricType& Metric() { return *metric; }
188 
190  template<typename Archive>
191  void Serialize(Archive& ar, const unsigned int version);
192 };
193 
195 template<typename MetricType, typename VecType>
196 struct BoundTraits<BallBound<MetricType, VecType>>
197 {
199  const static bool HasTightBounds = false;
200 };
201 
202 } // namespace bound
203 } // namespace mlpack
204 
205 #include "ballbound_impl.hpp"
206 
207 #endif // MLPACK_CORE_TREE_DBALLBOUND_HPP
ElemType & Radius()
Modify the radius of the ball.
Definition: ballbound.hpp:91
void Center(VecType &center) const
Place the center of BallBound into the given vector.
Definition: ballbound.hpp:120
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: binarize.hpp:18
A class to obtain compile-time traits about BoundType classes.
ElemType Radius() const
Get the radius of the ball.
Definition: ballbound.hpp:89
ElemType radius
The radius of the ball bound.
Definition: ballbound.hpp:42
MetricType & Metric()
Modify the distance metric used in this bound.
Definition: ballbound.hpp:187
void Serialize(Archive &ar, const unsigned int version)
Serialize the bound.
BallBound()
Empty Constructor.
The core includes that mlpack expects; standard C++ includes and Armadillo.
VecType Vec
A public version of the vector type.
Definition: ballbound.hpp:38
ElemType MinWidth() const
Get the minimum width of the bound (this is same as the diameter).
Definition: ballbound.hpp:105
const MetricType & Metric() const
Returns the distance metric used in this bound.
Definition: ballbound.hpp:185
size_t Dim() const
Get the dimensionality of the ball.
Definition: ballbound.hpp:99
MetricType * metric
The metric used in this bound.
Definition: ballbound.hpp:46
Ball bound encloses a set of points at a specific distance (radius) from a specific point (center)...
Definition: ballbound.hpp:32
~BallBound()
Destructor to release allocated memory.
bool Contains(const VecType &point) const
Determines if a point is within this bound.
bool ownsMetric
To know whether this object allocated memory to the metric member variable.
Definition: ballbound.hpp:54
ElemType MaxDistance(const OtherVecType &point, typename std::enable_if_t< IsVector< OtherVecType >::value > *=0) const
Computes maximum distance.
math::RangeType< ElemType > operator[](const size_t i) const
Get the range in a certain dimension.
VecType::elem_type ElemType
The underlying data type.
Definition: ballbound.hpp:36
VecType & Center()
Modify the center point of the ball.
Definition: ballbound.hpp:96
BallBound & operator=(const BallBound &other)
For the same reason as the copy constructor: to prevent memory leaks.
ElemType MinDistance(const OtherVecType &point, typename std::enable_if_t< IsVector< OtherVecType >::value > *=0) const
Calculates minimum bound-to-point squared distance.
VecType center
The center of the ball bound.
Definition: ballbound.hpp:44
const VecType & Center() const
Get the center point of the ball.
Definition: ballbound.hpp:94
ElemType Diameter() const
Returns the diameter of the ballbound.
Definition: ballbound.hpp:182
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.
const BallBound & operator|=(const BallBound &other)
Expand the bound to include the given node.
If value == true, then VecType is some sort of Armadillo vector or subview.
Definition: arma_traits.hpp:35
typename enable_if< B, T >::type enable_if_t
Definition: prereqs.hpp:59