numpy - Implementing Discrete Gaussian Kernel in Python? -
i'm looking implement discrete gaussian kernel defined lindeberg in work scale space theory.
it defined t(n,t) = exp(-t)*i_n(t) i_n modified bessel function of first kind.
i trying implement in python using numpy , scipy running trouble.
def discrete_gaussian_kernel(t, n): return math.exp(-t) * scipy.special.iv(n, t)
i try plotting with:
import math import numpy np import scipy matplotlib import pyplot plt def kernel(t, n): return math.exp(-t) * scipy.special.iv(n, t) ns = np.linspace(-5, 5, 1000) y0 = discrete_gaussian_kernel(0.5, ns) y1 = discrete_gaussian_kernel(1, ns) y2 = discrete_gaussian_kernel(2, ns) y3 = discrete_gaussian_kernel(4, ns) plt.plot(ns, y0, ns, y1, ns, y2, ns, y3) plt.xlim([-4, 4]) plt.ylim([0, 0.7])
the output looks like:
from wikipedia article, should like:
i assume i'm making trivial mistake. :/ thoughts? thanks!
edit: wrote equivalent scipy.special.ive(n, t)
. i'm pretty sure it's supposed modified bessel function of first kind, not second, can confirm?
if want wikipedia plot, replace
ns = np.linspace(-5, 5, 1000)
with
ns = np.arange(-5, 5+1)
namely, formula use makes sense @ integer points. bessel function function of negative order oscillating function, http://dlmf.nist.gov/10.27#e2 plot looks fine me.
Comments
Post a Comment