Hybrid Kolmogorov-Arnold Multi-Layer Perceptrons for PyTorch
Project description
📖 Overview
kan-mlp-hybrid is a PyTorch library that bridges the gap between the compositional efficiency of Multi-Layer Perceptrons (MLPs) and the univariate approximation power of Kolmogorov-Arnold Networks (KANs).
While standard MLPs use fixed activation functions (like ReLU or SiLU) and learnable linear weights, and pure KANs use learnable spline-based activations on edges with no linear weights, Hybrid KAN-MLPs combine both. This allows the network to learn arbitrary univariate activation functions per neuron while maintaining the efficient high-dimensional feature routing of dense linear layers.
Key Features
- 🚀 Drop-in PyTorch Modules: Easily replace
nn.Linearornn.Sequentialwith our hybrid layers. - 📈 Superior Parameter Efficiency: Decouples the spline grid size from the quadratic width term, avoiding the $O(N^2LG)$ parameter explosion of pure KANs.
- 🧠 Multiple Architectures: Includes LA-MLP (Learnable Activation), PPH-Net (Parallel Pathway), and MoE-KAN-MLP (Mixture-of-Experts).
- 📊 Benchmarked: Proven to outperform standard MLPs on mixed-characteristic functions, tabular data, and time-series forecasting.
🛠️ Installation
You can install the package directly from PyPI:
pip install kan-mlp-hybrid
Or install from source for the latest updates:
git clone https://github.com/useCallback/kan-mlp-hybrid.git
cd kan-mlp-hybrid
pip install -e .
🚀 Quick Start
Using the Learnable Activation MLP (LA-MLP) is as simple as using a standard PyTorch MLP.
import torch
from kan_mlp_hybrid import LAMLP
# Initialize an LA-MLP model
# in_features: 5, hidden layers: [64, 64], out_features: 1
model = LAMLP(
in_features=5,
hidden_features=[64, 64],
out_features=1,
num_layers=3,
grid_size=5, # Number of B-spline grid intervals
spline_order=3 # Order of the piecewise polynomial
)
# Forward pass
x = torch.randn(32, 5)
y = model(x)
print(y.shape) # Output: torch.Size([32, 1])
Available Architectures
LAMLP: Replaces fixed activation functions in standard MLPs with learnable, spline-based univariate functions. Best overall performance and efficiency.PPHNet: Processes inputs through parallel KAN and MLP pathways, fusing them via a learned gating mechanism.MoEKANMLP: A sparsely gated architecture containing a heterogeneous pool of KAN and MLP experts.PureKAN: A baseline implementation of a pure Kolmogorov-Arnold Network.
📓 Interactive Colab Notebooks
We provide ready-to-run Google Colab notebooks demonstrating how to use kan-mlp-hybrid across various domains:
- Tabular Data (Classification & Regression): Breast Cancer & California Housing datasets using
LAMLPandPPHNet. - Computer Vision: MNIST digit classification using
MoEKANMLP. - Natural Language Processing: AG News text classification using TF-IDF and
PureKAN.
🔬 Scientific Background
This library is based on the theoretical synthesis of the Universal Approximation Theorem (underpinning MLPs) and the Kolmogorov-Arnold representation theorem (underpinning KANs).
By utilizing the LALinear layer, the linear transformations $W$ efficiently handle high-dimensional basis projection, while the learnable activations $\phi$ achieve exponential convergence on the projected 1D manifolds.
For a deep dive into the mathematical formulations, parameter complexity analysis, and architectural brainstorming that led to this package, please refer to the RESEARCH_NOTES.md and PAPER_DRAFT.md files in the GitHub repository.
👨💻 Author
Khalfoun Mohamed El Mehdi
- GitHub: @useCallback
- PyPI: FastFourierTransform
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
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 kan_mlp_hybrid-0.1.1.tar.gz.
File metadata
- Download URL: kan_mlp_hybrid-0.1.1.tar.gz
- Upload date:
- Size: 13.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d72b32f4795ce723e7e9d93a4336862ba63add69a6b7d3fb053008d7a52d705a
|
|
| MD5 |
864ee84f0793125c4215b47bc6641aa3
|
|
| BLAKE2b-256 |
f70f29ce34fc3747a5f95caf8719dec2feacceef19436ce07aeb7456b1de8780
|
File details
Details for the file kan_mlp_hybrid-0.1.1-py3-none-any.whl.
File metadata
- Download URL: kan_mlp_hybrid-0.1.1-py3-none-any.whl
- Upload date:
- Size: 17.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cce3c682e54740630ff6657f191910e03cb01da468b2ba2e8686555b6fcd201c
|
|
| MD5 |
13059c642e548d193926a7a1444db55b
|
|
| BLAKE2b-256 |
fd9a8700d1f28a01093160c091cdf87258bc2c5d71f9b96c5d99b30e62810e19
|