Construct a Vandermonde matrix from a 1-D or batched vector.
Given an input of shape (*, n), returns the
(*, n, N) tensor whose -th column is a power of
:
Vandermonde matrices arise naturally in polynomial fitting and interpolation: the columns are the basis evaluated at the data points.
Parameters
Input tensor of shape
(*, n); a 0-d tensor is a vector of one.
Floating, complex or integer; an integer input stays integral.N(int or None, keyword - only)= NoneNumber of columns. Defaults to (square output per vector).
increasing(bool, keyword - only)= TrueDefault
True: column 0 is , as the reference orders
it. False reverses the columns.Returns
Tensor(*, n, N) Vandermonde tensor; int64 for an integer input.
Raises
RuntimeErrorIf
x is a bool tensor (a dtype-mismatch refusal, also a
TypeError, as the reference's); cast it first.Notes
The powers are a running product of x, as the reference builds
them, so they are exact for an integer input and the derivative at
is the exact one. The default was decreasing powers.
Vandermonde matrices become highly ill-conditioned as grows (condition number grows exponentially) — for polynomial regression beyond degree prefer an orthogonal-polynomial basis or QR-based fitting.
Examples
>>> import lucid
>>> from lucid.linalg import vander
>>> vander(lucid.tensor([1.0, 2.0, 3.0]))
tensor([[1., 1., 1.], [1., 2., 4.], [1., 3., 9.]])