MLPACK  1.0.10
ballbound.hpp
Go to the documentation of this file.
1 
23 #ifndef __MLPACK_CORE_TREE_BALLBOUND_HPP
24 #define __MLPACK_CORE_TREE_BALLBOUND_HPP
25 
26 #include <mlpack/core.hpp>
28 
29 namespace mlpack {
30 namespace bound {
31 
40 template<typename VecType = arma::vec,
41  typename TMetricType = metric::LMetric<2, true> >
42 class BallBound
43 {
44  public:
45  typedef VecType Vec;
47  typedef TMetricType MetricType;
48 
49  private:
50 
52  double radius;
53 
55  VecType center;
56 
58  TMetricType* metric;
59 
66  bool ownsMetric;
67 
68  public:
69 
71  BallBound();
72 
78  BallBound(const size_t dimension);
79 
86  BallBound(const double radius, const VecType& center);
87 
89  BallBound(const BallBound& other);
90 
92  BallBound& operator=(const BallBound& other);
93 
95  ~BallBound();
96 
98  double Radius() const { return radius; }
100  double& Radius() { return radius; }
101 
103  const VecType& Center() const { return center; }
105  VecType& Center() { return center; }
106 
108  double Dim() const { return center.n_elem; }
109 
114  double MinWidth() const { return radius * 2.0; }
115 
117  math::Range operator[](const size_t i) const;
118 
122  bool Contains(const VecType& point) const;
123 
129  void Centroid(VecType& centroid) const { centroid = center; }
130 
134  template<typename OtherVecType>
135  double MinDistance(const OtherVecType& point,
136  typename boost::enable_if<IsVector<OtherVecType> >* = 0)
137  const;
138 
142  double MinDistance(const BallBound& other) const;
143 
147  template<typename OtherVecType>
148  double MaxDistance(const OtherVecType& point,
149  typename boost::enable_if<IsVector<OtherVecType> >* = 0)
150  const;
151 
155  double MaxDistance(const BallBound& other) const;
156 
160  template<typename OtherVecType>
162  const OtherVecType& other,
163  typename boost::enable_if<IsVector<OtherVecType> >* = 0) const;
164 
170  math::Range RangeDistance(const BallBound& other) const;
171 
175  const BallBound& operator|=(const BallBound& other);
176 
185  template<typename MatType>
186  const BallBound& operator|=(const MatType& data);
187 
191  double Diameter() const { return 2 * radius; }
192 
196  TMetricType Metric() const { return *metric; }
197 
201  std::string ToString() const;
202 
203 };
204 
205 }; // namespace bound
206 }; // namespace mlpack
207 
208 #include "ballbound_impl.hpp"
209 
210 #endif // __MLPACK_CORE_TREE_DBALLBOUND_HPP
bool Contains(const VecType &point) const
Determines if a point is within this bound.
BallBound()
Empty Constructor.
const BallBound & operator|=(const BallBound &other)
Expand the bound to include the given node.
std::string ToString() const
Returns a string representation of this object.
void Centroid(VecType &centroid) const
Place the centroid of BallBound into the given vector.
Definition: ballbound.hpp:129
double MaxDistance(const OtherVecType &point, typename boost::enable_if< IsVector< OtherVecType > > *=0) const
Computes maximum distance.
math::Range operator[](const size_t i) const
Get the range in a certain dimension.
const VecType & Center() const
Get the center point of the ball.
Definition: ballbound.hpp:103
double Dim() const
Get the dimensionality of the ball.
Definition: ballbound.hpp:108
Ball bound encloses a set of points at a specific distance (radius) from a specific point (center)...
Definition: ballbound.hpp:42
BallBound & operator=(const BallBound &other)
For the same reason as the Copy Constructor. To prevent memory leaks.
bool ownsMetric
To know whether this object allocated memory to the metric member variable.
Definition: ballbound.hpp:66
double MinDistance(const OtherVecType &point, typename boost::enable_if< IsVector< OtherVecType > > *=0) const
Calculates minimum bound-to-point squared distance.
double Diameter() const
Returns the diameter of the ballbound.
Definition: ballbound.hpp:191
VecType & Center()
Modify the center point of the ball.
Definition: ballbound.hpp:105
TMetricType MetricType
Need this for Binary Space Partion Tree.
Definition: ballbound.hpp:47
math::Range RangeDistance(const OtherVecType &other, typename boost::enable_if< IsVector< OtherVecType > > *=0) const
Calculates minimum and maximum bound-to-point distance.
double radius
The radius of the ball bound.
Definition: ballbound.hpp:52
The L_p metric for arbitrary integer p, with an option to take the root.
Definition: lmetric.hpp:73
double MinWidth() const
Get the minimum width of the bound (this is same as the diameter).
Definition: ballbound.hpp:114
~BallBound()
Destructor to release allocated memory.
TMetricType * metric
The metric used in this bound.
Definition: ballbound.hpp:58
TMetricType Metric() const
Returns the distance metric used in this bound.
Definition: ballbound.hpp:196
VecType center
The center of the ball bound.
Definition: ballbound.hpp:55
double & Radius()
Modify the radius of the ball.
Definition: ballbound.hpp:100
double Radius() const
Get the radius of the ball.
Definition: ballbound.hpp:98
If value == true, then VecType is some sort of Armadillo vector or subview.
Definition: arma_traits.hpp:45
Simple real-valued range.
Definition: range.hpp:31