资源算法OrthNet

OrthNet

2019-09-19 | |  213 |   0 |   0

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 tfimport numpy as npfrom orthnet import Legendrex_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 torchimport numpy as npfrom orthnet import Legendrex = torch.DoubleTensor(np.random.random((10, 2)))L = Legendre(x, 5)print(L.tensor)

with Numpy

import numpy as npfrom orthnet import Legendrex = 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: - orthnet.TensorflowBackend() - orthnet.TorchBackend() - orthnet.NumpyBackend()

An example to specify the backend is as follows.

import numpy as npfrom orthnet import Legendre, NumpyBackendx = 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 npfrom orthnet import Legendre, enum_dimdim = 2degree = 5x = 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


上一篇:OpenPose

下一篇:Deeplab v2

用户评价
全部评价

热门资源

  • TensorFlow-Course

    This repository aims to provide simple and read...

  • seetafaceJNI

    项目介绍 基于中科院seetaface2进行封装的JAVA...

  • mxnet_VanillaCNN

    This is a mxnet implementation of the Vanilla C...

  • DuReader_QANet_BiDAF

    Machine Reading Comprehension on DuReader Usin...

  • Klukshu-Sockeye-...

    KLUKSHU SOCKEYE PROJECTS 2016 This repositor...