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

Slightly confused about the notation used in this package #20

Closed
jishnub opened this issue Nov 26, 2020 · 2 comments · Fixed by #21
Closed

Slightly confused about the notation used in this package #20

jishnub opened this issue Nov 26, 2020 · 2 comments · Fixed by #21

Comments

@jishnub
Copy link

jishnub commented Nov 26, 2020

The order k in this package appears to differ from the corresponding usage in other packages such as Dierckx or in scipy.interpolate (which also uses Dierckx I believe). It appears that k here is somewhat equivalent to k+1 in these packages. For example, in scipy:

In [1]: from scipy import interpolate

In [2]: knots = [0,0,1,2,3,4,4]; k = 2; c = [1,0,0,0,0];

In [3]: interpolate.BSpline(knots, c, k)(1)
Out[3]: array(0.5)

In [4]: c = [0,1,0,0,0];

In [5]: interpolate.BSpline(knots, c, k)(1)
Out[5]: array(0.5)

In Dierckx,

julia> k = 2; breakpoints = 0:4;

julia> t = vcat([breakpoints[1] for i in 1:k], breakpoints[2:end-1], [breakpoints[end] for i = 1:k])
7-element Array{Int64,1}:
 0
 0
 1
 2
 3
 4
 4

julia> c = [1,0,0,0,0];

julia> Dierckx.Spline1D(t, c, k, 0, 0)(1) # matches with scipy
0.5

# comparing with this package
julia> basis = BSplineBasis(k, breakpoints); knots(basis) == t
true

whereas in this package

julia> basis = BSplineBasis(2, 0:4)
5-element BSplineBasis{UnitRange{Int64}}:
 order: 2
 breakpoints: 0:4

julia> knots(basis)
7-element BSplines.KnotVector{Int64,UnitRange{Int64}}:
 0
 0
 1
 2
 3
 4
 4

julia> bsplines(basis, 1)
2-element OffsetArray(::Array{Float64,1}, 2:3) with eltype Float64 with indices 2:3:
 1.0
 0.0

julia> basis = BSplineBasis(3, 0:4)
6-element BSplineBasis{UnitRange{Int64}}:
 order: 3
 breakpoints: 0:4

julia> knots(basis)
9-element BSplines.KnotVector{Int64,UnitRange{Int64}}:
 0
 0
 0
 1
 2
 3
 4
 4
 4

julia> bsplines(basis, 1)
3-element OffsetArray(::Array{Float64,1}, 2:4) with eltype Float64 with indices 2:4:
 0.5
 0.5
 0.0

Using order=3 in this package leads to values that seem to match the results for k=2 in scipy, although the knots differ as expected at the edges. I wonder if these differences could be explained in the documentation?

@sostock
Copy link
Owner

sostock commented Nov 26, 2020

You are correct: what scipy.interpolate and Dierckx call k is equivalent to k+1 in this package. In Dierckx and scipy.interpolate, k refers to the degree of the B-splines, not the order (as in this package). A B-spline of order k is a piecewise polynomial of degree k-1. It is unfortunate that the letter k is used sometimes for the order and sometimes for the degree.

It would indeed be good to add a note about that to the documentation.

@sostock
Copy link
Owner

sostock commented Nov 28, 2020

@jishnub Do you think the additions to the documentation in #21 are fine, or would you change something?

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

Successfully merging a pull request may close this issue.

2 participants