helpers.distance_matrix

helpers.distance_matrix(arr, metric='euclidean', p=2)

Distance matrix based on specified distance measure

Parameters

Name Type Description Default
arr numpy.numpy.ndarray A design matrix required
metric str Specifiy the following distance measure: ‘euclidean’: Usual distance between the two vectors (L_2 norm) ‘maximum’: Maximum distance between two components of x and y (supremum norm) ‘manhattan’: Absolute distance between the two vectors (L_1 norm) ‘minkowski’: The p norm, the pth root of the sum of the pth powers of the differences of the components 'euclidean'
p int The power of the Minkowski distance. Defaults to 2. 2

Returns

Type Description
numpy.numpy.ndarray The calculated distance matrix baed on specified distance measure

Examples:

import pyLHD
random_lhd = pyLHD.LatinHypercube(size = (5,3))
pyLHD.distance_matrix(random_lhd)
array([[0.        , 0.66332496, 0.84852814, 0.74833148, 0.82462113],
       [0.66332496, 0.        , 0.6       , 0.6       , 0.48989795],
       [0.84852814, 0.6       , 0.        , 1.16619038, 1.07703296],
       [0.74833148, 0.6       , 1.16619038, 0.        , 0.34641016],
       [0.82462113, 0.48989795, 1.07703296, 0.34641016, 0.        ]])
pyLHD.distance_matrix(random_lhd, metric = 'manhattan')
array([[0. , 1. , 1.2, 1.2, 1.4],
       [1. , 0. , 1. , 1. , 0.8],
       [1.2, 1. , 0. , 2. , 1.8],
       [1.2, 1. , 2. , 0. , 0.6],
       [1.4, 0.8, 1.8, 0.6, 0. ]])
pyLHD.distance_matrix(random_lhd, metric = 'minkowski', p=5)
array([[0.        , 0.60098442, 0.80031226, 0.61547698, 0.62872057],
       [0.60098442, 0.        , 0.46090632, 0.46090632, 0.40487949],
       [0.80031226, 0.46090632, 0.        , 0.86462021, 0.83898042],
       [0.61547698, 0.46090632, 0.86462021, 0.        , 0.24914619],
       [0.62872057, 0.40487949, 0.83898042, 0.24914619, 0.        ]])