polynomial_exponents¶
- sofia_redux.toolkit.resampling.polynomial_exponents(order, ndim=None, use_max_order=False)[source]¶
Define a set of polynomial exponents.
The resampling algorithm uses defines a set of polynomial exponents as an array of shape (dimensions, terms) for an equation of the form:
\[f( \Phi ) = \sum_{m=1}^{M}{c_m \Phi_m}\]for \(M\) terms. Here, \(\Phi_m\) represents the product of independent variables, each raised to an appropriate power as defined by
exponents
. For example, consider the equation for 2-dimensional data with independent variables \(x\) and \(y\):\[f(x, y) = c_1 + c_2 x + c_3 x^2 + c_4 y + c_5 x y + c_6 y^2\]In this case:
exponents = [[0, 0], # represents a constant or x^0 y^0 [1, 0], # represents x [2, 0], # represents x^2 [0, 1], # represents y [1, 1], # represents xy [0, 2]] # represents y^2
The resampling algorithm solves for the coefficients (\(c\)) by converting \(f(X) \rightarrow f(\Phi)\) for \(K-\text{dimensional}\) independent variables (\(X\)) and
exponents
(\(p\)) by setting:\[\Phi_m = \prod_{k=1}^{K}{X_{k}^{p_{m, k}}}\]In most of the code, the \(\Phi\) terms are interchangable with “polynomial terms”, and in the above example \(\Phi_5 = xy\) since exponents[4] = [1, 1] representing \(x^1 y^1\).
Note that for all terms (\(m\)) in each dimension \(k\), \(\sum_{k=1}^{K}{p_{m, k}} \leq max(\text{order})\). In addition, if
use_max_order
isFalse
(default), \(p_{m,k} \leq \text{order}[k]\).- Parameters:
- orderint or array_like of int
Polynomial order for which to generate exponents. If an array will create full polynomial exponents over all len(order) dimensions.
- ndimint, optional
If set, return Taylor expansion for
ndim
dimensions for the givenorder
iforder
is not an array.- use_max_orderbool, optional
This keyword is only applicable for multi-dimensional data when orders are unequal across dimensions. When
True
, the maximum exponent for each dimension is equal to max(order). IfFalse
, the maximum available exponent for dimension k is equal to order[k].
- Returns:
- exponentsnumpy.ndarray
(n_terms, n_dimensions) array of polynomial exponents.
Examples
>>> polynomial_exponents(3) array([[0], [1], [2], [3]])
>>> polynomial_exponents([1, 2]) array([[0, 0], [1, 0], [0, 1], [1, 1], [0, 2]])
>>> polynomial_exponents(3, ndim=2) array([[0, 0], [1, 0], [2, 0], [3, 0], [0, 1], [1, 1], [2, 1], [0, 2], [1, 2], [0, 3]])