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 generate_mackey_glass_data

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 = generate_mackey_glass_data()

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.0.tar.gz (12.0 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.0-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: timekan-0.1.0.tar.gz
  • Upload date:
  • Size: 12.0 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.0.tar.gz
Algorithm Hash digest
SHA256 180fb7cb4d449975471f08b8bb8e5fdefe6089ddbcccbbcb504af186ccb54b8e
MD5 014d2891f2a4d91b8486351f8d86a3cd
BLAKE2b-256 a6d9026739b24a13060e3b3ce111dbceb1dd4900b053f048bf5f8e0f07274e7c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: timekan-0.1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a5a494f512cd840d8e8878351d3b1e8097d65bb02577f6cbba24a2d652128bd9
MD5 e5bd07e61a608bee933069f4f107f4ba
BLAKE2b-256 a545fa1ea59100a1d04f7e5441527f9616696a2beab87d0bf9008fc586209447

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