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 single-kan

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.2.0.tar.gz (5.5 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.2.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: single_kan-0.2.0.tar.gz
  • Upload date:
  • Size: 5.5 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.2.0.tar.gz
Algorithm Hash digest
SHA256 8cd75f8dbf3cac8e791230b18a9d1382ecab20e6ef3a4723aaa8374bbd031c18
MD5 f8d635d7253c272ae9757d90b500ec55
BLAKE2b-256 3ac59a086d70124f04e680cd47922a931380cb026fc9a9b9b33f2d1fe0362026

See more details on using hashes here.

File details

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

File metadata

  • Download URL: single_kan-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.1 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1d80eb38d12a3058b7425d29c3282b9839eadb138d7693f7c5dfbff7e5450c0f
MD5 c7efa6cba5e07c2ab76a5651c0d6e6fb
BLAKE2b-256 387cb07fd405506d15ff8d72a3b364d00d76c5ff53e135aed0de76095f948389

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