Skip to main content

Python library designed to integrate Kolmogorov Arnold Networks with recurrent mechanisms.

Project description

TimeKAN

TimeKAN is a Python library that enhances time series modeling by integrating Kolmogorov-Arnold Networks (KAN) with recurrent neural network architectures like LSTM and GRU. It’s designed to improve prediction accuracy on complex datasets, such as chaotic time series.

Installation

Install TimeKAN via pip:

pip install timekan

Alternatively, clone the repository and install locally:

git clone https://github.com/SamerMakni/timekan.git
cd timekan
pip install .

Requirements: Python >= 3.9, PyTorch >= 2.4.0

Here’s a simple example training a TKANLSTMRegressor on Mackey-Glass data:

import torch
import torch.nn as nn
from timekan.models.tkan_lstm import tKANLSTM
from timekan.utils.datasets import mackey_glass

class TKANLSTMRegressor(nn.Module):
    def __init__(self, input_dim, hidden_dim):
        super().__init__()
        self.tkan = tKANLSTM(
            input_dim=input_dim,
            hidden_dim=hidden_dim,
            return_sequences=False,
            bidirectional=True,
            kan_type='fourier',
            sub_kan_configs={'gridsize': 50, 'addbias': True}
        )
        self.regressor = nn.Linear(hidden_dim * 2, 1)

    def forward(self, x):
        features = self.tkan(x)
        return self.regressor(features).squeeze(-1)

x_train, y_train, x_test, y_test = mackey_glass()

model = TKANLSTMRegressor(input_dim=1, hidden_dim=16)
criterion = nn.MSELoss()
optimizer = torch.optim.Adam(model.parameters(), lr=0.001)

for epoch in range(10):
    model.train()
    optimizer.zero_grad()
    outputs = model(x_train)
    loss = criterion(outputs, y_train)
    loss.backward()
    optimizer.step()
    print(f"Epoch {epoch + 1}/10, Training MSE: {loss.item():.4f}")

model.eval()
with torch.no_grad():
    test_outputs = model(x_test)
    test_mse = criterion(test_outputs, y_test).item()
    print(f"Test MSE: {test_mse:.4f}")

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

timekan-0.1.1.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

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

timekan-0.1.1-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

File details

Details for the file timekan-0.1.1.tar.gz.

File metadata

  • Download URL: timekan-0.1.1.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.10

File hashes

Hashes for timekan-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7028e09d1abcbff3ca75c6ef715699d64c2fa861868f5c14ec6e6409df078d9c
MD5 caa4d4bb798eb2950dbe05e3a14fee92
BLAKE2b-256 b1e4fbc8fe76ef1121ddce3b8402a5b7851bde75ac2448ac829d27d6dde9df03

See more details on using hashes here.

File details

Details for the file timekan-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: timekan-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 14.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.10

File hashes

Hashes for timekan-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b2727bc50fa1712eefcccd9c0793919232c30d50b04030bbbcbc09e5fb2c7c8e
MD5 a83c5f9594ed531e3626cdcbd2336f68
BLAKE2b-256 a00e3108c8150b7f9e57157f876f70f956d9ed6e9d199d6788ba0dd9cb1addbd

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