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
BUG: dblquad and args kwarg #17776
Comments
Hi @RichardAFrazin, thank you for reporting. Boundaries and tolerances are very important as it will impact how the domain is discretised and walked through. See #17554. Unrelated (I think), consider updating SciPy and NumPy. These are very old versions and we pushed in both literally thousands of bug fixes and improvements. |
Seeing this is exactly the same case/distribution as the other issue. I did not check your formula, there might as well be an issue there. Closing for now as I am pretty certain there is no bug. If you still find something I am happy to reopen. Thanks again 😃 |
It looks like the problem in 17554 was due trying to integrate over a
narrow spike in a large domain. In my case, the boundaries are tight,
extending only to +- 5 standard deviations from the center in each
direction. My formula for the normal is correct.
I will try updating scipy and numpy
…On Thu, Jan 12, 2023 at 9:22 AM Pamphile Roy ***@***.***> wrote:
Hi @RichardAFrazin <https://github.com/RichardAFrazin>, thank you for
reporting. Boundaries and tolerances are very important as it will impact
how the domain is discretised and walked through. See #17554
<#17554>.
Unrelated (I think), consider updating SciPy and NumPy. These are very old
versions and we pushed in both literally thousands of bug fixes and
improvements.Message ID: ***@***.***>
|
Did you try adjusting the tolerance and other parameters of the function? |
Yes, I did.
…On Thu, Jan 12, 2023 at 3:08 PM Pamphile Roy ***@***.***> wrote:
Did you try adjusting the tolerance and other parameters of the function?
—
Reply to this email directly, view it on GitHub
<#17776 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AH47V5QFFPDD3MOIQDCTH33WSBQDRANCNFSM6AAAAAATZJWZSA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
I modified your code so that: def g(x,y,xc,yc):
print(xc, yc)
return (1/(2*np.pi*sig*sig))*np.exp(- ((x-xc)**2 + (y-yc)**2)/(2*sig*sig) ) It prints lots of (5.0, -3.0). So I don't think |
I know you can pass the 2nd parameters via the args kwarg, but something
screwy is happening.
…On Thu, Jan 12, 2023 at 3:09 PM Matt Haberland ***@***.***> wrote:
I modified your code so that:
def g(x,y,xc,yc):
print(xc, yc)
return (1/(2*np.pi*sig*sig))*np.exp(- ((x-xc)**2 + (y-yc)**2)/(2*sig*sig) )
It prints lots of (5.0, -3.0). So I don't think args is the problem.
However, I haven't gotten the correct result from the integral yet.
—Message ID: ***@***.***>
|
I did check them carefully. Please point out the error in my original bug
report if you think I did not.
…On Thu, Jan 12, 2023 at 3:14 PM Matt Haberland ***@***.***> wrote:
< dblquad(g,x0-5*sig,x0+5*sig,y0-5*sig,y0+5*sig,args=(x0,y0))
Check the order of your arguments:
[image: image]
<https://user-images.githubusercontent.com/6570539/212171149-4fb3300e-3d07-4acf-ab4a-9c8bc5a8dc67.png>Message
ID: ***@***.***>
|
Make it |
I am pretty sure the function is not correct. I tried to plotted it and it's flat. |
I think the function is fine: g(y0, x0, x0, y0) - stats.multivariate_normal([x0, y0], cov=np.eye(2)*sig**2).pdf([x0, y0]) # -1.3877787807814457e-17 The main problem is the order that |
If you plotted it with a line going through the center, it's not flat.
…On Thu, Jan 12, 2023 at 3:18 PM Pamphile Roy ***@***.***> wrote:
I am pretty sure the function is not correct. I tried to plotted it and
it's flat.
—
Reply to this email directly, view it on GitHub
<#17776 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AH47V5XGS643UIO4O3LHMHDWSBRI7ANCNFSM6AAAAAATZJWZSA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Yes, the problem does indeed seem to be y,x instead of x,y. Thank you. I
appreciate the help!
…On Thu, Jan 12, 2023 at 3:21 PM Matt Haberland ***@***.***> wrote:
I think the function is fine:
g(y0, x0, x0, y0) - stats.multivariate_normal([x0, y0], cov=sig).pdf([x0, y0]) # 0.0
It's just the order that x and y are passed into the function. dblquad
<https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.dblquad.html>
expects y, x, but the original code was x, y.
—
Reply to this email directly, view it on GitHub
<#17776 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AH47V5WHXZQHGVAUZDC4QDTWSBRTBANCNFSM6AAAAAATZJWZSA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
|
I was missing that |
Yes, I agree.
…On Thu, Jan 12, 2023 at 3:41 PM Matt Haberland ***@***.***> wrote:
I was missing that cov should have been np.eye(2) * sig**2 instead of np.eye(2)
* sig before. Not sure what is going wrong with the plot @tupui
<https://github.com/tupui> but the function is OK aside from the argument
order.
Message ID: ***@***.***>
|
Describe your issue.
There is a bug with scipy.dblquad that seems to be involved with using the args kwarg. The example below is the integral of a 2D Normal distribution, which should be unity. I am using the args kwarg to pass the coords of the center of the Normal. Note that the boundary of the integral is also using the same variable that are passed in args (although I don't know why that might matter).
Reproducing Code Example
Error message
no error message, just the wrong answer!
SciPy/NumPy/Python version information
np 1.16.2 scipy 1.2.1
The text was updated successfully, but these errors were encountered: