Home

Awesome

OrthNet

TensorFlow, PyTorch and Numpy layers for generating multi-dimensional Orthogonal Polynomials

1. Installation
2. Usage
3. Polynomials
4. Base Class(Poly)

Installation:

  1. the stable version:
    pip3 install orthnet

  2. the dev version:

git clone https://github.com/orcuslc/orthnet.git && cd orthnet
python3 setup.py build_ext --inplace && python3 setup.py install

Usage:

with TensorFlow

import tensorflow as tf
import numpy as np
from orthnet import Legendre

x_data = np.random.random((10, 2))
x = tf.placeholder(dtype = tf.float32, shape = [None, 2])
L = Legendre(x, 5)

with tf.Session() as sess:
    print(L.tensor, feed_dict = {x: x_data})

with PyTorch

import torch
import numpy as np
from orthnet import Legendre

x = torch.DoubleTensor(np.random.random((10, 2)))
L = Legendre(x, 5)
print(L.tensor)

with Numpy

import numpy as np
from orthnet import Legendre

x = np.random.random((10, 2))
L = Legendre(x, 5)
print(L.tensor)

Specify Backend

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.

import numpy as np
from orthnet import Legendre, NumpyBackend

x = np.random.random((10, 2))
L = Legendre(x, 5, backend = NumpyBackend())
print(L.tensor)

Specify tensor product combinations

In some scenarios, users may provide pre-computed tensor product combinations to save computing time. An example of providing combinations is as follows.

import numpy as np
from orthnet import Legendre, enum_dim

dim = 2
degree = 5
x = np.random.random((10, dim))
L = Legendre(x, degree, combinations = enum_dim(degree, dim))
print(L.tensor)

Polynomials:

ClassPolynomial
orthnet.Legendre(Poly)Legendre polynomial
orthnet.Legendre_Normalized(Poly)Normalized Legendre polynomial
orthnet.Laguerre(Poly)Laguerre polynomial
orthnet.Hermite(Poly)Hermite polynomial of the first kind (in probability theory)
orthnet.Hermite2(Poly)Hermite polynomial of the second kind (in physics)
orthnet.Chebyshev(Poly)Chebyshev polynomial of the first kind
orthnet.Chebyshev2(Poly)Chebyshev polynomial of the second kind
orthnet.Jacobi(Poly, alpha, beta)Jacobi polynomial

Base class:

Class Poly(x, degree, combination = None):