[Numpy-discussion] Polynomial evaluation inconsistencies (original) (raw)

Ilhan Polat ilhanpolat at gmail.com
Sat Jun 30 15:08:17 EDT 2018


I think restricting polynomials to time series is not a generic way and quite specific.

Apart from the series and certain filter design actual usage of polynomials are always presented with decreasing order (control and signal processing included because they use powers of s and inverse powers of z if needed). So if that is the use case then probably it should go under a namespace of TimeSeries or at least require an option to present it in reverse. In my opinion polynomials are way more general than that domain and to everyone else it seems to me that "the intuitive way" is the decreasing powers.

For the design

This isn't a great design, because they represent: p(x) = c[0] * x^2 + c[1] * x^1 + c[2] * x^0

I don't see the problem actually. If I ask someone to write down the coefficients of a polynomial I don't think anyone would start from c[2].

On Sat, Jun 30, 2018 at 8:30 PM, Charles R Harris <charlesr.harris at gmail.com

wrote:

On Sat, Jun 30, 2018 at 12:09 PM, Eric Wieser <wieser.eric+numpy at gmail.com_ _> wrote: > if a single program uses both np.polyval() and np.polynomail.Polynomial, it seems bound to cause unnecessary confusion.

Yes, I would recommend definitely not doing that! > I still think it would make more sense for np.polyval() to use conventional indexing Unfortunately, it's too late for "making sense" to factor into the design. polyval is being used in the wild, so we're stuck with it behaving the way it does. At best, we can deprecate it and start telling people to move from np.polyval over to np.polynomial.polynomial.polyval. Perhaps we need to make this namespace less cumbersome in order for that to be a reasonable option. I also wonder if we want a more lightweight polynomial object without the extra domain and range information, which seem like they make Polynomial a more questionable drop-in replacement for poly1d. The defaults for domain and window make it like a regular polynomial. For fitting, it does adjust the range, but the usual form can be recovered with p.convert() and will usually have more accurate coefficients due to using a better conditioned matrix during the fit. In [1]: from numpy.polynomial import Polynomial as P In [2]: p = P([1, 2, 3], domain=(0,2)) In [3]: p(0) Out[3]: 2.0 In [4]: p.convert() Out[4]: Polynomial([ 2., -4., 3.], domain=[-1., 1.], window=[-1., 1.]) In [5]: p.convert()(0) Out[5]: 2.0 Chuck


NumPy-Discussion mailing list NumPy-Discussion at python.org https://mail.python.org/mailman/listinfo/numpy-discussion -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20180630/6cd33e2c/attachment-0001.html>



More information about the NumPy-Discussion mailing list