mlpack  2.0.1
ballbound.hpp
Go to the documentation of this file.
1 
14 #ifndef __MLPACK_CORE_TREE_BALLBOUND_HPP
15 #define __MLPACK_CORE_TREE_BALLBOUND_HPP
16 
17 #include <mlpack/core.hpp>
19 #include "bound_traits.hpp"
20 
21 namespace mlpack {
22 namespace bound {
23 
32 template<typename VecType = arma::vec,
33  typename TMetricType = metric::LMetric<2, true> >
34 class BallBound
35 {
36  public:
37  typedef VecType Vec;
39  typedef TMetricType MetricType;
40 
41  private:
43  double radius;
45  VecType center;
47  TMetricType* metric;
48 
55  bool ownsMetric;
56 
57  public:
58 
60  BallBound();
61 
67  BallBound(const size_t dimension);
68 
75  BallBound(const double radius, const VecType& center);
76 
78  BallBound(const BallBound& other);
79 
81  BallBound& operator=(const BallBound& other);
82 
84  BallBound(BallBound&& other);
85 
87  ~BallBound();
88 
90  double Radius() const { return radius; }
92  double& Radius() { return radius; }
93 
95  const VecType& Center() const { return center; }
97  VecType& Center() { return center; }
98 
100  double Dim() const { return center.n_elem; }
101 
106  double MinWidth() const { return radius * 2.0; }
107 
109  math::Range operator[](const size_t i) const;
110 
114  bool Contains(const VecType& point) const;
115 
121  void Center(VecType& center) const { center = this->center; }
122 
126  template<typename OtherVecType>
127  double MinDistance(const OtherVecType& point,
128  typename boost::enable_if<IsVector<OtherVecType> >* = 0)
129  const;
130 
134  double MinDistance(const BallBound& other) const;
135 
139  template<typename OtherVecType>
140  double MaxDistance(const OtherVecType& point,
141  typename boost::enable_if<IsVector<OtherVecType> >* = 0)
142  const;
143 
147  double MaxDistance(const BallBound& other) const;
148 
152  template<typename OtherVecType>
154  const OtherVecType& other,
155  typename boost::enable_if<IsVector<OtherVecType> >* = 0) const;
156 
162  math::Range RangeDistance(const BallBound& other) const;
163 
167  const BallBound& operator|=(const BallBound& other);
168 
177  template<typename MatType>
178  const BallBound& operator|=(const MatType& data);
179 
183  double Diameter() const { return 2 * radius; }
184 
186  const TMetricType& Metric() const { return *metric; }
188  TMetricType& Metric() { return *metric; }
189 
191  template<typename Archive>
192  void Serialize(Archive& ar, const unsigned int version);
193 };
194 
196 template<typename VecType, typename TMetricType>
197 struct BoundTraits<BallBound<VecType, TMetricType>>
198 {
200  const static bool HasTightBounds = false;
201 };
202 
203 } // namespace bound
204 } // namespace mlpack
205 
206 #include "ballbound_impl.hpp"
207 
208 #endif // __MLPACK_CORE_TREE_DBALLBOUND_HPP
double MaxDistance(const OtherVecType &point, typename boost::enable_if< IsVector< OtherVecType > > *=0) const
Computes maximum distance.
const TMetricType & Metric() const
Returns the distance metric used in this bound.
Definition: ballbound.hpp:186
BallBound()
Empty Constructor.
Linear algebra utility functions, generally performed on matrices or vectors.
double Radius() const
Get the radius of the ball.
Definition: ballbound.hpp:90
A class to obtain compile-time traits about BoundType classes.
void Serialize(Archive &ar, const unsigned int version)
Serialize the bound.
const VecType & Center() const
Get the center point of the ball.
Definition: ballbound.hpp:95
const BallBound & operator|=(const BallBound &other)
Expand the bound to include the given node.
void Center(VecType &center) const
Place the center of BallBound into the given vector.
Definition: ballbound.hpp:121
TMetricType & Metric()
Modify the distance metric used in this bound.
Definition: ballbound.hpp:188
math::Range operator[](const size_t i) const
Get the range in a certain dimension.
double MinDistance(const OtherVecType &point, typename boost::enable_if< IsVector< OtherVecType > > *=0) const
Calculates minimum bound-to-point squared distance.
Ball bound encloses a set of points at a specific distance (radius) from a specific point (center)...
Definition: ballbound.hpp:34
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:55
VecType & Center()
Modify the center point of the ball.
Definition: ballbound.hpp:97
TMetricType MetricType
Needed for BinarySpaceTree.
Definition: ballbound.hpp:39
math::Range RangeDistance(const OtherVecType &other, typename boost::enable_if< IsVector< OtherVecType > > *=0) const
Calculates minimum and maximum bound-to-point distance.
Simple real-valued range.
Definition: range.hpp:21
double radius
The radius of the ball bound.
Definition: ballbound.hpp:43
Include all of the base components required to write MLPACK methods, and the main MLPACK Doxygen docu...
The L_p metric for arbitrary integer p, with an option to take the root.
Definition: lmetric.hpp:65
double Diameter() const
Returns the diameter of the ballbound.
Definition: ballbound.hpp:183
bool Contains(const VecType &point) const
Determines if a point is within this bound.
~BallBound()
Destructor to release allocated memory.
TMetricType * metric
The metric used in this bound.
Definition: ballbound.hpp:47
double MinWidth() const
Get the minimum width of the bound (this is same as the diameter).
Definition: ballbound.hpp:106
VecType center
The center of the ball bound.
Definition: ballbound.hpp:45
double & Radius()
Modify the radius of the ball.
Definition: ballbound.hpp:92
double Dim() const
Get the dimensionality of the ball.
Definition: ballbound.hpp:100
If value == true, then VecType is some sort of Armadillo vector or subview.
Definition: arma_traits.hpp:37