I found through some experimentation that barycenctric lagrange does not "weight" points like I had hoped. It is still very unstable if your input arrays are large (i.e. it still tries to construct the nth degree polynomial).
Barycentric has stability improvements for when the values are large.
Lagrange is good if your x and y are close to 0. So x = [20000, 20001, 20002] will be much less stable than [0, 1, 2]. The weights in barycentric, therefore, are simply a way of scaling your values to 0.
So the lagrange interpolation as follows:
x_scaled = x - x[0]
y_scaled = y - y[0]
polynomial = scipy.lagrange(x_scaled, y_scaled)
interp_y = polynomial(interp_x - x[0]) + y[0]
is the same as:
interp_y = scipy.barycentric_interpolate(x, y, interp_x)
So obviously the second one is much easier to implement in code, and they give the same result.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…