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

Smooth shows large biases when numberOfPoints is low #293

Closed
veillette opened this issue Mar 16, 2023 · 3 comments
Closed

Smooth shows large biases when numberOfPoints is low #293

veillette opened this issue Mar 16, 2023 · 3 comments
Assignees

Comments

@veillette
Copy link
Contributor

veillette commented Mar 16, 2023

The blue and pink curve started the same, but I applied the smooth button to the blue curve.

Below, this looks right for 400 points
http://localhost:63342/phetsims/calculus-grapher/calculus-grapher_en.html?brand=phet&ea&debugger&dev&numberOfPoints=400
Calculus Grapher screenshot (46)

The smoothing process, should be a weighted average, but should not biased the curve.
Notice that the centers don't match anymore below (Below numberOfPoints=100).

http://localhost:63342/phetsims/calculus-grapher/calculus-grapher_en.html?brand=phet&ea&debugger&dev&numberOfPoints=100
Calculus Grapher screenshot (48)

This becomes very apparent when the number of points is ~100. It looks fine for 400 points.
We should investigate what is going, and if it is worth fixing.

@veillette veillette self-assigned this Mar 16, 2023
@veillette veillette changed the title Smooth is biased Smooth shows large biases when numberOfPoints is low Mar 16, 2023
@veillette
Copy link
Contributor Author

I understand what is going on. This is the result of the interplay between the discretization of weighted sum average and the discretization of the curve itself. This phenomenon becomes only apparent then when we reduced the number of points, such that the number of points on the left and on the right becomes unequal.

To remedy to this, we can explicitly fold our sum, such that we guarantee by construct that for every point that is pick to the left, we pick one to the right. This is easy do to. Unfortunately, this makes the code less readable but I'll add more comments/documentation to compensate for that.

veillette added a commit that referenced this issue Mar 16, 2023
Signed-off-by: Martin Veillette <[email protected]>
@veillette
Copy link
Contributor Author

This was added in the commit above. In summary, we folded a sum of f(x) that would go from -x' to x' into a sum from that goes from 0 to x', but summing f(x') and f(-x). Special care is taken that we don't double count f(0) in this process.

I have added a lot of documentation to it, which is useful anyway as the code review mentioned that our documentation of these mathematical processes were scant..

I tested that it is working properly and that the smoothing does not show a bias.

@veillette
Copy link
Contributor Author

I'm inclined to close this, but I'll use it as example in #292 to point to the usefulness of the query parameters to detect faulty logic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant