mlpack  3.4.2
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:
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 
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>
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>
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
mlpack::bound::BallBound::BallBound
BallBound(const BallBound &other)
Copy constructor. To prevent memory leaks.
mlpack::bound::BallBound::Metric
MetricType & Metric()
Modify the distance metric used in this bound.
Definition: ballbound.hpp:202
mlpack::bound::BallBound::BallBound
BallBound(const ElemType radius, const VecType &center)
Create the ball bound with the specified radius and center.
mlpack::bound::BallBound::Radius
ElemType & Radius()
Modify the radius of the ball.
Definition: ballbound.hpp:90
mlpack::bound::BallBound::Vec
VecType Vec
A public version of the vector type.
Definition: ballbound.hpp:38
prereqs.hpp
The core includes that mlpack expects; standard C++ includes and Armadillo.
mlpack::bound::BallBound::Center
void Center(VecType &center) const
Place the center of BallBound into the given vector.
Definition: ballbound.hpp:121
mlpack::bound::BoundTraits
A class to obtain compile-time traits about BoundType classes.
Definition: bound_traits.hpp:27
mlpack::bound::BallBound::BallBound
BallBound()
Empty Constructor.
lmetric.hpp
mlpack::bound::BallBound::MinDistance
ElemType MinDistance(const BallBound &other) const
Calculates minimum bound-to-bound squared distance.
mlpack::bound::BallBound::operator|=
const BallBound & operator|=(const BallBound &other)
Expand the bound to include the given node.
mlpack::bound::BallBound::RangeDistance
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.
mlpack::bound::BallBound::serialize
void serialize(Archive &ar, const unsigned int version)
Serialize the bound.
mlpack
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: add_to_cli11.hpp:21
mlpack::bound::BallBound::ElemType
VecType::elem_type ElemType
The underlying data type.
Definition: ballbound.hpp:36
mlpack::bound::BallBound::Diameter
ElemType Diameter() const
Returns the diameter of the ballbound.
Definition: ballbound.hpp:197
std::enable_if_t
typename enable_if< B, T >::type enable_if_t
Definition: prereqs.hpp:70
mlpack::bound::BallBound::Dim
size_t Dim() const
Get the dimensionality of the ball.
Definition: ballbound.hpp:98
mlpack::bound::BallBound::BallBound
BallBound(BallBound &&other)
Move constructor: take possession of another bound.
mlpack::bound::BallBound::operator[]
math::RangeType< ElemType > operator[](const size_t i) const
Get the range in a certain dimension.
mlpack::bound::BallBound::~BallBound
~BallBound()
Destructor to release allocated memory.
mlpack::bound::BallBound::Contains
bool Contains(const VecType &point) const
Determines if a point is within this bound.
mlpack::bound::BallBound::Radius
ElemType Radius() const
Get the radius of the ball.
Definition: ballbound.hpp:88
mlpack::bound::BallBound::operator=
BallBound & operator=(const BallBound &other)
For the same reason as the copy constructor: to prevent memory leaks.
mlpack::bound::BallBound::operator|=
const BallBound & operator|=(const MatType &data)
Expand the bound to include the given point.
mlpack::bound::BallBound::RangeDistance
math::RangeType< ElemType > RangeDistance(const BallBound &other) const
Calculates minimum and maximum bound-to-bound distance.
mlpack::bound::BallBound::Center
const VecType & Center() const
Get the center point of the ball.
Definition: ballbound.hpp:93
bound_traits.hpp
mlpack::math::RangeType< ElemType >
mlpack::bound::BoundTraits::HasTightBounds
static const bool HasTightBounds
If true, then the bounds for each dimension are tight.
Definition: bound_traits.hpp:31
mlpack::bound::BallBound::Metric
const MetricType & Metric() const
Returns the distance metric used in this bound.
Definition: ballbound.hpp:200
mlpack::bound::BallBound::Center
VecType & Center()
Modify the center point of the ball.
Definition: ballbound.hpp:95
mlpack::bound::BallBound::BallBound
BallBound(const size_t dimension)
Create the ball bound with the specified dimensionality.
mlpack::bound::BallBound
Ball bound encloses a set of points at a specific distance (radius) from a specific point (center).
Definition: ballbound.hpp:33
mlpack::bound::BallBound::MaxDistance
ElemType MaxDistance(const OtherVecType &point, typename std::enable_if_t< IsVector< OtherVecType >::value > *=0) const
Computes maximum distance.
mlpack::bound::BallBound::MaxDistance
ElemType MaxDistance(const BallBound &other) const
Computes maximum distance.
mlpack::bound::BallBound::MinDistance
ElemType MinDistance(const OtherVecType &point, typename std::enable_if_t< IsVector< OtherVecType >::value > *=0) const
Calculates minimum bound-to-point squared distance.
mlpack::bound::BallBound::MinWidth
ElemType MinWidth() const
Get the minimum width of the bound (this is same as the diameter).
Definition: ballbound.hpp:104
IsVector
If value == true, then VecType is some sort of Armadillo vector or subview.
Definition: arma_traits.hpp:36