---
name: "mlpack_metric_LMetric"
section: "3"
platform: "linux"
package: "mlpack-doc"
version: "1.0.10-1"
release: "Debian 8 (Jessie)"
platforms: ["linux"]
url: "https://new.carta.tech/mlpack_metric_LMetric"
---

# mlpack\_metric\_LMetric(3)

The L\_p metric for arbitrary integer p, with an option to take the root.

## NAME

mlpack::metric::LMetric\< Power, TakeRoot \> -

The L\_p metric for arbitrary integer p, with an option to take the root.

## SYNOPSIS

### Public Member Functions

**LMetric** ()\
 std::string **ToString** () const \

### Static Public Member Functions

template\<typename VecType1 , typename VecType2 \> static double **Evaluate** (const VecType1 &a, const VecType2 &b)\
 *Computes the distance between two points.*

## Detailed Description

### template\<int Power, bool TakeRoot = true\>class mlpack::metric::LMetric\< Power, TakeRoot \>

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 $:

.PP 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,

.PP 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:

- •

  ManhattanDistance

- •

  EuclideanDistance

- •

  SquaredEuclideanDistance

**Template Parameters:**

*Power* Power of metric; i.e. Power = 1 gives the L1-norm (Manhattan distance). \
 *TakeRoot* If 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 73 of file lmetric.hpp.

## Constructor & Destructor Documentation

### template\<int Power, bool TakeRoot = true\> mlpack::metric::LMetric\< Power, TakeRoot \>::LMetric ()` [inline]`

Definition at line 80 of file lmetric.hpp.

## Member Function Documentation

### template\<int Power, bool TakeRoot = true\> template\<typename VecType1 , typename VecType2 \> static double mlpack::metric::LMetric\< Power, TakeRoot \>::Evaluate (const VecType1 &a, const VecType2 &b)` [static]`

Computes the distance between two points.

Referenced by mlpack::kernel::SphericalKernel::ConvolutionIntegral(), mlpack::kernel::GaussianKernel::ConvolutionIntegral(), mlpack::kernel::SphericalKernel::Evaluate(), mlpack::kernel::TriangularKernel::Evaluate(), mlpack::kernel::LaplacianKernel::Evaluate(), and mlpack::kernel::GaussianKernel::Evaluate().

### template\<int Power, bool TakeRoot = true\> std::string mlpack::metric::LMetric\< Power, TakeRoot \>::ToString () const

## Author

Generated automatically by Doxygen for MLPACK from the source code.
