-
-
Notifications
You must be signed in to change notification settings - Fork 46
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
Extrapolation options #356
Extrapolation options #356
Conversation
This looks like a great idea. It should be an EnumX enum though instead of just symbols in order to autocomplete and spellcheck properly. |
Derivative extrapolation now also looking good: using DataInterpolations
using CairoMakie
using Random
Random.seed!(2)
t = cumsum(rand(5))
u = rand(5)
t_eval = range(-1, 3.5, length = 1000)
fig = Figure()
ax_itp = Axis(fig[1,1]; title = "(inter/extra)polation")
ax_deriv = Axis(fig[2,1]; title = "(inter/extra)polation first derivative")
ax_deriv2 = Axis(fig[3,1]; title = "(inter/extra)polation second derivative")
scatter!(ax_itp, t,u; label = "data")
for extrapolation_type in [ExtrapolationType.constant, ExtrapolationType.linear, ExtrapolationType.extension]
A = QuadraticSpline(u,t; extrapolation_up = extrapolation_type, extrapolation_down = extrapolation_type)
lines!(ax_itp, t_eval, A.(t_eval); label = string(extrapolation_type))
lines!(ax_deriv, t_eval, DataInterpolations.derivative.(Ref(A), t_eval); label = string(extrapolation_type))
lines!(ax_deriv2, t_eval, DataInterpolations.derivative.(Ref(A), t_eval, 2); label = string(extrapolation_type))
end
axislegend(ax_itp)
axislegend(ax_deriv)
axislegend(ax_deriv2)
fig |
And the integral: using DataInterpolations
using CairoMakie
using Random
Random.seed!(2)
t = cumsum(rand(5))
u = rand(5)
t_eval = range(-2, 5.5, length = 1000)
fig = Figure()
ax_itp = Axis(fig[1,1]; title = "(inter/extra)polation")
ax_antideriv = Axis(fig[2,1]; title = "(inter/extra)polation antiderivative")
scatter!(ax_itp, t,u; label = "data")
for extrapolation_type in [ExtrapolationType.constant, ExtrapolationType.linear, ExtrapolationType.extension]
A = QuadraticSpline(u,t; extrapolation_up = extrapolation_type, extrapolation_down = extrapolation_type)
lines!(ax_itp, t_eval, A.(t_eval); label = string(extrapolation_type))
lines!(ax_antideriv, t_eval, DataInterpolations.integral.(Ref(A), t_eval); label = string(extrapolation_type))
end
axislegend(ax_itp)
axislegend(ax_antideriv)
fig |
I've found myself in a refactoring rabbit hole again 😅
|
Can you do the refactors in different PRs? |
Not really, or I have to do them before this one. Is it fine by you if I wrap up what I'm doing here and make some follow-up issues? |
Thats alright, refactors that are not strictly needed in this one can have follow up issues/PRs. |
@sathvikbhagavan sorry for the spam but just to let you know that this PR is ready for review |
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.
A few comments
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.
Almost there. A few minor comments.
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.
LGTM!
Fixes #355.
This is what I have in mind:
Let me know whether this is a good approach before I apply it to all interpolation types, integrals, derivatives.