What is formulation of Linear Bspline Interpolation ?

63 Views Asked by At

In Julia language, Linear interpolation can be performed by specifying the parameters of the function:(http://juliamath.github.io/Interpolations.jl/latest/devdocs/) For example:

julia> A = reshape(1:27, 3, 3, 3)
3×3×3 reshape(::UnitRange{Int64}, 3, 3, 3) with eltype Int64:
[:, :, 1] =
 1  4  7
 2  5  8
 3  6  9

[:, :, 2] =
 10  13  16
 11  14  17
 12  15  18

[:, :, 3] =
 19  22  25
 20  23  26
 21  24  27

julia> itp = interpolate(A, BSpline(Linear()));

julia> x = (1.2, 1.4, 1.7)
(1.2, 1.4, 1.7)

julia> itp(x...)
8.7
julia> wis = Interpolations.weightedindexes((Interpolations.value_weights,), Interpolations.itpinfo(itp)..., x)
(Interpolations.WeightedAdjIndex{2, Float64}(1, (0.8, 0.19999999999999996)), Interpolations.WeightedAdjIndex{2, Float64}(1, (0.6000000000000001, 0.3999999999999999)), Interpolations.WeightedAdjIndex{2, Float64}(1, (0.30000000000000004, 0.7)))

julia> wis[1]
Interpolations.WeightedAdjIndex{2, Float64}(1, (0.8, 0.19999999999999996))

julia> wis[2]
Interpolations.WeightedAdjIndex{2, Float64}(1, (0.6000000000000001, 0.3999999999999999))

julia> wis[3]
Interpolations.WeightedAdjIndex{2, Float64}(1, (0.30000000000000004, 0.7))

julia> Interpolations.InterpGetindex(A)[wis...]
8.7
  0.8 * A[1, wis[2], wis[3]] + 0.2 * A[2, wis[2], wis[3]]
= 0.6 * (0.8 * A[1, 1, wis[3]] + 0.2 * A[2, 1, wis[3]]) +
  0.4 * (0.8 * A[1, 2, wis[3]] + 0.2 * A[2, 2, wis[3]])
= 0.3 * (0.6 * (0.8 * A[1, 1, 1] + 0.2 * A[2, 1, 1]) +
         0.4 * (0.8 * A[1, 2, 1] + 0.2 * A[2, 2, 1])  ) +
  0.7 * (0.6 * (0.8 * A[1, 1, 2] + 0.2 * A[2, 1, 2]) +
         0.4 * (0.8 * A[1, 2, 2] + 0.2 * A[2, 2, 2])  )

How are the weights that appear in the formula calculated?

1

There are 1 best solutions below

1
On BEST ANSWER

First of all, i had to load the corresponding package:

using Pkg
Pkg.add("Interpolations")

Now consider your point x which is $(1.2\ ,\ 1.4\ ,\ 1.7\ )$. It is located in the given range in the cube $[1,2]^3$ between $1$ and $2$ in each component, and taking the components one by one:

  • in the $x$-direction (first direction) the point $1.2$ has weights $$ \left(\frac{2-1.2}{2-1},\frac{1.2-1}{2-1}\right)=(\ 0.8, \ 0.2\ )\ , $$ matching

      julia> wis[1]
      Interpolations.WeightedAdjIndex{2, Float64}(1, (0.8, 0.19999999999999996))
    
  • in the $y$-direction (second direction) the point $1.4$ has weights $$ \left(\frac{2-1.4}{2-1},\frac{1.4-1}{2-1}\right)=(\ 0.6, \ 0.4\ )\ , $$ matching

      julia> wis[2]
      Interpolations.WeightedAdjIndex{2, Float64}(1, (0.6000000000000001, 0.3999999999999999))
    
  • in the $z$-direction (third direction) the point $1.7$ has weights $$ \left(\frac{2-1.7}{2-1},\frac{1.7-1}{2-1}\right)=(\ 0.3, \ 0.7\ )\ . $$ matching

      julia> wis[3]
      Interpolations.WeightedAdjIndex{2, Float64}(1, (0.30000000000000004, 0.7))
    

In general, a point $x$ (usually) between $a$ and $b$ gets (for a linear interpolation) the weights

  • $\lambda_a=(b-x)/(b-a)$ for the point $a$ and
  • $\lambda_b=(x-a)/(b-a)$ for the point $b$. These weights have the two properties: $$ \begin{aligned} 1 &=\lambda_a+\lambda_b\ ,\\ x &=\lambda_a\cdot a+\lambda_b\cdot b\ . \end{aligned} $$