performance - Why is fitting a polynomial faster than changing polynomial basis? -
given data points on interval [–1, 1] , best-fit chebyshev polynomial points, want convert chebyshev polynomial legendre polynomial.
there 2 ways it, shown in code below. direct way call convert(kind = legendre)
on chebyshev polynomial, took 19.591 seconds. alternative call legendre.fit
on data points, took 3.356 seconds.
import numpy np numpy.polynomial import chebyshev, legendre x = np.linspace(-1, 1, 1000) y = 1.0 / (1 + x ** 2) + 1e-3 * np.random.random(1000) t = chebyshev.fit(x, y, 99) timeit import timeit timeit("t.convert(kind = legendre)", setup = "from __main__ import x, y, t, legendre", number = 200) timeit("legendre.fit(x, y, 99)", setup = "from __main__ import x, y, legendre", number = 200)
question: why legendre.fit
faster convert(kind = legendre)
? doing wrongly?
Comments
Post a Comment