Skip to content
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

.mean() and .moment(1) returning incorrect answers for sharp, non-zero values at extrema #104

Open
sschmidt23 opened this issue Jul 15, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@sschmidt23
Copy link
Collaborator

It looks like the .mean() and .moment(1) methods produce faulty answers when there is a sudden rise to a non-zero value at either extrema of a qp.interp grid (may happen in others, but I found for sure in qp.interp). For example, if you try:

import numpy as np
import qp
from scipy.stats import norm
zgrid = np.linspace(0,3,301)
func1 = norm(loc=3.0, scale=0.05)
func2 = norm(loc=3.0, scale=0.25)
x1 = func1.pdf(zgrid)
x2 = func2.pdf(zgrid)
ydata = np.vstack((x1, x2)) 
ens = qp.Ensemble(qp.interp, data=dict(xvals=zgrid, yvals = ydata))
ens.mean()

you get:

array([[3.19960439],
           [2.84842853]])

The first value, with the very small half-Gaussian centered right on the end point of 3.0, is incorrectly overshot, while the broader half-Gaussian with scale=0.25 produces the correct answer for 2.8484. So, this problem seems to only occur for a rapid rise in the PDF. I noticed this while computing means for some FZBoost PDFs where the mean was being reported as high as z=3.5 when the grid stopped at z=3.0, which is obviously a problem.

@sschmidt23 sschmidt23 added the bug Something isn't working label Jul 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant