TensorFlow, PyTorch and Numpy layers for generating Orthogonal Polynomials

Overview

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:

Class Polynomial
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):

  • Inputs:
    • x a tensor
    • degree highest degree for target polynomials
    • combination optional, tensor product combinations
  • Attributes:
    • Poly.tensor the tensor of function values (with degree from 0 to Poly.degree(included))
    • Poly.length the number of function basis (columns) in Poly.tensor
    • Poly.index the index of the first combination of each degree in Poly.combinations
    • Poly.combinations all combinations of tensor product
    • Poly.tensor_of_degree(degree) return all polynomials of given degrees
    • Poly.eval(coefficients) return the function values with given coefficients
    • Poly.quadrature(function, weight) return Gauss quadrature with given function and weight
You might also like...
A repository that shares tuning results of trained models generated by TensorFlow / Keras. Post-training quantization (Weight Quantization, Integer Quantization, Full Integer Quantization, Float16 Quantization), Quantization-aware training. TensorFlow Lite. OpenVINO. CoreML. TensorFlow.js. TF-TRT. MediaPipe. ONNX. [.tflite,.h5,.pb,saved_model,tfjs,tftrt,mlmodel,.xml/.bin, .onnx]  An Ensemble of CNN (Python 3.5.1 Tensorflow 1.3 numpy 1.13)
An Ensemble of CNN (Python 3.5.1 Tensorflow 1.3 numpy 1.13)

An Ensemble of CNN (Python 3.5.1 Tensorflow 1.3 numpy 1.13)

Unofficial PyTorch implementation of Attention Free Transformer (AFT) layers by Apple Inc.
Unofficial PyTorch implementation of Attention Free Transformer (AFT) layers by Apple Inc.

aft-pytorch Unofficial PyTorch implementation of Attention Free Transformer's layers by Zhai, et al. [abs, pdf] from Apple Inc. Installation You can i

A library to inspect itermediate layers of PyTorch models.
A library to inspect itermediate layers of PyTorch models.

A library to inspect itermediate layers of PyTorch models. Why? It's often the case that we want to inspect intermediate layers of a model without mod

a reccurrent neural netowrk that when trained on a peice of text and fed a starting prompt will write its on 250 character text using LSTM layers

RNN-Playwrite a reccurrent neural netowrk that when trained on a peice of text and fed a starting prompt will write its on 250 character text using LS

Meta Language-Specific Layers in Multilingual Language Models

Meta Language-Specific Layers in Multilingual Language Models This repo contains the source codes for our paper On Negative Interference in Multilingu

 Improving Deep Network Debuggability via Sparse Decision Layers
Improving Deep Network Debuggability via Sparse Decision Layers

Improving Deep Network Debuggability via Sparse Decision Layers This repository contains the code for our paper: Leveraging Sparse Linear Layers for D

Spectral Tensor Train Parameterization of Deep Learning Layers
Spectral Tensor Train Parameterization of Deep Learning Layers

Spectral Tensor Train Parameterization of Deep Learning Layers This repository is the official implementation of our AISTATS 2021 paper titled "Spectr

RepMLP: Re-parameterizing Convolutions into Fully-connected Layers for Image Recognition

RepMLP: Re-parameterizing Convolutions into Fully-connected Layers for Image Recognition (PyTorch) Paper: https://arxiv.org/abs/2105.01883 Citation: @

Comments
  • Cuda support

    Cuda support

    Hi,

    First of all thank your for developing this project. Is it possible to create the Jacobi.tensor in the gpu? Currently I am creating the tensor in the cpu and then moving them to gpu, which is time consuming.

    Cheers

    opened by mariolinovIC 1
  • Jacobi polynomial incorrect evaluation

    Jacobi polynomial incorrect evaluation

    Hi, I have noticed than when I evaluate Jacobi polynomial with alpha=1 and beta=1 the results are not ok. Particularly I tried in range (-1,1) and I noticed the problem for n greater than 1 (i.e., 2,3,4). Thank you for your support.

    opened by mariolinovIC 0
Owner
Chuan
+1s.
Chuan
Compare outputs between layers written in Tensorflow and layers written in Pytorch

Compare outputs of Wasserstein GANs between TensorFlow vs Pytorch This is our testing module for the implementation of improved WGAN in Pytorch Prereq

Hung Nguyen 72 Dec 20, 2022
Deploy tensorflow graphs for fast evaluation and export to tensorflow-less environments running numpy.

Deploy tensorflow graphs for fast evaluation and export to tensorflow-less environments running numpy. Now with tensorflow 1.0 support. Evaluation usa

Marcel R. 349 Aug 6, 2022
Paddle implementation for "Highly Efficient Knowledge Graph Embedding Learning with Closed-Form Orthogonal Procrustes Analysis" (NAACL 2021)

ProcrustEs-KGE Paddle implementation for Highly Efficient Knowledge Graph Embedding Learning with Orthogonal Procrustes Analysis ?? A more detailed re

Lincedo Lab 4 Jun 9, 2021
Orthogonal Over-Parameterized Training

The inductive bias of a neural network is largely determined by the architecture and the training algorithm. To achieve good generalization, how to effectively train a neural network is of great importance. We propose a novel orthogonal over-parameterized training (OPT) framework that can provably minimize the hyperspherical energy which characterizes the diversity of neurons on a hypersphere. See our previous work -- MHE for an in-depth introduction.

Weiyang Liu 11 Apr 18, 2022
Orthogonal Jacobian Regularization for Unsupervised Disentanglement in Image Generation (ICCV 2021)

Orthogonal Jacobian Regularization for Unsupervised Disentanglement in Image Generation Home | PyTorch BigGAN Discovery | TensorFlow ProGAN Regulariza

Yuxiang Wei 54 Dec 30, 2022
Composable transformations of Python+NumPy programsComposable transformations of Python+NumPy programs

Chex Chex is a library of utilities for helping to write reliable JAX code. This includes utils to help: Instrument your code (e.g. assertions) Debug

DeepMind 506 Jan 8, 2023
MLP-Numpy - A simple modular implementation of Multi Layer Perceptron in pure Numpy.

MLP-Numpy A simple modular implementation of Multi Layer Perceptron in pure Numpy. I used the Iris dataset from scikit-learn library for the experimen

Soroush Omranpour 1 Jan 1, 2022
⚡️Optimizing einsum functions in NumPy, Tensorflow, Dask, and more with contraction order optimization.

Optimized Einsum Optimized Einsum: A tensor contraction order optimizer Optimized einsum can significantly reduce the overall execution time of einsum

Daniel Smith 653 Dec 30, 2022
Simple helper library to convert a collection of numpy data to tfrecord, and build a tensorflow dataset from the tfrecord.

numpy2tfrecord Simple helper library to convert a collection of numpy data to tfrecord, and build a tensorflow dataset from the tfrecord. Installation

Ryo Yonetani 2 Jan 16, 2022
Bayesian-Torch is a library of neural network layers and utilities extending the core of PyTorch to enable the user to perform stochastic variational inference in Bayesian deep neural networks

Bayesian-Torch is a library of neural network layers and utilities extending the core of PyTorch to enable the user to perform stochastic variational inference in Bayesian deep neural networks. Bayesian-Torch is designed to be flexible and seamless in extending a deterministic deep neural network architecture to corresponding Bayesian form by simply replacing the deterministic layers with Bayesian layers.

Intel Labs 210 Jan 4, 2023