New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The representation of polynomials with Polynomial class using "domain" and "window" is not clearly explained in the class documentation #9533
Comments
Unexpected, but correct ;) The polynomial coefficients give
Or don't bother with the domain at all
|
If |
Ok, i see my mistake: currently >>> from numpy.polynomial import Polynomial as P
>>> p = P([1,1], domain=[0,1])
>>> p(0)
0.0 Then i consider this a documentation issue, the current documentation is quite unclear:
I'll change the title of this issue to make it about documentation and will think about a documentation patch. Nevertheless, i would expect the |
numpy.polynomial.polynomial.Polynomial.linspace
wrt domain
@alexeymuranov - if you can clarify the documentation, that would be great; I've been confused about this a lot. Frankly, easiest might simply be to describe the scaling that actually happens in the form of an equation, and then give an example or two. And/or add a link to p.s. Note that the same documentation would be helpful in all the polynomical classes. Possibly it is best added to |
That would ruin the whole purpose of using |
@charris, the special role of >>> from numpy.polynomial import Polynomial as P
>>> p = P([0,1], domain=[0,1])
>>> p(0)
-1.0 is quite confusing. A different but related issue is how polynomials are printed by default. In the above example one gets: >>> print(p)
poly([ 0. 1.])
>>> print("p(%g) = %g" % (0, p(0)))
p(0) = -1 which looks like an utter nonsense :). I suppose i was confused by the suggestive |
@mhvk, the current behaviour is in fact quite easy to explain: the internal representation of a polynomial In other words, p = Polynomial([2, 0, 1], domain=[0,1], window=[-1,1])) represents the actual polynomial |
Looks exactly like I would expect ;) You are arguing apriori assumptions, I would argue that such assumptions should be adjusted pending experience with the actual mechanism, for which there is, IMHO, good reason. |
The value at |
On Thu, Aug 10, 2017 at 8:55 AM, Alexey Muranov ***@***.***> wrote:
Looks exactly like I would expect ;)
The value at 0 of the polynomial with coefficient 0, 1 (the polynomial X)
is -1??
Assumes facts not in evidence.
Chuck
|
I am complaining about the interfaces (the API and the |
@alexeymuranov - changing the API is really not an option at this point, it would just break code. But adding to the documentation something that would help someone like you, for whom the current logic is not obvious, as well as for, who has been continuously confused by what the "domain" and "window" really refer to (it is mostly which is which that I find confusing), is very helpful. |
Note that |
If you want plain old polynomials, do not specify the domain. That is the default and was intentional. If you want to use more sophisticated things, then domain and window are available, probably in that order. For things like fitting, where the domain is crucial for accurate results, the domain is adusted by the algorithm, but can be overridden. |
I think I can see an argument for requiring (read: warning otherwise) that the domain and window are either not specified or both specified? That seems to be where the confusion comes from. |
@eric-wieser The |
While I agree with the need for numerical stability, as someone used to
It is not at all obvious that the first object in the repr is not the coefficients in the data domain, but the coefficients in the scaled domain. I think this deserves something along the lines of
right in the middle of docs for the Polynomial class AND in the This should probably be a short PR instead of a comment rant, shouldn't it...? |
This commit adds a note about the `coef` array in Polynomial being stored in the domain scaled according to the `window` and `domain` parameters, and not, as a np.polyfit user may expect, in the usual data coordinates. This is a followup to issue numpy#9533.
Expected result:
(array([ 0., 1.]), array([ 1., 2.]))
.This is with Python 3.6.0, NumPy 1.12.0.
Update. A simpler example of unexpected behaviour:
The documentation of
domain
andwindow
parameters inPolynomial
:The text was updated successfully, but these errors were encountered: