only do scipy imports when necessary
import logging
import math
-import numpy as np
import torch
-from scipy.fftpack import fft
-from scipy.integrate import cumtrapz
from ..constraints import Positive
from .kernel import Kernel
@@ -157,6 +154,10 @@ class SpectralMixtureKernel(Kernel):
This will often be better than the standard initialize_from_data method.
"""
+ import numpy as np
+ from scipy.fftpack import fft
+ from scipy.integrate import cumtrapz
+
N = train_x.size(-2)
emp_spect = np.abs(fft(train_y.cpu().detach().numpy())) ** 2 / N
M = math.floor(N / 2)
