mlpack
Public Types | Public Member Functions | List of all members
mlpack::bound::BallBound< MetricType, VecType > Class Template Reference

Ball bound encloses a set of points at a specific distance (radius) from a specific point (center). More...

#include <ballbound.hpp>

Public Types

typedef VecType::elem_type ElemType
 The underlying data type.
 
typedef VecType Vec
 A public version of the vector type.
 

Public Member Functions

 BallBound ()
 Empty Constructor.
 
 BallBound (const size_t dimension)
 Create the ball bound with the specified dimensionality. More...
 
 BallBound (const ElemType radius, const VecType &center)
 Create the ball bound with the specified radius and center. More...
 
 BallBound (const BallBound &other)
 Copy constructor. To prevent memory leaks. More...
 
BallBoundoperator= (const BallBound &other)
 For the same reason as the copy constructor: to prevent memory leaks.
 
 BallBound (BallBound &&other)
 Move constructor: take possession of another bound. More...
 
BallBoundoperator= (BallBound &&other)
 Move assignment operator.
 
 ~BallBound ()
 Destructor to release allocated memory.
 
ElemType Radius () const
 Get the radius of the ball.
 
ElemTypeRadius ()
 Modify the radius of the ball.
 
const VecType & Center () const
 Get the center point of the ball.
 
VecType & Center ()
 Modify the center point of the ball.
 
size_t Dim () const
 Get the dimensionality of the ball.
 
ElemType MinWidth () const
 Get the minimum width of the bound (this is same as the diameter). More...
 
math::RangeType< ElemTypeoperator[] (const size_t i) const
 Get the range in a certain dimension.
 
bool Contains (const VecType &point) const
 Determines if a point is within this bound. More...
 
void Center (VecType &center) const
 Place the center of BallBound into the given vector. More...
 
template<typename OtherVecType >
ElemType MinDistance (const OtherVecType &point, typename std::enable_if_t< IsVector< OtherVecType >::value > *=0) const
 Calculates minimum bound-to-point squared distance. More...
 
ElemType MinDistance (const BallBound &other) const
 Calculates minimum bound-to-bound squared distance. More...
 
template<typename OtherVecType >
ElemType MaxDistance (const OtherVecType &point, typename std::enable_if_t< IsVector< OtherVecType >::value > *=0) const
 Computes maximum distance. More...
 
ElemType MaxDistance (const BallBound &other) const
 Computes maximum distance. More...
 
template<typename OtherVecType >
math::RangeType< ElemTypeRangeDistance (const OtherVecType &other, typename std::enable_if_t< IsVector< OtherVecType >::value > *=0) const
 Calculates minimum and maximum bound-to-point distance. More...
 
math::RangeType< ElemTypeRangeDistance (const BallBound &other) const
 Calculates minimum and maximum bound-to-bound distance. More...
 
const BallBoundoperator|= (const BallBound &other)
 Expand the bound to include the given node.
 
template<typename MatType >
const BallBoundoperator|= (const MatType &data)
 Expand the bound to include the given point. More...
 
ElemType Diameter () const
 Returns the diameter of the ballbound.
 
const MetricType & Metric () const
 Returns the distance metric used in this bound.
 
MetricType & Metric ()
 Modify the distance metric used in this bound.
 
template<typename Archive >
void serialize (Archive &ar, const uint32_t version)
 Serialize the bound. More...
 
template<typename OtherVecType >
math::RangeType< typename BallBound< MetricType, VecType >::ElemTypeRangeDistance (const OtherVecType &point, typename std::enable_if_t< IsVector< OtherVecType >::value > *) const
 Calculates minimum and maximum bound-to-bound squared distance. More...
 
template<typename MatType >
const BallBound< MetricType, VecType > & operator|= (const MatType &data)
 Expand the bound to include the given bound. More...
 

Detailed Description

template<typename MetricType = metric::LMetric<2, true>, typename VecType = arma::vec>
class mlpack::bound::BallBound< MetricType, VecType >

Ball bound encloses a set of points at a specific distance (radius) from a specific point (center).

MetricType is the custom metric type that defaults to the Euclidean (L2) distance.

Template Parameters
MetricTypemetric type used in the distance measure.
VecTypeType of vector (arma::vec or arma::sp_vec or similar).

Constructor & Destructor Documentation

◆ BallBound() [1/4]

template<typename MetricType , typename VecType >
mlpack::bound::BallBound< MetricType, VecType >::BallBound ( const size_t  dimension)

Create the ball bound with the specified dimensionality.

Parameters
dimensionDimensionality of ball bound.

◆ BallBound() [2/4]

template<typename MetricType , typename VecType>
mlpack::bound::BallBound< MetricType, VecType >::BallBound ( const ElemType  radius,
const VecType &  center 
)

Create the ball bound with the specified radius and center.

Parameters
radiusRadius of ball bound.
centerCenter of ball bound.

◆ BallBound() [3/4]

template<typename MetricType , typename VecType>
mlpack::bound::BallBound< MetricType, VecType >::BallBound ( const BallBound< MetricType, VecType > &  other)

Copy constructor. To prevent memory leaks.

Copy Constructor. To prevent memory leaks.

◆ BallBound() [4/4]

template<typename MetricType , typename VecType>
mlpack::bound::BallBound< MetricType, VecType >::BallBound ( BallBound< MetricType, VecType > &&  other)

Move constructor: take possession of another bound.

Move constructor.

Member Function Documentation

◆ Center()

template<typename MetricType = metric::LMetric<2, true>, typename VecType = arma::vec>
void mlpack::bound::BallBound< MetricType, VecType >::Center ( VecType &  center) const
inline

Place the center of BallBound into the given vector.

Parameters
centerVector which the centroid will be written to.

◆ Contains()

template<typename MetricType , typename VecType>
bool mlpack::bound::BallBound< MetricType, VecType >::Contains ( const VecType &  point) const

Determines if a point is within this bound.

Determines if a point is within the bound.

Parameters
pointPoint to check the condition.

◆ MaxDistance() [1/2]

template<typename MetricType , typename VecType >
template<typename OtherVecType >
BallBound< MetricType, VecType >::ElemType mlpack::bound::BallBound< MetricType, VecType >::MaxDistance ( const OtherVecType &  point,
typename std::enable_if_t< IsVector< OtherVecType >::value > *  = 0 
) const

Computes maximum distance.

Parameters
pointPoint to which the maximum distance is requested.

◆ MaxDistance() [2/2]

template<typename MetricType , typename VecType >
BallBound< MetricType, VecType >::ElemType mlpack::bound::BallBound< MetricType, VecType >::MaxDistance ( const BallBound< MetricType, VecType > &  other) const

Computes maximum distance.

Parameters
otherBound to which the maximum distance is requested.

◆ MinDistance() [1/2]

template<typename MetricType , typename VecType >
template<typename OtherVecType >
BallBound< MetricType, VecType >::ElemType mlpack::bound::BallBound< MetricType, VecType >::MinDistance ( const OtherVecType &  point,
typename std::enable_if_t< IsVector< OtherVecType >::value > *  = 0 
) const

Calculates minimum bound-to-point squared distance.

Parameters
pointPoint to which the minimum distance is requested.

◆ MinDistance() [2/2]

template<typename MetricType , typename VecType >
BallBound< MetricType, VecType >::ElemType mlpack::bound::BallBound< MetricType, VecType >::MinDistance ( const BallBound< MetricType, VecType > &  other) const

Calculates minimum bound-to-bound squared distance.

Parameters
otherBound to which the minimum distance is requested.

◆ MinWidth()

template<typename MetricType = metric::LMetric<2, true>, typename VecType = arma::vec>
ElemType mlpack::bound::BallBound< MetricType, VecType >::MinWidth ( ) const
inline

Get the minimum width of the bound (this is same as the diameter).

For ball bounds, width along all dimensions remain same.

◆ operator|=() [1/2]

template<typename MetricType = metric::LMetric<2, true>, typename VecType = arma::vec>
template<typename MatType >
const BallBound& mlpack::bound::BallBound< MetricType, VecType >::operator|= ( const MatType &  data)

Expand the bound to include the given point.

The centroid is recalculated to be the center of all of the given points.

Template Parameters
MatTypeType of matrix; could be arma::mat, arma::spmat, or a vector.
dataData points to add.

◆ operator|=() [2/2]

template<typename MetricType = metric::LMetric<2, true>, typename VecType = arma::vec>
template<typename MatType >
const BallBound<MetricType, VecType>& mlpack::bound::BallBound< MetricType, VecType >::operator|= ( const MatType &  data)

Expand the bound to include the given bound.

template<typename MetricType, typename VecType> const BallBound<VecType>& BallBound<MetricType, VecType>::operator|=( const BallBound<VecType>& other) { double dist = metric->Evaluate(center, other);

Now expand the radius as necessary. if (dist > radius) radius = dist;

return *this; } Expand the bound to include the given point. Algorithm adapted from Jack Ritter, "An Efficient Bounding Sphere" in Graphics Gems (1990). The difference lies in the way we initialize the ball bound. The way we expand the bound is same.

◆ RangeDistance() [1/3]

template<typename MetricType = metric::LMetric<2, true>, typename VecType = arma::vec>
template<typename OtherVecType >
math::RangeType<ElemType> mlpack::bound::BallBound< MetricType, VecType >::RangeDistance ( const OtherVecType &  other,
typename std::enable_if_t< IsVector< OtherVecType >::value > *  = 0 
) const

Calculates minimum and maximum bound-to-point distance.

Parameters
otherPoint to which the minimum and maximum distances are requested.

◆ RangeDistance() [2/3]

template<typename MetricType , typename VecType >
math::RangeType< typename BallBound< MetricType, VecType >::ElemType > mlpack::bound::BallBound< MetricType, VecType >::RangeDistance ( const BallBound< MetricType, VecType > &  other) const

Calculates minimum and maximum bound-to-bound distance.

Example: bound1.MinDistanceSq(other) for minimum distance.

Parameters
otherBound to which the minimum and maximum distances are requested.

◆ RangeDistance() [3/3]

template<typename MetricType = metric::LMetric<2, true>, typename VecType = arma::vec>
template<typename OtherVecType >
math::RangeType<typename BallBound<MetricType, VecType>::ElemType> mlpack::bound::BallBound< MetricType, VecType >::RangeDistance ( const OtherVecType &  point,
typename std::enable_if_t< IsVector< OtherVecType >::value > *   
) const

Calculates minimum and maximum bound-to-bound squared distance.

Example: bound1.MinDistanceSq(other) for minimum squared distance.

◆ serialize()

template<typename MetricType , typename VecType >
template<typename Archive >
void mlpack::bound::BallBound< MetricType, VecType >::serialize ( Archive &  ar,
const uint32_t  version 
)

Serialize the bound.

Serialize the BallBound.


The documentation for this class was generated from the following files: