Skip to main content

Kolmogorov-Arnold Networks using Learnable Wavelets (Morlet)

Project description

# Torch Wavelet KAN

[![PyPI version](https://img.shields.io/pypi/v/torch-wavelet-kan.svg)](https://pypi.org/project/torch-wavelet-kan/)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
[![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)

**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

```bash
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.1.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.1-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: torch_wavelet_kan-0.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 2c5803ea0f59b0f39488e359e0e547271db0e9d8f7e8bfe1daa2884fc089001d
MD5 dda5a78ad251d738321b0d5add3cc09e
BLAKE2b-256 821f269fe1f4b7f751ea28b39f930478a82c2688f5359bbf02c316f928baeac0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for torch_wavelet_kan-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b97b717d0900670d949472498f05b56034367964e1e057ca83ffafe2e5f10a4b
MD5 b5c65051f420c7b17ebe19767779dd03
BLAKE2b-256 5763b3878ae66530dc9e52316c85f72568aef8bc9704140b2860659f646b20e2

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