class ABCPolyBase(abc.ABC): (source)
Known subclasses: numpy.polynomial.chebyshev.Chebyshev
, numpy.polynomial.hermite.Hermite
, numpy.polynomial.hermite_e.HermiteE
, numpy.polynomial.laguerre.Laguerre
, numpy.polynomial.legendre.Legendre
, numpy.polynomial.polynomial.Polynomial
An abstract base class for immutable series classes. ABCPolyBase provides the standard Python numerical methods '+', '-', '*', '//', '%', 'divmod', '**', and '()' along with the methods listed below. .. versionadded:: 1.9.0 Parameters ---------- coef : array_like Series coefficients in order of increasing degree, i.e., ``(1, 2, 3)`` gives ``1*P_0(x) + 2*P_1(x) + 3*P_2(x)``, where ``P_i`` is the basis polynomials of degree ``i``. domain : (2,) array_like, optional Domain to use. The interval ``[domain[0], domain[1]]`` is mapped to the interval ``[window[0], window[1]]`` by shifting and scaling. The default value is the derived class domain. window : (2,) array_like, optional Window, see domain for its use. The default value is the derived class window. symbol : str, optional Symbol used to represent the independent variable in string representations of the polynomial expression, e.g. for printing. The symbol must be a valid Python identifier. Default value is 'x'. .. versionadded:: 1.24 Attributes ---------- coef : (N,) ndarray Series coefficients in order of increasing degree. domain : (2,) ndarray Domain that is mapped to window. window : (2,) ndarray Window that domain is mapped to. symbol : str Symbol representing the independent variable. Class Attributes ---------------- maxpower : int Maximum power allowed, i.e., the largest number ``n`` such that ``p(x)**n`` is allowed. This is to limit runaway polynomial size. domain : (2,) ndarray Default domain of the class. window : (2,) ndarray Default window of the class.
Class Method | basis |
Series basis polynomial of degree deg . |
Class Method | cast |
Convert series to series of this class. |
Class Method | fit |
Least squares fit to data. |
Class Method | fromroots |
Return series instance that has the specified roots. |
Class Method | identity |
Identity function. |
Method | __add__ |
Undocumented |
Method | __call__ |
Undocumented |
Method | __divmod__ |
Undocumented |
Method | __eq__ |
Undocumented |
Method | __floordiv__ |
Undocumented |
Method | __format__ |
Undocumented |
Method | __getstate__ |
Undocumented |
Method | __init__ |
Undocumented |
Method | __iter__ |
Undocumented |
Method | __len__ |
Undocumented |
Method | __mod__ |
Undocumented |
Method | __mul__ |
Undocumented |
Method | __ne__ |
Undocumented |
Method | __neg__ |
Undocumented |
Method | __pos__ |
Undocumented |
Method | __pow__ |
Undocumented |
Method | __radd__ |
Undocumented |
Method | __rdiv__ |
Undocumented |
Method | __rdivmod__ |
Undocumented |
Method | __repr__ |
Undocumented |
Method | __rfloordiv__ |
Undocumented |
Method | __rmod__ |
Undocumented |
Method | __rmul__ |
Undocumented |
Method | __rsub__ |
Undocumented |
Method | __rtruediv__ |
Undocumented |
Method | __setstate__ |
Undocumented |
Method | __str__ |
Undocumented |
Method | __sub__ |
Undocumented |
Method | __truediv__ |
Undocumented |
Method | convert |
Convert series to a different kind and/or domain and/or window. |
Method | copy |
Return a copy. |
Method | cutdeg |
Truncate series to the given degree. |
Method | degree |
The degree of the series. |
Method | deriv |
Differentiate. |
Method | has |
Check if coefficients match. |
Method | has |
Check if domains match. |
Method | has |
Check if types match. |
Method | has |
Check if windows match. |
Method | integ |
Integrate. |
Method | linspace |
Return x, y values at equally spaced points in domain. |
Method | mapparms |
Return the mapping parameters. |
Method | roots |
Return the roots of the series polynomial. |
Method | trim |
Remove trailing coefficients |
Method | truncate |
Truncate series to length size . |
Class Variable | __array |
Undocumented |
Class Variable | __hash__ |
Undocumented |
Class Variable | maxpower |
Undocumented |
Instance Variable | __dict__ |
Undocumented |
Instance Variable | coef |
Undocumented |
Instance Variable | domain |
Undocumented |
Instance Variable | window |
Undocumented |
Property | basis |
Undocumented |
Property | symbol |
Undocumented |
Class Method | _repr |
Undocumented |
Class Method | _str |
String representation of a single polynomial term using ** and _ to represent superscripts and subscripts, respectively. |
Class Method | _str |
String representation of single polynomial term using unicode characters for superscripts and subscripts. |
Static Method | _add |
Undocumented |
Static Method | _der |
Undocumented |
Static Method | _div |
Undocumented |
Static Method | _fit |
Undocumented |
Static Method | _fromroots |
Undocumented |
Static Method | _int |
Undocumented |
Static Method | _line |
Undocumented |
Static Method | _mul |
Undocumented |
Static Method | _pow |
Undocumented |
Static Method | _repr |
Undocumented |
Static Method | _roots |
Undocumented |
Static Method | _sub |
Undocumented |
Static Method | _val |
Undocumented |
Method | _generate |
Generate the full string representation of the polynomial, using term_method to generate each polynomial term. |
Method | _get |
Interpret other as polynomial coefficients. |
Method | _repr |
Undocumented |
Class Variable | _subscript |
Undocumented |
Class Variable | _superscript |
Undocumented |
Class Variable | _use |
Undocumented |
Instance Variable | _symbol |
Undocumented |
Series basis polynomial of degree deg
.
Returns the series representing the basis polynomial of degree deg
.
Parameters | |
deg:int | Degree of the basis polynomial for the series. Must be >= 0. |
domain:{None, array_like}, optional | If given, the array must be of the form [beg, end], where beg and end are the endpoints of the domain. If None is given then the class domain is used. The default is None. |
window:{None, array_like}, optional | If given, the resulting array must be if the form [beg, end], where beg and end are the endpoints of the window. If None is given then the class window is used. The default is None. |
symbol:str , optional | Symbol representing the independent variable. Default is 'x'. |
Returns | |
series | new_series - A series with the coefficient of the deg term set to one and
all others zero. |
Convert series to series of this class.
The series
is expected to be an instance of some polynomial
series of one of the types supported by by the numpy.polynomial
module, but could be some other class that supports the convert
method.
See Also
convert
- similar instance method
Parameters | |
series:series | The series instance to be converted. |
domain:{None, array_like}, optional | If given, the array must be of the form [beg, end], where beg and end are the endpoints of the domain. If None is given then the class domain is used. The default is None. |
window:{None, array_like}, optional | If given, the resulting array must be if the form [beg, end], where beg and end are the endpoints of the window. If None is given then the class window is used. The default is None. |
Returns | |
series | new_series - A series of the same kind as the calling class and equal to
series when evaluated. |
def fit(cls, x, y, deg, domain=None, rcond=None, full=False, w=None, window=None, symbol='x'): (source) ¶
Least squares fit to data.
Return a series instance that is the least squares fit to the data
y
sampled at x
. The domain of the returned instance can be
specified and this will often result in a superior fit with less
chance of ill conditioning.
Parameters | |
x:array_like , shape(M , ) | x-coordinates of the M sample points (x[i], y[i]). |
y:array_like , shape(M , ) | y-coordinates of the M sample points (x[i], y[i]). |
deg:int or 1-D array_like | Degree(s) of the fitting polynomials. If deg is a single integer
all terms up to and including the deg 'th term are included in the
fit. For NumPy versions >= 1.11.0 a list of integers specifying the
degrees of the terms to include may be used instead. |
domain:{None, [beg , end] , []}, optional | Domain to use for the returned series. If None,
then a minimal domain that covers the points x is chosen. If
[] the class domain is used. The default value was the
class domain in NumPy 1.4 and None in later versions.
The [] option was added in numpy 1.5.0. |
rcond:float , optional | Relative condition number of the fit. Singular values smaller than this relative to the largest singular value will be ignored. The default value is len(x)*eps, where eps is the relative precision of the float type, about 2e-16 in most cases. |
full:bool , optional | Switch determining nature of return value. When it is False (the default) just the coefficients are returned, when True diagnostic information from the singular value decomposition is also returned. |
w:array_like , shape(M , ), optional | Weights. If not None, the weight w[i] applies to the unsquared residual y[i] - y_hat[i] at x[i]. Ideally the weights are chosen so that the errors of the products w[i]*y[i] all have the same variance. When using inverse-variance weighting, use w[i] = 1/sigma(y[i]). The default value is None.
New in version 1.5.0.
|
window:{[beg, end]}, optional | Window to use for the returned series. The default value is the default class domain
New in version 1.6.0.
|
symbol:str , optional | Symbol representing the independent variable. Default is 'x'. |
Returns | |
|
Return series instance that has the specified roots.
Returns a series representing the product (x - r[0])*(x - r[1])*...*(x - r[n-1]), where r is a list of roots.
Parameters | |
roots:array_like | List of roots. |
domain:{[], None, array_like}, optional | Domain for the resulting series. If None the domain is the interval from the smallest root to the largest. If [] the domain is the class domain. The default is []. |
window:{None, array_like}, optional | Window for the returned series. If None the class window is used. The default is None. |
symbol:str , optional | Symbol representing the independent variable. Default is 'x'. |
Returns | |
series | new_series - Series with the specified roots. |
Identity function.
If p is the returned series, then p(x) == x for all values of x.
Parameters | |
domain:{None, array_like}, optional | If given, the array must be of the form [beg, end], where beg and end are the endpoints of the domain. If None is given then the class domain is used. The default is None. |
window:{None, array_like}, optional | If given, the resulting array must be if the form [beg, end], where beg and end are the endpoints of the window. If None is given then the class window is used. The default is None. |
symbol:str , optional | Symbol representing the independent variable. Default is 'x'. |
Returns | |
series | new_series - Series of representing the identity. |
Convert series to a different kind and/or domain and/or window.
Notes
Conversion between domains and class types can result in numerically ill defined series.
Parameters | |
domain:array_like , optional | The domain of the converted series. If the value is None,
the default domain of kind is used. |
kind:class , optional | The polynomial series type class to which the current instance should be converted. If kind is None, then the class of the current instance is used. |
window:array_like , optional | The window of the converted series. If the value is None,
the default window of kind is used. |
Returns | |
series | new_series - The returned class can be of different type than the current instance and/or have a different domain and/or different window. |
Truncate series to the given degree.
Reduce the degree of the series to deg
by discarding the
high order terms. If deg
is greater than the current degree a
copy of the current series is returned. This can be useful in least
squares where the coefficients of the high degree terms may be very
small.
Parameters | |
deg:non-negative int | The series is reduced to degree deg by discarding the high
order terms. The value of deg must be a non-negative integer. |
Returns | |
series | new_series - New instance of series with reduced degree. |
The degree of the series.
Returns | |
int | degree - Degree of the series, one less than the number of coefficients. |
Differentiate.
Return a series instance of that is the derivative of the current series.
Parameters | |
m:non-negative int | Find the derivative of order m . |
Returns | |
series | new_series - A new series representing the derivative. The domain is the same as the domain of the differentiated series. |
Check if coefficients match.
Parameters | |
other:class instance | The other class must have the coef attribute. |
Returns | |
boolean | bool - True if the coefficients are the same, False otherwise. |
Check if domains match.
Parameters | |
other:class instance | The other class must have the domain attribute. |
Returns | |
boolean | bool - True if the domains are the same, False otherwise. |
Check if types match.
Parameters | |
other:object | Class instance. |
Returns | |
boolean | bool - True if other is same class as self |
Check if windows match.
Parameters | |
other:class instance | The other class must have the window attribute. |
Returns | |
boolean | bool - True if the windows are the same, False otherwise. |
Integrate.
Return a series instance that is the definite integral of the current series.
Parameters | |
m:non-negative int | The number of integrations to perform. |
k:array_like | Integration constants. The first constant is applied to the
first integration, the second to the second, and so on. The
list of values must less than or equal to m in length and any
missing values are set to zero. |
lbnd:Scalar | The lower bound of the definite integral. |
Returns | |
series | new_series - A new series representing the integral. The domain is the same as the domain of the integrated series. |
Return x, y values at equally spaced points in domain.
Returns the x, y values at n
linearly spaced points across the
domain. Here y is the value of the polynomial at the points x. By
default the domain is the same as that of the series instance.
This method is intended mostly as a plotting aid.
Parameters | |
n:int , optional | Number of point pairs to return. The default value is 100. |
domain:{None, array_like}, optional | If not None, the specified domain is used instead of that of the calling instance. It should be of the form [beg,end]. The default is None which case the class domain is used. |
Returns | |
ndarray | x, y - x is equal to linspace(self.domain[0], self.domain[1], n) and y is the series evaluated at element of x. |
Return the mapping parameters.
The returned values define a linear map off + scl*x that is applied to the input arguments before the series is evaluated. The map depends on the domain and window; if the current domain is equal to the window the resulting map is the identity. If the coefficients of the series instance are to be used by themselves outside this class, then the linear function must be substituted for the x in the standard representation of the base polynomials.
Notes
If the current domain is the interval [l1, r1] and the window is [l2, r2], then the linear mapping function L is defined by the equations:
L(l1) = l2 L(r1) = r2
Returns | |
float or complex | off, scl - The mapping function is defined by off + scl*x. |
Return the roots of the series polynomial.
Compute the roots for the series. Note that the accuracy of the roots decrease the further outside the domain they lie.
Returns | |
ndarray | roots - Array containing the roots of the series. |
Remove trailing coefficients
Remove trailing coefficients until a coefficient is reached whose
absolute value greater than tol
or the beginning of the series is
reached. If all the coefficients would be removed the series is set
to [0]. A new series instance is returned with the new
coefficients. The current instance remains unchanged.
Parameters | |
tol:non-negative number. | All trailing coefficients less than tol will be removed. |
Returns | |
series | new_series - New instance of series with trimmed coefficients. |
Truncate series to length size
.
Reduce the series to length size
by discarding the high
degree terms. The value of size
must be a positive integer. This
can be useful in least squares where the coefficients of the
high degree terms may be very small.
Parameters | |
size:positive int | The series is reduced to length size by discarding the high
degree terms. The value of size must be a positive integer. |
Returns | |
series | new_series - New instance of series with truncated coefficients. |
numpy.polynomial.polynomial.Polynomial
String representation of a single polynomial term using ** and _ to represent superscripts and subscripts, respectively.
numpy.polynomial.polynomial.Polynomial
String representation of single polynomial term using unicode characters for superscripts and subscripts.
Generate the full string representation of the polynomial, using term_method to generate each polynomial term.
Interpret other as polynomial coefficients.
The other
argument is checked to see if it is of the same
class as self with identical domain and window. If so,
return its coefficients, otherwise return other
.
Parameters | |
other:anything | Object to be checked. |
Returns | |
coef | The coefficients of`other` if it is a compatible instance,
of ABCPolyBase, otherwise other . |
Raises | |
TypeError | When other is an incompatible instance of ABCPolyBase. |