Skip to main content

Data-driven learning of dynamical system in the SUBNET structure and ANNs

Project description

deepSI

deepSI provides a lightweight pytorch based framework for data-driven learning of dynamical systems (i.e. system identification). It contains a large forcus on the SUBNET method which is able to robustly model many systems.

⚠️ deepSI has been refractored without backward compatibility (5 December 2024) ⚠️

If you need to install the legacy version you can do this with

pip install git+https://github.com/GerbenBeintema/deepSI@legacy

and using the legacy documentation provided in https://github.com/GerbenBeintema/deepSI/tree/legacy.

Example usage

# Imports
import numpy as np
import deepSI as dsi

# Generate or load data 
np.random.seed(0)
ulist = np.random.randn(10_000) # Input sequence
x = [0, 0] # Initial state
ylist = [] # Output sequence
for uk in ulist:
    ylist.append(x[1]*x[0]*0.1 + x[0] + np.random.randn()*1e-3)  # Compute output
    x = x[0]/(1.2+x[1]**2) + x[1]*0.4, \
        x[1]/(1.2+x[0]**2) + x[0]*0.4 + uk*(1+x[0]**2/10) # Advance state

# Put the input and output sequence in the Input_output_data format
data = dsi.Input_output_data(u=ulist, y=np.array(ylist)) 

# Split dataset
train, val, test  = data[:8000], data[8000:9000], data[9000:]

# Create model
nu, ny, norm = dsi.get_nu_ny_and_auto_norm(data) # Characterize data
model = dsi.SUBNET(nu, ny, norm, nx=2, nb=20, na=20) # Creates encoder, f and h as MLP

# Train model on data using Adam
train_dict = dsi.fit(model, train, val, n_its=10_000, T=20, batch_size=256, val_freq=100)

# Simulate model on the test input sequence (using the encoder to initialize the state)
test_p = model.simulate(test)

# Visualize simulation of the model
from matplotlib import pyplot as plt
plt.figure(figsize=(7,3))
plt.plot(test.y, label='Real Data')
plt.plot(test_p.y, label=f'Model Sim. (NRMS = {((test.y-test_p.y)**2).mean()**0.5/test.y.std():.2%})', linestyle='--')
plt.title('Comparison of Real Data and Model Simulation', fontsize=14, fontweight='bold')
plt.legend(); plt.xlabel('Time Index'); plt.ylabel('y'); plt.grid(); plt.tight_layout(pad=0.5)
plt.show()

dsi SUBNET result on example

Installation

conda install -c anaconda git
pip install git+https://github.com/GerbenBeintema/deepSI@main

Features

  • A number of popular SUBNET model structures
    • SUBNET encoder structue (deepSI.models.SUBNET). Featuring in: [1], [2], [3], [4], [5]
    • Continuous time SUBNET encoder structure (deepSI.models.SUBNET_CT). Featuring in: [1], [2], [3]
    • Base class for fully custom SUBNET structures with shared parameters between f, h or encoder. (deepSI.models.Custom_SUBNET) as used in:
    • CNN SUBNET (CNN_SUBNET). Featuring in: [1] Chapter 4, [2]
    • LPV SUBNET (SUBNET_LPV and SUBNET_LPV_ext_scheduled). Featuring in: [1]
    • port HNN SUBNET (pHNN_SUBNET). Featuring in: [1]
    • Koopman SUBNET (Koopman_SUBNET). Featuring in: [1]
  • Connection to nonlinear_benchmarks to easily load and evaluate on benchmarks.
  • Low amount of code such that it can be easily forked and edited to add missing features.

Futher documentation

Check out examples/1. Overview deepSI.ipynb.

Contributing

deepSI is in ongoing development and anyone can contribute to any part of module.

todo list and known issues

  • Expand demonstration notebook with pHNN examples
  • Issue where discrete time is printed in Input_output_data with torch.Tensors, and np.arrays sample time.
  • General documentation
  • known issue: CT SUBNET and DT SUBNET does not produce the correct initial when the sampling time is altered. (the encoder assumes that the sampling time does not change)
  • pypi data upload such that it can be easily installed with pip install deepSI
  • Improve speed with copy if enough memory is available. Also pre-transfer to GPU and maybe asyncroness getting of arrays.
  • Known issue: Using the compile function in fit will sometimes result in a memory leak

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

deepsi-0.4.1.tar.gz (19.6 kB view details)

Uploaded Source

Built Distribution

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

deepsi-0.4.1-py3-none-any.whl (21.3 kB view details)

Uploaded Python 3

File details

Details for the file deepsi-0.4.1.tar.gz.

File metadata

  • Download URL: deepsi-0.4.1.tar.gz
  • Upload date:
  • Size: 19.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.10

File hashes

Hashes for deepsi-0.4.1.tar.gz
Algorithm Hash digest
SHA256 036bf716b0c4f217b6122ed7e8caeadb0f1eb41f1669d48f0849a14054fe89cb
MD5 1dfc0065c74075e98b121a585345be6f
BLAKE2b-256 67d31b76352d32f42b9c4063354e6fc7d7511c1515047314b22a7ec9b8285992

See more details on using hashes here.

File details

Details for the file deepsi-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: deepsi-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 21.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.10

File hashes

Hashes for deepsi-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ef02a554548cab50bed5a10e1758eccc05a65082a682be11ff38e5d4b5907cdd
MD5 9cb3930114371d3753e40dda73571db4
BLAKE2b-256 af2db73048ce8d23e789c0fce99824a2b2ca6ee869c7235ccd0396bc4a0f5d08

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