mlpack  master
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
mlpack::metric::LMetric< TPower, TTakeRoot > Class Template Reference

The L_p metric for arbitrary integer p, with an option to take the root. More...

Public Member Functions

 LMetric ()
 
template<typename Archive >
void Serialize (Archive &, const unsigned int)
 Serialize the metric (nothing to do). More...
 

Static Public Member Functions

template<typename VecTypeA , typename VecTypeB >
static VecTypeA::elem_type Evaluate (const VecTypeA &a, const VecTypeB &b)
 Computes the distance between two points. More...
 

Static Public Attributes

static const int Power = TPower
 The power of the metric. More...
 
static const bool TakeRoot = TTakeRoot
 Whether or not the root is taken. More...
 

Detailed Description

template<int TPower, bool TTakeRoot = true>
class mlpack::metric::LMetric< TPower, TTakeRoot >

The L_p metric for arbitrary integer p, with an option to take the root.

This class implements the standard L_p metric for two arbitrary vectors $ x $ and $ y $ of dimensionality $ n $:

\[ d(x, y) = \left( \sum_{i = 1}^{n} | x_i - y_i |^p \right)^{\frac{1}{p}}. \]

The value of p is given as a template parameter.

In addition, the function $ d(x, y) $ can be simplified, neglecting the p-root calculation. This is done by specifying the TakeRoot template parameter to be false. Then,

\[ d(x, y) = \sum_{i = 1}^{n} | x_i - y_i |^p \]

It is faster to compute that distance, so TakeRoot is by default off. However, when TakeRoot is false, the distance given is not actually a true metric – it does not satisfy the triangle inequality. Some mlpack methods do not require the triangle inequality to operate correctly (such as the BinarySpaceTree), but setting TakeRoot = false in some cases will cause incorrect results.

A few convenience typedefs are given:

Template Parameters
PowerPower of metric; i.e. Power = 1 gives the L1-norm (Manhattan distance).
TakeRootIf true, the Power'th root of the result is taken before it is returned. Setting this to false causes the metric to not satisfy the Triangle Inequality (be careful!).

Definition at line 63 of file lmetric.hpp.

Constructor & Destructor Documentation

template<int TPower, bool TTakeRoot = true>
mlpack::metric::LMetric< TPower, TTakeRoot >::LMetric ( )
inline

Member Function Documentation

template<int TPower, bool TTakeRoot = true>
template<typename VecTypeA , typename VecTypeB >
static VecTypeA::elem_type mlpack::metric::LMetric< TPower, TTakeRoot >::Evaluate ( const VecTypeA &  a,
const VecTypeB &  b 
)
static

Computes the distance between two points.

Template Parameters
VecTypeAType of first vector (generally arma::vec or arma::sp_vec).
VecTypeBType of second vector.
Parameters
aFirst vector.
bSecond vector.
Returns
Distance between vectors a and b.

Referenced by mlpack::kernel::SphericalKernel::ConvolutionIntegral(), mlpack::kernel::GaussianKernel::ConvolutionIntegral(), mlpack::kernel::SphericalKernel::Evaluate(), mlpack::kernel::TriangularKernel::Evaluate(), mlpack::kernel::LaplacianKernel::Evaluate(), mlpack::kernel::GaussianKernel::Evaluate(), and mlpack::metric::LMetric< TPower, TTakeRoot >::LMetric().

template<int TPower, bool TTakeRoot = true>
template<typename Archive >
void mlpack::metric::LMetric< TPower, TTakeRoot >::Serialize ( Archive &  ,
const unsigned  int 
)
inline

Serialize the metric (nothing to do).

Definition at line 88 of file lmetric.hpp.

Member Data Documentation

template<int TPower, bool TTakeRoot = true>
const int mlpack::metric::LMetric< TPower, TTakeRoot >::Power = TPower
static

The power of the metric.

Definition at line 91 of file lmetric.hpp.

template<int TPower, bool TTakeRoot = true>
const bool mlpack::metric::LMetric< TPower, TTakeRoot >::TakeRoot = TTakeRoot
static

Whether or not the root is taken.

Definition at line 93 of file lmetric.hpp.


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