-
Notifications
You must be signed in to change notification settings - Fork 356
Open
Description
Describe the bug
gak(x,y)
returns nan
for all x,y
.
To Reproduce
import random
import numpy
from math import pi as π
from tslearn.metrics import sigma_gak, gak
def test_reproduce():
f0 = 20e9
period = 1/f0
ω0 = 2*π*f0
# works at length 405; dies at 410:
waveforms = numpy.empty(shape=(5, 410))
times = numpy.linspace(-period/2, period/2, waveforms.shape[1])
for i in range(waveforms.shape[0]):
φ = random.gauss(0.0, 0.5)
k = 3 + random.uniform(-0.5, 0.5)
waveforms[i, :] = 0.5*(numpy.tanh(k*ω0*times + φ) + 1) + random.uniform(-0.05, 0.05)
typical_values = 0.5*(numpy.tanh(3*ω0*times) + 1)
σ = sigma_gak(typical_values)
scores = numpy.empty(waveforms.shape[0])
for i in range(waveforms.shape[0]):
scores[i] = gak(typical_values, waveforms[i, :], sigma=σ)
print(scores)
print(gak(waveforms[0, :], waveforms[0, :], sigma=σ))
Expected behavior
The computation should not return NaN; maybe it needs to be stabilized with the log-sum-exp method?
Environment (please complete the following information):
- OS: ARM MacOS
- tslearn version: 0.6.3