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 
81  HollowBallBound(const HollowBallBound& other);
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 
127  template<typename VecType>
128  bool Contains(const VecType& point) const;
129 
133  bool Contains(const HollowBallBound& other) const;
134 
140  template<typename VecType>
141  void Center(VecType& center) const { center = this->center; }
142 
146  template<typename VecType>
147  ElemType MinDistance(const VecType& point,
149  const;
150 
154  ElemType MinDistance(const HollowBallBound& other) const;
155 
159  template<typename VecType>
160  ElemType MaxDistance(const VecType& point,
162  const;
163 
167  ElemType MaxDistance(const HollowBallBound& other) const;
168 
172  template<typename VecType>
174  const VecType& other,
175  typename std::enable_if_t<IsVector<VecType>::value>* = 0) const;
176 
183 
192  template<typename MatType>
193  const HollowBallBound& operator|=(const MatType& data);
194 
203  const HollowBallBound& operator|=(const HollowBallBound& other);
204 
208  ElemType Diameter() const { return 2 * radii.Hi(); }
209 
211  const MetricType& Metric() const { return *metric; }
213  MetricType& Metric() { return *metric; }
214 
216  template<typename Archive>
217  void serialize(Archive& ar, const unsigned int version);
218 };
219 
221 template<typename MetricType, typename ElemType>
223 {
225  const static bool HasTightBounds = false;
226 };
227 
228 } // namespace bound
229 } // namespace mlpack
230 
231 #include "hollow_ball_bound_impl.hpp"
232 
233 #endif // MLPACK_CORE_TREE_HOLLOW_BALL_BOUND_HPP
ElemType Diameter() const
Returns the diameter of the ballbound.
T Hi() const
Get the upper bound.
Definition: range.hpp:66
TMetricType MetricType
A public version of the metric type.
const MetricType & Metric() const
Returns the distance metric used in this bound.
typename enable_if< B, T >::type enable_if_t
Definition: prereqs.hpp:58
.hpp
Definition: add_to_po.hpp:21
A class to obtain compile-time traits about BoundType classes.
const arma::Col< ElemType > & Center() const
Get the center point of the ball.
ElemType InnerRadius() const
Get the innner radius of the ball.
HollowBallBound & operator=(const HollowBallBound &other)
For the same reason as the copy constructor: to prevent memory leaks.
The core includes that mlpack expects; standard C++ includes and Armadillo.
ElemType & InnerRadius()
Modify the inner radius of the ball.
arma::Col< ElemType > & HollowCenter()
Modify the center point of the hollow.
ElemType MaxDistance(const VecType &point, typename std::enable_if_t< IsVector< VecType >::value > *=0) const
Computes maximum distance.
const arma::Col< ElemType > & HollowCenter() const
Get the center point of the hollow.
bool Contains(const VecType &point) const
Determines if a point is within this bound.
T Lo() const
Get the lower bound.
Definition: range.hpp:61
arma::Col< ElemType > & Center()
Modify the center point of the ball.
HollowBallBound()
Empty Constructor.
MetricType & Metric()
Modify the distance metric used in this bound.
math::RangeType< ElemType > operator[](const size_t i) const
Get the range in a certain dimension.
void serialize(Archive &ar, const unsigned int version)
Serialize the bound.
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.
void Center(VecType &center) const
Place the center of BallBound into the given vector.
ElemType MinWidth() const
Get the minimum width of the bound (this is same as the diameter).
ElemType MinDistance(const VecType &point, typename std::enable_if_t< IsVector< VecType >::value > *=0) const
Calculates minimum bound-to-point squared distance.
size_t Dim() const
Get the dimensionality of the ball.
Hollow ball bound encloses a set of points at a specific distance (radius) from a specific point (cen...
const HollowBallBound & operator|=(const MatType &data)
Expand the bound to include the given point.
~HollowBallBound()
Destructor to release allocated memory.
If value == true, then VecType is some sort of Armadillo vector or subview.
Definition: arma_traits.hpp:35
ElemType OuterRadius() const
Get the outer radius of the ball.
ElemType & OuterRadius()
Modify the outer radius of the ball.