Jump to content

Multidimensional interpolation: Difference between revisions

From Wikibase
Describe the nested route by what it does, since the basis values are no longer tabulated here. AI-assisted (RonzzWikiCowriter) (via update-page on MediaWiki MCP Server)
Rewrite Pointwise interpolation around one-dimensional passes with any rule; add Chasnov citation. AI-assisted (RonzzWikiCowriter) (via update-page on MediaWiki MCP Server)
Line 216: Line 216:
=== Pointwise interpolation ===
=== Pointwise interpolation ===


Pointwise interpolation (or '''point evaluation''') asks only for the value of $f$ at one new point $(x_1^*,\cdots,x_m^*)$ inside the data range, without constructing $f$ anywhere else. It says what is to be computed, not how $f$ is defined: the interpolation scheme, whether a single polynomial, a piecewise spline, a radial basis expansion, or a weighted average, fixes the rule, and pointwise evaluation fixes that only one number is wanted out of it. Where the interpolant is cheap to write down the distinction hardly matters; where it is expensive, as with a high-degree polynomial in many variables or a spline with many knots, building the whole of it costs far more than one evaluation needs.
Pointwise interpolation (or '''point evaluation''') asks only for the value of $f$ at one new point $(x_1^*,\cdots,x_m^*)$ inside the data range, without constructing $f$ anywhere else. It says what is to be computed, not how $f$ is defined: the interpolation scheme, whether piecewise linear, a cubic spline, or a single polynomial, fixes the values everywhere, and pointwise evaluation fixes that only one of them is wanted. Building the whole interpolant is a separate undertaking, and the heavier one: the developed form of a high-degree polynomial in many variables runs to $n^m$ terms and, as [[#Grid_interpolation|grid interpolation]] showed, evaluating it develops large cancellations. The passes below never form it.


Nearly every scheme is linear in the readings, in the sense that
'''One variable at a time.''' A grid is a family of straight lines, one along each variable, and each of those lines is an ordinary one-dimensional dataset. A one-dimensional rule applied to the lines of one direction, and then to the lines of the next, reaches the query point, and the rule itself is a free choice. [[Person:Jeffrey R. Chasnov|Chasnov]] states the two-variable case in full: on an $(n+1)\times(n+1)$ grid, first perform $n+1$ one-dimensional interpolations in one variable, giving the interpolant at the $n+1$ points $(x_0,y^*),\cdots,(x_n,y^*)$ of the line crossed at the target coordinate, then a single one-dimensional interpolation in the other variable, giving the value at $(x^*,y^*)$. The two- and three-dimensional interpolation routines of numerical software address exactly this problem; MATLAB's are <code>interp2</code> and <code>interp3</code><ref>{{#cite:Q2421}}</ref>.
 
'''The rule, named once.''' Let


$$
$$
f(x_1^*,\cdots,x_m^*)=\sum_{i_1=0}^{n-1}\cdots\sum_{i_m=0}^{n-1}w_{i_1,\cdots,i_m}(x_1^*,\cdots,x_m^*)\,y_{i_1,\cdots,i_m}
\mathcal{I}\big[\{v_k\}_{k=0}^{n-1}\big](t)
$$
$$


for weights $w$ fixed by the nodes, the query point, and the scheme, but not by the readings. Pointwise evaluation is then the computation of those weights and one weighted sum, and what the weights cost is what separates one scheme from another:
be the value at $t$ that the chosen rule gives to readings $v_0,\cdots,v_{n-1}$ taken at the nodes $t_0,\cdots,t_{n-1}$ of one variable. The rule may be [[Piecewise_linear_interpolation|piecewise linear]], a cubic spline with whatever end condition ([[Cubic_spline_interpolation|cubic spline interpolation]]), a monotone or shape-preserving scheme, or a single polynomial through the whole line. Everything below holds for any of them.


* a '''piecewise''' scheme, such as a spline or the multilinear interpolant of a cell, gives nonzero weight only to the nodes near the query point, a fixed stencil whose size follows the degree and not the number of nodes, so the work does not grow with the grid;
'''Two variables.''' With readings $y_{i_1,i_2}$ on $n$ nodes per axis, the first pass holds $x_1$ at each of its nodes in turn and interpolates the $n$ readings of that line in $x_2$:
* a '''global''' scheme, such as the tensor-product Lagrange polynomial of [[#Grid_interpolation|grid interpolation]], gives nonzero weight to every node, so all $n^m$ weights are needed;
 
* a scheme fixed by a '''linear system''', such as radial basis interpolation or kriging, draws its weights from the solution of a system built on the nodes; the evaluation is then a weighted sum, and a single query point can be served through the transposed system instead of through the coefficients.
$$
y^*_{i_1}=\mathcal{I}\big[\{y_{i_1,i_2}\}_{i_2=0}^{n-1}\big](x_2^*),\qquad \forall i_1\in [0,n-1],\, i_1 \in \mathbb{N}
$$


'''The tensor-product Lagrange case.''' There the weights factor, $w_{i_1,\cdots,i_m}(x_1^*,\cdots,x_m^*)=\prod_{j=1}^{m}L^{(j)}_{i_j}(x_j^*)$, so the $n^m$ terms need never be formed: the sum regroups into nested sums, one variable at a time,
The $n$ values $y^*_{i_1}$ are the interpolant at $(x_{1,i_1},x_2^*)$: the grid's lines, crossed at the target $x_2^*$. They are readings on a single line of the other direction, so one more pass finishes:


$$
$$
f(x_1^*,\cdots,x_m^*)=\sum_{i_m=0}^{n-1}L^{(m)}_{i_m}(x_m^*)\sum_{i_{m-1}=0}^{n-1}L^{(m-1)}_{i_{m-1}}(x_{m-1}^*)\cdots\sum_{i_1=0}^{n-1}L^{(1)}_{i_1}(x_1^*)\,y_{i_1,\cdots,i_m}
f(x_1^*,x_2^*)\approx\mathcal{I}\big[\{y^*_{i_1}\}_{i_1=0}^{n-1}\big](x_1^*)
$$
$$


In two dimensions the first pass interpolates along $x_1$ inside each row $x_2=x_{2,i_2}$, at the target $x_1^*$:
The first pass costs $n$ one-dimensional interpolations and the second costs $1$.
 
'''$m$ variables.''' Each pass removes one variable: the first leaves $n^{m-1}$ values, one per combination of the remaining nodes, the next $n^{m-2}$, and so on down to one, so the passes cost $n^{m-1}, n^{m-2}, \cdots, n^0$ interpolations whatever the rule:


$$
$$
y^*_{i_2}=\sum_{i_1=0}^{n-1}L^{(1)}_{i_1}(x_1^*)\,y_{i_1,i_2},\qquad \forall i_2\in [0,n-1], i_2 \in \mathbb{N}
\sum_{k=0}^{m-1}n^{k}=\frac{n^{m}-1}{n-1}
$$
$$


The $n$ intermediate values $y^*_{i_2}$ sit at the coordinates $(x_1^*,x_{2,i_2})$, i.e., on a one-dimensional grid in $x_2$, so a second pass interpolates them at $x_2^*$:
{| class="wikitable"
|+ One-dimensional interpolations for one query point, with $n=4$ nodes per axis
! $m$ !! first pass !! second pass !! third pass !! fourth pass !! total
|-
! 2
| 4 || 1 || – || – || 5
|-
! 3
| 16 || 4 || 1 || – || 21
|-
! 4
| 64 || 16 || 4 || 1 || 85
|}
 
'''What the rule changes, and what it does not.''' The passes run the same way for every rule, but what each pass has to read, and how smooth the result is, are the rule's doing:
 
* a '''local''' rule, such as piecewise linear, reads only the two nodes bracketing the target on its line. Only the lines that bracket the target then need interpolating, so the work follows the stencil and not the grid: two lines in the first pass of the station example below, and two readings on each of them;
* a '''global''' rule, such as a cubic spline or a single polynomial through the whole line, draws on every node of its line, so every line of every pass is interpolated. What is saved is then not the count of interpolations but everything that is never built: the coefficient form of the surface, and with it the cancellation that [[#Grid_interpolation|grid interpolation]] pays for;
* whichever the rule, each line interpolation reproduces the readings at its own nodes, so the composed value at a datapoint is exactly the reading there;
* smoothness is inherited: piecewise linear passes give a surface that is continuous but creased along the lines between cells, whereas spline passes give one that is smooth in each variable.
 
'''Rules linear in the readings.''' Nearly every rule computes its value as a weighted sum


$$
$$
f(x_1^*,x_2^*)=\sum_{i_2=0}^{n-1}L^{(2)}_{i_2}(x_2^*)\,y^*_{i_2}
\mathcal{I}\big[\{v_k\}_{k=0}^{n-1}\big](t)=\sum_{k=0}^{n-1}\varphi_k(t)\,v_k
$$
$$


The first pass costs $n$ one-dimensional interpolations and the second costs $1$. In $m$ dimensions the passes shrink by one variable each time, costing $n^{m-1}, n^{m-2}, \cdots, n^0$:
whose weights $\varphi_k$ are fixed by the nodes and by $t$, but not by the readings: the hats of the two neighbouring nodes for a piecewise linear rule, the cardinal splines for a spline rule. Two passes with such a rule give


$$
$$
\sum_{k=0}^{m-1}n^{k}=\frac{n^{m}-1}{n-1}
f(x_1^*,x_2^*)=\sum_{i_1=0}^{n-1}\sum_{i_2=0}^{n-1}\varphi^{(1)}_{i_1}(x_1^*)\,\varphi^{(2)}_{i_2}(x_2^*)\,y_{i_1,i_2}
$$
$$


Each of those weighted sums costs $n$ multiplications, so the nested passes cost $n(n^{m}-1)/(n-1)$ in all. That is fewer than the $m\,n^m$ multiplications needed to sum the $n^m$ terms of [[#Grid_interpolation|grid interpolation]] term by term, because each pass collapses one variable: the first pass does range over the $n^{m-1}$ combinations of known nodes, as a direct sum does, but afterwards one variable is pinned at the target $x_j^*$ and contributes one position instead of $n$. Nothing is thrown away: the same $n^m$ terms are summed either way, and the two counts answer different questions, the value at one point and the whole surface.
in which the weights of the two directions multiply. The $n^2$ products are the same under either nesting of the two sums, and in $m$ variables under any order of the $m$ passes, so the order in which the variables are collapsed changes nothing<ref>{{#cite:Q2391}}</ref>. A rule that is not linear in its readings, such as a monotone or shape-preserving one, offers no such weights, and the passes may then answer differently in different orders.


The order of the passes does not matter. Collapsing $x_1$ first and then $x_2$ gives the same result as collapsing $x_2$ first and then $x_1$, because the tensor product sum can be regrouped; every ordering evaluates the same polynomial as [[#Grid_interpolation|grid interpolation]]<ref>{{#cite:Q2391}}</ref>.
'''The station grid again.''' Applied to the sixteen readings of [[#Grid_interpolation|grid interpolation]], the passes at $1.4^\circ$E, $51.6^\circ$N give, for three rules:


{| class="wikitable"
{| class="wikitable"
|+ Multiplications at one query point in the tensor-product Lagrange case, for $n=4$ nodes per axis
|+ Value at $1.4^\circ$E, $51.6^\circ$N, from the same sixteen readings and three one-dimensional rules
! $m$ !! direct sum, $m\,n^m$ !! nested, $n\sum_{k=0}^{m-1}n^{k}$
! rule !! value ($^\circ$C)
|-
|-
! 2
! piecewise linear
| 32 || 20
| 22.1000
|-
|-
! 3
! natural cubic spline
| 192 || 84
| 22.1157
|-
|-
! 4
! not-a-knot cubic spline
| 1024 || 340
| 22.1162
|}
|}


For the tensor-product Lagrange case the passes are most conveniently written as contractions, one per variable:
The last entry is the number that [[#Grid_interpolation|grid interpolation]] reaches by summing its 16 monomials, and not by accident: a line of four nodes has a single cubic piece, so on such a line the not-a-knot spline is the one cubic through its four readings, and the composed surface is the one that section builds. A longer line, or the natural end condition, departs from it; on these nearly planar readings the natural spline already differs in the fourth decimal, and on readings less nearly planar it would differ more.
 
The passes in code, with the rule passed in as an argument:


<syntaxhighlight lang="python" copy>
<syntaxhighlight lang="python" copy>
import numpy as np
import numpy as np
from scipy.interpolate import CubicSpline


temperature = [[22.8, 23.6, 24.9, 26.1],
temperature = np.array([[22.8, 23.6, 24.9, 26.1],
              [21.7, 22.5, 23.9, 25.0],
                        [21.7, 22.5, 23.9, 25.0],
              [20.1, 20.9, 22.3, 23.5],
                        [20.1, 20.9, 22.3, 23.5],
              [18.4, 19.1, 20.6, 21.8]]  # row = latitude, column = longitude
                        [18.4, 19.1, 20.6, 21.8]])   # row = latitude, column = longitude


def lagrange_point(nodes, values, point):
def passes(nodes, values, point, rule):
     """Value at `point` of the tensor-product Lagrange interpolant.
     """Value at `point` of the grid interpolant, one one-dimensional pass per variable.


     nodes  -- one 1-D array of node coordinates per variable, in the same order
     nodes  -- node coordinates of each variable, in the order of the axes of `values`
              as the axes of `values`
     values -- m-dimensional array of readings, values[i_1, ..., i_m]
     values -- m-dimensional array, values[i_1, ..., i_m]
     rule  -- rule(nodes, readings, t), the one-dimensional rule evaluated at t
     point  -- the m query coordinates
     """
     """
     data = np.asarray(values, dtype=float)
     data = np.asarray(values, dtype=float)
     for axis in range(len(nodes) - 1, -1, -1):       # collapse one variable per pass
     for axis, target in enumerate(point):         # one pass per variable, first axis first
         w = [np.prod([(point[axis] - k) / (i - k) for k in nodes[axis] if k != i])
         data = np.apply_along_axis(
            for i in nodes[axis]]
            lambda line: rule(np.asarray(nodes[axis], dtype=float), line, target), 0, data)
        data = np.tensordot(data, w, axes=([axis], [0]))
     return float(data)
     return float(data)


print(lagrange_point([np.arange(50.0, 54.0), np.arange(0.0, 4.0)],
linear  = lambda nodes, line, t: float(np.interp(t, nodes, line))
                    temperature, [51.6, 1.4]))
spline  = lambda nodes, line, t: float(CubicSpline(nodes, line)(t))
natural = lambda nodes, line, t: float(CubicSpline(nodes, line, bc_type="natural")(t))
 
latitude, longitude = np.arange(50.0, 54.0), np.arange(0.0, 4.0)
for name, rule in [("piecewise linear", linear), ("natural cubic spline", natural),
                  ("not-a-knot cubic spline", spline)]:
    print(name, passes([latitude, longitude], temperature, [51.6, 1.4], rule))
</syntaxhighlight>
</syntaxhighlight>


For the station grid that call returns <code>22.1162048...</code>, the same number the example of [[#Grid_interpolation|grid interpolation]] reaches by summing its 16 monomials. It gets there by touching the data in two passes: four longitude interpolations give $24.0936$, $23.0384$, $21.4328$, and $19.6656\ ^\circ$C on the rows at $50$, $51$, $52$, and $53^\circ$N, and one latitude interpolation of those four gives the reading at the query point.
Swapping the two variables in <code>nodes</code> and in <code>point</code> alike, and transposing the array of readings, returns the same three values, the two nestings differing only in the last bits of the floating-point sum.
 
With the spline rule the passes touch the data twice: four longitude interpolations give $24.0936$, $23.0384$, $21.4328$, and $19.6656\ ^\circ$C on the rows at $50$, $51$, $52$, and $53^\circ$N, and one latitude interpolation of those four gives the reading at the query point. The piecewise linear rule touches four readings in all, which is the whole of its work.


<blockquote>
<blockquote>
Because these readings happen to be close to planar, the piecewise scheme described above costs four readings instead of sixteen: bilinear interpolation of the four stations surrounding the query point gives $22.100\ ^\circ$C, only $0.02\ ^\circ$C away from the grid interpolant. The two are not interchangeable, however: the bilinear interpolant is merely continuous where cells meet, whereas the grid interpolant is a single polynomial and therefore smooth everywhere.
The piecewise scheme described above reads four readings instead of sixteen, and because these readings happen to be close to planar it also lands close: bilinear interpolation of the four stations surrounding the query point gives $22.100\ ^\circ$C, only $0.02\ ^\circ$C away from the grid interpolant. The two are not interchangeable, however: the bilinear interpolant is merely continuous where cells meet, whereas the grid interpolant is a single polynomial and therefore smooth everywhere.
</blockquote>
</blockquote>



Revision as of 15:15, 27 October 2026

Languages: English · français · Esperanto

Multidimensional interpolation is the process of finding a multivariable function $f(x_1,\cdots,x_m)$ that for a definite set of datapoints $\{(x_{1,i},\cdots,x_{m,i},y_i)\mid i\in [0,n], i \in \mathbb{N}\}$ satisfies $f(x_{1,i},\cdots,x_{m,i})=y_i$.

Methods

Grid interpolation

If a "grid" of $n^m$ datapoints is known, one on each combination of $n$ nodes in each of the $m$ variables:

$$ \{(x_{1,i_1},\cdots,x_{m,i_m},y_{i_1,\cdots,i_m})\mid i_1,\cdots,i_m \in [0,n-1],\, i_1,\cdots,i_m \in \mathbb{N}\} $$

then the interpolant is the multivariable Lagrange polynomial

$$ f(x_1,\cdots,x_m)=\sum_{i_1=0}^{n-1}\cdots\sum_{i_m=0}^{n-1}y_{i_1,\cdots,i_m}\prod_{j=1}^{m}L^{(j)}_{i_j}(x_j),\qquad L^{(j)}_{i}(x_j)=\prod_{\substack{k=0\\k\neq i}}^{n-1}\frac{x_j-x_{j,k}}{x_{j,i}-x_{j,k}} $$

where $L^{(j)}_i$ is the Lagrange basis polynomial of the variable $x_j$, built on that variable's $n$ nodes.

Each factor $L^{(j)}_{i_j}(x_j)$ equals one at the node $x_{j,i_j}$ and zero at the other $n-1$ nodes of $x_j$. The product of the $m$ factors is therefore one at the single datapoint $(x_{1,i_1},\cdots,x_{m,i_m})$ and zero at every other datapoint, so each of the $n^m$ terms carries exactly its own reading and vanishes at all the rest, and the sum passes through all $n^m$ datapoints.

The result is the tensor product interpolant, and it is unique among polynomials of degree at most $n-1$ in each variable: a difference of two of them vanishes at all $n^m$ nodes, and such a difference, read as a polynomial of degree at most $n-1$ in $x_1$, has $n$ roots for every fixed choice of the other variables, so each of its coefficients vanishes at those choices, one variable at a time[1]. In the Lagrange basis the coefficients are the readings themselves, so nothing is solved for: the $n^m$ coefficients and the $n^m$ datapoints are the same numbers.

Pointwise interpolation

Pointwise interpolation (or point evaluation) asks only for the value of $f$ at one new point $(x_1^*,\cdots,x_m^*)$ inside the data range, without constructing $f$ anywhere else. It says what is to be computed, not how $f$ is defined: the interpolation scheme, whether piecewise linear, a cubic spline, or a single polynomial, fixes the values everywhere, and pointwise evaluation fixes that only one of them is wanted. Building the whole interpolant is a separate undertaking, and the heavier one: the developed form of a high-degree polynomial in many variables runs to $n^m$ terms and, as grid interpolation showed, evaluating it develops large cancellations. The passes below never form it.

One variable at a time. A grid is a family of straight lines, one along each variable, and each of those lines is an ordinary one-dimensional dataset. A one-dimensional rule applied to the lines of one direction, and then to the lines of the next, reaches the query point, and the rule itself is a free choice. Chasnov states the two-variable case in full: on an $(n+1)\times(n+1)$ grid, first perform $n+1$ one-dimensional interpolations in one variable, giving the interpolant at the $n+1$ points $(x_0,y^*),\cdots,(x_n,y^*)$ of the line crossed at the target coordinate, then a single one-dimensional interpolation in the other variable, giving the value at $(x^*,y^*)$. The two- and three-dimensional interpolation routines of numerical software address exactly this problem; MATLAB's are interp2 and interp3[2].

The rule, named once. Let

$$ \mathcal{I}\big[\{v_k\}_{k=0}^{n-1}\big](t) $$

be the value at $t$ that the chosen rule gives to readings $v_0,\cdots,v_{n-1}$ taken at the nodes $t_0,\cdots,t_{n-1}$ of one variable. The rule may be piecewise linear, a cubic spline with whatever end condition (cubic spline interpolation), a monotone or shape-preserving scheme, or a single polynomial through the whole line. Everything below holds for any of them.

Two variables. With readings $y_{i_1,i_2}$ on $n$ nodes per axis, the first pass holds $x_1$ at each of its nodes in turn and interpolates the $n$ readings of that line in $x_2$:

$$ y^*_{i_1}=\mathcal{I}\big[\{y_{i_1,i_2}\}_{i_2=0}^{n-1}\big](x_2^*),\qquad \forall i_1\in [0,n-1],\, i_1 \in \mathbb{N} $$

The $n$ values $y^*_{i_1}$ are the interpolant at $(x_{1,i_1},x_2^*)$: the grid's lines, crossed at the target $x_2^*$. They are readings on a single line of the other direction, so one more pass finishes:

$$ f(x_1^*,x_2^*)\approx\mathcal{I}\big[\{y^*_{i_1}\}_{i_1=0}^{n-1}\big](x_1^*) $$

The first pass costs $n$ one-dimensional interpolations and the second costs $1$.

$m$ variables. Each pass removes one variable: the first leaves $n^{m-1}$ values, one per combination of the remaining nodes, the next $n^{m-2}$, and so on down to one, so the passes cost $n^{m-1}, n^{m-2}, \cdots, n^0$ interpolations whatever the rule:

$$ \sum_{k=0}^{m-1}n^{k}=\frac{n^{m}-1}{n-1} $$

One-dimensional interpolations for one query point, with $n=4$ nodes per axis
$m$ first pass second pass third pass fourth pass total
2 4 1 – – 5
3 16 4 1 – 21
4 64 16 4 1 85

What the rule changes, and what it does not. The passes run the same way for every rule, but what each pass has to read, and how smooth the result is, are the rule's doing:

  • a local rule, such as piecewise linear, reads only the two nodes bracketing the target on its line. Only the lines that bracket the target then need interpolating, so the work follows the stencil and not the grid: two lines in the first pass of the station example below, and two readings on each of them;
  • a global rule, such as a cubic spline or a single polynomial through the whole line, draws on every node of its line, so every line of every pass is interpolated. What is saved is then not the count of interpolations but everything that is never built: the coefficient form of the surface, and with it the cancellation that grid interpolation pays for;
  • whichever the rule, each line interpolation reproduces the readings at its own nodes, so the composed value at a datapoint is exactly the reading there;
  • smoothness is inherited: piecewise linear passes give a surface that is continuous but creased along the lines between cells, whereas spline passes give one that is smooth in each variable.

Rules linear in the readings. Nearly every rule computes its value as a weighted sum

$$ \mathcal{I}\big[\{v_k\}_{k=0}^{n-1}\big](t)=\sum_{k=0}^{n-1}\varphi_k(t)\,v_k $$

whose weights $\varphi_k$ are fixed by the nodes and by $t$, but not by the readings: the hats of the two neighbouring nodes for a piecewise linear rule, the cardinal splines for a spline rule. Two passes with such a rule give

$$ f(x_1^*,x_2^*)=\sum_{i_1=0}^{n-1}\sum_{i_2=0}^{n-1}\varphi^{(1)}_{i_1}(x_1^*)\,\varphi^{(2)}_{i_2}(x_2^*)\,y_{i_1,i_2} $$

in which the weights of the two directions multiply. The $n^2$ products are the same under either nesting of the two sums, and in $m$ variables under any order of the $m$ passes, so the order in which the variables are collapsed changes nothing[3]. A rule that is not linear in its readings, such as a monotone or shape-preserving one, offers no such weights, and the passes may then answer differently in different orders.

The station grid again. Applied to the sixteen readings of grid interpolation, the passes at $1.4^\circ$E, $51.6^\circ$N give, for three rules:

Value at $1.4^\circ$E, $51.6^\circ$N, from the same sixteen readings and three one-dimensional rules
rule value ($^\circ$C)
piecewise linear 22.1000
natural cubic spline 22.1157
not-a-knot cubic spline 22.1162

The last entry is the number that grid interpolation reaches by summing its 16 monomials, and not by accident: a line of four nodes has a single cubic piece, so on such a line the not-a-knot spline is the one cubic through its four readings, and the composed surface is the one that section builds. A longer line, or the natural end condition, departs from it; on these nearly planar readings the natural spline already differs in the fourth decimal, and on readings less nearly planar it would differ more.

The passes in code, with the rule passed in as an argument:

import numpy as np
from scipy.interpolate import CubicSpline

temperature = np.array([[22.8, 23.6, 24.9, 26.1],
                        [21.7, 22.5, 23.9, 25.0],
                        [20.1, 20.9, 22.3, 23.5],
                        [18.4, 19.1, 20.6, 21.8]])   # row = latitude, column = longitude

def passes(nodes, values, point, rule):
    """Value at `point` of the grid interpolant, one one-dimensional pass per variable.

    nodes  -- node coordinates of each variable, in the order of the axes of `values`
    values -- m-dimensional array of readings, values[i_1, ..., i_m]
    rule   -- rule(nodes, readings, t), the one-dimensional rule evaluated at t
    """
    data = np.asarray(values, dtype=float)
    for axis, target in enumerate(point):         # one pass per variable, first axis first
        data = np.apply_along_axis(
            lambda line: rule(np.asarray(nodes[axis], dtype=float), line, target), 0, data)
    return float(data)

linear  = lambda nodes, line, t: float(np.interp(t, nodes, line))
spline  = lambda nodes, line, t: float(CubicSpline(nodes, line)(t))
natural = lambda nodes, line, t: float(CubicSpline(nodes, line, bc_type="natural")(t))

latitude, longitude = np.arange(50.0, 54.0), np.arange(0.0, 4.0)
for name, rule in [("piecewise linear", linear), ("natural cubic spline", natural),
                   ("not-a-knot cubic spline", spline)]:
    print(name, passes([latitude, longitude], temperature, [51.6, 1.4], rule))

Swapping the two variables in nodes and in point alike, and transposing the array of readings, returns the same three values, the two nestings differing only in the last bits of the floating-point sum.

With the spline rule the passes touch the data twice: four longitude interpolations give $24.0936$, $23.0384$, $21.4328$, and $19.6656\ ^\circ$C on the rows at $50$, $51$, $52$, and $53^\circ$N, and one latitude interpolation of those four gives the reading at the query point. The piecewise linear rule touches four readings in all, which is the whole of its work.

The piecewise scheme described above reads four readings instead of sixteen, and because these readings happen to be close to planar it also lands close: bilinear interpolation of the four stations surrounding the query point gives $22.100\ ^\circ$C, only $0.02\ ^\circ$C away from the grid interpolant. The two are not interchangeable, however: the bilinear interpolant is merely continuous where cells meet, whereas the grid interpolant is a single polynomial and therefore smooth everywhere.

References