Skip to main content

Python libaray for SKAN (Single-parameterized KAN)

Project description

SKAN: Single-Parameterized KAN Network

English / 简体中文

Introduction

SKAN is an innovative KAN (Kolmogorov-Arnold Network) network, characterized by its core feature where each basis function depends on only one learnable parameter, as proposed in this paper [1]. This design enables SKAN to scale up to larger networks while maintaining the same number of parameters, thereby more effectively capturing complex interactions between parameters. This repository provides a complete code implementation of SKAN, including the construction of basic SKAN networks, SKAN networks with custom basis functions, and a series of learnable functions mentioned in paper [1]. The SKAN library is built on the PyTorch framework, with defined networks inheriting from PyTorch's nn.Module, ensuring full compatibility with the PyTorch ecosystem (including CUDA support).

The SKAN network also serves as an ideal example of the EKE Principle (Efficient KAN Extension Principle). The EKE Principle emphasizes that in KAN networks, network performance can be more effectively enhanced by increasing parameters rather than complicating basis functions.

Usage Guide

Installing SKAN

SKAN can be easily installed via PyPI using the following command:

pip install skan

Building Basic Networks

Below is a basic example of using the SKAN network, demonstrating how to construct a SKAN network for MNIST handwritten digit classification:

import torch
from skan import SKANNetwork

# Select device, prioritizing GPU if available
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
# Construct SKAN network with 784 input nodes, 100 hidden nodes, and 10 output nodes
net = SKANNetwork([784, 100, 10]).to(device)

If basis_function is not specified, the lshifted_softplus function is used by default, which performed best in the tests of paper [1]. If the device supports GPU and the relevant drivers are installed, the network in the above code will perform computations on the GPU.

Using Preset Basis Functions

The SKAN library provides multiple preset single-parameter learnable functions, which are mentioned in the paper. Here's an example of how to use a preset single-parameter learnable function:

import torch
from skan import SKANNetwork
from skan.basis import lrelu

device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
# Construct SKAN network using lrelu as the basis function
net = SKANNetwork([784, 100, 10], basis_function=lrelu).to(device)

Customizing SKAN Networks

The SKAN library supports user-defined basis functions. Here's an example of a custom basis function:

import torch
import numpy as np

# Define custom basis function
def lshifted_softplus(x, k):
    return torch.log(1 + torch.exp(k*x)) - np.log(2)

device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
# Construct SKAN network using the custom basis function
net = SKANNetwork([784, 100, 10], basis_function=lshifted_softplus).to(device)

Custom basis functions should accept two parameters: the input value x and a unique learnable parameter k (keep this order of parameters). It is important to ensure that the basis function supports NumPy broadcasting operations and only uses libraries built on NumPy (such as PyTorch).

Reference

[1] LSS-SKAN: Efficient Kolmogorov–Arnold Networks based on Single-Parameterized Function(submited to arxiv)

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

single_kan-0.1.0.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

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

single_kan-0.1.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file single_kan-0.1.0.tar.gz.

File metadata

  • Download URL: single_kan-0.1.0.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for single_kan-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0199a9c810d5196b00a81dbbd14de9d2cbce419329d8f7c6a94850e97e4f625a
MD5 2b68140fc755da6f33462147ddd37af9
BLAKE2b-256 56e792f9fdb96f8838420df9c33e964df05f5bf57a4b22b9fd87127b5bbc7290

See more details on using hashes here.

File details

Details for the file single_kan-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: single_kan-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for single_kan-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a6a7f0fc0e8c4b5389a17cd1eb7ad441fc47bfd473b616e87f09a955d069af77
MD5 edcf3beb3c5a447c0e20a677afbde4a3
BLAKE2b-256 48955293f1239256b025a3a644ae9abc5e03cfb1fe6ca3ae387c29d0d4398ba5

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