sampling.mm.jd

sampling.mm.jd(X, p=1.0)

Computes and counts the distinct p-norm distances between all pairs of points in X. It returns: 1) A list of distinct distances (sorted), and 2) A corresponding multiplicity array that indicates how often each distance occurs.

Parameters

Name Type Description Default
X np.ndarray A 2D array of shape (n, d) representing n points in d-dimensional space. required
p float The distance norm to use. p=1 uses the Manhattan (L1) norm, while p=2 uses the Euclidean (L2) norm. Defaults to 1.0 (Manhattan norm). 1.0

Returns

Name Type Description
(np.ndarray, np.ndarray) A tuple (J, distinct_d), where: - distinct_d is a 1D float array of unique, sorted distances between points. - J is a 1D integer array that provides the multiplicity (occurrence count) of each distance in distinct_d.

Notes

Many thanks to the original author of this code, A Sobester, for providing the original Matlab code under the GNU Licence. Original Matlab Code: Copyright 2007 A Sobester: “This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU General Public License and GNU Lesser General Public License along with this program. If not, see http://www.gnu.org/licenses/.”

Examples

>>> import numpy as np
>>> from spotoptim.sampling.mm import jd
>>> # A small 3-point set in 2D
>>> X = np.array([[0.0, 0.0],
...               [1.0, 1.0],
...               [2.0, 2.0]])
>>> J, distinct_d = jd(X, p=2.0)
>>> print("Distinct distances:", distinct_d)
>>> print("Occurrences:", J)
# Possible output (using Euclidean norm):
# Distinct distances: [1.41421356 2.82842712]
# Occurrences: [1 1]
# Explanation: Distances are sqrt(2) between consecutive points and 2*sqrt(2) for the farthest pair.
    Distinct distances: [1.41421356 2.82842712]
    Occurrences: [2 1]