mlpack  master
Public Types | Public Member Functions | Private Attributes | 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...

Public Types

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

Public Member Functions

 BallBound ()
 Empty Constructor. More...
 
 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...
 
 BallBound (BallBound &&other)
 Move constructor: take possession of another bound. More...
 
 ~BallBound ()
 Destructor to release allocated memory. More...
 
const VecType & Center () const
 Get the center point of the ball. More...
 
VecType & Center ()
 Modify the center point of the ball. More...
 
void Center (VecType &center) const
 Place the center of BallBound into the given vector. More...
 
bool Contains (const VecType &point) const
 Determines if a point is within this bound. More...
 
ElemType Diameter () const
 Returns the diameter of the ballbound. More...
 
size_t Dim () const
 Get the dimensionality of the ball. 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...
 
const MetricType & Metric () const
 Returns the distance metric used in this bound. More...
 
MetricType & Metric ()
 Modify the distance metric used in this bound. 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...
 
ElemType MinWidth () const
 Get the minimum width of the bound (this is same as the diameter). More...
 
BallBoundoperator= (const BallBound &other)
 For the same reason as the copy constructor: to prevent memory leaks. More...
 
math::RangeType< ElemTypeoperator[] (const size_t i) const
 Get the range in a certain dimension. More...
 
const BallBoundoperator|= (const BallBound &other)
 Expand the bound to include the given node. More...
 
template<typename MatType >
const BallBoundoperator|= (const MatType &data)
 Expand the bound to include the given point. More...
 
ElemType Radius () const
 Get the radius of the ball. More...
 
ElemTypeRadius ()
 Modify the radius of the ball. 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...
 
template<typename Archive >
void Serialize (Archive &ar, const unsigned int version)
 Serialize the bound. More...
 

Private Attributes

VecType center
 The center of the ball bound. More...
 
MetricType * metric
 The metric used in this bound. More...
 
bool ownsMetric
 To know whether this object allocated memory to the metric member variable. More...
 
ElemType radius
 The radius of the ball 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).

Definition at line 32 of file ballbound.hpp.

Member Typedef Documentation

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

The underlying data type.

Definition at line 36 of file ballbound.hpp.

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

A public version of the vector type.

Definition at line 38 of file ballbound.hpp.

Constructor & Destructor Documentation

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

Empty Constructor.

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

Create the ball bound with the specified dimensionality.

Parameters
dimensionDimensionality of ball bound.
template<typename MetricType = metric::LMetric<2, true>, typename VecType = arma::vec>
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.
template<typename MetricType = metric::LMetric<2, true>, typename VecType = arma::vec>
mlpack::bound::BallBound< MetricType, VecType >::BallBound ( const BallBound< MetricType, VecType > &  other)

Copy constructor. To prevent memory leaks.

template<typename MetricType = metric::LMetric<2, true>, typename VecType = arma::vec>
mlpack::bound::BallBound< MetricType, VecType >::BallBound ( BallBound< MetricType, VecType > &&  other)

Move constructor: take possession of another bound.

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

Destructor to release allocated memory.

Member Function Documentation

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

Get the center point of the ball.

Definition at line 94 of file ballbound.hpp.

References mlpack::bound::BallBound< MetricType, VecType >::center.

Referenced by mlpack::tree::ProjVector::Project().

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

Modify the center point of the ball.

Definition at line 96 of file ballbound.hpp.

References mlpack::bound::BallBound< MetricType, VecType >::center.

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

Determines if a point is within this bound.

Referenced by mlpack::bound::BallBound< MetricType, VecType >::MinWidth().

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

Returns the diameter of the ballbound.

Definition at line 182 of file ballbound.hpp.

References mlpack::bound::BallBound< MetricType, VecType >::radius.

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

Get the dimensionality of the ball.

Definition at line 99 of file ballbound.hpp.

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

Computes maximum distance.

Referenced by mlpack::bound::BallBound< MetricType, VecType >::Center().

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

Computes maximum distance.

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

Returns the distance metric used in this bound.

Definition at line 185 of file ballbound.hpp.

References mlpack::bound::BallBound< MetricType, VecType >::metric.

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

Modify the distance metric used in this bound.

Definition at line 187 of file ballbound.hpp.

References mlpack::bound::BallBound< MetricType, VecType >::metric, and mlpack::bound::BallBound< MetricType, VecType >::Serialize().

template<typename MetricType = metric::LMetric<2, true>, typename VecType = arma::vec>
template<typename OtherVecType >
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.

Referenced by mlpack::bound::BallBound< MetricType, VecType >::Center().

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

Calculates minimum bound-to-bound squared distance.

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.

Definition at line 105 of file ballbound.hpp.

References mlpack::bound::BallBound< MetricType, VecType >::Contains(), and mlpack::bound::BallBound< MetricType, VecType >::operator[]().

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

For the same reason as the copy constructor: to prevent memory leaks.

template<typename MetricType = metric::LMetric<2, true>, typename VecType = arma::vec>
math::RangeType<ElemType> mlpack::bound::BallBound< MetricType, VecType >::operator[] ( const size_t  i) const

Get the range in a certain dimension.

Referenced by mlpack::bound::BallBound< MetricType, VecType >::MinWidth().

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

Expand the bound to include the given node.

Referenced by mlpack::bound::BallBound< MetricType, VecType >::Center().

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.
template<typename MetricType = metric::LMetric<2, true>, typename VecType = arma::vec>
ElemType mlpack::bound::BallBound< MetricType, VecType >::Radius ( ) const
inline

Get the radius of the ball.

Definition at line 89 of file ballbound.hpp.

References mlpack::bound::BallBound< MetricType, VecType >::radius.

Referenced by mlpack::tree::ProjVector::Project().

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

Modify the radius of the ball.

Definition at line 91 of file ballbound.hpp.

References mlpack::bound::BallBound< MetricType, VecType >::radius.

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.

Referenced by mlpack::bound::BallBound< MetricType, VecType >::Center().

template<typename MetricType = metric::LMetric<2, true>, typename VecType = arma::vec>
math::RangeType<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.

template<typename MetricType = metric::LMetric<2, true>, typename VecType = arma::vec>
template<typename Archive >
void mlpack::bound::BallBound< MetricType, VecType >::Serialize ( Archive &  ar,
const unsigned int  version 
)

Serialize the bound.

Referenced by mlpack::bound::BallBound< MetricType, VecType >::Metric().

Member Data Documentation

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

The center of the ball bound.

Definition at line 44 of file ballbound.hpp.

Referenced by mlpack::bound::BallBound< MetricType, VecType >::Center().

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

The metric used in this bound.

Definition at line 46 of file ballbound.hpp.

Referenced by mlpack::bound::BallBound< MetricType, VecType >::Metric().

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

To know whether this object allocated memory to the metric member variable.

This will be true except in the copy constructor and the overloaded assignment operator. We need this to know whether we should delete the metric member variable in the destructor.

Definition at line 54 of file ballbound.hpp.

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

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