So this is a follow-up question to this one: ARX Models in Gekko.
I think I didn't give enough details and my question was not very clear. First of all, I am looking for the model of my system to use it in an MPC so the identification needs to be good in order to get good results from my MPC.
This is the code I used to the system Identification with GEKKO. I used data of about 5 hours where the fridge was only controlled by a thermostat. There was data coming from my sensor every 5 sec.
Identification with Sysid()
from gekko import GEKKO
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
#Load data
a_dataframe = pd.read_csv("State.txt")
a_dataframe.columns = ["State"]
u = a_dataframe["State"]
b_dataframe = pd.read_csv("Temp.txt")
b_dataframe.columns = ["Temp"]
T = b_dataframe["Temp"]
t = np.linspace(0,17180,3436)
#Identification
m = GEKKO()
na = 1 # output coefficients
nb = 1 # input coefficients
yp,p,K = m.sysid(t,u,T,na,nb,shift='calc',pred='meas')
#Plots
plt.figure()
plt.subplot(2,1,1)
plt.plot(t,u)
plt.subplot(2,1,2)
plt.plot(t,T)
plt.plot(t,yp)
plt.xlabel('Time')
plt.show()
The results I got with sysid() were not good. Despite these results,
I simulated the ARX model with the following code. Using the p dictionary that I got from sysid().
Simulation
from gekko import GEKKO
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
na = 1# Number of A coefficients
nb = 1 # Number of B coefficients
ny = 1 # Number of outputs
nu = 1 # Number of inputs
# A (na x ny)
# actual A,B,C values are from 5 h data
A = np.array([[1.00037807]])
# B (ny x (nb x nu))
B= np.array([[[-0.01318095]]])
C = np.array([-0.00162522])
# create parameter dictionary
# parameter dictionary p['a'], p['b'], p['c']
# a (coefficients for a polynomial, na x ny)
# b (coefficients for b polynomial, ny x (nb x nu))
# c (coefficients for output bias, ny)
p = {'a':A,'b':B,'c':C}
m = GEKKO(remote=True)
y,u = m.arx(p)
# load inputs
#tf = 719 # final time
u1 = np.append(np.ones(500),np.zeros(500),0)
u2 = np.append(u1, np.ones(500),0)
u3 = np.append(u2, np.zeros(500),0)
u4 = np.append(u3, np.ones(500),0)
u5 = np.append(u4, np.zeros(936),0)
u[0].value = u5
cv = y[0]
mv= u[0]
cv.value = 14.2
m.time = np.linspace(0,17180,3436)
m.options.imode = 4
m.options.nodes= 2
#m.options.SOLVER = 1
# simulate
m.solve()
The Simulation results:
The changes in temperature are not logical. At the end the fridge is off and the temperature keeps on decresing. And my fridge ist not powerful enough to attein -5 °C. My questions are:
- What am I potentially doing wrong here? did I use enough data for the identification?
- Why do I get other coefficients for p when using linear regression than with sysid()? (Code from my last post)
- Does sysid() proceed like linear regression?
- Why do I get better fitting results with linear regression but the temperature does not change much when plotting the simulation? (See simulation plot of linear regression in my last post)
Thanks in advance :)

