-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
ENH: improve integrate.simpson for even number of points #18209
Conversation
The macOS-meson workflow has started to fail, not due to changes introduced in this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, some comments around on the deprecation. I think there is a backwards compatibility issue for anyone using positional arguments (see my comment below)
Co-authored-by: Jake Bowhay <60778417+j-bowhay@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @andyfaff all the maths looks in order to me and this gives a nice improvement
I cannot remember, was there a post on the mailing list about the deprecation aspect? |
Have just written an email. I'd give it a couple of days before merging. Do you have any concerns about implementation? |
Thanks had another skim and tried the example from the original issue on this branch. This gives a clear improvement so let get it in |
SciPy version 1.11 changes how Simpson quadrature is computed with an even number of points (scipy/scipy#18209). This caused some test to fail, as the values of the integrals and metrics used change, causing in some cases several discrepancies (#551). This has been fixed to make the tests compatible with both previous versions and versions after 1.11, in two main ways: - By making some comparisons more lenient, allowing for higher relative or absolute tolerances. - By rewriting some tests in order to be less sensitive to changes in quadrature by design.
Closes #5618
This PR improves the accuracy of
integrate.simpson
when there is an even number of points (odd number of intervals).Historical behaviour has been to use trapezoidal integration for the last/first intervals and adding it on to the
_basic_simpson
sum of the other intervals. This is what theeven
kwd was used for. Wheneven='avg'
the mean oflast
andfirst
approaches was returned.It was pointed out in #18151 that there is a more accurate way of dealing with this situation, as outlined on wikipedia. This uses a parabolic segment over the last three points to calculate the sum of the last interval, thereby using simpson behaviour for the last interval as well.
This PR:
'simpson'
option to theeven
kwd.even='simpson'
should offer improved behaviour in most cases (i.e. it continues the quadratic nature of the rest of the summation) this now becomes the default for theeven
kwd.even='simpson'
offers this improved behaviour it shouldn't be necessary to access the{'first', 'last', 'avg'}
options anymore. It's therefore suggested that theeven
kwd be deprecated and removed in a future version of scipy. After that point the'simpson'
behaviour will be used all the time.even
kwdis removed from the function signature and replaced by
**kwds. Existing code that uses
even` will continue to work, but will receive a warning.simpson
integration over multiple axes, for odd and even number of points in the integration axis. These tests were missing and strengthen the test suite.If there is downstream code using
simpson
they will:DeprecationWarning
. This may come as a surprise as theeven
keyword forsimpson
has been present for a long time.