Skip to main content

Kolmogorov-Arnold Networks using Learnable Wavelets (Morlet)

Project description

Torch Wavelet KAN

PyPI version License Python 3.8+

Torch Wavelet KAN is a lightweight, efficient PyTorch implementation of Kolmogorov-Arnold Networks (KAN) using Learnable Morlet Wavelets.

While standard KANs rely on B-Splines (which require fixed grids and are computationally heavy), Torch Wavelet KAN uses continuous wavelet transforms to capture high-frequency components and local features more effectively.

🚀 Features

  • Grid-Free: Unlike Spline-KANs, Wavelets do not require maintaining a grid, making them more adaptable to data distribution shifts.
  • Learnable Parameters: Simultaneously learns the Weights, Scale (Dilation), and Translation (Shift) of every wavelet.
  • PyTorch Native: Fully compatible with nn.Sequential, standard optimizers (Adam/SGD), and GPU acceleration.

📦 Installation

pip install torch-wavelet-kan

⚡ Quick Start

Here is how to use WaveletKANLayer as a drop-in replacement for nn.Linear.

import torch
import torch.nn as nn
from torch_wavelet_kan import WaveletKANLayer

# 1. Define the Model
# Input: 2 features -> Hidden: 5 neurons -> Output: 1 value
model = nn.Sequential(
    WaveletKANLayer(in_features=2, out_features=5, num_wavelets=3),
    nn.BatchNorm1d(5), # Optional: Batch Norm often helps KANs
    WaveletKANLayer(in_features=5, out_features=1, num_wavelets=3)
)

# 2. Forward Pass
x = torch.randn(16, 2) # Batch size 16
output = model(x)

print(output.shape) # torch.Size([16, 1])

📖 API Documentation

WaveletKANLayer

WaveletKANLayer(in_features, out_features, num_wavelets=5, epsilon=1e-5)
Parameter Type Default Description
in_features int Required Size of each input sample.
out_features int Required Size of each output sample.
num_wavelets int 5 The number of wavelets to superimpose for each connection. Higher values increase model capacity but cost more memory.
epsilon float 1e-5 Small constant for numerical stability during division.

🧠 The Math

The standard KAN decomposition theorem states that any multivariate continuous function can be represented as a superposition of univariate functions.

In Wavelet KAN, we approximate these univariate functions $\phi$ using a sum of Morlet Wavelets:

$$\phi(x) = \sum_{i=1}^{N} w_i \cdot \psi\left(\frac{x - \mu_i}{s_i}\right)$$

Where:

  • $w_i$: The learnable amplitude (weight).
  • $\mu_i$: The learnable translation (where the wavelet is centered).
  • $s_i$: The learnable scale (how wide/narrow the frequency is).
  • $\psi(t) = e^{-t^2/2} \cos(5t)$: The Morlet wavelet function.

🤝 Contributing

Contributions are welcome! If you find a bug or have an idea for a new wavelet type (e.g., Mexican Hat), please open an issue or submit a Pull Request.

  1. Fork the repo
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

📜 License

Distributed under the MIT License. See LICENSE for more information.

📚 Acknowledgements

This library is inspired by the paper "Wav-KAN: Wavelet Kolmogorov-Arnold Networks" (2024).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

torch_wavelet_kan-0.0.2.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

torch_wavelet_kan-0.0.2-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file torch_wavelet_kan-0.0.2.tar.gz.

File metadata

  • Download URL: torch_wavelet_kan-0.0.2.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for torch_wavelet_kan-0.0.2.tar.gz
Algorithm Hash digest
SHA256 c51381601b94a4386ed623bed82213ff10140803c83212eac4b0164379bb5fa7
MD5 adef9160b26a08f6c0651857a6510859
BLAKE2b-256 bf263e0c4420296d52d548801bb8049383eeba804342c459875c908825bc273d

See more details on using hashes here.

File details

Details for the file torch_wavelet_kan-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for torch_wavelet_kan-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5d8964872067f874417f9e18e89ba16fedb41a41758854d71e036151999d42e7
MD5 0cd03a3214f8fd5f368e3b94ca69e6e1
BLAKE2b-256 0c1186254eabe12d9b1500cf6ceb255bbad3e98d6c1e5bccaff0d6f447586179

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page