Distance metrics

Implementations of common distance metrics.

Author

Simone Balducci

namespace clue

Typedefs

template<std::size_t Ndim, std::floating_point TData>
using Point = std::array<TData, Ndim + 1>
template<std::size_t Ndim, std::floating_point TData = float>
class ChebyshevMetric
#include <DistanceMetrics.hpp>

Chebyshev distance metric This class implements the Chebyshev distance metric in Ndim dimensions.

Template Parameters:
std::size_t Ndim

Number of dimensions

std::floating_point TData = float

Data type for the coordinates

Public Types

using value_type = std::remove_cv_t<std::remove_reference_t<TData>>

Public Functions

ALPAKA_FN_HOST_ACC inline constexpr ChebyshevMetric()

Default constructor.

ALPAKA_FN_HOST_ACC inline constexpr auto operator()(const Point<Ndim, value_type> &lhs, const Point<Ndim, value_type> &rhs) const

Compute the Chebyshev distance between two points.

Parameters:
const Point<Ndim, value_type> &lhs

First point

const Point<Ndim, value_type> &rhs

Second point

Returns:

Chebyshev distance between the two points

template<std::size_t Ndim, std::floating_point TData = float>
class EuclideanMetric
#include <DistanceMetrics.hpp>

Euclidean distance metric.

This class implements the Euclidean distance metric in Ndim dimensions.

Template Parameters:
std::size_t Ndim

Number of dimensions

std::floating_point TData = float

Data type for the coordinates

Public Types

using value_type = std::remove_cv_t<std::remove_reference_t<TData>>

Public Functions

ALPAKA_FN_HOST_ACC inline constexpr EuclideanMetric()

Default constructor.

Returns:

EuclideanMetric object

ALPAKA_FN_HOST_ACC inline constexpr auto operator()(const Point<Ndim, value_type> &lhs, const Point<Ndim, value_type> &rhs) const

Compute the Euclidean distance between two points.

Parameters:
const Point<Ndim, value_type> &lhs

First point

const Point<Ndim, value_type> &rhs

Second point

Returns:

Euclidean distance between the two points

template<std::size_t Ndim, std::floating_point TData = float>
class ManhattanMetric
#include <DistanceMetrics.hpp>

Manhattan distance metric This class implements the Manhattan distance metric in Ndim dimensions.

Template Parameters:
std::size_t Ndim

Number of dimensions

std::floating_point TData = float

Data type for the coordinates

Public Types

using value_type = std::remove_cv_t<std::remove_reference_t<TData>>

Public Functions

ALPAKA_FN_HOST_ACC inline constexpr ManhattanMetric()

Default constructor.

ALPAKA_FN_HOST_ACC inline constexpr auto operator()(const Point<Ndim, value_type> &lhs, const Point<Ndim, value_type> &rhs) const

Compute the Manhattan distance between two points.

Parameters:
const Point<Ndim, value_type> &lhs

First point

const Point<Ndim, value_type> &rhs

Second point

Returns:

Manhattan distance between the two points

template<std::size_t Ndim, std::floating_point TData = float>
class PeriodicEuclideanMetric
#include <DistanceMetrics.hpp>

Periodic Euclidean distance metric This class implements the Euclidean distance metric in Ndim dimensions for coordinate systems where one or more coordinates are defined in a periodic domain. The distance is then computed by treating the coordinates as euclidean.. This metric expects a period for each dimension, where a period equal to 0 means that the coordinate is not periodic. The periodic coordinates are expected to be defined in the range [0, period).

Template Parameters:
std::size_t Ndim

Number of dimensions

std::floating_point TData = float

Data type for the coordinates

Public Types

using value_type = std::remove_cv_t<std::remove_reference_t<TData>>

Public Functions

ALPAKA_FN_HOST_ACC inline constexpr PeriodicEuclideanMetric(const std::array<value_type, Ndim> &periods)

Constructor periodic euclidian metric with periods.

Parameters:
const std::array<value_type, Ndim> &periods

Periods for each dimension If a coordinate is not periodic, the corresponding period should be set to 0.f

Returns:

PeriodicEuclideanMetric object

ALPAKA_FN_HOST_ACC inline constexpr PeriodicEuclideanMetric(std::array<value_type, Ndim> &&periods)

Move constructor periodic euclidian metric with periods.

Parameters:
std::array<value_type, Ndim> &&periods

Periods for each dimension If a coordinate is not periodic, the corresponding period should be set to 0.f

Returns:

PeriodicEuclideanMetric object

ALPAKA_FN_HOST_ACC inline constexpr auto operator()(const Point<Ndim, value_type> &lhs, const Point<Ndim, value_type> &rhs) const

Compute the Periodic Euclidean distance between two points.

Parameters:
const Point<Ndim, value_type> &lhs

First point

const Point<Ndim, value_type> &rhs

Second point

Returns:

Periodic Euclidean distance between the two points

Private Members

std::array<value_type, Ndim> m_periods
template<std::size_t Ndim, std::floating_point TData = float>
class WeightedChebyshevMetric
#include <DistanceMetrics.hpp>

Weighted Chebyshev distance metric This class implements the weighted Chebyshev distance metric in Ndim dimensions.

Template Parameters:
std::size_t Ndim

Number of dimensions

std::floating_point TData = float

Data type for the coordinates

Public Types

using value_type = std::remove_cv_t<std::remove_reference_t<TData>>

Public Functions

template<std::floating_point... TValues>
ALPAKA_FN_HOST_ACC inline constexpr WeightedChebyshevMetric(TValues... weights)

Constructor weighted chebyshev metric with weights.

Parameters:
TValues... weights

Weights for each dimension

Returns:

WeightedChebyshevMetric object

ALPAKA_FN_HOST_ACC inline constexpr WeightedChebyshevMetric(const std::array<value_type, Ndim> &weights)

Constructor weighted chebyshev metric with weights.

Parameters:
const std::array<value_type, Ndim> &weights

Weights for each dimension

Returns:

WeightedChebyshevMetric object

ALPAKA_FN_HOST_ACC inline constexpr WeightedChebyshevMetric(std::array<value_type, Ndim> &&weights)

Move constructor weighted chebyshev metric with weights.

Parameters:
std::array<value_type, Ndim> &&weights

Weights for each dimension

Returns:

WeightedChebyshevMetric object

ALPAKA_FN_HOST_ACC inline constexpr auto operator()(const Point<Ndim, value_type> &lhs, const Point<Ndim, value_type> &rhs) const

Compute the Weighted Chebyshev distance between two points.

Parameters:
const Point<Ndim, value_type> &lhs

First point

const Point<Ndim, value_type> &rhs

Second point

Returns:

Weighted Chebyshev distance between the two points

Private Members

std::array<value_type, Ndim> m_weights
template<std::size_t Ndim, std::floating_point TData = float>
class WeightedEuclideanMetric
#include <DistanceMetrics.hpp>

Weighted Euclidean distance metric This class implements the Weighted Euclidean distance metric in Ndim dimensions.

Template Parameters:
std::size_t Ndim

Number of dimensions

std::floating_point TData = float

Data type for the coordinates

Public Types

using value_type = std::remove_cv_t<std::remove_reference_t<TData>>

Public Functions

template<std::floating_point... TValues>
ALPAKA_FN_HOST_ACC inline constexpr WeightedEuclideanMetric(TValues... weights)

Constructor euclidian metric with weights.

Parameters:
TValues... weights

Weights for each dimension

Returns:

WeightedEuclideanMetric object

ALPAKA_FN_HOST_ACC inline constexpr WeightedEuclideanMetric(const std::array<value_type, Ndim> &weights)

Constructor euclidian metric with weights.

Parameters:
const std::array<value_type, Ndim> &weights

Weights for each dimension

Returns:

WeightedEuclideanMetric object

ALPAKA_FN_HOST_ACC inline constexpr WeightedEuclideanMetric(std::array<value_type, Ndim> &&weights)

Move constructor euclidian metric with weights.

Parameters:
std::array<value_type, Ndim> &&weights

Weights for each dimension

Returns:

WeightedEuclideanMetric object

ALPAKA_FN_HOST_ACC inline constexpr auto operator()(const Point<Ndim, value_type> &lhs, const Point<Ndim, value_type> &rhs) const

Compute the Weighted Euclidean distance between two points.

Parameters:
const Point<Ndim, value_type> &lhs

First point

const Point<Ndim, value_type> &rhs

Second point

Returns:

Weighted Euclidean distance between the two points

Private Members

std::array<value_type, Ndim> m_weights
namespace concepts
namespace metrics

Typedefs

template<std::size_t Ndim, std::floating_point TData = float>
using Euclidean = clue::EuclideanMetric<Ndim, TData>

Alias for Euclidean distance metric.

@tparam Ndim Number of dimensions
@tparam TData Point coordinates and weights data type
template<std::size_t Ndim, std::floating_point TData = float>
using WeightedEuclidean = clue::WeightedEuclideanMetric<Ndim, TData>

Alias for Weighted Euclidean distance metric.

@tparam Ndim Number of dimensions
@tparam TData Point coordinates and weights data type
template<std::size_t Ndim, std::floating_point TData = float>
using PeriodicEuclidean = clue::PeriodicEuclideanMetric<Ndim, TData>

Alias for Periodic Euclidean distance metric.

@tparam Ndim Number of dimensions
@tparam TData Point coordinates and weights data type
template<std::size_t Ndim, std::floating_point TData = float>
using Manhattan = clue::ManhattanMetric<Ndim, TData>

Alias for Manhattan distance metric.

@tparam Ndim Number of dimensions
@tparam TData Point coordinates and weights data type
template<std::size_t Ndim, std::floating_point TData = float>
using Chebyshev = clue::ChebyshevMetric<Ndim, TData>

Alias for Chebyshev distance metric.

@tparam Ndim Number of dimensions
@tparam TData Point coordinates and weights data type
template<std::size_t Ndim, std::floating_point TData = float>
using WeightedChebyshev = clue::WeightedChebyshevMetric<Ndim, TData>

Alias for Weighted Chebyshev distance metric.

@tparam Ndim Number of dimensions
@tparam TData Point coordinates and weights data type