12 #ifndef MLPACK_CORE_TREE_BALLBOUND_IMPL_HPP 13 #define MLPACK_CORE_TREE_BALLBOUND_IMPL_HPP 25 template<
typename MetricType,
typename VecType>
28 metric(new MetricType()),
37 template<
typename MetricType,
typename VecType>
41 metric(new MetricType()),
51 template<
typename MetricType,
typename VecType>
53 const VecType& center) :
56 metric(new MetricType()),
61 template<
typename MetricType,
typename VecType>
70 template<
typename MetricType,
typename VecType>
76 radius = other.radius;
77 center = other.center;
78 metric = other.metric;
85 template<
typename MetricType,
typename VecType>
90 ownsMetric(other.ownsMetric)
94 other.center = VecType();
96 other.ownsMetric =
false;
100 template<
typename MetricType,
typename VecType>
106 radius = other.radius;
107 center = std::move(other.center);
108 metric = other.metric;
109 ownsMetric = other.ownsMetric;
112 other.center = VecType();
113 other.metric =
nullptr;
114 other.ownsMetric =
false;
120 template<
typename MetricType,
typename VecType>
128 template<
typename MetricType,
typename VecType>
135 return math::Range(center[i] - radius, center[i] + radius);
141 template<
typename MetricType,
typename VecType>
147 return metric->Evaluate(center, point) <= radius;
153 template<
typename MetricType,
typename VecType>
154 template<
typename OtherVecType>
157 const OtherVecType& point,
161 return std::numeric_limits<ElemType>::max();
169 template<
typename MetricType,
typename VecType>
175 return std::numeric_limits<ElemType>::max();
178 const ElemType delta = metric->Evaluate(center, other.center) - radius -
187 template<
typename MetricType,
typename VecType>
188 template<
typename OtherVecType>
191 const OtherVecType& point,
195 return std::numeric_limits<ElemType>::max();
197 return metric->Evaluate(point, center) + radius;
203 template<
typename MetricType,
typename VecType>
209 return std::numeric_limits<ElemType>::max();
211 return metric->Evaluate(other.center, center) + radius + other.radius;
219 template<
typename MetricType,
typename VecType>
220 template<
typename OtherVecType>
223 const OtherVecType& point,
227 return math::Range(std::numeric_limits<ElemType>::max(),
228 std::numeric_limits<ElemType>::max());
231 const ElemType dist = metric->Evaluate(center, point);
237 template<
typename MetricType,
typename VecType>
243 return math::Range(std::numeric_limits<ElemType>::max(),
244 std::numeric_limits<ElemType>::max());
247 const ElemType dist = metric->Evaluate(center, other.center);
248 const ElemType sumradius = radius + other.radius;
277 template<
typename MetricType,
typename VecType>
278 template<
typename MatType>
284 center = data.col(0);
289 for (
size_t i = 0; i < data.n_cols; ++i)
291 const ElemType dist = metric->Evaluate(center, (VecType) data.col(i));
298 const VecType diff = data.col(i) - center;
299 center += ((dist - radius) / (2 * dist)) * diff;
300 radius = 0.5 * (dist + radius);
308 template<
typename MetricType,
typename VecType>
309 template<
typename Archive>
314 ar(CEREAL_NVP(radius));
315 ar(CEREAL_NVP(center));
317 if (cereal::is_loading<Archive>())
325 ar(CEREAL_NVP(ownsMetric));
331 #endif // MLPACK_CORE_TREE_DBALLBOUND_IMPL_HPP double ClampNonNegative(const double d)
Forces a number to be non-negative, turning negative numbers into zero.
Definition: clamp.hpp:28
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
BallBound()
Empty Constructor.
Definition: ballbound_impl.hpp:26
Definition: pointer_wrapper.hpp:23
RangeType< double > Range
3.0.0 TODO: break reverse-compatibility by changing RangeType to Range.
Definition: range.hpp:19
Miscellaneous math clamping routines.
Ball bound encloses a set of points at a specific distance (radius) from a specific point (center)...
Definition: ballbound.hpp:32
~BallBound()
Destructor to release allocated memory.
Definition: ballbound_impl.hpp:121
bool Contains(const VecType &point) const
Determines if a point is within this bound.
Definition: ballbound_impl.hpp:142
Simple real-valued range.
Definition: range.hpp:19
Bounds that are useful for binary space partitioning trees.
VecType::elem_type ElemType
The underlying data type.
Definition: ballbound.hpp:36
#define CEREAL_POINTER(T)
Cereal does not support the serialization of raw pointer.
Definition: pointer_wrapper.hpp:96
ElemType MinDistance(const OtherVecType &point, typename std::enable_if_t< IsVector< OtherVecType >::value > *=0) const
Calculates minimum bound-to-point squared distance.
Definition: ballbound_impl.hpp:156
BallBound & operator=(const BallBound &other)
For the same reason as the copy constructor: to prevent memory leaks.
Definition: ballbound_impl.hpp:71
ElemType MaxDistance(const OtherVecType &point, typename std::enable_if_t< IsVector< OtherVecType >::value > *=0) const
Computes maximum distance.
Definition: ballbound_impl.hpp:190
math::RangeType< ElemType > operator[](const size_t i) const
Get the range in a certain dimension.
Definition: ballbound_impl.hpp:130
void serialize(Archive &ar, const uint32_t version)
Serialize the bound.
Definition: ballbound_impl.hpp:310
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.
const BallBound & operator|=(const BallBound &other)
Expand the bound to include the given node.
If value == true, then VecType is some sort of Armadillo vector or subview.
Definition: arma_traits.hpp:35