Chris@87: """ Chris@87: Objects for dealing with Hermite_e series. Chris@87: Chris@87: This module provides a number of objects (mostly functions) useful for Chris@87: dealing with Hermite_e series, including a `HermiteE` class that Chris@87: encapsulates the usual arithmetic operations. (General information Chris@87: on how this module represents and works with such polynomials is in the Chris@87: docstring for its "parent" sub-package, `numpy.polynomial`). Chris@87: Chris@87: Constants Chris@87: --------- Chris@87: - `hermedomain` -- Hermite_e series default domain, [-1,1]. Chris@87: - `hermezero` -- Hermite_e series that evaluates identically to 0. Chris@87: - `hermeone` -- Hermite_e series that evaluates identically to 1. Chris@87: - `hermex` -- Hermite_e series for the identity map, ``f(x) = x``. Chris@87: Chris@87: Arithmetic Chris@87: ---------- Chris@87: - `hermemulx` -- multiply a Hermite_e series in ``P_i(x)`` by ``x``. Chris@87: - `hermeadd` -- add two Hermite_e series. Chris@87: - `hermesub` -- subtract one Hermite_e series from another. Chris@87: - `hermemul` -- multiply two Hermite_e series. Chris@87: - `hermediv` -- divide one Hermite_e series by another. Chris@87: - `hermeval` -- evaluate a Hermite_e series at given points. Chris@87: - `hermeval2d` -- evaluate a 2D Hermite_e series at given points. Chris@87: - `hermeval3d` -- evaluate a 3D Hermite_e series at given points. Chris@87: - `hermegrid2d` -- evaluate a 2D Hermite_e series on a Cartesian product. Chris@87: - `hermegrid3d` -- evaluate a 3D Hermite_e series on a Cartesian product. Chris@87: Chris@87: Calculus Chris@87: -------- Chris@87: - `hermeder` -- differentiate a Hermite_e series. Chris@87: - `hermeint` -- integrate a Hermite_e series. Chris@87: Chris@87: Misc Functions Chris@87: -------------- Chris@87: - `hermefromroots` -- create a Hermite_e series with specified roots. Chris@87: - `hermeroots` -- find the roots of a Hermite_e series. Chris@87: - `hermevander` -- Vandermonde-like matrix for Hermite_e polynomials. Chris@87: - `hermevander2d` -- Vandermonde-like matrix for 2D power series. Chris@87: - `hermevander3d` -- Vandermonde-like matrix for 3D power series. Chris@87: - `hermegauss` -- Gauss-Hermite_e quadrature, points and weights. Chris@87: - `hermeweight` -- Hermite_e weight function. Chris@87: - `hermecompanion` -- symmetrized companion matrix in Hermite_e form. Chris@87: - `hermefit` -- least-squares fit returning a Hermite_e series. Chris@87: - `hermetrim` -- trim leading coefficients from a Hermite_e series. Chris@87: - `hermeline` -- Hermite_e series of given straight line. Chris@87: - `herme2poly` -- convert a Hermite_e series to a polynomial. Chris@87: - `poly2herme` -- convert a polynomial to a Hermite_e series. Chris@87: Chris@87: Classes Chris@87: ------- Chris@87: - `HermiteE` -- A Hermite_e series class. Chris@87: Chris@87: See also Chris@87: -------- Chris@87: `numpy.polynomial` Chris@87: Chris@87: """ Chris@87: from __future__ import division, absolute_import, print_function Chris@87: Chris@87: import warnings Chris@87: import numpy as np Chris@87: import numpy.linalg as la Chris@87: Chris@87: from . import polyutils as pu Chris@87: from ._polybase import ABCPolyBase Chris@87: Chris@87: __all__ = [ Chris@87: 'hermezero', 'hermeone', 'hermex', 'hermedomain', 'hermeline', Chris@87: 'hermeadd', 'hermesub', 'hermemulx', 'hermemul', 'hermediv', Chris@87: 'hermepow', 'hermeval', 'hermeder', 'hermeint', 'herme2poly', Chris@87: 'poly2herme', 'hermefromroots', 'hermevander', 'hermefit', 'hermetrim', Chris@87: 'hermeroots', 'HermiteE', 'hermeval2d', 'hermeval3d', 'hermegrid2d', Chris@87: 'hermegrid3d', 'hermevander2d', 'hermevander3d', 'hermecompanion', Chris@87: 'hermegauss', 'hermeweight'] Chris@87: Chris@87: hermetrim = pu.trimcoef Chris@87: Chris@87: Chris@87: def poly2herme(pol): Chris@87: """ Chris@87: poly2herme(pol) Chris@87: Chris@87: Convert a polynomial to a Hermite series. Chris@87: Chris@87: Convert an array representing the coefficients of a polynomial (relative Chris@87: to the "standard" basis) ordered from lowest degree to highest, to an Chris@87: array of the coefficients of the equivalent Hermite series, ordered Chris@87: from lowest to highest degree. Chris@87: Chris@87: Parameters Chris@87: ---------- Chris@87: pol : array_like Chris@87: 1-D array containing the polynomial coefficients Chris@87: Chris@87: Returns Chris@87: ------- Chris@87: c : ndarray Chris@87: 1-D array containing the coefficients of the equivalent Hermite Chris@87: series. Chris@87: Chris@87: See Also Chris@87: -------- Chris@87: herme2poly Chris@87: Chris@87: Notes Chris@87: ----- Chris@87: The easy way to do conversions between polynomial basis sets Chris@87: is to use the convert method of a class instance. Chris@87: Chris@87: Examples Chris@87: -------- Chris@87: >>> from numpy.polynomial.hermite_e import poly2herme Chris@87: >>> poly2herme(np.arange(4)) Chris@87: array([ 2., 10., 2., 3.]) Chris@87: Chris@87: """ Chris@87: [pol] = pu.as_series([pol]) Chris@87: deg = len(pol) - 1 Chris@87: res = 0 Chris@87: for i in range(deg, -1, -1): Chris@87: res = hermeadd(hermemulx(res), pol[i]) Chris@87: return res Chris@87: Chris@87: Chris@87: def herme2poly(c): Chris@87: """ Chris@87: Convert a Hermite series to a polynomial. Chris@87: Chris@87: Convert an array representing the coefficients of a Hermite series, Chris@87: ordered from lowest degree to highest, to an array of the coefficients Chris@87: of the equivalent polynomial (relative to the "standard" basis) ordered Chris@87: from lowest to highest degree. Chris@87: Chris@87: Parameters Chris@87: ---------- Chris@87: c : array_like Chris@87: 1-D array containing the Hermite series coefficients, ordered Chris@87: from lowest order term to highest. Chris@87: Chris@87: Returns Chris@87: ------- Chris@87: pol : ndarray Chris@87: 1-D array containing the coefficients of the equivalent polynomial Chris@87: (relative to the "standard" basis) ordered from lowest order term Chris@87: to highest. Chris@87: Chris@87: See Also Chris@87: -------- Chris@87: poly2herme Chris@87: Chris@87: Notes Chris@87: ----- Chris@87: The easy way to do conversions between polynomial basis sets Chris@87: is to use the convert method of a class instance. Chris@87: Chris@87: Examples Chris@87: -------- Chris@87: >>> from numpy.polynomial.hermite_e import herme2poly Chris@87: >>> herme2poly([ 2., 10., 2., 3.]) Chris@87: array([ 0., 1., 2., 3.]) Chris@87: Chris@87: """ Chris@87: from .polynomial import polyadd, polysub, polymulx Chris@87: Chris@87: [c] = pu.as_series([c]) Chris@87: n = len(c) Chris@87: if n == 1: Chris@87: return c Chris@87: if n == 2: Chris@87: return c Chris@87: else: Chris@87: c0 = c[-2] Chris@87: c1 = c[-1] Chris@87: # i is the current degree of c1 Chris@87: for i in range(n - 1, 1, -1): Chris@87: tmp = c0 Chris@87: c0 = polysub(c[i - 2], c1*(i - 1)) Chris@87: c1 = polyadd(tmp, polymulx(c1)) Chris@87: return polyadd(c0, polymulx(c1)) Chris@87: Chris@87: # Chris@87: # These are constant arrays are of integer type so as to be compatible Chris@87: # with the widest range of other types, such as Decimal. Chris@87: # Chris@87: Chris@87: # Hermite Chris@87: hermedomain = np.array([-1, 1]) Chris@87: Chris@87: # Hermite coefficients representing zero. Chris@87: hermezero = np.array([0]) Chris@87: Chris@87: # Hermite coefficients representing one. Chris@87: hermeone = np.array([1]) Chris@87: Chris@87: # Hermite coefficients representing the identity x. Chris@87: hermex = np.array([0, 1]) Chris@87: Chris@87: Chris@87: def hermeline(off, scl): Chris@87: """ Chris@87: Hermite series whose graph is a straight line. Chris@87: Chris@87: Chris@87: Chris@87: Parameters Chris@87: ---------- Chris@87: off, scl : scalars Chris@87: The specified line is given by ``off + scl*x``. Chris@87: Chris@87: Returns Chris@87: ------- Chris@87: y : ndarray Chris@87: This module's representation of the Hermite series for Chris@87: ``off + scl*x``. Chris@87: Chris@87: See Also Chris@87: -------- Chris@87: polyline, chebline Chris@87: Chris@87: Examples Chris@87: -------- Chris@87: >>> from numpy.polynomial.hermite_e import hermeline Chris@87: >>> from numpy.polynomial.hermite_e import hermeline, hermeval Chris@87: >>> hermeval(0,hermeline(3, 2)) Chris@87: 3.0 Chris@87: >>> hermeval(1,hermeline(3, 2)) Chris@87: 5.0 Chris@87: Chris@87: """ Chris@87: if scl != 0: Chris@87: return np.array([off, scl]) Chris@87: else: Chris@87: return np.array([off]) Chris@87: Chris@87: Chris@87: def hermefromroots(roots): Chris@87: """ Chris@87: Generate a HermiteE series with given roots. Chris@87: Chris@87: The function returns the coefficients of the polynomial Chris@87: Chris@87: .. math:: p(x) = (x - r_0) * (x - r_1) * ... * (x - r_n), Chris@87: Chris@87: in HermiteE form, where the `r_n` are the roots specified in `roots`. Chris@87: If a zero has multiplicity n, then it must appear in `roots` n times. Chris@87: For instance, if 2 is a root of multiplicity three and 3 is a root of Chris@87: multiplicity 2, then `roots` looks something like [2, 2, 2, 3, 3]. The Chris@87: roots can appear in any order. Chris@87: Chris@87: If the returned coefficients are `c`, then Chris@87: Chris@87: .. math:: p(x) = c_0 + c_1 * He_1(x) + ... + c_n * He_n(x) Chris@87: Chris@87: The coefficient of the last term is not generally 1 for monic Chris@87: polynomials in HermiteE form. Chris@87: Chris@87: Parameters Chris@87: ---------- Chris@87: roots : array_like Chris@87: Sequence containing the roots. Chris@87: Chris@87: Returns Chris@87: ------- Chris@87: out : ndarray Chris@87: 1-D array of coefficients. If all roots are real then `out` is a Chris@87: real array, if some of the roots are complex, then `out` is complex Chris@87: even if all the coefficients in the result are real (see Examples Chris@87: below). Chris@87: Chris@87: See Also Chris@87: -------- Chris@87: polyfromroots, legfromroots, lagfromroots, hermfromroots, Chris@87: chebfromroots. Chris@87: Chris@87: Examples Chris@87: -------- Chris@87: >>> from numpy.polynomial.hermite_e import hermefromroots, hermeval Chris@87: >>> coef = hermefromroots((-1, 0, 1)) Chris@87: >>> hermeval((-1, 0, 1), coef) Chris@87: array([ 0., 0., 0.]) Chris@87: >>> coef = hermefromroots((-1j, 1j)) Chris@87: >>> hermeval((-1j, 1j), coef) Chris@87: array([ 0.+0.j, 0.+0.j]) Chris@87: Chris@87: """ Chris@87: if len(roots) == 0: Chris@87: return np.ones(1) Chris@87: else: Chris@87: [roots] = pu.as_series([roots], trim=False) Chris@87: roots.sort() Chris@87: p = [hermeline(-r, 1) for r in roots] Chris@87: n = len(p) Chris@87: while n > 1: Chris@87: m, r = divmod(n, 2) Chris@87: tmp = [hermemul(p[i], p[i+m]) for i in range(m)] Chris@87: if r: Chris@87: tmp[0] = hermemul(tmp[0], p[-1]) Chris@87: p = tmp Chris@87: n = m Chris@87: return p[0] Chris@87: Chris@87: Chris@87: def hermeadd(c1, c2): Chris@87: """ Chris@87: Add one Hermite series to another. Chris@87: Chris@87: Returns the sum of two Hermite series `c1` + `c2`. The arguments Chris@87: are sequences of coefficients ordered from lowest order term to Chris@87: highest, i.e., [1,2,3] represents the series ``P_0 + 2*P_1 + 3*P_2``. Chris@87: Chris@87: Parameters Chris@87: ---------- Chris@87: c1, c2 : array_like Chris@87: 1-D arrays of Hermite series coefficients ordered from low to Chris@87: high. Chris@87: Chris@87: Returns Chris@87: ------- Chris@87: out : ndarray Chris@87: Array representing the Hermite series of their sum. Chris@87: Chris@87: See Also Chris@87: -------- Chris@87: hermesub, hermemul, hermediv, hermepow Chris@87: Chris@87: Notes Chris@87: ----- Chris@87: Unlike multiplication, division, etc., the sum of two Hermite series Chris@87: is a Hermite series (without having to "reproject" the result onto Chris@87: the basis set) so addition, just like that of "standard" polynomials, Chris@87: is simply "component-wise." Chris@87: Chris@87: Examples Chris@87: -------- Chris@87: >>> from numpy.polynomial.hermite_e import hermeadd Chris@87: >>> hermeadd([1, 2, 3], [1, 2, 3, 4]) Chris@87: array([ 2., 4., 6., 4.]) Chris@87: Chris@87: """ Chris@87: # c1, c2 are trimmed copies Chris@87: [c1, c2] = pu.as_series([c1, c2]) Chris@87: if len(c1) > len(c2): Chris@87: c1[:c2.size] += c2 Chris@87: ret = c1 Chris@87: else: Chris@87: c2[:c1.size] += c1 Chris@87: ret = c2 Chris@87: return pu.trimseq(ret) Chris@87: Chris@87: Chris@87: def hermesub(c1, c2): Chris@87: """ Chris@87: Subtract one Hermite series from another. Chris@87: Chris@87: Returns the difference of two Hermite series `c1` - `c2`. The Chris@87: sequences of coefficients are from lowest order term to highest, i.e., Chris@87: [1,2,3] represents the series ``P_0 + 2*P_1 + 3*P_2``. Chris@87: Chris@87: Parameters Chris@87: ---------- Chris@87: c1, c2 : array_like Chris@87: 1-D arrays of Hermite series coefficients ordered from low to Chris@87: high. Chris@87: Chris@87: Returns Chris@87: ------- Chris@87: out : ndarray Chris@87: Of Hermite series coefficients representing their difference. Chris@87: Chris@87: See Also Chris@87: -------- Chris@87: hermeadd, hermemul, hermediv, hermepow Chris@87: Chris@87: Notes Chris@87: ----- Chris@87: Unlike multiplication, division, etc., the difference of two Hermite Chris@87: series is a Hermite series (without having to "reproject" the result Chris@87: onto the basis set) so subtraction, just like that of "standard" Chris@87: polynomials, is simply "component-wise." Chris@87: Chris@87: Examples Chris@87: -------- Chris@87: >>> from numpy.polynomial.hermite_e import hermesub Chris@87: >>> hermesub([1, 2, 3, 4], [1, 2, 3]) Chris@87: array([ 0., 0., 0., 4.]) Chris@87: Chris@87: """ Chris@87: # c1, c2 are trimmed copies Chris@87: [c1, c2] = pu.as_series([c1, c2]) Chris@87: if len(c1) > len(c2): Chris@87: c1[:c2.size] -= c2 Chris@87: ret = c1 Chris@87: else: Chris@87: c2 = -c2 Chris@87: c2[:c1.size] += c1 Chris@87: ret = c2 Chris@87: return pu.trimseq(ret) Chris@87: Chris@87: Chris@87: def hermemulx(c): Chris@87: """Multiply a Hermite series by x. Chris@87: Chris@87: Multiply the Hermite series `c` by x, where x is the independent Chris@87: variable. Chris@87: Chris@87: Chris@87: Parameters Chris@87: ---------- Chris@87: c : array_like Chris@87: 1-D array of Hermite series coefficients ordered from low to Chris@87: high. Chris@87: Chris@87: Returns Chris@87: ------- Chris@87: out : ndarray Chris@87: Array representing the result of the multiplication. Chris@87: Chris@87: Notes Chris@87: ----- Chris@87: The multiplication uses the recursion relationship for Hermite Chris@87: polynomials in the form Chris@87: Chris@87: .. math:: Chris@87: Chris@87: xP_i(x) = (P_{i + 1}(x) + iP_{i - 1}(x))) Chris@87: Chris@87: Examples Chris@87: -------- Chris@87: >>> from numpy.polynomial.hermite_e import hermemulx Chris@87: >>> hermemulx([1, 2, 3]) Chris@87: array([ 2., 7., 2., 3.]) Chris@87: Chris@87: """ Chris@87: # c is a trimmed copy Chris@87: [c] = pu.as_series([c]) Chris@87: # The zero series needs special treatment Chris@87: if len(c) == 1 and c[0] == 0: Chris@87: return c Chris@87: Chris@87: prd = np.empty(len(c) + 1, dtype=c.dtype) Chris@87: prd[0] = c[0]*0 Chris@87: prd[1] = c[0] Chris@87: for i in range(1, len(c)): Chris@87: prd[i + 1] = c[i] Chris@87: prd[i - 1] += c[i]*i Chris@87: return prd Chris@87: Chris@87: Chris@87: def hermemul(c1, c2): Chris@87: """ Chris@87: Multiply one Hermite series by another. Chris@87: Chris@87: Returns the product of two Hermite series `c1` * `c2`. The arguments Chris@87: are sequences of coefficients, from lowest order "term" to highest, Chris@87: e.g., [1,2,3] represents the series ``P_0 + 2*P_1 + 3*P_2``. Chris@87: Chris@87: Parameters Chris@87: ---------- Chris@87: c1, c2 : array_like Chris@87: 1-D arrays of Hermite series coefficients ordered from low to Chris@87: high. Chris@87: Chris@87: Returns Chris@87: ------- Chris@87: out : ndarray Chris@87: Of Hermite series coefficients representing their product. Chris@87: Chris@87: See Also Chris@87: -------- Chris@87: hermeadd, hermesub, hermediv, hermepow Chris@87: Chris@87: Notes Chris@87: ----- Chris@87: In general, the (polynomial) product of two C-series results in terms Chris@87: that are not in the Hermite polynomial basis set. Thus, to express Chris@87: the product as a Hermite series, it is necessary to "reproject" the Chris@87: product onto said basis set, which may produce "unintuitive" (but Chris@87: correct) results; see Examples section below. Chris@87: Chris@87: Examples Chris@87: -------- Chris@87: >>> from numpy.polynomial.hermite_e import hermemul Chris@87: >>> hermemul([1, 2, 3], [0, 1, 2]) Chris@87: array([ 14., 15., 28., 7., 6.]) Chris@87: Chris@87: """ Chris@87: # s1, s2 are trimmed copies Chris@87: [c1, c2] = pu.as_series([c1, c2]) Chris@87: Chris@87: if len(c1) > len(c2): Chris@87: c = c2 Chris@87: xs = c1 Chris@87: else: Chris@87: c = c1 Chris@87: xs = c2 Chris@87: Chris@87: if len(c) == 1: Chris@87: c0 = c[0]*xs Chris@87: c1 = 0 Chris@87: elif len(c) == 2: Chris@87: c0 = c[0]*xs Chris@87: c1 = c[1]*xs Chris@87: else: Chris@87: nd = len(c) Chris@87: c0 = c[-2]*xs Chris@87: c1 = c[-1]*xs Chris@87: for i in range(3, len(c) + 1): Chris@87: tmp = c0 Chris@87: nd = nd - 1 Chris@87: c0 = hermesub(c[-i]*xs, c1*(nd - 1)) Chris@87: c1 = hermeadd(tmp, hermemulx(c1)) Chris@87: return hermeadd(c0, hermemulx(c1)) Chris@87: Chris@87: Chris@87: def hermediv(c1, c2): Chris@87: """ Chris@87: Divide one Hermite series by another. Chris@87: Chris@87: Returns the quotient-with-remainder of two Hermite series Chris@87: `c1` / `c2`. The arguments are sequences of coefficients from lowest Chris@87: order "term" to highest, e.g., [1,2,3] represents the series Chris@87: ``P_0 + 2*P_1 + 3*P_2``. Chris@87: Chris@87: Parameters Chris@87: ---------- Chris@87: c1, c2 : array_like Chris@87: 1-D arrays of Hermite series coefficients ordered from low to Chris@87: high. Chris@87: Chris@87: Returns Chris@87: ------- Chris@87: [quo, rem] : ndarrays Chris@87: Of Hermite series coefficients representing the quotient and Chris@87: remainder. Chris@87: Chris@87: See Also Chris@87: -------- Chris@87: hermeadd, hermesub, hermemul, hermepow Chris@87: Chris@87: Notes Chris@87: ----- Chris@87: In general, the (polynomial) division of one Hermite series by another Chris@87: results in quotient and remainder terms that are not in the Hermite Chris@87: polynomial basis set. Thus, to express these results as a Hermite Chris@87: series, it is necessary to "reproject" the results onto the Hermite Chris@87: basis set, which may produce "unintuitive" (but correct) results; see Chris@87: Examples section below. Chris@87: Chris@87: Examples Chris@87: -------- Chris@87: >>> from numpy.polynomial.hermite_e import hermediv Chris@87: >>> hermediv([ 14., 15., 28., 7., 6.], [0, 1, 2]) Chris@87: (array([ 1., 2., 3.]), array([ 0.])) Chris@87: >>> hermediv([ 15., 17., 28., 7., 6.], [0, 1, 2]) Chris@87: (array([ 1., 2., 3.]), array([ 1., 2.])) Chris@87: Chris@87: """ Chris@87: # c1, c2 are trimmed copies Chris@87: [c1, c2] = pu.as_series([c1, c2]) Chris@87: if c2[-1] == 0: Chris@87: raise ZeroDivisionError() Chris@87: Chris@87: lc1 = len(c1) Chris@87: lc2 = len(c2) Chris@87: if lc1 < lc2: Chris@87: return c1[:1]*0, c1 Chris@87: elif lc2 == 1: Chris@87: return c1/c2[-1], c1[:1]*0 Chris@87: else: Chris@87: quo = np.empty(lc1 - lc2 + 1, dtype=c1.dtype) Chris@87: rem = c1 Chris@87: for i in range(lc1 - lc2, - 1, -1): Chris@87: p = hermemul([0]*i + [1], c2) Chris@87: q = rem[-1]/p[-1] Chris@87: rem = rem[:-1] - q*p[:-1] Chris@87: quo[i] = q Chris@87: return quo, pu.trimseq(rem) Chris@87: Chris@87: Chris@87: def hermepow(c, pow, maxpower=16): Chris@87: """Raise a Hermite series to a power. Chris@87: Chris@87: Returns the Hermite series `c` raised to the power `pow`. The Chris@87: argument `c` is a sequence of coefficients ordered from low to high. Chris@87: i.e., [1,2,3] is the series ``P_0 + 2*P_1 + 3*P_2.`` Chris@87: Chris@87: Parameters Chris@87: ---------- Chris@87: c : array_like Chris@87: 1-D array of Hermite series coefficients ordered from low to Chris@87: high. Chris@87: pow : integer Chris@87: Power to which the series will be raised Chris@87: maxpower : integer, optional Chris@87: Maximum power allowed. This is mainly to limit growth of the series Chris@87: to unmanageable size. Default is 16 Chris@87: Chris@87: Returns Chris@87: ------- Chris@87: coef : ndarray Chris@87: Hermite series of power. Chris@87: Chris@87: See Also Chris@87: -------- Chris@87: hermeadd, hermesub, hermemul, hermediv Chris@87: Chris@87: Examples Chris@87: -------- Chris@87: >>> from numpy.polynomial.hermite_e import hermepow Chris@87: >>> hermepow([1, 2, 3], 2) Chris@87: array([ 23., 28., 46., 12., 9.]) Chris@87: Chris@87: """ Chris@87: # c is a trimmed copy Chris@87: [c] = pu.as_series([c]) Chris@87: power = int(pow) Chris@87: if power != pow or power < 0: Chris@87: raise ValueError("Power must be a non-negative integer.") Chris@87: elif maxpower is not None and power > maxpower: Chris@87: raise ValueError("Power is too large") Chris@87: elif power == 0: Chris@87: return np.array([1], dtype=c.dtype) Chris@87: elif power == 1: Chris@87: return c Chris@87: else: Chris@87: # This can be made more efficient by using powers of two Chris@87: # in the usual way. Chris@87: prd = c Chris@87: for i in range(2, power + 1): Chris@87: prd = hermemul(prd, c) Chris@87: return prd Chris@87: Chris@87: Chris@87: def hermeder(c, m=1, scl=1, axis=0): Chris@87: """ Chris@87: Differentiate a Hermite_e series. Chris@87: Chris@87: Returns the series coefficients `c` differentiated `m` times along Chris@87: `axis`. At each iteration the result is multiplied by `scl` (the Chris@87: scaling factor is for use in a linear change of variable). The argument Chris@87: `c` is an array of coefficients from low to high degree along each Chris@87: axis, e.g., [1,2,3] represents the series ``1*He_0 + 2*He_1 + 3*He_2`` Chris@87: while [[1,2],[1,2]] represents ``1*He_0(x)*He_0(y) + 1*He_1(x)*He_0(y) Chris@87: + 2*He_0(x)*He_1(y) + 2*He_1(x)*He_1(y)`` if axis=0 is ``x`` and axis=1 Chris@87: is ``y``. Chris@87: Chris@87: Parameters Chris@87: ---------- Chris@87: c : array_like Chris@87: Array of Hermite_e series coefficients. If `c` is multidimensional Chris@87: the different axis correspond to different variables with the Chris@87: degree in each axis given by the corresponding index. Chris@87: m : int, optional Chris@87: Number of derivatives taken, must be non-negative. (Default: 1) Chris@87: scl : scalar, optional Chris@87: Each differentiation is multiplied by `scl`. The end result is Chris@87: multiplication by ``scl**m``. This is for use in a linear change of Chris@87: variable. (Default: 1) Chris@87: axis : int, optional Chris@87: Axis over which the derivative is taken. (Default: 0). Chris@87: Chris@87: .. versionadded:: 1.7.0 Chris@87: Chris@87: Returns Chris@87: ------- Chris@87: der : ndarray Chris@87: Hermite series of the derivative. Chris@87: Chris@87: See Also Chris@87: -------- Chris@87: hermeint Chris@87: Chris@87: Notes Chris@87: ----- Chris@87: In general, the result of differentiating a Hermite series does not Chris@87: resemble the same operation on a power series. Thus the result of this Chris@87: function may be "unintuitive," albeit correct; see Examples section Chris@87: below. Chris@87: Chris@87: Examples Chris@87: -------- Chris@87: >>> from numpy.polynomial.hermite_e import hermeder Chris@87: >>> hermeder([ 1., 1., 1., 1.]) Chris@87: array([ 1., 2., 3.]) Chris@87: >>> hermeder([-0.25, 1., 1./2., 1./3., 1./4 ], m=2) Chris@87: array([ 1., 2., 3.]) Chris@87: Chris@87: """ Chris@87: c = np.array(c, ndmin=1, copy=1) Chris@87: if c.dtype.char in '?bBhHiIlLqQpP': Chris@87: c = c.astype(np.double) Chris@87: cnt, iaxis = [int(t) for t in [m, axis]] Chris@87: Chris@87: if cnt != m: Chris@87: raise ValueError("The order of derivation must be integer") Chris@87: if cnt < 0: Chris@87: raise ValueError("The order of derivation must be non-negative") Chris@87: if iaxis != axis: Chris@87: raise ValueError("The axis must be integer") Chris@87: if not -c.ndim <= iaxis < c.ndim: Chris@87: raise ValueError("The axis is out of range") Chris@87: if iaxis < 0: Chris@87: iaxis += c.ndim Chris@87: Chris@87: if cnt == 0: Chris@87: return c Chris@87: Chris@87: c = np.rollaxis(c, iaxis) Chris@87: n = len(c) Chris@87: if cnt >= n: Chris@87: return c[:1]*0 Chris@87: else: Chris@87: for i in range(cnt): Chris@87: n = n - 1 Chris@87: c *= scl Chris@87: der = np.empty((n,) + c.shape[1:], dtype=c.dtype) Chris@87: for j in range(n, 0, -1): Chris@87: der[j - 1] = j*c[j] Chris@87: c = der Chris@87: c = np.rollaxis(c, 0, iaxis + 1) Chris@87: return c Chris@87: Chris@87: Chris@87: def hermeint(c, m=1, k=[], lbnd=0, scl=1, axis=0): Chris@87: """ Chris@87: Integrate a Hermite_e series. Chris@87: Chris@87: Returns the Hermite_e series coefficients `c` integrated `m` times from Chris@87: `lbnd` along `axis`. At each iteration the resulting series is Chris@87: **multiplied** by `scl` and an integration constant, `k`, is added. Chris@87: The scaling factor is for use in a linear change of variable. ("Buyer Chris@87: beware": note that, depending on what one is doing, one may want `scl` Chris@87: to be the reciprocal of what one might expect; for more information, Chris@87: see the Notes section below.) The argument `c` is an array of Chris@87: coefficients from low to high degree along each axis, e.g., [1,2,3] Chris@87: represents the series ``H_0 + 2*H_1 + 3*H_2`` while [[1,2],[1,2]] Chris@87: represents ``1*H_0(x)*H_0(y) + 1*H_1(x)*H_0(y) + 2*H_0(x)*H_1(y) + Chris@87: 2*H_1(x)*H_1(y)`` if axis=0 is ``x`` and axis=1 is ``y``. Chris@87: Chris@87: Parameters Chris@87: ---------- Chris@87: c : array_like Chris@87: Array of Hermite_e series coefficients. If c is multidimensional Chris@87: the different axis correspond to different variables with the Chris@87: degree in each axis given by the corresponding index. Chris@87: m : int, optional Chris@87: Order of integration, must be positive. (Default: 1) Chris@87: k : {[], list, scalar}, optional Chris@87: Integration constant(s). The value of the first integral at Chris@87: ``lbnd`` is the first value in the list, the value of the second Chris@87: integral at ``lbnd`` is the second value, etc. If ``k == []`` (the Chris@87: default), all constants are set to zero. If ``m == 1``, a single Chris@87: scalar can be given instead of a list. Chris@87: lbnd : scalar, optional Chris@87: The lower bound of the integral. (Default: 0) Chris@87: scl : scalar, optional Chris@87: Following each integration the result is *multiplied* by `scl` Chris@87: before the integration constant is added. (Default: 1) Chris@87: axis : int, optional Chris@87: Axis over which the integral is taken. (Default: 0). Chris@87: Chris@87: .. versionadded:: 1.7.0 Chris@87: Chris@87: Returns Chris@87: ------- Chris@87: S : ndarray Chris@87: Hermite_e series coefficients of the integral. Chris@87: Chris@87: Raises Chris@87: ------ Chris@87: ValueError Chris@87: If ``m < 0``, ``len(k) > m``, ``np.isscalar(lbnd) == False``, or Chris@87: ``np.isscalar(scl) == False``. Chris@87: Chris@87: See Also Chris@87: -------- Chris@87: hermeder Chris@87: Chris@87: Notes Chris@87: ----- Chris@87: Note that the result of each integration is *multiplied* by `scl`. Chris@87: Why is this important to note? Say one is making a linear change of Chris@87: variable :math:`u = ax + b` in an integral relative to `x`. Then Chris@87: .. math::`dx = du/a`, so one will need to set `scl` equal to Chris@87: :math:`1/a` - perhaps not what one would have first thought. Chris@87: Chris@87: Also note that, in general, the result of integrating a C-series needs Chris@87: to be "reprojected" onto the C-series basis set. Thus, typically, Chris@87: the result of this function is "unintuitive," albeit correct; see Chris@87: Examples section below. Chris@87: Chris@87: Examples Chris@87: -------- Chris@87: >>> from numpy.polynomial.hermite_e import hermeint Chris@87: >>> hermeint([1, 2, 3]) # integrate once, value 0 at 0. Chris@87: array([ 1., 1., 1., 1.]) Chris@87: >>> hermeint([1, 2, 3], m=2) # integrate twice, value & deriv 0 at 0 Chris@87: array([-0.25 , 1. , 0.5 , 0.33333333, 0.25 ]) Chris@87: >>> hermeint([1, 2, 3], k=1) # integrate once, value 1 at 0. Chris@87: array([ 2., 1., 1., 1.]) Chris@87: >>> hermeint([1, 2, 3], lbnd=-1) # integrate once, value 0 at -1 Chris@87: array([-1., 1., 1., 1.]) Chris@87: >>> hermeint([1, 2, 3], m=2, k=[1, 2], lbnd=-1) Chris@87: array([ 1.83333333, 0. , 0.5 , 0.33333333, 0.25 ]) Chris@87: Chris@87: """ Chris@87: c = np.array(c, ndmin=1, copy=1) Chris@87: if c.dtype.char in '?bBhHiIlLqQpP': Chris@87: c = c.astype(np.double) Chris@87: if not np.iterable(k): Chris@87: k = [k] Chris@87: cnt, iaxis = [int(t) for t in [m, axis]] Chris@87: Chris@87: if cnt != m: Chris@87: raise ValueError("The order of integration must be integer") Chris@87: if cnt < 0: Chris@87: raise ValueError("The order of integration must be non-negative") Chris@87: if len(k) > cnt: Chris@87: raise ValueError("Too many integration constants") Chris@87: if iaxis != axis: Chris@87: raise ValueError("The axis must be integer") Chris@87: if not -c.ndim <= iaxis < c.ndim: Chris@87: raise ValueError("The axis is out of range") Chris@87: if iaxis < 0: Chris@87: iaxis += c.ndim Chris@87: Chris@87: if cnt == 0: Chris@87: return c Chris@87: Chris@87: c = np.rollaxis(c, iaxis) Chris@87: k = list(k) + [0]*(cnt - len(k)) Chris@87: for i in range(cnt): Chris@87: n = len(c) Chris@87: c *= scl Chris@87: if n == 1 and np.all(c[0] == 0): Chris@87: c[0] += k[i] Chris@87: else: Chris@87: tmp = np.empty((n + 1,) + c.shape[1:], dtype=c.dtype) Chris@87: tmp[0] = c[0]*0 Chris@87: tmp[1] = c[0] Chris@87: for j in range(1, n): Chris@87: tmp[j + 1] = c[j]/(j + 1) Chris@87: tmp[0] += k[i] - hermeval(lbnd, tmp) Chris@87: c = tmp Chris@87: c = np.rollaxis(c, 0, iaxis + 1) Chris@87: return c Chris@87: Chris@87: Chris@87: def hermeval(x, c, tensor=True): Chris@87: """ Chris@87: Evaluate an HermiteE series at points x. Chris@87: Chris@87: If `c` is of length `n + 1`, this function returns the value: Chris@87: Chris@87: .. math:: p(x) = c_0 * He_0(x) + c_1 * He_1(x) + ... + c_n * He_n(x) Chris@87: Chris@87: The parameter `x` is converted to an array only if it is a tuple or a Chris@87: list, otherwise it is treated as a scalar. In either case, either `x` Chris@87: or its elements must support multiplication and addition both with Chris@87: themselves and with the elements of `c`. Chris@87: Chris@87: If `c` is a 1-D array, then `p(x)` will have the same shape as `x`. If Chris@87: `c` is multidimensional, then the shape of the result depends on the Chris@87: value of `tensor`. If `tensor` is true the shape will be c.shape[1:] + Chris@87: x.shape. If `tensor` is false the shape will be c.shape[1:]. Note that Chris@87: scalars have shape (,). Chris@87: Chris@87: Trailing zeros in the coefficients will be used in the evaluation, so Chris@87: they should be avoided if efficiency is a concern. Chris@87: Chris@87: Parameters Chris@87: ---------- Chris@87: x : array_like, compatible object Chris@87: If `x` is a list or tuple, it is converted to an ndarray, otherwise Chris@87: it is left unchanged and treated as a scalar. In either case, `x` Chris@87: or its elements must support addition and multiplication with Chris@87: with themselves and with the elements of `c`. Chris@87: c : array_like Chris@87: Array of coefficients ordered so that the coefficients for terms of Chris@87: degree n are contained in c[n]. If `c` is multidimensional the Chris@87: remaining indices enumerate multiple polynomials. In the two Chris@87: dimensional case the coefficients may be thought of as stored in Chris@87: the columns of `c`. Chris@87: tensor : boolean, optional Chris@87: If True, the shape of the coefficient array is extended with ones Chris@87: on the right, one for each dimension of `x`. Scalars have dimension 0 Chris@87: for this action. The result is that every column of coefficients in Chris@87: `c` is evaluated for every element of `x`. If False, `x` is broadcast Chris@87: over the columns of `c` for the evaluation. This keyword is useful Chris@87: when `c` is multidimensional. The default value is True. Chris@87: Chris@87: .. versionadded:: 1.7.0 Chris@87: Chris@87: Returns Chris@87: ------- Chris@87: values : ndarray, algebra_like Chris@87: The shape of the return value is described above. Chris@87: Chris@87: See Also Chris@87: -------- Chris@87: hermeval2d, hermegrid2d, hermeval3d, hermegrid3d Chris@87: Chris@87: Notes Chris@87: ----- Chris@87: The evaluation uses Clenshaw recursion, aka synthetic division. Chris@87: Chris@87: Examples Chris@87: -------- Chris@87: >>> from numpy.polynomial.hermite_e import hermeval Chris@87: >>> coef = [1,2,3] Chris@87: >>> hermeval(1, coef) Chris@87: 3.0 Chris@87: >>> hermeval([[1,2],[3,4]], coef) Chris@87: array([[ 3., 14.], Chris@87: [ 31., 54.]]) Chris@87: Chris@87: """ Chris@87: c = np.array(c, ndmin=1, copy=0) Chris@87: if c.dtype.char in '?bBhHiIlLqQpP': Chris@87: c = c.astype(np.double) Chris@87: if isinstance(x, (tuple, list)): Chris@87: x = np.asarray(x) Chris@87: if isinstance(x, np.ndarray) and tensor: Chris@87: c = c.reshape(c.shape + (1,)*x.ndim) Chris@87: Chris@87: if len(c) == 1: Chris@87: c0 = c[0] Chris@87: c1 = 0 Chris@87: elif len(c) == 2: Chris@87: c0 = c[0] Chris@87: c1 = c[1] Chris@87: else: Chris@87: nd = len(c) Chris@87: c0 = c[-2] Chris@87: c1 = c[-1] Chris@87: for i in range(3, len(c) + 1): Chris@87: tmp = c0 Chris@87: nd = nd - 1 Chris@87: c0 = c[-i] - c1*(nd - 1) Chris@87: c1 = tmp + c1*x Chris@87: return c0 + c1*x Chris@87: Chris@87: Chris@87: def hermeval2d(x, y, c): Chris@87: """ Chris@87: Evaluate a 2-D HermiteE series at points (x, y). Chris@87: Chris@87: This function returns the values: Chris@87: Chris@87: .. math:: p(x,y) = \\sum_{i,j} c_{i,j} * He_i(x) * He_j(y) Chris@87: Chris@87: The parameters `x` and `y` are converted to arrays only if they are Chris@87: tuples or a lists, otherwise they are treated as a scalars and they Chris@87: must have the same shape after conversion. In either case, either `x` Chris@87: and `y` or their elements must support multiplication and addition both Chris@87: with themselves and with the elements of `c`. Chris@87: Chris@87: If `c` is a 1-D array a one is implicitly appended to its shape to make Chris@87: it 2-D. The shape of the result will be c.shape[2:] + x.shape. Chris@87: Chris@87: Parameters Chris@87: ---------- Chris@87: x, y : array_like, compatible objects Chris@87: The two dimensional series is evaluated at the points `(x, y)`, Chris@87: where `x` and `y` must have the same shape. If `x` or `y` is a list Chris@87: or tuple, it is first converted to an ndarray, otherwise it is left Chris@87: unchanged and if it isn't an ndarray it is treated as a scalar. Chris@87: c : array_like Chris@87: Array of coefficients ordered so that the coefficient of the term Chris@87: of multi-degree i,j is contained in ``c[i,j]``. If `c` has Chris@87: dimension greater than two the remaining indices enumerate multiple Chris@87: sets of coefficients. Chris@87: Chris@87: Returns Chris@87: ------- Chris@87: values : ndarray, compatible object Chris@87: The values of the two dimensional polynomial at points formed with Chris@87: pairs of corresponding values from `x` and `y`. Chris@87: Chris@87: See Also Chris@87: -------- Chris@87: hermeval, hermegrid2d, hermeval3d, hermegrid3d Chris@87: Chris@87: Notes Chris@87: ----- Chris@87: Chris@87: .. versionadded::1.7.0 Chris@87: Chris@87: """ Chris@87: try: Chris@87: x, y = np.array((x, y), copy=0) Chris@87: except: Chris@87: raise ValueError('x, y are incompatible') Chris@87: Chris@87: c = hermeval(x, c) Chris@87: c = hermeval(y, c, tensor=False) Chris@87: return c Chris@87: Chris@87: Chris@87: def hermegrid2d(x, y, c): Chris@87: """ Chris@87: Evaluate a 2-D HermiteE series on the Cartesian product of x and y. Chris@87: Chris@87: This function returns the values: Chris@87: Chris@87: .. math:: p(a,b) = \sum_{i,j} c_{i,j} * H_i(a) * H_j(b) Chris@87: Chris@87: where the points `(a, b)` consist of all pairs formed by taking Chris@87: `a` from `x` and `b` from `y`. The resulting points form a grid with Chris@87: `x` in the first dimension and `y` in the second. Chris@87: Chris@87: The parameters `x` and `y` are converted to arrays only if they are Chris@87: tuples or a lists, otherwise they are treated as a scalars. In either Chris@87: case, either `x` and `y` or their elements must support multiplication Chris@87: and addition both with themselves and with the elements of `c`. Chris@87: Chris@87: If `c` has fewer than two dimensions, ones are implicitly appended to Chris@87: its shape to make it 2-D. The shape of the result will be c.shape[2:] + Chris@87: x.shape. Chris@87: Chris@87: Parameters Chris@87: ---------- Chris@87: x, y : array_like, compatible objects Chris@87: The two dimensional series is evaluated at the points in the Chris@87: Cartesian product of `x` and `y`. If `x` or `y` is a list or Chris@87: tuple, it is first converted to an ndarray, otherwise it is left Chris@87: unchanged and, if it isn't an ndarray, it is treated as a scalar. Chris@87: c : array_like Chris@87: Array of coefficients ordered so that the coefficients for terms of Chris@87: degree i,j are contained in ``c[i,j]``. If `c` has dimension Chris@87: greater than two the remaining indices enumerate multiple sets of Chris@87: coefficients. Chris@87: Chris@87: Returns Chris@87: ------- Chris@87: values : ndarray, compatible object Chris@87: The values of the two dimensional polynomial at points in the Cartesian Chris@87: product of `x` and `y`. Chris@87: Chris@87: See Also Chris@87: -------- Chris@87: hermeval, hermeval2d, hermeval3d, hermegrid3d Chris@87: Chris@87: Notes Chris@87: ----- Chris@87: Chris@87: .. versionadded::1.7.0 Chris@87: Chris@87: """ Chris@87: c = hermeval(x, c) Chris@87: c = hermeval(y, c) Chris@87: return c Chris@87: Chris@87: Chris@87: def hermeval3d(x, y, z, c): Chris@87: """ Chris@87: Evaluate a 3-D Hermite_e series at points (x, y, z). Chris@87: Chris@87: This function returns the values: Chris@87: Chris@87: .. math:: p(x,y,z) = \\sum_{i,j,k} c_{i,j,k} * He_i(x) * He_j(y) * He_k(z) Chris@87: Chris@87: The parameters `x`, `y`, and `z` are converted to arrays only if Chris@87: they are tuples or a lists, otherwise they are treated as a scalars and Chris@87: they must have the same shape after conversion. In either case, either Chris@87: `x`, `y`, and `z` or their elements must support multiplication and Chris@87: addition both with themselves and with the elements of `c`. Chris@87: Chris@87: If `c` has fewer than 3 dimensions, ones are implicitly appended to its Chris@87: shape to make it 3-D. The shape of the result will be c.shape[3:] + Chris@87: x.shape. Chris@87: Chris@87: Parameters Chris@87: ---------- Chris@87: x, y, z : array_like, compatible object Chris@87: The three dimensional series is evaluated at the points Chris@87: `(x, y, z)`, where `x`, `y`, and `z` must have the same shape. If Chris@87: any of `x`, `y`, or `z` is a list or tuple, it is first converted Chris@87: to an ndarray, otherwise it is left unchanged and if it isn't an Chris@87: ndarray it is treated as a scalar. Chris@87: c : array_like Chris@87: Array of coefficients ordered so that the coefficient of the term of Chris@87: multi-degree i,j,k is contained in ``c[i,j,k]``. If `c` has dimension Chris@87: greater than 3 the remaining indices enumerate multiple sets of Chris@87: coefficients. Chris@87: Chris@87: Returns Chris@87: ------- Chris@87: values : ndarray, compatible object Chris@87: The values of the multidimensional polynomial on points formed with Chris@87: triples of corresponding values from `x`, `y`, and `z`. Chris@87: Chris@87: See Also Chris@87: -------- Chris@87: hermeval, hermeval2d, hermegrid2d, hermegrid3d Chris@87: Chris@87: Notes Chris@87: ----- Chris@87: Chris@87: .. versionadded::1.7.0 Chris@87: Chris@87: """ Chris@87: try: Chris@87: x, y, z = np.array((x, y, z), copy=0) Chris@87: except: Chris@87: raise ValueError('x, y, z are incompatible') Chris@87: Chris@87: c = hermeval(x, c) Chris@87: c = hermeval(y, c, tensor=False) Chris@87: c = hermeval(z, c, tensor=False) Chris@87: return c Chris@87: Chris@87: Chris@87: def hermegrid3d(x, y, z, c): Chris@87: """ Chris@87: Evaluate a 3-D HermiteE series on the Cartesian product of x, y, and z. Chris@87: Chris@87: This function returns the values: Chris@87: Chris@87: .. math:: p(a,b,c) = \\sum_{i,j,k} c_{i,j,k} * He_i(a) * He_j(b) * He_k(c) Chris@87: Chris@87: where the points `(a, b, c)` consist of all triples formed by taking Chris@87: `a` from `x`, `b` from `y`, and `c` from `z`. The resulting points form Chris@87: a grid with `x` in the first dimension, `y` in the second, and `z` in Chris@87: the third. Chris@87: Chris@87: The parameters `x`, `y`, and `z` are converted to arrays only if they Chris@87: are tuples or a lists, otherwise they are treated as a scalars. In Chris@87: either case, either `x`, `y`, and `z` or their elements must support Chris@87: multiplication and addition both with themselves and with the elements Chris@87: of `c`. Chris@87: Chris@87: If `c` has fewer than three dimensions, ones are implicitly appended to Chris@87: its shape to make it 3-D. The shape of the result will be c.shape[3:] + Chris@87: x.shape + y.shape + z.shape. Chris@87: Chris@87: Parameters Chris@87: ---------- Chris@87: x, y, z : array_like, compatible objects Chris@87: The three dimensional series is evaluated at the points in the Chris@87: Cartesian product of `x`, `y`, and `z`. If `x`,`y`, or `z` is a Chris@87: list or tuple, it is first converted to an ndarray, otherwise it is Chris@87: left unchanged and, if it isn't an ndarray, it is treated as a Chris@87: scalar. Chris@87: c : array_like Chris@87: Array of coefficients ordered so that the coefficients for terms of Chris@87: degree i,j are contained in ``c[i,j]``. If `c` has dimension Chris@87: greater than two the remaining indices enumerate multiple sets of Chris@87: coefficients. Chris@87: Chris@87: Returns Chris@87: ------- Chris@87: values : ndarray, compatible object Chris@87: The values of the two dimensional polynomial at points in the Cartesian Chris@87: product of `x` and `y`. Chris@87: Chris@87: See Also Chris@87: -------- Chris@87: hermeval, hermeval2d, hermegrid2d, hermeval3d Chris@87: Chris@87: Notes Chris@87: ----- Chris@87: Chris@87: .. versionadded::1.7.0 Chris@87: Chris@87: """ Chris@87: c = hermeval(x, c) Chris@87: c = hermeval(y, c) Chris@87: c = hermeval(z, c) Chris@87: return c Chris@87: Chris@87: Chris@87: def hermevander(x, deg): Chris@87: """Pseudo-Vandermonde matrix of given degree. Chris@87: Chris@87: Returns the pseudo-Vandermonde matrix of degree `deg` and sample points Chris@87: `x`. The pseudo-Vandermonde matrix is defined by Chris@87: Chris@87: .. math:: V[..., i] = He_i(x), Chris@87: Chris@87: where `0 <= i <= deg`. The leading indices of `V` index the elements of Chris@87: `x` and the last index is the degree of the HermiteE polynomial. Chris@87: Chris@87: If `c` is a 1-D array of coefficients of length `n + 1` and `V` is the Chris@87: array ``V = hermevander(x, n)``, then ``np.dot(V, c)`` and Chris@87: ``hermeval(x, c)`` are the same up to roundoff. This equivalence is Chris@87: useful both for least squares fitting and for the evaluation of a large Chris@87: number of HermiteE series of the same degree and sample points. Chris@87: Chris@87: Parameters Chris@87: ---------- Chris@87: x : array_like Chris@87: Array of points. The dtype is converted to float64 or complex128 Chris@87: depending on whether any of the elements are complex. If `x` is Chris@87: scalar it is converted to a 1-D array. Chris@87: deg : int Chris@87: Degree of the resulting matrix. Chris@87: Chris@87: Returns Chris@87: ------- Chris@87: vander : ndarray Chris@87: The pseudo-Vandermonde matrix. The shape of the returned matrix is Chris@87: ``x.shape + (deg + 1,)``, where The last index is the degree of the Chris@87: corresponding HermiteE polynomial. The dtype will be the same as Chris@87: the converted `x`. Chris@87: Chris@87: Examples Chris@87: -------- Chris@87: >>> from numpy.polynomial.hermite_e import hermevander Chris@87: >>> x = np.array([-1, 0, 1]) Chris@87: >>> hermevander(x, 3) Chris@87: array([[ 1., -1., 0., 2.], Chris@87: [ 1., 0., -1., -0.], Chris@87: [ 1., 1., 0., -2.]]) Chris@87: Chris@87: """ Chris@87: ideg = int(deg) Chris@87: if ideg != deg: Chris@87: raise ValueError("deg must be integer") Chris@87: if ideg < 0: Chris@87: raise ValueError("deg must be non-negative") Chris@87: Chris@87: x = np.array(x, copy=0, ndmin=1) + 0.0 Chris@87: dims = (ideg + 1,) + x.shape Chris@87: dtyp = x.dtype Chris@87: v = np.empty(dims, dtype=dtyp) Chris@87: v[0] = x*0 + 1 Chris@87: if ideg > 0: Chris@87: v[1] = x Chris@87: for i in range(2, ideg + 1): Chris@87: v[i] = (v[i-1]*x - v[i-2]*(i - 1)) Chris@87: return np.rollaxis(v, 0, v.ndim) Chris@87: Chris@87: Chris@87: def hermevander2d(x, y, deg): Chris@87: """Pseudo-Vandermonde matrix of given degrees. Chris@87: Chris@87: Returns the pseudo-Vandermonde matrix of degrees `deg` and sample Chris@87: points `(x, y)`. The pseudo-Vandermonde matrix is defined by Chris@87: Chris@87: .. math:: V[..., deg[1]*i + j] = He_i(x) * He_j(y), Chris@87: Chris@87: where `0 <= i <= deg[0]` and `0 <= j <= deg[1]`. The leading indices of Chris@87: `V` index the points `(x, y)` and the last index encodes the degrees of Chris@87: the HermiteE polynomials. Chris@87: Chris@87: If ``V = hermevander2d(x, y, [xdeg, ydeg])``, then the columns of `V` Chris@87: correspond to the elements of a 2-D coefficient array `c` of shape Chris@87: (xdeg + 1, ydeg + 1) in the order Chris@87: Chris@87: .. math:: c_{00}, c_{01}, c_{02} ... , c_{10}, c_{11}, c_{12} ... Chris@87: Chris@87: and ``np.dot(V, c.flat)`` and ``hermeval2d(x, y, c)`` will be the same Chris@87: up to roundoff. This equivalence is useful both for least squares Chris@87: fitting and for the evaluation of a large number of 2-D HermiteE Chris@87: series of the same degrees and sample points. Chris@87: Chris@87: Parameters Chris@87: ---------- Chris@87: x, y : array_like Chris@87: Arrays of point coordinates, all of the same shape. The dtypes Chris@87: will be converted to either float64 or complex128 depending on Chris@87: whether any of the elements are complex. Scalars are converted to Chris@87: 1-D arrays. Chris@87: deg : list of ints Chris@87: List of maximum degrees of the form [x_deg, y_deg]. Chris@87: Chris@87: Returns Chris@87: ------- Chris@87: vander2d : ndarray Chris@87: The shape of the returned matrix is ``x.shape + (order,)``, where Chris@87: :math:`order = (deg[0]+1)*(deg([1]+1)`. The dtype will be the same Chris@87: as the converted `x` and `y`. Chris@87: Chris@87: See Also Chris@87: -------- Chris@87: hermevander, hermevander3d. hermeval2d, hermeval3d Chris@87: Chris@87: Notes Chris@87: ----- Chris@87: Chris@87: .. versionadded::1.7.0 Chris@87: Chris@87: """ Chris@87: ideg = [int(d) for d in deg] Chris@87: is_valid = [id == d and id >= 0 for id, d in zip(ideg, deg)] Chris@87: if is_valid != [1, 1]: Chris@87: raise ValueError("degrees must be non-negative integers") Chris@87: degx, degy = ideg Chris@87: x, y = np.array((x, y), copy=0) + 0.0 Chris@87: Chris@87: vx = hermevander(x, degx) Chris@87: vy = hermevander(y, degy) Chris@87: v = vx[..., None]*vy[..., None,:] Chris@87: return v.reshape(v.shape[:-2] + (-1,)) Chris@87: Chris@87: Chris@87: def hermevander3d(x, y, z, deg): Chris@87: """Pseudo-Vandermonde matrix of given degrees. Chris@87: Chris@87: Returns the pseudo-Vandermonde matrix of degrees `deg` and sample Chris@87: points `(x, y, z)`. If `l, m, n` are the given degrees in `x, y, z`, Chris@87: then Hehe pseudo-Vandermonde matrix is defined by Chris@87: Chris@87: .. math:: V[..., (m+1)(n+1)i + (n+1)j + k] = He_i(x)*He_j(y)*He_k(z), Chris@87: Chris@87: where `0 <= i <= l`, `0 <= j <= m`, and `0 <= j <= n`. The leading Chris@87: indices of `V` index the points `(x, y, z)` and the last index encodes Chris@87: the degrees of the HermiteE polynomials. Chris@87: Chris@87: If ``V = hermevander3d(x, y, z, [xdeg, ydeg, zdeg])``, then the columns Chris@87: of `V` correspond to the elements of a 3-D coefficient array `c` of Chris@87: shape (xdeg + 1, ydeg + 1, zdeg + 1) in the order Chris@87: Chris@87: .. math:: c_{000}, c_{001}, c_{002},... , c_{010}, c_{011}, c_{012},... Chris@87: Chris@87: and ``np.dot(V, c.flat)`` and ``hermeval3d(x, y, z, c)`` will be the Chris@87: same up to roundoff. This equivalence is useful both for least squares Chris@87: fitting and for the evaluation of a large number of 3-D HermiteE Chris@87: series of the same degrees and sample points. Chris@87: Chris@87: Parameters Chris@87: ---------- Chris@87: x, y, z : array_like Chris@87: Arrays of point coordinates, all of the same shape. The dtypes will Chris@87: be converted to either float64 or complex128 depending on whether Chris@87: any of the elements are complex. Scalars are converted to 1-D Chris@87: arrays. Chris@87: deg : list of ints Chris@87: List of maximum degrees of the form [x_deg, y_deg, z_deg]. Chris@87: Chris@87: Returns Chris@87: ------- Chris@87: vander3d : ndarray Chris@87: The shape of the returned matrix is ``x.shape + (order,)``, where Chris@87: :math:`order = (deg[0]+1)*(deg([1]+1)*(deg[2]+1)`. The dtype will Chris@87: be the same as the converted `x`, `y`, and `z`. Chris@87: Chris@87: See Also Chris@87: -------- Chris@87: hermevander, hermevander3d. hermeval2d, hermeval3d Chris@87: Chris@87: Notes Chris@87: ----- Chris@87: Chris@87: .. versionadded::1.7.0 Chris@87: Chris@87: """ Chris@87: ideg = [int(d) for d in deg] Chris@87: is_valid = [id == d and id >= 0 for id, d in zip(ideg, deg)] Chris@87: if is_valid != [1, 1, 1]: Chris@87: raise ValueError("degrees must be non-negative integers") Chris@87: degx, degy, degz = ideg Chris@87: x, y, z = np.array((x, y, z), copy=0) + 0.0 Chris@87: Chris@87: vx = hermevander(x, degx) Chris@87: vy = hermevander(y, degy) Chris@87: vz = hermevander(z, degz) Chris@87: v = vx[..., None, None]*vy[..., None,:, None]*vz[..., None, None,:] Chris@87: return v.reshape(v.shape[:-3] + (-1,)) Chris@87: Chris@87: Chris@87: def hermefit(x, y, deg, rcond=None, full=False, w=None): Chris@87: """ Chris@87: Least squares fit of Hermite series to data. Chris@87: Chris@87: Return the coefficients of a HermiteE series of degree `deg` that is Chris@87: the least squares fit to the data values `y` given at points `x`. If Chris@87: `y` is 1-D the returned coefficients will also be 1-D. If `y` is 2-D Chris@87: multiple fits are done, one for each column of `y`, and the resulting Chris@87: coefficients are stored in the corresponding columns of a 2-D return. Chris@87: The fitted polynomial(s) are in the form Chris@87: Chris@87: .. math:: p(x) = c_0 + c_1 * He_1(x) + ... + c_n * He_n(x), Chris@87: Chris@87: where `n` is `deg`. Chris@87: Chris@87: Parameters Chris@87: ---------- Chris@87: x : array_like, shape (M,) Chris@87: x-coordinates of the M sample points ``(x[i], y[i])``. Chris@87: y : array_like, shape (M,) or (M, K) Chris@87: y-coordinates of the sample points. Several data sets of sample Chris@87: points sharing the same x-coordinates can be fitted at once by Chris@87: passing in a 2D-array that contains one dataset per column. Chris@87: deg : int Chris@87: Degree of the fitting polynomial Chris@87: rcond : float, optional Chris@87: Relative condition number of the fit. Singular values smaller than Chris@87: this relative to the largest singular value will be ignored. The Chris@87: default value is len(x)*eps, where eps is the relative precision of Chris@87: the float type, about 2e-16 in most cases. Chris@87: full : bool, optional Chris@87: Switch determining nature of return value. When it is False (the Chris@87: default) just the coefficients are returned, when True diagnostic Chris@87: information from the singular value decomposition is also returned. Chris@87: w : array_like, shape (`M`,), optional Chris@87: Weights. If not None, the contribution of each point Chris@87: ``(x[i],y[i])`` to the fit is weighted by `w[i]`. Ideally the Chris@87: weights are chosen so that the errors of the products ``w[i]*y[i]`` Chris@87: all have the same variance. The default value is None. Chris@87: Chris@87: Returns Chris@87: ------- Chris@87: coef : ndarray, shape (M,) or (M, K) Chris@87: Hermite coefficients ordered from low to high. If `y` was 2-D, Chris@87: the coefficients for the data in column k of `y` are in column Chris@87: `k`. Chris@87: Chris@87: [residuals, rank, singular_values, rcond] : list Chris@87: These values are only returned if `full` = True Chris@87: Chris@87: resid -- sum of squared residuals of the least squares fit Chris@87: rank -- the numerical rank of the scaled Vandermonde matrix Chris@87: sv -- singular values of the scaled Vandermonde matrix Chris@87: rcond -- value of `rcond`. Chris@87: Chris@87: For more details, see `linalg.lstsq`. Chris@87: Chris@87: Warns Chris@87: ----- Chris@87: RankWarning Chris@87: The rank of the coefficient matrix in the least-squares fit is Chris@87: deficient. The warning is only raised if `full` = False. The Chris@87: warnings can be turned off by Chris@87: Chris@87: >>> import warnings Chris@87: >>> warnings.simplefilter('ignore', RankWarning) Chris@87: Chris@87: See Also Chris@87: -------- Chris@87: chebfit, legfit, polyfit, hermfit, polyfit Chris@87: hermeval : Evaluates a Hermite series. Chris@87: hermevander : pseudo Vandermonde matrix of Hermite series. Chris@87: hermeweight : HermiteE weight function. Chris@87: linalg.lstsq : Computes a least-squares fit from the matrix. Chris@87: scipy.interpolate.UnivariateSpline : Computes spline fits. Chris@87: Chris@87: Notes Chris@87: ----- Chris@87: The solution is the coefficients of the HermiteE series `p` that Chris@87: minimizes the sum of the weighted squared errors Chris@87: Chris@87: .. math:: E = \\sum_j w_j^2 * |y_j - p(x_j)|^2, Chris@87: Chris@87: where the :math:`w_j` are the weights. This problem is solved by Chris@87: setting up the (typically) overdetermined matrix equation Chris@87: Chris@87: .. math:: V(x) * c = w * y, Chris@87: Chris@87: where `V` is the pseudo Vandermonde matrix of `x`, the elements of `c` Chris@87: are the coefficients to be solved for, and the elements of `y` are the Chris@87: observed values. This equation is then solved using the singular value Chris@87: decomposition of `V`. Chris@87: Chris@87: If some of the singular values of `V` are so small that they are Chris@87: neglected, then a `RankWarning` will be issued. This means that the Chris@87: coefficient values may be poorly determined. Using a lower order fit Chris@87: will usually get rid of the warning. The `rcond` parameter can also be Chris@87: set to a value smaller than its default, but the resulting fit may be Chris@87: spurious and have large contributions from roundoff error. Chris@87: Chris@87: Fits using HermiteE series are probably most useful when the data can Chris@87: be approximated by ``sqrt(w(x)) * p(x)``, where `w(x)` is the HermiteE Chris@87: weight. In that case the weight ``sqrt(w(x[i])`` should be used Chris@87: together with data values ``y[i]/sqrt(w(x[i])``. The weight function is Chris@87: available as `hermeweight`. Chris@87: Chris@87: References Chris@87: ---------- Chris@87: .. [1] Wikipedia, "Curve fitting", Chris@87: http://en.wikipedia.org/wiki/Curve_fitting Chris@87: Chris@87: Examples Chris@87: -------- Chris@87: >>> from numpy.polynomial.hermite_e import hermefik, hermeval Chris@87: >>> x = np.linspace(-10, 10) Chris@87: >>> err = np.random.randn(len(x))/10 Chris@87: >>> y = hermeval(x, [1, 2, 3]) + err Chris@87: >>> hermefit(x, y, 2) Chris@87: array([ 1.01690445, 1.99951418, 2.99948696]) Chris@87: Chris@87: """ Chris@87: order = int(deg) + 1 Chris@87: x = np.asarray(x) + 0.0 Chris@87: y = np.asarray(y) + 0.0 Chris@87: Chris@87: # check arguments. Chris@87: if deg < 0: Chris@87: raise ValueError("expected deg >= 0") Chris@87: if x.ndim != 1: Chris@87: raise TypeError("expected 1D vector for x") Chris@87: if x.size == 0: Chris@87: raise TypeError("expected non-empty vector for x") Chris@87: if y.ndim < 1 or y.ndim > 2: Chris@87: raise TypeError("expected 1D or 2D array for y") Chris@87: if len(x) != len(y): Chris@87: raise TypeError("expected x and y to have same length") Chris@87: Chris@87: # set up the least squares matrices in transposed form Chris@87: lhs = hermevander(x, deg).T Chris@87: rhs = y.T Chris@87: if w is not None: Chris@87: w = np.asarray(w) + 0.0 Chris@87: if w.ndim != 1: Chris@87: raise TypeError("expected 1D vector for w") Chris@87: if len(x) != len(w): Chris@87: raise TypeError("expected x and w to have same length") Chris@87: # apply weights. Don't use inplace operations as they Chris@87: # can cause problems with NA. Chris@87: lhs = lhs * w Chris@87: rhs = rhs * w Chris@87: Chris@87: # set rcond Chris@87: if rcond is None: Chris@87: rcond = len(x)*np.finfo(x.dtype).eps Chris@87: Chris@87: # Determine the norms of the design matrix columns. Chris@87: if issubclass(lhs.dtype.type, np.complexfloating): Chris@87: scl = np.sqrt((np.square(lhs.real) + np.square(lhs.imag)).sum(1)) Chris@87: else: Chris@87: scl = np.sqrt(np.square(lhs).sum(1)) Chris@87: scl[scl == 0] = 1 Chris@87: Chris@87: # Solve the least squares problem. Chris@87: c, resids, rank, s = la.lstsq(lhs.T/scl, rhs.T, rcond) Chris@87: c = (c.T/scl).T Chris@87: Chris@87: # warn on rank reduction Chris@87: if rank != order and not full: Chris@87: msg = "The fit may be poorly conditioned" Chris@87: warnings.warn(msg, pu.RankWarning) Chris@87: Chris@87: if full: Chris@87: return c, [resids, rank, s, rcond] Chris@87: else: Chris@87: return c Chris@87: Chris@87: Chris@87: def hermecompanion(c): Chris@87: """ Chris@87: Return the scaled companion matrix of c. Chris@87: Chris@87: The basis polynomials are scaled so that the companion matrix is Chris@87: symmetric when `c` is an HermiteE basis polynomial. This provides Chris@87: better eigenvalue estimates than the unscaled case and for basis Chris@87: polynomials the eigenvalues are guaranteed to be real if Chris@87: `numpy.linalg.eigvalsh` is used to obtain them. Chris@87: Chris@87: Parameters Chris@87: ---------- Chris@87: c : array_like Chris@87: 1-D array of HermiteE series coefficients ordered from low to high Chris@87: degree. Chris@87: Chris@87: Returns Chris@87: ------- Chris@87: mat : ndarray Chris@87: Scaled companion matrix of dimensions (deg, deg). Chris@87: Chris@87: Notes Chris@87: ----- Chris@87: Chris@87: .. versionadded::1.7.0 Chris@87: Chris@87: """ Chris@87: # c is a trimmed copy Chris@87: [c] = pu.as_series([c]) Chris@87: if len(c) < 2: Chris@87: raise ValueError('Series must have maximum degree of at least 1.') Chris@87: if len(c) == 2: Chris@87: return np.array([[-c[0]/c[1]]]) Chris@87: Chris@87: n = len(c) - 1 Chris@87: mat = np.zeros((n, n), dtype=c.dtype) Chris@87: scl = np.hstack((1., np.sqrt(np.arange(1, n)))) Chris@87: scl = np.multiply.accumulate(scl) Chris@87: top = mat.reshape(-1)[1::n+1] Chris@87: bot = mat.reshape(-1)[n::n+1] Chris@87: top[...] = np.sqrt(np.arange(1, n)) Chris@87: bot[...] = top Chris@87: mat[:, -1] -= (c[:-1]/c[-1])*(scl/scl[-1]) Chris@87: return mat Chris@87: Chris@87: Chris@87: def hermeroots(c): Chris@87: """ Chris@87: Compute the roots of a HermiteE series. Chris@87: Chris@87: Return the roots (a.k.a. "zeros") of the polynomial Chris@87: Chris@87: .. math:: p(x) = \\sum_i c[i] * He_i(x). Chris@87: Chris@87: Parameters Chris@87: ---------- Chris@87: c : 1-D array_like Chris@87: 1-D array of coefficients. Chris@87: Chris@87: Returns Chris@87: ------- Chris@87: out : ndarray Chris@87: Array of the roots of the series. If all the roots are real, Chris@87: then `out` is also real, otherwise it is complex. Chris@87: Chris@87: See Also Chris@87: -------- Chris@87: polyroots, legroots, lagroots, hermroots, chebroots Chris@87: Chris@87: Notes Chris@87: ----- Chris@87: The root estimates are obtained as the eigenvalues of the companion Chris@87: matrix, Roots far from the origin of the complex plane may have large Chris@87: errors due to the numerical instability of the series for such Chris@87: values. Roots with multiplicity greater than 1 will also show larger Chris@87: errors as the value of the series near such points is relatively Chris@87: insensitive to errors in the roots. Isolated roots near the origin can Chris@87: be improved by a few iterations of Newton's method. Chris@87: Chris@87: The HermiteE series basis polynomials aren't powers of `x` so the Chris@87: results of this function may seem unintuitive. Chris@87: Chris@87: Examples Chris@87: -------- Chris@87: >>> from numpy.polynomial.hermite_e import hermeroots, hermefromroots Chris@87: >>> coef = hermefromroots([-1, 0, 1]) Chris@87: >>> coef Chris@87: array([ 0., 2., 0., 1.]) Chris@87: >>> hermeroots(coef) Chris@87: array([-1., 0., 1.]) Chris@87: Chris@87: """ Chris@87: # c is a trimmed copy Chris@87: [c] = pu.as_series([c]) Chris@87: if len(c) <= 1: Chris@87: return np.array([], dtype=c.dtype) Chris@87: if len(c) == 2: Chris@87: return np.array([-c[0]/c[1]]) Chris@87: Chris@87: m = hermecompanion(c) Chris@87: r = la.eigvals(m) Chris@87: r.sort() Chris@87: return r Chris@87: Chris@87: Chris@87: def hermegauss(deg): Chris@87: """ Chris@87: Gauss-HermiteE quadrature. Chris@87: Chris@87: Computes the sample points and weights for Gauss-HermiteE quadrature. Chris@87: These sample points and weights will correctly integrate polynomials of Chris@87: degree :math:`2*deg - 1` or less over the interval :math:`[-\inf, \inf]` Chris@87: with the weight function :math:`f(x) = \exp(-x^2/2)`. Chris@87: Chris@87: Parameters Chris@87: ---------- Chris@87: deg : int Chris@87: Number of sample points and weights. It must be >= 1. Chris@87: Chris@87: Returns Chris@87: ------- Chris@87: x : ndarray Chris@87: 1-D ndarray containing the sample points. Chris@87: y : ndarray Chris@87: 1-D ndarray containing the weights. Chris@87: Chris@87: Notes Chris@87: ----- Chris@87: Chris@87: .. versionadded::1.7.0 Chris@87: Chris@87: The results have only been tested up to degree 100, higher degrees may Chris@87: be problematic. The weights are determined by using the fact that Chris@87: Chris@87: .. math:: w_k = c / (He'_n(x_k) * He_{n-1}(x_k)) Chris@87: Chris@87: where :math:`c` is a constant independent of :math:`k` and :math:`x_k` Chris@87: is the k'th root of :math:`He_n`, and then scaling the results to get Chris@87: the right value when integrating 1. Chris@87: Chris@87: """ Chris@87: ideg = int(deg) Chris@87: if ideg != deg or ideg < 1: Chris@87: raise ValueError("deg must be a non-negative integer") Chris@87: Chris@87: # first approximation of roots. We use the fact that the companion Chris@87: # matrix is symmetric in this case in order to obtain better zeros. Chris@87: c = np.array([0]*deg + [1]) Chris@87: m = hermecompanion(c) Chris@87: x = la.eigvals(m) Chris@87: x.sort() Chris@87: Chris@87: # improve roots by one application of Newton Chris@87: dy = hermeval(x, c) Chris@87: df = hermeval(x, hermeder(c)) Chris@87: x -= dy/df Chris@87: Chris@87: # compute the weights. We scale the factor to avoid possible numerical Chris@87: # overflow. Chris@87: fm = hermeval(x, c[1:]) Chris@87: fm /= np.abs(fm).max() Chris@87: df /= np.abs(df).max() Chris@87: w = 1/(fm * df) Chris@87: Chris@87: # for Hermite_e we can also symmetrize Chris@87: w = (w + w[::-1])/2 Chris@87: x = (x - x[::-1])/2 Chris@87: Chris@87: # scale w to get the right value Chris@87: w *= np.sqrt(2*np.pi) / w.sum() Chris@87: Chris@87: return x, w Chris@87: Chris@87: Chris@87: def hermeweight(x): Chris@87: """Weight function of the Hermite_e polynomials. Chris@87: Chris@87: The weight function is :math:`\exp(-x^2/2)` and the interval of Chris@87: integration is :math:`[-\inf, \inf]`. the HermiteE polynomials are Chris@87: orthogonal, but not normalized, with respect to this weight function. Chris@87: Chris@87: Parameters Chris@87: ---------- Chris@87: x : array_like Chris@87: Values at which the weight function will be computed. Chris@87: Chris@87: Returns Chris@87: ------- Chris@87: w : ndarray Chris@87: The weight function at `x`. Chris@87: Chris@87: Notes Chris@87: ----- Chris@87: Chris@87: .. versionadded::1.7.0 Chris@87: Chris@87: """ Chris@87: w = np.exp(-.5*x**2) Chris@87: return w Chris@87: Chris@87: Chris@87: # Chris@87: # HermiteE series class Chris@87: # Chris@87: Chris@87: class HermiteE(ABCPolyBase): Chris@87: """An HermiteE series class. Chris@87: Chris@87: The HermiteE class provides the standard Python numerical methods Chris@87: '+', '-', '*', '//', '%', 'divmod', '**', and '()' as well as the Chris@87: attributes and methods listed in the `ABCPolyBase` documentation. Chris@87: Chris@87: Parameters Chris@87: ---------- Chris@87: coef : array_like Chris@87: Laguerre coefficients in order of increasing degree, i.e, Chris@87: ``(1, 2, 3)`` gives ``1*He_0(x) + 2*He_1(X) + 3*He_2(x)``. Chris@87: domain : (2,) array_like, optional Chris@87: Domain to use. The interval ``[domain[0], domain[1]]`` is mapped Chris@87: to the interval ``[window[0], window[1]]`` by shifting and scaling. Chris@87: The default value is [-1, 1]. Chris@87: window : (2,) array_like, optional Chris@87: Window, see `domain` for its use. The default value is [-1, 1]. Chris@87: Chris@87: .. versionadded:: 1.6.0 Chris@87: Chris@87: """ Chris@87: # Virtual Functions Chris@87: _add = staticmethod(hermeadd) Chris@87: _sub = staticmethod(hermesub) Chris@87: _mul = staticmethod(hermemul) Chris@87: _div = staticmethod(hermediv) Chris@87: _pow = staticmethod(hermepow) Chris@87: _val = staticmethod(hermeval) Chris@87: _int = staticmethod(hermeint) Chris@87: _der = staticmethod(hermeder) Chris@87: _fit = staticmethod(hermefit) Chris@87: _line = staticmethod(hermeline) Chris@87: _roots = staticmethod(hermeroots) Chris@87: _fromroots = staticmethod(hermefromroots) Chris@87: Chris@87: # Virtual properties Chris@87: nickname = 'herme' Chris@87: domain = np.array(hermedomain) Chris@87: window = np.array(hermedomain)