TensorFlow, PyTorch and Numpy layers for generating multi-dimensional Orthogonal Polynomials
1. Installation
2. Usage
3. Polynomials
4. Base Class(Poly)
the stable version:
pip3 install orthnetthe dev version:
git clone https://github.com/orcuslc/orthnet.git && cd orthnet
python3 setup.py build_ext --inplace && python3 setup.py install
importtensorflowastfimportnumpyasnpfromorthnetimportLegendrex_data=np.random.random((10, 2))
x=tf.placeholder(dtype=tf.float32, shape= [None, 2])
L=Legendre(x, 5)
withtf.Session() assess:
print(L.tensor, feed_dict= {x: x_data})importtorchimportnumpyasnpfromorthnetimportLegendrex=torch.DoubleTensor(np.random.random((10, 2)))
L=Legendre(x, 5)
print(L.tensor)importnumpyasnpfromorthnetimportLegendrex=np.random.random((10, 2))
L=Legendre(x, 5)
print(L.tensor)In some scenarios, users can specify the exact backend compatible with the input x. The backends provided are:
An example to specify the backend is as follows.
importnumpyasnpfromorthnetimportLegendre, NumpyBackendx=np.random.random((10, 2))
L=Legendre(x, 5, backend=NumpyBackend())
print(L.tensor)In some scenarios, users may provide pre-computed tensor product combinations to save computing time. An example of providing combinations is as follows.
importnumpyasnpfromorthnetimportLegendre, enum_dimdim=2degree=5x=np.random.random((10, dim))
L=Legendre(x, degree, combinations=enum_dim(degree, dim))
print(L.tensor)Class Poly(x, degree, combination = None):
- Inputs:
xa tensordegreehighest degree for target polynomialscombinationoptional, tensor product combinations
- Attributes:
Poly.tensorthe tensor of function values (with degree from 0 toPoly.degree(included))Poly.lengththe number of function basis (columns) inPoly.tensorPoly.indexthe index of the first combination of each degree inPoly.combinationsPoly.combinationsall combinations of tensor productPoly.tensor_of_degree(degree)return all polynomials of given degreesPoly.eval(coefficients)return the function values with given coefficientsPoly.quadrature(function, weight)return Gauss quadrature with given function and weight