ot.dist with metric='minkowski' always gives p=1 despite setting it to other values
luchungi opened this issue · 3 comments
Describe the bug
ot.dist with metric='minkowski' always gives p=1 despite setting it to other values
To Reproduce
See code sample
Screenshots
Code sample
import numpy as np
import matplotlib.pyplot as plt
import ot
x = np.linspace(0, 1, 1001)
M1 = ot.dist(x.reshape(-1, 1), metric='minkowski', p=1)
M2 = ot.dist(x.reshape(-1, 1), metric='minkowski', p=2)
E1 = ot.dist(x.reshape(-1, 1), metric='euclidean')
E2 = ot.dist(x.reshape(-1, 1), metric='sqeuclidean')
fig, ax = plt.subplots(1, 4, figsize=(20, 4))
ax[0].plot(M1[500])
ax[0].set_title('Minkowski p=1')
ax[1].plot(M2[500])
ax[1].set_title('Minkowski p=2')
ax[2].plot(E1[500])
ax[2].set_title('Euclidean')
ax[3].plot(E2[500])
ax[3].set_title('Squared Euclidean')
Expected behavior
E.g. setting p=2 should produce the same result is sqeuclidean
Environment (please complete the following information):
- OS (e.g. MacOS, Windows, Linux): MacOS
- Python version: 3.10.16
- How was POT installed (source,
pip
,conda
): pip
Output of the following code snippet:
macOS-15.1.1-arm64-arm-64bit
Python 3.10.16 | packaged by conda-forge | (main, Dec 5 2024, 14:20:01) [Clang 18.1.8 ]
NumPy 1.26.4
SciPy 1.15.0
POT 0.9.5
Oups this is not OK. We will look into it. Feel free to propose a fix in PR if you find where the problem is.
Ho but on tre other hand, the minkowski in 1d is always the same because it is (|.|^p)^{1/p} which is absolute value. Note that square euclidian is |.|^2 that is why it is different. Could you check that it returns different distances in 2D please?
Ah of course! Silly me.. It all works fine. I will close this.