-
Notifications
You must be signed in to change notification settings - Fork 4
/
_hermite.py
39 lines (36 loc) · 1.1 KB
/
_hermite.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from ..utils import check_backend
from .polynomial import Poly
class Hermite(Poly):
"""
Hermite polynomials of the first kind (in probability theory)
"""
def __init__(self, x, degree, backend = None, **kw):
"""
input:
- x: a tensor
- degree: highest degree of polynomial
"""
if backend is None:
self._backend = check_backend(x)
else:
self._backend = backend
initial = [lambda x: self._backend.ones_like(x), lambda x: x]
recurrence = lambda p1, p2, n, x: self._backend.multiply(x, p1) - p2*n
Poly.__init__(self, self._backend, x, degree, initial, recurrence, **kw)
class Hermite2(Poly):
"""
Hermite polynomials of the second kind (in Physics)
"""
def __init__(self, x, degree, backend = None, **kw):
"""
input:
- x: a tensor
- degree: highest degree of polynomial
"""
if backend is None:
self._backend = check_backend(x)
else:
self._backend = backend
initial = [lambda x: self._backend.ones_like(x), lambda x: x*2]
recurrence = lambda p1, p2, n, x: (self._backend.multiply(x, p1) - p2*n)*2
Poly.__init__(self, self._backend, x, degree, initial, recurrence, **kw)