Skip to main content

Shannon-wavelet favicon Jax Wavelet Toolbox (jaxwt)

GitHub Actions Documentation Status PyPI Versions PyPI - Project PyPI - License Black code style PyPi - downloads

Differentiable and GPU-enabled fast wavelet transforms in JAX.

Features

  • wavedec and waverec implement 1d analysis and synthesis transforms.

  • Similarly, wavedec2 and waverec2 provide 2d transform support.

  • The cwt-function supports 1d continuous wavelet transforms.

  • The WaveletPacket object supports 1d wavelet packet transforms.

  • WaveletPacket2d implements two-dimensional wavelet packet transforms.

  • swt and iswt allow 1d-stationary transformations.

This toolbox extends PyWavelets. We additionally provide GPU and gradient support via a Jax backend.

Installation

To install Jax, head over to https://github.com/google/jax#installation and follow the procedure described there. Afterward, type pip install jaxwt to install the Jax-Wavelet-Toolbox. You can uninstall it later by typing pip uninstall jaxwt.

Documentation

Complete documentation of all toolbox functions is available at readthedocs.

Transform Examples:

To compute a one-dimensional fast wavelet transform, consider the code snippet below:

import jax.numpy as jnp
import jaxwt as jwt

import pywt
import numpy as np;

# generate an input of even length.
data = jnp.array([0., 1, 2, 3, 4, 5, 6, 7, 7, 6, 5, 4, 3, 2, 1, 0])

# compare the forward fwt coefficients
print(pywt.wavedec(np.array(data), 'haar', mode='zero', level=2))
print(jwt.wavedec(data, 'haar', mode='zero', level=2))

# invert the fwt.
print(jwt.waverec(jwt.wavedec(data, 'haar', mode='zero', level=2),
                  'haar'))

The snipped also evaluates the pywt implementation to demonstrate that the coefficients are the same. Use jaxwt if you require gradient or GPU support.

The process for two-dimensional fast wavelet transforms works similarly:

import jaxwt as jwt
import jax.numpy as jnp
from scipy.datasets import face

image = jnp.transpose(
    face(), [2, 0, 1]).astype(jnp.float32)
transformed = jwt.wavedec2(image, "haar",
                           level=2, mode="reflect")
reconstruction = jwt.waverec2(transformed, "haar")
jnp.max(jnp.abs(image - reconstruction))

jaxwt allows transforming batched data. The example above moves the color channel to the front because wavedec2 transforms the last two axes by default. We can avoid doing so by using the axes argument. Consider the batched example below:

import jaxwt as jwt
import jax.numpy as jnp
from scipy.datasets import face

image = jnp.stack(
    [face(), face(), face()], axis=0
     ).astype(jnp.float32)
transformed = jwt.wavedec2(image, "haar",
                           level=2, mode="reflect",
                           axes=(1,2))
reconstruction = jwt.waverec2(transformed, "haar", axes=(1,2))
jnp.max(jnp.abs(image - reconstruction))

For more code examples, follow the documentation link above or visit the examples folder.

Testing

Unit tests are handled by nox. Clone the repository and run it with the following:

$ pip install nox
$ git clone https://github.com/v0lta/Jax-Wavelet-Toolbox
$ cd Jax-Wavelet-Toolbox
$ nox -s test

Goals

  • In the spirit of Jax, the aim is to be 100% pywt compatible. Whenever possible, interfaces should be the same results identical.

64-Bit floating-point numbers

If you need 64-bit floating point support, set the Jax config flag:

from jax.config import config
config.update("jax_enable_x64", True)

Citation

If you use this work in a scientific context, please cite the following:

@phdthesis{handle:20.500.11811/9245,
  urn: https://nbn-resolving.org/urn:nbn:de:hbz:5-63361,
  author = {{Moritz Wolter}},
  title = {Frequency Domain Methods in Recurrent Neural Networks for Sequential Data Processing},
  school = {Rheinische Friedrich-Wilhelms-Universität Bonn},
  year = 2021,
  month = jul,
  url = {https://hdl.handle.net/20.500.11811/9245}
}

Metadata

Release files for jaxwt 0.1.1

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

Source distribution (sdist)

Source distribution for jaxwt 0.1.1
File Size Uploaded
jaxwt-0.1.1.tar.gz 28.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jaxwt 0.1.1
File Interpreter ABI Platform
jaxwt-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 55.3 kB

Release files / jaxwt-0.1.1.tar.gz

Download URL jaxwt-0.1.1.tar.gz
Size 28.5 kB
Tags Source
SHA-256 checksum
How to use checksums
672c394e979ac517625121bb6196b51cc3d41547668354c081f7d7ed274589dd
BLAKE2b-256 checksum
How to use checksums
8e17c84e28e78bfb3b626977390e915b563d940b7c06a7f15739834071f713a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.12

Release files / jaxwt-0.1.1-py3-none-any.whl

Download URL jaxwt-0.1.1-py3-none-any.whl
Size 26.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
465844856b53d7f2dfaeafdd84b51a64b69ee8d300cd2498748b7c146cc24d5b
BLAKE2b-256 checksum
How to use checksums
2131cb87159d6e1f746b41a0f158cd3fc64e9fbd5237823b256259db9192b6b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.12

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

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