Micro Kolmogorov–Arnold Network (MicroKAN)
This repository contains a minimal Python implementation of the Kolmogorov–Arnold Network (KAN) architecture, adapted for edge devices such as the Raspberry Pi. It eliminates non-essential dependencies of the original KAN implementations and targets constrained systems.
Features
- Streamlined implementation requiring only PyTorch, NumPy, PyYAML, and tqdm.
- Verified on Raspberry Pi 3 Model B with Python 3.10.
- Removes heavy dependencies such as scikit-learn, pandas, matplotlib, and sympy.
Test Setup
- Raspberry Pi 3 Model B (ARMv7)
- Bullseye OS
- Python 3.10
- PyTorch 1.13
- NumPy 1.23
Installation
System packages
sudo apt-get update
sudo apt-get install --no-install-recommends \
python3 python3-pip libblas3 libgomp1 libopenblas0 python3-typing-extensions libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libgdbm-dev lzma lzma-dev tcl-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev wget curl make build-essential openssl
Python setup
See full tutorial at samwestby
curl https://pyenv.run | bash
# ...
pyenv install 3.10.12
pyenv shell 3.10.12
Python packages
python3.10 -m pip install \
https://github.com/maxisoft/pytorch-arm/releases/download/v1.0.0/numpy-1.23.5-cp310-cp310-linux_armv7l.whl \
https://github.com/maxisoft/pytorch-arm/releases/download/v1.0.0/torch-1.13.0a0+git7c98e70-cp310-cp310-linux_armv7l.whl \
https://github.com/maxisoft/pytorch-arm/releases/download/v1.0.0/PyYAML-6.0-cp310-cp310-linux_armv7l.whl
python3.10 -m pip install tqdm
MicroKAN
python3.10 -m pip install microkan
Example Usage
The API is nearly identical to the original pykan, except that auxiliary arguments related to file saving and verbose outputs have been removed. Refer to the original KAN documentation for detailed parameter options. Here is a working example of microkan:
from microkan import *
import os
set_seed(0)
model = KAN(width=[2, 1, 1], grid=3, k=3, seed=1).speed(compile=False)
f = lambda x: torch.exp(torch.sin(torch.pi * x[:, [0]]) + x[:, [1]] ** 2)
dataset = create_dataset(f, n_var=2, train_num=10, test_num=5)
model.fit(dataset, opt="LBFGS", steps=10)
print(model(dataset["test_input"]))
os.makedirs("microkan", exist_ok=True)
model.saveckpt("microkan/example_model")
# Loading example
loaded = KAN.loadckpt("microkan/example_model")
print(loaded(dataset["test_input"]))
Performance Timing
The table below reports mean inference times (± standard deviation) on a Raspberry Pi 3 Model B and an Intel Core i5-1235U, illustrating typical speed differences across varying KAN architectures.
| Architecture | Grid | k | RPI3 Time (ms) | PC Time (ms) |
|---|---|---|---|---|
| [6, 80, 3] | 9 | 1 | 19.5 ± 2.6 | 1.4 ± 0.4 |
| [6, 40, 55, 75, 3] | 5 | 2 | 98.6 ± 14.9 | 3.6 ± 1.0 |
| [6, 55, 65, 3] | 5 | 4 | 110.1 ± 13.2 | 3.6 ± 1.1 |
| [6, 45, 3] | 3 | 2 | 31.4 ± 4.4 | 1.2 ± 0.7 |
| [6, 80, 75, 3] | 3 | 4 | 116.1 ± 12.7 | 3.7 ± 1.0 |
| [6, 100, 65, 90, 3] | 3 | 2 | 113.6 ± 13.3 | 3.9 ± 1.1 |
Other Platforms
This implementation may also operate on platforms beyond ARMv7, provided that compatible PyTorch builds are available for the target architecture. However, these configurations have not been tested, and functionality or performance is not verified outside the specified ARMv7 environment.
Acknowledgments
- Based on PyEnv Python Version Manager.
- Original Kolmogorov–Arnold Network concept implemented in pykan.
- ARM builds of PyTorch and dependencies courtesy of maxisoft/pytorch-arm.
Metadata
Release files for microkan 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| microkan-0.1.0.tar.gz | 32.1 kB | Without provenance | Details for microkan-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| microkan-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for microkan-0.1.0-py3-none-any.whl |
Total release size: 64.5 kB
Release files / microkan-0.1.0.tar.gz
| Download URL | microkan-0.1.0.tar.gz |
|---|---|
| Size | 32.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e846e03e42b1f527c1c121380137b8bc6efa14a34deecdd0d1538422f2d42e68
|
|
BLAKE2b-256 checksum How to use checksums |
b09876fed6a5e260d3987149bca347a37ec9cd78711b2cda422b8222cfafb6a5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.5
|
Release files / microkan-0.1.0-py3-none-any.whl
| Download URL | microkan-0.1.0-py3-none-any.whl |
|---|---|
| Size | 32.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f4fa6a918b9971a360766b75f896cd1ad938d2f024c948051bb6fd9f8302c022
|
|
BLAKE2b-256 checksum How to use checksums |
14901ab4dfbb1a7942fa4c492d43790d1d540603fcc79521661971b6d9860476
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.5
|
Security for microkan 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.