mlpack  3.4.2
hollow_ball_bound.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_CORE_TREE_HOLLOW_BALL_BOUND_HPP
13 #define MLPACK_CORE_TREE_HOLLOW_BALL_BOUND_HPP
14 
15 #include <mlpack/prereqs.hpp>
17 #include "bound_traits.hpp"
18 
19 namespace mlpack {
20 namespace bound {
21 
31 template<typename TMetricType = metric::LMetric<2, true>,
32  typename ElemType = double>
34 {
35  public:
37  typedef TMetricType MetricType;
38 
39  private:
43  arma::Col<ElemType> center;
45  arma::Col<ElemType> hollowCenter;
47  MetricType* metric;
48 
55  bool ownsMetric;
56 
57  public:
60 
66  HollowBallBound(const size_t dimension);
67 
75  template<typename VecType>
76  HollowBallBound(const ElemType innerRadius,
77  const ElemType outerRadius,
78  const VecType& center);
79 
82 
85 
88 
91 
93  ElemType OuterRadius() const { return radii.Hi(); }
95  ElemType& OuterRadius() { return radii.Hi(); }
96 
98  ElemType InnerRadius() const { return radii.Lo(); }
100  ElemType& InnerRadius() { return radii.Lo(); }
101 
103  const arma::Col<ElemType>& Center() const { return center; }
105  arma::Col<ElemType>& Center() { return center; }
106 
108  const arma::Col<ElemType>& HollowCenter() const { return hollowCenter; }
110  arma::Col<ElemType>& HollowCenter() { return hollowCenter; }
111 
113  size_t Dim() const { return center.n_elem; }
114 
119  ElemType MinWidth() const { return radii.Hi() * 2.0; }
120 
122  math::RangeType<ElemType> operator[](const size_t i) const;
123 
129  template<typename VecType>
130  bool Contains(const VecType& point) const;
131 
137  bool Contains(const HollowBallBound& other) const;
138 
144  template<typename VecType>
145  void Center(VecType& center) const { center = this->center; }
146 
152  template<typename VecType>
153  ElemType MinDistance(const VecType& point,
155  const;
156 
162  ElemType MinDistance(const HollowBallBound& other) const;
163 
169  template<typename VecType>
170  ElemType MaxDistance(const VecType& point,
172  const;
173 
179  ElemType MaxDistance(const HollowBallBound& other) const;
180 
187  template<typename VecType>
189  const VecType& other,
190  typename std::enable_if_t<IsVector<VecType>::value>* = 0) const;
191 
201 
210  template<typename MatType>
211  const HollowBallBound& operator|=(const MatType& data);
212 
222 
226  ElemType Diameter() const { return 2 * radii.Hi(); }
227 
229  const MetricType& Metric() const { return *metric; }
231  MetricType& Metric() { return *metric; }
232 
234  template<typename Archive>
235  void serialize(Archive& ar, const unsigned int version);
236 };
237 
239 template<typename MetricType, typename ElemType>
240 struct BoundTraits<HollowBallBound<MetricType, ElemType>>
241 {
243  const static bool HasTightBounds = false;
244 };
245 
246 } // namespace bound
247 } // namespace mlpack
248 
249 #include "hollow_ball_bound_impl.hpp"
250 
251 #endif // MLPACK_CORE_TREE_HOLLOW_BALL_BOUND_HPP
mlpack::bound::HollowBallBound::HollowCenter
arma::Col< ElemType > & HollowCenter()
Modify the center point of the hollow.
Definition: hollow_ball_bound.hpp:110
mlpack::bound::HollowBallBound::operator|=
const HollowBallBound & operator|=(const MatType &data)
Expand the bound to include the given point.
mlpack::bound::HollowBallBound::MaxDistance
ElemType MaxDistance(const VecType &point, typename std::enable_if_t< IsVector< VecType >::value > *=0) const
Computes maximum distance.
mlpack::bound::HollowBallBound::Dim
size_t Dim() const
Get the dimensionality of the ball.
Definition: hollow_ball_bound.hpp:113
mlpack::bound::HollowBallBound::Center
const arma::Col< ElemType > & Center() const
Get the center point of the ball.
Definition: hollow_ball_bound.hpp:103
prereqs.hpp
The core includes that mlpack expects; standard C++ includes and Armadillo.
mlpack::bound::HollowBallBound::HollowBallBound
HollowBallBound(const size_t dimension)
Create the ball bound with the specified dimensionality.
mlpack::bound::HollowBallBound::Diameter
ElemType Diameter() const
Returns the diameter of the ballbound.
Definition: hollow_ball_bound.hpp:226
mlpack::math::RangeType::Lo
T Lo() const
Get the lower bound.
Definition: range.hpp:61
mlpack::bound::HollowBallBound::MinWidth
ElemType MinWidth() const
Get the minimum width of the bound (this is same as the diameter).
Definition: hollow_ball_bound.hpp:119
mlpack::bound::BoundTraits
A class to obtain compile-time traits about BoundType classes.
Definition: bound_traits.hpp:27
lmetric.hpp
mlpack::bound::HollowBallBound::InnerRadius
ElemType InnerRadius() const
Get the innner radius of the ball.
Definition: hollow_ball_bound.hpp:98
mlpack::bound::HollowBallBound::operator|=
const HollowBallBound & operator|=(const HollowBallBound &other)
Expand the bound to include the given bound.
mlpack::bound::HollowBallBound::Contains
bool Contains(const HollowBallBound &other) const
Determines if another bound is within this bound.
mlpack::bound::HollowBallBound::HollowCenter
const arma::Col< ElemType > & HollowCenter() const
Get the center point of the hollow.
Definition: hollow_ball_bound.hpp:108
mlpack::bound::HollowBallBound::operator=
HollowBallBound & operator=(const HollowBallBound &other)
For the same reason as the copy constructor: to prevent memory leaks.
mlpack
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: add_to_cli11.hpp:21
mlpack::bound::HollowBallBound::Center
arma::Col< ElemType > & Center()
Modify the center point of the ball.
Definition: hollow_ball_bound.hpp:105
std::enable_if_t
typename enable_if< B, T >::type enable_if_t
Definition: prereqs.hpp:70
mlpack::bound::HollowBallBound::HollowBallBound
HollowBallBound(const HollowBallBound &other)
Copy constructor. To prevent memory leaks.
mlpack::bound::HollowBallBound::MaxDistance
ElemType MaxDistance(const HollowBallBound &other) const
Computes maximum distance.
mlpack::bound::HollowBallBound::HollowBallBound
HollowBallBound(HollowBallBound &&other)
Move constructor: take possession of another bound.
mlpack::bound::HollowBallBound::RangeDistance
math::RangeType< ElemType > RangeDistance(const HollowBallBound &other) const
Calculates minimum and maximum bound-to-bound distance.
mlpack::bound::HollowBallBound::MinDistance
ElemType MinDistance(const HollowBallBound &other) const
Calculates minimum bound-to-bound squared distance.
mlpack::bound::HollowBallBound::Contains
bool Contains(const VecType &point) const
Determines if a point is within this bound.
mlpack::bound::HollowBallBound::serialize
void serialize(Archive &ar, const unsigned int version)
Serialize the bound.
mlpack::bound::HollowBallBound::HollowBallBound
HollowBallBound()
Empty Constructor.
bound_traits.hpp
mlpack::bound::HollowBallBound::InnerRadius
ElemType & InnerRadius()
Modify the inner radius of the ball.
Definition: hollow_ball_bound.hpp:100
mlpack::bound::HollowBallBound
Hollow ball bound encloses a set of points at a specific distance (radius) from a specific point (cen...
Definition: hollow_ball_bound.hpp:34
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::math::RangeType::Hi
T Hi() const
Get the upper bound.
Definition: range.hpp:66
mlpack::bound::HollowBallBound::Metric
const MetricType & Metric() const
Returns the distance metric used in this bound.
Definition: hollow_ball_bound.hpp:229
mlpack::bound::HollowBallBound::OuterRadius
ElemType OuterRadius() const
Get the outer radius of the ball.
Definition: hollow_ball_bound.hpp:93
mlpack::bound::HollowBallBound::operator[]
math::RangeType< ElemType > operator[](const size_t i) const
Get the range in a certain dimension.
mlpack::bound::HollowBallBound::MetricType
TMetricType MetricType
A public version of the metric type.
Definition: hollow_ball_bound.hpp:37
mlpack::bound::HollowBallBound::Metric
MetricType & Metric()
Modify the distance metric used in this bound.
Definition: hollow_ball_bound.hpp:231
mlpack::bound::HollowBallBound::OuterRadius
ElemType & OuterRadius()
Modify the outer radius of the ball.
Definition: hollow_ball_bound.hpp:95
mlpack::bound::HollowBallBound::RangeDistance
math::RangeType< ElemType > RangeDistance(const VecType &other, typename std::enable_if_t< IsVector< VecType >::value > *=0) const
Calculates minimum and maximum bound-to-point distance.
mlpack::bound::HollowBallBound::~HollowBallBound
~HollowBallBound()
Destructor to release allocated memory.
mlpack::bound::HollowBallBound::Center
void Center(VecType &center) const
Place the center of BallBound into the given vector.
Definition: hollow_ball_bound.hpp:145
mlpack::bound::HollowBallBound::HollowBallBound
HollowBallBound(const ElemType innerRadius, const ElemType outerRadius, const VecType &center)
Create the ball bound with the specified radius and center.
mlpack::bound::HollowBallBound::MinDistance
ElemType MinDistance(const VecType &point, typename std::enable_if_t< IsVector< VecType >::value > *=0) const
Calculates minimum bound-to-point squared distance.
IsVector
If value == true, then VecType is some sort of Armadillo vector or subview.
Definition: arma_traits.hpp:36