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