Python: Identifying a State Space Model for a System
Asked Answered
C

5

8

I am looking to obtain a state space model for a system I have, using python.

I have tested the actual system, so I have the inputs to it and I have measured the outputs. so I have sets of corresponding inputs and outputs.

Is there a function somewhere, for python, where I can supply the function with the set of inputs and outputs of the system, and the function will then provide me with a state space model that represents the system?

Cyclopean answered 8/6, 2016 at 6:53 Comment(0)
M
6

I tried this package available on GitHub: SIPPY (Systems Identification Package for PYthon).

It works well and it is quite simple to use. There are many identification algorithms that can be used for state-space models (N4SID, MOESP, CVA, PARSIM methods). I think it's the most complete code available in Python.

Mulish answered 6/4, 2018 at 22:38 Comment(0)
M
2

You want to use the n4sid method, this is the only code I know of in Python: pyN4DIS

Marney answered 28/6, 2017 at 15:21 Comment(0)
M
1

Industrial chemical and refining applications are some of the earliest applications of model predictive control. They often use other forms for identification such as ARX (Auto-Regressive eXogenous inputs), FIR (Finite Impulse Response), or Transfer Function models. There are good commercial tools for identifying models such as MATLAB System Identification Toolbox, DMC+ (AspenTech), and RMPCT (Honeywell). There are some recent developments with Seeq system identification in Python. The SIPPY package is an alternative but installation of dependency Slycot (recently commercialized) can be a challenge with the required Fortran compilers. Here is a simple MIMO identification from another post on Model Predictive Control that uses gekko available with pip install gekko.

System Identification

from gekko import GEKKO
import pandas as pd
import matplotlib.pyplot as plt

# load data and parse into columns
url = 'http://apmonitor.com/do/uploads/Main/tclab_dyn_data2.txt'
data = pd.read_csv(url)
t = data['Time']
u = data[['H1','H2']]
y = data[['T1','T2']]

# generate time-series model
m = GEKKO(remote=False) # remote=True for MacOS

# system identification
na = 2 # output coefficients
nb = 2 # input coefficients
yp,p,K = m.sysid(t,u,y,na,nb,diaglevel=1)

plt.figure()
plt.subplot(2,1,1)
plt.plot(t,u)
plt.legend([r'$u_0$',r'$u_1$'])
plt.ylabel('MVs')
plt.subplot(2,1,2)
plt.plot(t,y)
plt.plot(t,yp)
plt.legend([r'$y_0$',r'$y_1$',r'$z_0$',r'$z_1$'])
plt.ylabel('CVs')
plt.xlabel('Time')
plt.savefig('sysid.png')
plt.show()

There are standard methods to exactly convert an ARX model to state space form. If the intended application is a predictive controller then the ARX model can be used instead of converting to state space form.

Median answered 2/7, 2022 at 12:58 Comment(0)
D
0

try reading this article: state space model and this state space model2 the latter uses other py packages to create a model, you can use this as module input for your purpose. Not sure if there are any packages other than these two sets of scripts

Dorthydortmund answered 8/6, 2016 at 7:5 Comment(0)
S
0

There is also sysid. I haven't tried any of these (yet) and am interested in hearing what else you have found or tried out so far.

Stonebroke answered 23/8, 2017 at 18:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.