This module provides a calculus for uni- and multivariate polynomials using the vector exponent notation [Wildhaber2019], Chapter 6. This calculus simplifies to use polynomials in (squared error) cost functions, e.g., as localized signal models.
Module Content
Polynomial Classes
Polynomial Operators
Operators for Univariate Polynomials
API (module: polynomial)
Classes
Methods
Poly
Univariate polyonimial in vector exponent notation: \(\alpha^\mathsf{T} x^q\)
MPoly
Multivariate polynomials \({\tilde{\alpha}}^\mathsf{T} (x^q \otimes y^r)\), or with factorized coefficient vector \((\alpha \otimes \beta )^\mathsf{T} (x^q \otimes y^r)\).
Sum of Polynomials \(\alpha^\mathsf{T} x^q + \beta^\mathsf{T} x^r\)
Product of Polynomials \(\alpha^\mathsf{T} x^q \cdot \beta^\mathsf{T} x^r\)
Square of a Polynomial \((\alpha^\mathsf{T} x^q)^2\)
Shift of a Polynomial \(\alpha^\mathsf{T} (x+ \gamma)^q\)
Dilation of a Polynomial \(\alpha^\mathsf{T} (\eta x)^q\)
Integral of a Polynomial \(\int (\alpha^\mathsf{T} x^q) dx\)
Derivative of a Polynomial \(\frac{d}{dx} (\alpha^\mathsf{T} x^q)\)
Operators handling univariate polynomials. Return parameters are highlighted in \(\color{blue}{blue}\).
poly_sum(polys)
poly_sum
\(\alpha^\mathsf{T} x^q + \dots + \beta^\mathsf{T} x^r = \color{blue}{\tilde{\alpha}^\mathsf{T} x^\tilde{q}}\)
poly_sum_coef(polys)
poly_sum_coef
\(\alpha^\mathsf{T} x^q + \dots + \beta^\mathsf{T} x^r = \color{blue}{\tilde{\alpha}}^\mathsf{T} x^\tilde{q}\)
poly_sum_coef_Ls(expos)
poly_sum_coef_Ls
\(\alpha^\mathsf{T} x^q + \dots + \beta^\mathsf{T} x^r = (\color{blue}{\Lambda_1} \alpha + \dots + \color{blue}{\Lambda_N}\beta)^\mathsf{T} x^{\tilde{q}}\)
poly_sum_expo(expos)
poly_sum_expo
\(\alpha^\mathsf{T} x^q + \dots + \beta^\mathsf{T} x^r = \tilde{\alpha}^\mathsf{T} x^{\color{blue}{\tilde{q}}}\)
poly_sum_expo_Ms(expos)
poly_sum_expo_Ms
\(\alpha^\mathsf{T} x^q + \dots + \beta^\mathsf{T} x^r = \tilde{\alpha}^\mathsf{T} x^{\color{blue}{M_1} q + \dots +\color{blue}{M_N} r}\)
>>> import lmlib as lm >>> >>> p1 = lm.Poly([1, 3, 5], [0, 1, 2]) >>> p2 = lm.Poly([2, -1], [0, 1]) >>> >>> p_sum = lm.poly_sum((p1, p2)) >>> print(p_sum) [ 1. 3. 5. 2. -1.], [0. 1. 2. 0. 1.]
poly_prod(polys)
poly_prod
\(\alpha^\mathsf{T} x^q \cdot \beta^\mathsf{T} x^q = \color{blue}{\tilde{\alpha}^\mathsf{T} x^\tilde{q}}\)
poly_prod_coef(polys)
poly_prod_coef
\(\alpha^\mathsf{T} x^q \cdot \beta^\mathsf{T} x^r = \color{blue}{\tilde{\alpha}}^\mathsf{T} x^\tilde{q}\)
poly_prod_expo(expos)
poly_prod_expo
\(\alpha^\mathsf{T} x^q \cdot \beta^\mathsf{T} x^r = \tilde{\alpha}^\mathsf{T} x^{\color{blue}{\tilde{q}}}\)
poly_prod_expo_Ms(expos)
poly_prod_expo_Ms
\(\alpha^\mathsf{T} x^q \cdot \beta^\mathsf{T} x^r = \tilde{\alpha}^\mathsf{T} x^{\color{blue}{M_1} q + \color{blue}{M_2} r}\)
>>> import lmlib as lm >>> >>> p1 = lm.Poly([1, 3, 5], [0, 1, 2]) >>> p2 = lm.Poly([2, -1], [0, 1]) >>> >>> p_prod = lm.poly_prod((p1, p2)) >>> print(p_prod) [ 2 -1 6 -3 10 -5], [0. 1. 1. 2. 2. 3.]
poly_square(poly)
poly_square
\((\alpha^\mathsf{T} x^q)^2 = \color{blue}{\tilde{\alpha}^\mathsf{T} x^\tilde{q}}\)
poly_square_coef(poly)
poly_square_coef
\(\color{blue}{\tilde{\alpha}}^\mathsf{T} x^\tilde{q}\)
poly_square_expo(expo)
poly_square_expo
\(\tilde{\alpha}^\mathsf{T} x^{\color{blue}{\tilde{q}}}\)
poly_square_expo_M(expo)
poly_square_expo_M
\(\tilde{\alpha}^\mathsf{T} x^{\color{blue}{M} q}\)
>>> import lmlib as lm >>> >>> p1 = lm.Poly([1, 3, 5], [0, 1, 2]) >>> >>> p_square = lm.poly_square(p1) >>> print(p_square) [ 1 3 5 3 9 15 5 15 25], [0. 1. 2. 1. 2. 3. 2. 3. 4.]
poly_shift(poly, gamma)
poly_shift
\(\alpha^\mathsf{T} (x+ \gamma)^q = \color{blue}{\tilde{\alpha}^\mathsf{T} x^\tilde{q}}\)
poly_shift_coef(poly, gamma)
poly_shift_coef
poly_shift_coef_L(expo, gamma)
poly_shift_coef_L
\(\color{blue}{\Lambda} \alpha^\mathsf{T} x^{\tilde{q}}\)
poly_shift_expo(expo)
poly_shift_expo
>>> import lmlib as lm >>> >>> p1 = lm.Poly([1, 3, 5], [0, 1, 2]) >>> gamma = 2 >>> p_shift = lm.poly_shift(p1, gamma) >>> print(p_shift) [27. 23. 5.], [0 1 2]
poly_dilation(poly, eta)
poly_dilation
\(\alpha^\mathsf{T} (\eta x)^q = \color{blue}{\tilde{\alpha}^\mathsf{T} x^q}\)
poly_dilation_coef(poly, eta)
poly_dilation_coef
\(\alpha^\mathsf{T} (\eta x)^q =\color{blue}{\tilde{\alpha}}^\mathsf{T} x^q\)
poly_dilation_coef_L(expo, eta)
poly_dilation_coef_L
\(\alpha^\mathsf{T} (\eta x)^q =\color{blue}{\Lambda} \alpha^\mathsf{T} x^{q}\)
>>> import lmlib as lm >>> >>> p1 = lm.Poly([1, 3, 5], [0, 1, 2]) >>> eta = -5 >>> p_dilation = lm.poly_dilation (p1, eta) >>> print(p_dilation) [ 1 -15 125], [0 1 2]
poly_int(poly)
poly_int
\(\int \big(\alpha^{\mathsf{T}}x^q\big) dx = \color{blue}{\tilde{\alpha}^\mathsf{T} x^\tilde{q}}\)
poly_int_coef(poly)
poly_int_coef
\(\int \big(\alpha^{\mathsf{T}}x^q\big) dx = \color{blue}{\tilde{\alpha}}^\mathsf{T} x^\tilde{q}\)
poly_int_coef_L(expo)
poly_int_coef_L
\(\int \big(\alpha^{\mathsf{T}}x^q\big) dx = \color{blue}{\Lambda} \alpha^\mathsf{T} x^{\tilde{q}}\)
poly_int_expo(expo)
poly_int_expo
\(\int \big(\alpha^{\mathsf{T}}x^q\big) dx = \tilde{\alpha}^\mathsf{T} x^{\color{blue}{\tilde{q}}}\)
>>> import lmlib as lm >>> >>> p1 = lm.Poly([1, 3, 5], [0, 1, 2]) >>> >>> p_int = lm.poly_int(p1) >>> print(p_int) [1. 1.5 1.66666667], [1 2 3]
poly_diff(poly)
poly_diff
\(\frac{d}{dx} \big(\alpha^{\mathsf{T}}x^q\big) = \color{blue}{\tilde{\alpha}^\mathsf{T} x^\tilde{q}}\)
poly_diff_coef(poly)
poly_diff_coef
\(\frac{d}{dx} \big(\alpha^{\mathsf{T}}x^q\big) =\color{blue}{\tilde{\alpha}}^\mathsf{T} x^\tilde{q}\)
poly_diff_coef_L(expo)
poly_diff_coef_L
\(\frac{d}{dx} \big(\alpha^{\mathsf{T}}x^q\big) =\color{blue}{\Lambda} \alpha^\mathsf{T} x^{\tilde{q}}\)
poly_diff_expo(expo)
poly_diff_expo
\(\frac{d}{dx} \big(\alpha^{\mathsf{T}}x^q\big) =\tilde{\alpha}^\mathsf{T} x^{\color{blue}{\tilde{q}}}\)
>>> import lmlib as lm >>> >>> p1 = lm.Poly([1, 3, 5], [0, 1, 2]) >>> >>> p_diff = lm.poly_diff(p1) >>> print(p_diff) [ 0 3 10], [0 0 1]
Bases: lmlib.polynomial.poly._PolyBase
lmlib.polynomial.poly._PolyBase
Polynomial class for uni-variate polynomials in vector exponent notation, [Wildhaber2019], see Chapter 6.
Such a polynomial p(x) in x is defined as
with coefficient vector \(\alpha \in \mathbb{R}^Q\), exponent vector \(q \in \mathbb{Z}_{\geq 0}^Q\), and function variable \(x \in \mathbb{R}\).
coef (array_like, shape=(Q)) – Coefficient vector
expo (array_like, shape=(Q)) – Exponent vector
Q : number of elements in exponent vector
Examples
>>> import lmlib as lm >>> p = Poly([0, 0.2, 3], [0, 1, 2]) >>> print(p)
Attributes
Poly.coef
Coefficient vector \(\alpha\)
Poly.expo
Exponent vector \(q\)
Poly.Q
Number of elements in exponent vector \(Q\)
Poly.coefs
Coefficient vector (i.e., not factorized)
Poly.expos
Exponent vectors
Poly.variable_count
Number of dependent variables
eval(variable)
eval
Evaluates the polynomial
variable (array_like, scalar) – Dependent variables of a polynomial.
out (ndarray) – Output of evaluated polynomial. Shape is identical as a dependent variable
ndarray
This polynomial class is for multivariate polynomials in vector exponent notation, see [Wildhaber2019], Chapter 6.
Such a multivariate polynomial is in general given by
where \(\tilde{\alpha} \in \mathbb{R}^{Q \times R}\) is the coefficient vectors, \(q \in \mathbb{Z}_{\geq 0}^Q\) and \(r \in \mathbb{Z}_{\geq 0}^R\) the exponent vectors, and \(x \in \mathbb{R}\) and \(y \in \mathbb{R}\) the independent variables.
As a special case, if the coefficient vector is in the form of a Kronecker product, i.e.,
where \(\alpha \in \mathbb{R}^Q\) and \(\beta \in \mathbb{R}^R\) are coefficient vectors, we denote a polynomial as factorized. This form often leads to algebraic simplifications (if it exists).
>>> # Bivariate (x,y) polynomial with factorized coefficients ([.2,.7],[-1.0,2.0,.1]) and terms x^1, x^2, y^1, y^2, y^3, and cross terms >>> l= lm.MPoly(([.2,.7],[-1.0,2.0,.1]),([1,2],[1,2,3])) >>> l.coefs # gets coefficients (array([0.2, 0.7]), array([-1. , 2. , 0.1])) >>> l.coef_fac # gets factorized coefficients (if available) array([-0.2 , 0.4 , 0.02, -0.7 , 1.4 , 0.07]) >>> l.eval([.3,.7]) # evaluating polynomial for x=.3 and y=.7 array(0.0386589)
>>> # Bivariate (x,y) polynomial with non-factorized coefficients ([.2,.7,1.3,1.4,.2,-1.6]) and terms x^1, x^2, y^1, y^2, y^3, and cross terms >>> l= lm.MPoly(([.2,.7,1.3,1.4,.2,-1.6],),([1,2],[1,2,3])) >>> l.eval([.3,.7]) # evaluating polynomial for x=.3 and y=.7 array(0.326298)
coefs (tuple of array_like) – Set of coefficient vector(s)
expos (tuple of array_like) – Set of exponent vector(s)
MPoly.coefs
MPoly.expos
MPoly.variable_count
MPoly.coefs_fac
Factorized coefficient vectors
eval(variables)
Evaluates the polynomial for given values (variables)
variables (tuple) – Dependent variables of a polynomial. Each element in variables has the same shape which is also the output shape.
Example
>>> # evaluate bivariate polynomial at multiple positions (x=.1 ... .4, y=.5) >>> l = lm.MPoly(([.2, .7], [1.3, 1.4, -.9],), ([0, 1], [0, 1, 2])) >>> l.eval(([.1, .2, .3, .4], [.5, .5, .5, .5])) array([0.47925, 0.6035, 0.72775, 0.852])
Sum of univariate polynomials Poly(alpha,q),... , Poly(beta,r), all of common variable x
Poly(alpha,q),... , Poly(beta,r)
polys (tuple of Poly) – (Poly(alpha,q),... , Poly(beta,r)), list of polynomials to be summed
(Poly(alpha,q),... , Poly(beta,r))
out (Poly) – Poly(alpha_tilde, q_tilde)
Poly(alpha_tilde, q_tilde)
References
[Wildhaber2019] (Eq. 6.4)
Coefficient vector \(\tilde{q}\) to sum of univariate polynomials polys, all of common variable x
polys
coef (ndarray) – alpha_tilde - Coefficient vector \(\tilde{\alpha}\)
alpha_tilde
Note
To get \(\tilde{q}\), see poly_sum_expo().
poly_sum_expo()
Exponent manipulation matrices \(\Lambda_1, ...., Lambda_N\) to sum univariate polynomials polys, all of common variable x
expos (tuple of array_like) – (q, ..., r), list of exponent vectors of polynomials to be summed
(q, ..., r)
Ls (list of ndarray) – (Lambda_1, ..., Lambda_N), Coefficient manipulation matrices, see also poly_sum()
(Lambda_1, ..., Lambda_N)
poly_sum()
Exponent vector \(\tilde{1}\) of sum of univariate polynomials with exponent vectors expos, all of common variable x
expos
expo ndarray – q_tilde, exponent vector \(\tilde{q}\)
q_tilde
To get \(\tilde{\alpha}\), see poly_sum_coef().
poly_sum_coef()
Exponent manipulation matrices \(M_1, ... , M_N\) to sum univariate polynomials with exponent vectors expos, all of common variable x
Ms (list of ndarray) – (M_1, ..., M_N), list of exponent manipulation matrices, see also poly_sum().
(M_1, ..., M_N)
Product of two univariate polynomials of common variable x
polys (tuple of Poly) – (poly_1, poly_2), two polynomials to be multiplied
(poly_1, poly_2)
out (Poly) – poly_tilde, product as polynomial \(\tilde{\alpha}^\mathsf{T} x^\tilde{q}\)
poly_tilde
[Wildhaber2019] (Eq. 6.14)
Coefficient vector \(\tilde{\alpha}\) of product of two univariate polynomials of common variable x
coef ndarray – alpha_tilde, coefficient vector \(\tilde{\alpha}\) of product polynomial \(\tilde{\alpha}^\mathsf{T} x^\tilde{q}\), see poly_prod()
poly_prod()
[Wildhaber2019] (Eq. 6.12)
Exponent vector \(\tilde{q}\) of product of two univariate polynomials of common variable x
expos (tuple of arraylike) – (q, r), exponent vectors of the two polynomials
(q, r)
coef ndarray – q_tilde, exponent vector \(\tilde{q}\) of product polynomial \(\tilde{\alpha}^\mathsf{T} x^\tilde{q}\), see poly_prod()
[Wildhaber2019] (Eq. 6.16)
Exponent manipulation matrices \(M_1, M_2\) of product of two univariate polynomials of common variable x
expos (tuple of arraylike) – (q, r), exponent vectors
Ms (list of ndarray) – (M_1, ..., M_N), list of exponent manipulation matrices for the two polynomial exponent vectors, i.e., the new exponent vector results from \(\tilde{q} = M_1 q + M_2 r\). See poly_prod().
Square of a univariate polynomial
poly (Poly) – poly, polynomial to be squared
poly
out (Poly) – squared polynomial
[Wildhaber2019] (Eq. 6.11)
Coefficient vector \(\tilde{\alpha}\) of squared polynomial, see poly_square()
poly_square()
coef ndarray, – alpha_tilde Coefficient vector \(\tilde{\alpha}\)
Exponent vector \(\tilde{q}\) of squared polynomial, see poly_square().
expo (array_like,) – q, exponent vector \(q\)
q
out ndarray, – q_tilde, exponent vector \(\tilde{q}\)
Exponent manipulation matrix \(M\) of squared polynomial, see poly_square()
M (ndarray,) – M, exponent manipulation matrix \(M\)
M
[Wildhaber2019] (Eq. 6.10, Eq. 6.13)
Shifting an univariate polynomial by constant value \(\gamma \in \mathbb{R}\)
poly (Poly) – polynomial to be shifted
gamma (float) – gamma, shift parameter \(\gamma\)
gamma
out (Poly) – shifted polynomial, \(\tilde{\alpha}^\mathsf{T} x^\tilde{q}\)
[Wildhaber2019] (Eq. 6.28)
Coefficient vector of shifted polynomial, see poly_shift()
poly_shift()
coef (ndarray) – alpha_tilde Coefficient vector \(\tilde{\alpha}\)
[Wildhaber2019] (Eq. 6.29)
Coefficient manipulation \(\Lambda}\) for shifted polynomial, see poly_shift()
L (ndarray) – L, coefficient manipulation matrices \(\Lambda\).
L
[Wildhaber2019] (Eq. 6.32)
Exponent vector \(\tilde{q}\) for shifted polynomial, see poly_shift()
expo (ndarray) – q_tilde, exponent vector \(\tilde{q}\).
[Wildhaber2019] (Eq. 6.30)
Dilation of a polynomial by scaling x by constant value \(\eta \in \mathbb{R}\)
poly (Poly) – polynomial to be scaled
eta (float) – eta, dilation factor \(\eta\)
eta
out (Poly) – dilated polynomial, \(\tilde{\alpha}^\mathsf{T} x^\tilde{q}\)
[Wildhaber2019] (Eq. 6.33)
Coefficient vector \(\tilde{\alpha}\) of dilated polynomial by scaling x by constant value \(\eta \in \mathbb{R}\), see poly_dilation().
poly_dilation()
coef ndarray – Coefficient vector \(\tilde{\alpha}\)
[Wildhaber2019] (Eq. 6.34)
Coefficient manipulation matrix \(\tilde{\Lambda}\) to dilated polynomial by scaling x by constant value \(\eta \in \mathbb{R}\), see poly_dilation().
L (ndarray) – L, Coefficient Manipulation Matrices \(\Lambda\)
[Wildhaber2019] (Eq. 6.35)
Indefinite integral of a polynomial
poly (Poly) – polynomial to be integrated
out (Poly) – polynomial, \(\tilde{\alpha}^\mathsf{T} x^\tilde{q}\)
[Wildhaber2019] (Eq. 6.17)
Coefficient vector \(\tilde{\alpha}\) of indefinite integral of a polynomial, see poly_int()
poly_int()
coef (ndarray,) – alpha_tilde, Coefficient vector \(\tilde{\alpha}\)
[Wildhaber2019] (Eq. 6.18)
Coefficient manipulation matrix \(\Lambda\) of indefinite integral of a polynomial, see poly_int().
expo (array_like) – q, Exponent vector \(q\)
L (ndarray) – L, coefficient Manipulation Matrices \(\Lambda\)
[Wildhaber2019] (Eq. 6.20-21)
Exponent vector \(\tilde{q}\) of indefinite integral of a polynomial, see poly_int().
expo (array_like) – q, exponent vector \(q\)
expo (ndarray) – q_tilde, exponent vector \(\tilde{q}\)
[Wildhaber2019] (Eq. 6.19)
Derivation of a polynomial
poly (Poly) – polynomial for derivation
out (Poly) – derivative \(\tilde{\alpha}^\mathsf{T} x^\tilde{q}\)
[Wildhaber2019] (Eq. 6.24)
Coefficient vector \(\tilde{\alpha}\) of polynomial derivation, see poly_diff()
poly_diff()
coef (ndarray) – alpha_tilde, coefficient vector \(\tilde{\alpha}\)
[Wildhaber2019] (Eq. 6.25)
Coefficient manipulation matrix \(\Lambda\) of polynomial derivation, see poly_diff()
expo (array_like) – Exponent vector \(q\)
L (ndarray) – L, coefficient manipulation matrices \(\Lambda\)
[Wildhaber2019] (Eq. 6.27)
Exponent vector \(\tilde{q}\) of polynomial derivation, see poly_diff()
[Wildhaber2019] (Eq. 6.26)