Kolmogorov-Arnold Networks using Learnable Wavelets (Morlet)
Project description
Torch Wavelet KAN
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.
- Fork the repo
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c51381601b94a4386ed623bed82213ff10140803c83212eac4b0164379bb5fa7
|
|
| MD5 |
adef9160b26a08f6c0651857a6510859
|
|
| BLAKE2b-256 |
bf263e0c4420296d52d548801bb8049383eeba804342c459875c908825bc273d
|
File details
Details for the file torch_wavelet_kan-0.0.2-py3-none-any.whl.
File metadata
- Download URL: torch_wavelet_kan-0.0.2-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5d8964872067f874417f9e18e89ba16fedb41a41758854d71e036151999d42e7
|
|
| MD5 |
0cd03a3214f8fd5f368e3b94ca69e6e1
|
|
| BLAKE2b-256 |
0c1186254eabe12d9b1500cf6ceb255bbad3e98d6c1e5bccaff0d6f447586179
|