Skip to main content

Tensorflow-kernels

Logo

A package with Tensorflow (both CPU and GPU) implementation of most popular Kernels for kernels methods (SVM, MKL...).

Those kernels works with tensor as inputs.

The main idea of this project is to exploit the powerfull of GPUs and modern CPUs on matrix and kernels elaborations. Actually the implemented kernels are:

  • Linear
  • RBF
  • Polynomial
  • CosineSimilarity
  • Fourier
  • Spline

Attention: Due to the GPUs usage the precision of decimal numbers may be different, and hence, the results may be slightly differs as well

Attention 2: Due to exploit the power of GPUs it's strongly recommended to work with float32 or even in half precision float16.

Examples:

A simple example with PolynomialKernel

import numpy as np
import tensorflow as tf
from kernels.polynomial_kernel import PolynomialKernel
from kernels import array_to_tensor, tensor_to_array

n = 2000
p = 1000
a = np.random.random((n, p)).astype(np.float32)
b = np.random.random((n, p)).astype(np.float32)

x = array_to_tensor(a, dtype=tf.float32)
y = array_to_tensor(b, dtype=tf.float32)


poly = PolynomialKernel(scale=1, bias=0, degree=4)
kernel = poly.compute(x, y)

print(tensor_to_array(kernel, dtype=np.float32))

A simple example with PSpectrumKernel. Attention: PSpectrum is still experimental and it exploits eager computation in order to work properly. Furthermore it maybe won't works with Tensorflow 2.0 since some packages have been removed.

Attention 2: Due to the usage of the type tf.string computation will be shared between GPUs and CPUs.

Attention 3: This kernel return tensor with type tf.int64.

import numpy as np
import tensorflow as tf
from kernels.experimental.p_spectrum_kernel import PSpectrumKernel
from kernels import array_to_tensor, tensor_to_array

a = np.array(['aaaaaaaa','bbbbbbb','ccccc','aaaaaaa','cccccc','bbbbbb'])
b = np.array(['aaaaaaaa','bbbbbbb','aaaaaaa','cccccc'])

x = array_to_tensor(a, dtype=tf.string)
y = array_to_tensor(b, dtype=tf.string)

p_spectrum = PSpectrumKernel(p=3)

kernel = p_spectrum.compute(x, y)

print(tensor_to_array(kernel, dtype=np.float32))

Credits:

The idea was born by using methods available here: https://github.com/gmum/pykernels

Release files for tensorflow-kernels 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for tensorflow-kernels 0.1.2
File Interpreter ABI Platform
tensorflow_kernels-0.1.2-py2-none-any.whl Python 2 none any Details

Release files / tensorflow_kernels-0.1.2-py2-none-any.whl

Download URL tensorflow_kernels-0.1.2-py2-none-any.whl
Size 14.2 kB
Tags Python 2
SHA-256 checksum
How to use checksums
c176e63d55742426304d7251b37d39db32752e72caf460afe67f3f8d5186828d
BLAKE2b-256 checksum
How to use checksums
86f240785f4f02373a3833984f5478dd375a3dae1e1dfceb442d824908d7b977
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.20.1 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/2.7.15rc1

Release history Release notifications | RSS feed

This release

0.1.2 This release

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page