polynomial_derivative_map

sofia_redux.toolkit.resampling.polynomial_derivative_map(exponents)[source]

Creates a mapping from polynomial exponents to derivatives.

Please see polynomial_exponents() for details on how a polynomial equation is defined within the resampling algorithm, and the use of the exponents array in defining the polynomial terms (\(\Phi\)).

Within the confines of the resampling algorithm, the polynomial exponents should have always been defined in a way that will always allow the derivative of a polynomial fit to be calculated from existing, pre-calculated \(\Phi\) terms.

For example, consider the 2-dimensional 2nd order polynomial equation and its derivatives in each dimension:

\[f(x, y) = c_1 + c_2 x + c_3 x^2 + c_4 y + c_5 x y + c_6 y^2\]
\[\frac{\partial f}{\partial x} = c_2 + 2 c_3 x + c_5 y\]
\[\frac{\partial f}{\partial y} = c_4 + c_5 x + 2 c_6 y\]

Converting \(f(x, y) \rightarrow f(\Phi)\) we get:

\[f(\Phi) = c_1 \Phi_1 + c_2 \Phi_2 + c_3 \Phi_3 + c_4 \Phi_4 + c_5 \Phi_5 + c_6 \Phi_6\]

It can then be seen that

\[\frac{\partial f}{\partial x} = c_2 \Phi_1 + 2 c_3 \Phi_2 + c_5 \Phi_4\]
\[\frac{\partial f}{\partial y} = c_4 \Phi_1 + c_5 \Phi_2 + 2 c_6 \Phi_4\]

Generalizing for a polynomial equation consisting of \(M\) terms of the independent variable \(X\) in \(K-\text{dimensions}\), a mapping (\(h\)) can be devised enabling calculation of the derivatives from pre-existing terms. For dimension \(k\):

\[\frac{\partial f}{\partial X_k} = \sum_{m=1}^{M} {h_{k, 0, m} \cdot c_{h_{k, 1, m}} \cdot \Phi_{h_{k, 2, m}}}\]

This allows the derivative to be calculated from the existing polynomial terms (\(\Phi\)) and coefficients (\(c\)). In addition, the mapping can be calculated prior to reduction and will therefore only need to be calculated once along with \(\Phi\). Once the coefficients are known, the derivatives can then be calculated using \(h\).

Derivatives may be evaluated using evaluate_derivative() and evaluate_derivatives().

Parameters:
exponentsnumpy.ndarray (n_terms, n_dimensions)

The exponents defining a polynomial equation.

Returns:
derivative_mapnumpy.ndarray of int

An array of shape (n_dimensions, 3, n_valid_terms). The second dimension (of size 3) gives a constant multiplier in the first element, the coefficient index in the second element, and the phi index in the second element. The third dimension will generally be of a smaller size than the number of terms in the polynomial equation as not all are required to calculate the derivative. Due to the fact that some dimensions may contain more valid terms than others, n_valid_terms is set to the maximum number of valid terms over all dimensions. Any invalid terms still remaining in the mapping array will have multipliers set to zero, and index pointers set to -1.