cpclab-unipi / sippy Goto Github PK
View Code? Open in Web Editor NEWSystems Identification Package for PYthon
License: GNU Lesser General Public License v3.0
Systems Identification Package for PYthon
License: GNU Lesser General Public License v3.0
the rescale method of functionset.py errors if stdev == 0.
def rescale(y):
ystd = np.std(y)
if ystd != 0:
y_scaled = old_div(y, ystd)
else:
y_scaled = y
return ystd, y_scaled
fixes it for me. idk if this is desired behavior.
EDIT:
Found a second occurrence of the problem in lines 205ff. Fix:
for j in range(m):
if Ustd[j] != 0:
B[:, j] = old_div(B[:, j], Ustd[j])
D[:, j] = old_div(D[:, j], Ustd[j])
I am solving a Box-Jenkins problem for a MIMO case that has two inputs and one output. What I noticed is that, the transfer functions that I am getting for each of the inputs share the same denominators and this seems to be for the all the cases that I am running.
Is this the cases that denominators (F ) are parametrised with the same parameters in the code?
Hello.
Is there a way to convert a discrete model identified by sippy to continuous one?
Thanks.
While using Mode="IC" I am having error saying "NameError: name 'Nb' is not defined". I would like to request your help on solving this issue. Thank you !
Today I used Sippy and I was very pleased.
It is very lean and it just do what is supposed to do without too many bells & whistles.
THIS is the way I love software! Very good job!
Nevertheless, I would suggest to give the user the possibility of selecting a validation dataset and to compute at least the basic metrics for validating the identified model, namely:
A sketch of the code could be something like the following (at least for the first point I mentioned)
# Residuals
eps = Y_val-y_hat.transpose() # Y_val is the output data used for validation, y_hat is the identified model output and eps is the residual
Y_val_bar = np.mean(Y_val, axis=0)
FIT_perc = np.round((1.0-np.linalg.norm(eps)/np.linalg.norm(Y_val-Y_val_bar))*100, 3)
print(FIT_perc)
Second suggestions is to set an option to get the system matrices in canonical observable form.
This is very handy when the outputs match with the actual sensors.
It would be convenient to be able to install SIPPY using pip
. To do this all that needs to be done is to upload the library to the Python Package Index (PyPI). Because a setup.py
file is already part of the repository this can be done very easily by following the Python Packaging Tutorial and starting at the "Generating Distribution Archives" step.
I'm trying to use this for my thesis, but the MOESP and N4SID algorithms seem not to give the right values. I'm using an input u in the form u = 5 * sin(0.3t) computing the output through scipy.signal.dlsim and my matrices have the form A = [0 1;-a -b] B = [0;1], C= [0, 1], D=0 with a and b between 0 and 2.
The generated matrices by the MOESP and N4SID are very far off, I'm not an experted in this field, do you have any idea why it is not working? They are accurate when I'm using an input of random variables between [-0.5,0.5].
How can forecast with trained model using samples not in training and testing.
Dear CPCLAB-UNIPI team,
I have started using SIPPY as the python version of system identification for my Thesis. I am implementing it on raspberry pi. In the beginning, I implemented a small discrete-time linear system in MATLAB, and also identified (with 99.94% match) with ARX model of the order [1 2 0].
My system (g_sample11) looks as below,
(0.001 z - 0.001)/ ( z - 0.006738)
Now, I am again trying to identify the same system with SIPPY with below function,
Id_ARX = system_identification(Yout1, Usim, 'ARX', IC ='AIC', tsample = ts, na_ord = [1, 1], nb_ord = [2, 2], delays = [0, 0], ARX_mod = 'LLS')
and
Id_ARX = system_identification(Yout1, Usim, 'ARX', tsample = ts, ARX_orders = [na_ord, nb_ord, theta], ARX_mod = 'RLLS')
where, identification parameters are,
na = 1
nb = 2
th = 0
na_ord = [na]
nb_ord = [[nb]]
nc_ord = [nc]
theta = [[th]]
ts = 5e-6
tfin = 0.02
npts = int(old_div(tfin, ts)) + 1
Time = np.linspace(0, tfin, npts)
I am providing the input signal as, [Usim,,] = fset.GBN_seq(npts, 0.08, Range = [-5, 5]), and output signal as,
Yout1, Time, Xsim = cnt.lsim(g_sample11, Usim, Time). Also, I have checked the output from the actual system and the identified system for 4000 points.
Here are the resulting input and output plots, please provide the insight to solve this problem. What am I doing wrong?
Greetings.
I was able to identify a system using ARMAX using the following command
sys_id_roll = system_identification(y_debiased.T, u_debiased[0], method, IC='BIC', na_ord=[2, 5], nb_ord=[1, 5], nc_ord=[0, 2], delays=[0, 0], ARMAX_max_iterations=300, tsample=dt, centering='MeanVal')
with the following result,
Armax model:
- Params:
na: 5 (2, 5)
nb: 5 (1, 5)
nc: 1 (0, 2)
delay: 0 (0, 0)
dt: 0.001
method: BIC
max iterations: 300
- Output:
G:
-0.2609 z^4 - 0.2886 z^3 + 0.6313 z^2 + 2.767 z - 2.718
------------------------------------------------------------
z^5 - 1.002 z^4 - 0.3068 z^3 + 0.325 z^2 + 0.6365 z - 0.6526
dt = 0.001
H:
z^5 + 0.7202 z^4
------------------------------------------------------------
z^5 - 1.002 z^4 - 0.3068 z^3 + 0.325 z^2 + 0.6365 z - 0.6526
dt = 0.001
Variance: 0.00754123994461
Max reached: False
However, when I try to simulate the identified system using the following command,
Y_id, T, Xsim = cnt.lsim(sys_id_roll.G, u_debiased[0], t)
It gives the following error,
Traceback (most recent call last):
File "prep_data.py", line 147, in <module>
Y_id, T, Xsim = cnt.lsim(sys_id_roll.G, u_debiased[0], t)
File "/home/labuser/.local/lib/python2.7/site-packages/control/matlab/timeresp.py", line 273, in lsim
T, yout, xout = forced_response(sys, T, U, X0, transpose = True)
File "/home/labuser/.local/lib/python2.7/site-packages/control/timeresp.py", line 344, in forced_response
raise ValueError("Time steps ``T`` must be multiples of " \
ValueError: Time steps ``T`` must be multiples of sampling time
Any ideas on what the problem could be?
Thanks
Dear SIPPY staff,
I am a beginner of SIPPY to use it for developing MPC framework.
I am studying system identification and SIPPY based on the book published by A. Kumar and Flores-Cerrillo, "Machine learning in python for dynamic process systems".
While I read this book and try some example codes, I wonders how to predict new output of ARX and extract coefficients with difference equation form.
In the manual, it is written that using fset.validation is proper to predict new output; However, its description is ambiguous.
I would appreciate you all if you let me know how to predict the new output or extract coefficients with difference equation format.
Here is my toy problem code:
from sippy import system_identification
from sippy import functionset as fset
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.preprocessing import StandardScaler
from sklearn.metrics import r2_score # model diagnostics
from statsmodels.graphics.tsaplots import plot_acf # model diagnostics
temp = pd.read_csv('simpleProcess.csv')
data = np.array(temp)
u = data[:,0, None]; y = data[:,1, None]
u_scaler = StandardScaler(with_std=False)
y_scaler = StandardScaler(with_std=False)
u_centered = u_scaler.fit_transform(u)
y_centered = y_scaler.fit_transform(y)
Id_ARX = system_identification(y_centered,u_centered, 'ARX', ARX_orders=[3,3,2]) # y(k)-y(k-1)-y(k-2)-y(k-3)=u(k-1)+u(k-2)+u(k-3)
y_centered_pred = np.transpose(Id_ARX.Yid)
y_centered_pred2 = fset.validation(Id_ARX, y_centered, u_centered, np.linspace(1,999,999), 1)
plt.figure()
plt.plot(y_centered, 'o', label='raw data')
plt.plot(y_centered_pred, '--', label='ARX fit')
plt.legend(); plt.xlabel('k'); plt.ylabel('y')
print('Fit accuracy=', r2_score(y_centered,y_centered_pred))
res = y_centered-y_centered_pred
plot_acf(res,lags=50)
plt.xlabel('lag')
ValueError Traceback (most recent call last)
Cell In[112], line 21
19 Id_ARX = system_identification(y_centered,u_centered, 'ARX', ARX_orders=[3,3,2]) # y(k)-y(k-1)-y(k-2)-y(k-3)=u(k-1)+u(k-2)+u(k-3)
20 y_centered_pred = np.transpose(Id_ARX.Yid)
---> 21 y_centered_pred2 = fset.validation(Id_ARX, y_centered, u_centered, np.linspace(1,999,999), 1)
23 plt.figure()
24 plt.plot(y_centered, 'o', label='raw data')
ValueError: A value (0.0) in x_new is below the interpolation range's minimum value (1.0).
Many experiments may only be performed in short operational bursts. To gain a better idea of the system behavior multiple runs can be used to help gain assurance, and provide better model fitting. Does this library support data, if it does how should the data be formatted?
I am working on Anaconda, i have added the SIPPY library in it. But when i run this example I get a message that says
" Kalman filter cannot be calculated
This message is printed when "sys_id=system_identification(y_tot,U,method,SS_fixed_order=2)" command is run.
What is the thing that I am missing?
Regards.
SS_max_order has no effect in any scenario, it will always search in the range from 1 to 10 (default value of SS_orders)
Line 736 in b699ab9
Hi.
I am trying to get a discrete model using N4SID with input/output data from a real system. The sampling time is 0.001. However, whether I set the tsample parameter to that value or not, I get the same identified system. Is this normal, or the resulting matrices (A, B, ...) should be different for different tsample?
Thanks
According to documentation "Using a fixed order value, the maximum order and the threshold value are not taken into account." but is the select_order_SIM, SS_threshold is not passing and the algorithm_1 is always taking default value 0.0.
Line 171 in b699ab9
Hello,
I hava some problems with sippy examples. The function validation gives wrong results.
Packages needed to reproduce :
Step to reproduce : lunch Ex_OPT_GEN-INOUT
Result :
C:...\control\timeresp.py:294: UserWarning: return_x specified for a transfer function system. Internal conversion to state space used; results may meaningless.
"return_x specified for a transfer function system. Internal "
C:...\control\timeresp.py:294: UserWarning: return_x specified for a transfer function system. Internal conversion to state space used; results may meaningless.
"return_x specified for a transfer function system. Internal "
C:...\control\timeresp.py:294: UserWarning: return_x specified for a transfer function system. Internal conversion to state space used; results may meaningless.
"return_x specified for a transfer function system. Internal "
C:/.../Examples/Ex_OPT_GEN-INOUT.py:230: RuntimeWarning: overflow encountered in square
EV = 100.0*(np.round((1.0 - np.mean((Ytotvalid - Yv_bj) ** 2)/np.std(Ytotvalid)), 2))
C:...\control\lti.py:199: UserWarning: call: evaluation above Nyquist frequency
warn("call: evaluation above Nyquist frequency")
C:...\control\lti.py:199: UserWarning: call: evaluation above Nyquist frequency
warn("call: evaluation above Nyquist frequency")
C:...\control\lti.py:199: UserWarning: call: evaluation above Nyquist frequency
warn("call: evaluation above Nyquist frequency")
C:...\control\lti.py:199: UserWarning: call: evaluation above Nyquist frequency
warn("call: evaluation above Nyquist frequency")
C:...\control\lti.py:199: UserWarning: call: evaluation above Nyquist frequency
warn("call: evaluation above Nyquist frequency")
C:...\control\lti.py:199: UserWarning: call: evaluation above Nyquist frequency
warn("call: evaluation above Nyquist frequency")
C:...\control\lti.py:199: UserWarning: call: evaluation above Nyquist frequency
warn("call: evaluation above Nyquist frequency")
C:...\control\lti.py:199: UserWarning: call: evaluation above Nyquist frequency
warn("call: evaluation above Nyquist frequency")
C:...\control\lti.py:199: UserWarning: call: evaluation above Nyquist frequency
warn("call: evaluation above Nyquist frequency")
C:...\control\lti.py:199: UserWarning: call: evaluation above Nyquist frequency
warn("call: evaluation above Nyquist frequency")
C:...\control\lti.py:199: UserWarning: call: evaluation above Nyquist frequency
warn("call: evaluation above Nyquist frequency")
C:...\control\lti.py:199: UserWarning: call: evaluation above Nyquist frequency
warn("call: evaluation above Nyquist frequency")
C:...\control\lti.py:199: UserWarning: call: evaluation above Nyquist frequency
warn("call: evaluation above Nyquist frequency")
C:...\control\lti.py:199: UserWarning: call: evaluation above Nyquist frequency
warn("call: evaluation above Nyquist frequency")
C:...\control\lti.py:199: UserWarning: call: evaluation above Nyquist frequency
warn("call: evaluation above Nyquist frequency")
Does anyone know how to fix it ?
Best regards.
Hi, I wonder how can I do the k-step ahead prediction after I fitted the system. (For example, I have a test data set and I want to use the model to do 1-step and 2-step prediction to see how it performs).
Moreover, what is the difference between the simulation and prediction modes? I am new to this filed and really appreciate your answer!
Hi,
I have been using SIPPY for system identification as part of my thesis. I have MISO system with discrete time series data of sampling time of 20 ms. I am trying to using either ARMAX or N4SID for this purpose. In both results, the initialisation seems way off the original data but N4SID was comparatively better. For N4SID, after I run the code, and generate the system responses using the results, the initial values seem completely off from the original data.
I read in the user manual that "for N4SID’, ’MOESP’ and ’CVA’ methods, x0 is filled with zeros (no estimate of the initial state is made)" but for "fsetSIM.SS_lsim_process_form(A,B,C,D,u,x0)", we can define our own x0. I have made trial and error with this x0 and have been able to fit the data reasonably well but i would like to request you to kindly guide me in understanding how to scientifically choose this x0 or is there a work around during the system identification process itself.
The main reason for my doubt is that the original data does not start from 0 but the sys response always try to start from 0 which i think is because the initial states are assumed 0 during system identification.
I am a newbie in this field so please excuse my lack of knowledge.
I look forward to your response.
Thank you
Regards,
Gopal.
Installed cmake
, sk-build
, but setup.py
still exists with an error, namely,
error: Setup script exited with ********************************************************************************
scikit-build could not get a working generator for your system. Aborting build.
Building windows wheels for Python 3.8 requires Microsoft Visual Studio 2019.
This is becoming tricky. Probably, dependencies are not sufficiently configured
Dear Sippy teams,
I have tried reproducing the MIMO example present in your publication but unfortunately, Sippy returns matrices of different order. If I change the 'SS_fixed_order' parameter, I am able to obtain matrices of required order but the error between SIPPY result and plant model is very high and does not look like what you have presented in the research paper. I am attaching the code I have used for your perusal. Request you to kindly have a look and advise changes.
Thanks and Regards,
Gopal.`
MIMO_SS.txt
`
Hey! First of all good job with this project. It looks it as a lot of potential. I am just having a problem with installing the setup.py file since this error is appearing:
"error: Setup script exited with Problem with the CMake installation, aborting build. CMake executable is cmake"
Can you explain how to solve this? Tried to search about it but could not find anything.
Thanks
Here we report an important issue received by mail,
which may help other users with similar problems ...
"Good afternoon,
I am trying to use SIPPY to identify systems for modal analysis and am having trouble with Slycot. I have all the dependencies for SIPPY installed with pip, but I could not get Slycot installed with pip; for this reason, I installed the pre-compiled version of Slycot from conda-forge using the command found at https://github.com/python-control/Slycot. I believe I have installed Slycot installed properly, because I can import it into a script without errors; however, running EX_SS.py prints “Kalman filter cannot be calculated” 3 times (I’m assuming for the 3 solvers that require Slycot). I have a few questions:
Have you encountered this problem before?
Do the other solvers rely on Slycot (will PARSIM-K or ARMAX give inaccurate results because Slycot is not well-installed)?
How can I remedy the situation?
I think the issue is that my python interpreter and SIPPY are installed with pip, but Slycot is installed with conda, so SIPPY is not finding the installed version of Slycot. For instance, running the command pytest –pyargs slycot
throws errors in pip because slycot is not there, but completes successfully when I run it in Anaconda Prompt. I would greatly appreciate any advice or guidance you have.
Best regards,
AS"
Is there any way to install it through Anaconda (Windows 10)?
Shapes of D and u[:, 0] will not get not align if there are more number of outputs than inputs.
Line 117 in 6f421c9
Hello.
When I use subspace methods e.g. N4SID, I always get a model with unstable zero(s) for the I/O data provided for identification. The accuracy I get compared with actual data is great e.g. 95% fit. However, the unstabl zero(s) doesn't not really represent the response of the actual system as it is not non-minimum phase. On the other hand, I don't get unstable zero(s) if I use the ARX or ARMAX methods. However, I get less accurate models that fit the provided I/O data.
Are there some settings in the subspace mehtods to avoid these unstable zero(s)?
Cheers.
Can anyone help me out in simulating a linear parameter varying model in case of state space variables.
This project uses slycot, which is licensed under GPLv2.
If my understanding is correct, it's not possible to license this under LGPL, it must also be GPL.
I am trying to identify a system with two inputs and one output. I am passing the following list for "BJ_orders".
[[[4, 5]], [11], [11], [5, 5], [[3, 0]]]. So far not been able to run a single identification. Is this correct way to input orders array?
On the other hand when I use ARMAX for the same problem with ARMAX_orders = [[0], [[4, 5]], [11], [[3, 0]]] seems working.
Is there anything that I am missing for BJ?
Hello,
I had / have an issue regarding the validation of my armax model using the functionsetSIM.validation method.
It said that my input Data had the wrong shape (N, 1)
and that he expected (N,)
or (1,N)
.
This message stayed the same even when I changed the shape. So I figured your code reshapes my Input Data in a way that it doesnt work for a Single Input System or I'm using your lib wrong
A simple np.reshape in front of cnt.lsim
in line 196 and the other in 219 could fix that for the single input case. So a simple if statement could work.
PS: First time posting an issue, so I'm sorry in advance if I left some critical info.
Best regards,
Niels
The doc specifies that the input to system_identification() should be of shape (n_y x L) for the output data y and of shape (n_u x L) for the input data u, where n_u and n_y refer to the number of output/input variables. In my case, for a SISO system n_u = n_y = 1.
I have a collection of input/output identification signals of shape (1 x L) for my SISO system which I would like to feed into the identification process at once. So, for instance, if I have a collection of K signals I can create u matrix of size K x M and y matrix of the same size. Is there a way to feed that into system_identification()?
Hello.
I would like to have a better understanding of what SS_p
and SS_f
are and how they affect the identification process. Is there a way to select reasonable values of them, based on the knowledge of the I/O data?
Thanks.
Hi! I am fitting an ARMAX model for a MISO system with the following orders: na = 3; nb = [3,3]; nc = [2]; nk=[0,0]. The coefficients of A, B, C that I get are very similar to the ones I get in matlab. However the Yid output I get is very close to the original, with an R^2 of 99.99% and does not make sense. The R^2 I get with the matlab output is 80%. When I set na = 0, it seems that the result makes sense, and when I set any value to na, the fitted output matches the original output.
I attempted to run the examples, but I could only get the SS.py
script to run. There appears to be a problem with the shape of one of the outputs of lsim
. The error messages can be found here, https://travis-ci.org/CameronDevine/SIPPY/jobs/413816972
Hello Sippy team
I am trying to identify the model of a balancing robot from the data obtained from a real one, the sampling is done in a closed loop because it is an unstable system. I'm using Sippy for system identification, the PARSIM-K option, and apparently I get the identification. My problem arises when I try to compare the real data with those generated by the model, not getting them to be valid.
Attached script and data file to be able to reproduce the problem.
Thank you for your attention
Best regards
Valentin Fernandez
Data
datos.csv
Script
PARSIM-K_id.txt
ERROR: Package 'sippy' requires a different Python: 3.6.12 not in '==2.7,>=3.5,<=3.7'
Thanks for sharing the system identification codes. Professor Gabriele Pannocchia introduced the CPCLAB-UNIPI github page in his lectures at the Chinese MPC school.
When I tried to execute the example codes, I found that the majority of them had a common problem with the fset.validation function. Is it a common bug or is it because I am using a different version of some of the packages? An inconsistent shape in line 805 of the fset.validation function is the cause of the issue. The Ex ARMAX, Ex ARMAX MIMO, Ex CST, Ex OPT GEN-INOUT, and Ex RECURSIVE all use fset.validation and all have the same issue.
The Ex ARX MIMO and Ex SS both function well.
Traceback (most recent call last):
File "C:/Users/bemnet/Desktop/First_Model/SIPPY-PYCHRM-master/Examples/Ex_ARMAX.py", line 174, in
Yv_armaxi = fset.validation(Id_ARMAXi,U_valid,Ytotvalid,Time)
File "C:\Users\bemnet\Desktop\First_Model\SIPPY-PYCHRM-master\sippy\functionset.py", line 196, in validation
Y_u, T, Xv = cnt.lsim((1/SYS.H[i,0])*SYS.G[i,:], u, Time)
File "C:\Users\bemnet\anaconda3\envs\SYSID_4PYCHRM\lib\site-packages\control\matlab\timeresp.py", line 297, in lsim
out = forced_response(sys, T, U, X0, return_x=True, transpose=True)
File "C:\Users\bemnet\anaconda3\envs\SYSID_4PYCHRM\lib\site-packages\control\timeresp.py", line 1007, in forced_response
U = _check_convert_array(U, legal_shapes,
File "C:\Users\bemnet\anaconda3\envs\SYSID_4PYCHRM\lib\site-packages\control\timeresp.py", line 805, in _check_convert_array
raise ValueError(err_msg_start + err_msg)
ValueError: Parameter U
: Wrong shape (rows, columns): (401, 1). Expected: (401,) or (1, 401).
Dear Sippy Team,
I'm having in issue regarding the prediction methods for non State Space Models.
For me it is not clear how the user is supposed to use the model after its identification.
I understand how to identify the models but afterwards I want to use the model for a prediction.
The documentation is a bit ambigious regarding this aspect.
I don't know which method to use for that.
For example is the method fset.validation
defined as a 1-step ahead simulation but the equation doesnt say y_hat_k+1.
So my understanding would be that this method is only used internally to validate the model after a training step. It is not supposed to be used as a prediction method.
So my question is: How is the user supposed to be simulating the identified system given a new input, as well as with optional old outputs(y(k-1)) ?
io_opt has "from .functionset_OPT_new import *". Should that be .functionset_OPT without the _new?
Supported is needed for 3.8, 3.9, 3.10, and onwards.
Support for 2.7 should probably be dropped.
I don't know what testing you've done, but it may be as simple as removing the <=3.8
restriction.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.