The py-orthpol
package defines the module orthpol
which can be used
easily construct univariate and multivariate orthogonal polynomials in Python.
The purpose of this code is to serve as a component in Python packages that
could use orthogonal polynomials as basis functions for various tasks.
For example:
- The polynomials can be used in least squares applications.
- The polynomials can serve as the mean in Gaussian process regression.
- etc.
The need to have an easy to use package that can generate polynomials orthogonal with respect to arbitrary weight functions is motivated by applications in the field of Uncertainty Quantification (UQ). In UQ, collections of such polynomials are known as generalized Polynomial Chaos (gPC). The author's goal is to provide a tool that makes it ridiculously easy to construct these polynomials.
- The recurrence coefficients for polynomials are normalized in PredictiveScienceLab/py-orthpol. This normalization has been removed.
- The code was refactored from Python2 to Python3
This package serves as a Python wrapper for the legacy Fortran code ORTHPOL. The original ORTHPOL code can be found here. The code that computes tensors products of univariate orthogonal polynomials is a transolation of Stockos C++ routines to Python.
To install this fork, simply clone the repository:
git clone https://github.com/moritzlange/py-orthpol.git
Go inside the directory and run:
python3 setup.py install
The original author provides several demos that demonstrate how polynomials can be constructed
both from simple weight functions as well as scipy.stats
random variables.
It is quite easy based on these examples to generalize to more complicated cases.
All one has to do is change the weight function or the random variable.
Here is a list of them:
- demos/demo1.py: Hermite polynomials using a weight function.
- demos/demo2.py: Laguerre polynomials using a weight function.
- demos/demo3.py: Chebyshev polynomials using a weight function.
- demos/demo4.py: Jacobi polynomials using a weight function.
- demos/demo5.py: Gegenbauer polynomials using a weight function.
- demos/demo6.py: Legendre polynomials using a weight function.
- demos/demo7.pv: Legendre polynomials using
scipy.stats.uniform()
. - demos/demo8.pv: Hermite polynomials using
scipy.stats.norm()
. - demos/demo9.pv: Shifted Hermite polynomials using a non-standard
scipy.stats.norm()
. - demos/demo10.py: Orthogonal polynomials with respect to a truncated normal.
- demos/demo11.py: 2D orthogonal polynomials using the
ProductBasis
class and a collection ofscipy.stats
random variables.