Closed veillette closed 1 year ago
In order to circumvent the artefacts noticed on the second derivative, I suggest trying to calculate the second derivative directly from the original function. I will report my progress in this issue.
Status: I have made some progress today but I'm not ready to commit it yet. I need to find a clean solution to handle the edges of the curve. Otherwise, it is looking good. I'll come back to it on Monday.
I committed my work.
In essence, the second derivative is calculated a double difference, except near discontinuities. Note that one needs a smooth point to the right and left of a given point to calculate correctly the second derivative. In those Near discontinuities, there is not enough 'room' to calculate the second derivative, therefore we "borrow" the y-value of the nearby point as a replacement (which is a good approximation, in general, and exact for parabola)
.
Assigning to @pixelzoom to review.
The work is all done in SecondDerivativeCurve.ts
.
I updated the all the documentation but let me know if I missed anything.
Feel free to close.
This is looking great. One suggestion: rename baseCurve
to originalCurve
in the subclasses of Curve.
In the commit above, I replaced all references of baseCurve
to originalCurve
.
This affects three classes: 'DerivativeCurve', 'SecondDerivativeCurve' and 'IntegralCurve'. I also updated local references of basePoints
to originalPoints
. The documentation has been updated as well.
After the refactoring, I searched for reference to 'base' in the three classes, and I could not find any.
Reassigning to @pixelzoom for review.
I confirmed that there are no remaining occurrences of baseCurve or basePoints. I played around with the sim for awhile, and it's looking good to me. The real test would be to have one of the subject-matter experts take it for a test-drive. I'll assign back to @veillette to decide if he wants to assign to someone else for "behavioral review", or whether to close this issue.
Let close this issue. I created an issue (#292) to let the QA team be on the lookout for this kind of problems.
The second derivative is calculated based on the first derivative. Although it is pleasing that we follow mathematical pattern, where the second derivative is merely the derivative of the first derivative, it comes with a set of challenges.
The calculation of the first derivative is only approximate, and therefore introduces errors. As a result, these errors are then baked in our curve. The second derivative accumulates, the error associated with the calculate of a derivative, and then the errors from its basecurve.
We can see the problematic below where I used the flags
numberOfPoints=100&screens=4&allPoints=true
The function is a parabola meeting a line. There is a small error in the function, which affects the derivative, (notice the small kink near the discontinuity). In turns this affects the second derivative. At this point the error has been amplified and it shows a large discrepancy.