# lmlib.polynomial.poly.MPoly#

class lmlib.polynomial.poly.MPoly(coefs, expos)#

Bases: lmlib.polynomial.poly._PolyBase

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)$$.

This polynomial class is for multivariate polynomials in vector exponent notation, see [Wildhaber2019], Chapter 6.

Such a multivariate polynomial is in general given by

$p(x) = \tilde{\alpha}^\mathsf{T}(x^q \otimes y^r) \ ,$

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.,

$p(x) = (\alpha \otimes \beta)^\mathsf{T}(x^q \otimes y^r) \ ,$

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).

Examples

>>> # 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= 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= 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)

Parameters
• coefs (tuple of array_like) – Set of coefficient vector(s)

• expos (tuple of array_like) – Set of exponent vector(s)

Methods

 __init__(coefs, expos) Constructor method eval(variables) Evaluates the polynomial for given values (variables)

Attributes

 coefs Coefficient vector (i.e., not factorized) coefs_fac Factorized coefficient vectors expos Exponent vectors variable_count Number of dependent variables
property coefs#

Coefficient vector (i.e., not factorized)

Type

tuple of ndarray

property coefs_fac#

Factorized coefficient vectors

Type

ndarray, None

eval(variables)#

Evaluates the polynomial for given values (variables)

Parameters

variables (tuple) – Dependent variables of a polynomial. Each element in variables has the same shape which is also the output shape.

Returns

out – Output of evaluated polynomial. Shape is identical as a dependent variable

Return type

ndarray

Example

>>> # evaluate bivariate polynomial at multiple positions (x=.1 ... .4, y=.5)
>>> l = 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])

property expos#

Exponent vectors

Type

tuple of ndarray

property variable_count#

Number of dependent variables

Type

int