Dynamic Estimation Introduction

Dynamic estimation is a method to align data and model predictions for time-varying systems. Dynamic models and data rarely align perfectly because of several factors including limiting assumptions that were used to build the model, incorrect model parameters, data that is corrupted by measurement noise, instrument calibration problems, measurement delay, and many other factors. All of these factors may cause mismatch between predicted and measured values.

The focus of this section is to develop methods with dynamic optimization to realign model predictions and measured values with the goal of estimating states and parameters. Another focus of this section is to understand model structure that can lead to poorly observable parameters and determine confidence regions for parameter estimates. The uncertainty analysis serves to not only predict unmeasured quantities but also to relate a confidence in those predictions.

Dynamic estimation algorithms optimize model predictions over a prior time horizon of measurements. These state and parameter values may then be used to update the model for improved forward prediction in time to anticipate future dynamic events. The updated model allows dynamic optimization or control actions with increased confidence.

Dynamic Parameter Estimation Example 1

Dynamic Parameter Estimation Example 2

A method to solve dynamic estimation is by numerically integrating the dynamic model at discrete time intervals, much like measuring a physical system at particular time points. The numerical solution is compared to measured values and the difference is minimized by adjusting parameters in the model. Excel, MATLAB, Python, and Simulink are used in the following example to both solve the differential equations that describe the velocity of a vehicle as well as minimize an objective function.

Dynamic Parameter Estimation Example 3

Estimate the parameter `k` in the exponential decay equation:

$$\frac{dx}{dt} = -k\,x$$

by minimizing the error between the predicted and measured `x` values. The `x` values are measured at the following time intervals.

t_data = [0, 0.1, 0.2, 0.4, 0.8, 1]
x_data = [2.0,  1.6,  1.2, 0.7,  0.3,  0.15]

Use an initial condition of `x=2` that matches the data. Verify the solution of `x` with the analytic expression `x(t)=2 exp(-k t)`.

from gekko import GEKKO

t_data = [0, 0.1, 0.2, 0.4, 0.8, 1]
x_data = [2.0,  1.6,  1.2, 0.7,  0.3,  0.15]

m = GEKKO(remote=False)
m.time = t_data
x = m.CV(value=x_data); x.FSTATUS = 1  # fit to measurement
k = m.FV(); k.STATUS = 1               # adjustable parameter
m.Equation(x.dt()== -k * x)            # differential equation

m.options.IMODE = 5   # dynamic estimation
m.options.NODES = 5   # collocation nodes
m.solve(disp=False)   # display solver output
k = k.value[0]

import numpy as np
import matplotlib.pyplot as plt  # plot solution
plt.plot(m.time,x.value,'bo',\
         label='Predicted (k='+str(np.round(k,2))+')')
plt.plot(m.time,x_data,'rx',label='Measured')
# plot exact solution
t = np.linspace(0,1); xe = 2*np.exp(-k*t)
plt.plot(t,xe,'k:',label='Exact Solution')
plt.legend()
plt.xlabel('Time'), plt.ylabel('Value')
plt.show()

Dynamic Parameter Estimation Example 4

Estimate the parameter `a,b,c,d` in the differential equation:

$$\frac{d^3x}{dt^3} = a\frac{d^2x}{dt^2}+b\frac{dx}{dt}+c x+d$$

by minimizing the error between the predicted and measured `x` values. The `x` values are measured at the following time intervals.

t_data = [0,0.1,0.2,0.4,0.8,1,1.5,2,2.5,3,3.5,4]
x_data = [2.0,1.6,1.2,0.7,0.3,0.15,0.1,0.05,0.03,0.02,0.015,0.01]

Use an initial condition of `x=2` that matches the data. Create new states `y=dx/dt` and `z=dy/dt` for the higher order derivative terms.

$$\frac{dx}{dt} = y$$ $$\frac{dy}{dt} = z$$ $$\frac{dz}{dt} = az+by+cx+d$$

from gekko import GEKKO

t_data = [0,0.1,0.2,0.4,0.8,1,1.5,2,2.5,3,3.5,4]
x_data = [2.0,1.6,1.2,0.7,0.3,0.15,0.1,\
          0.05,0.03,0.02,0.015,0.01]

m = GEKKO()
m.time = t_data

# states
x = m.CV(value=x_data); x.FSTATUS = 1  # fit to measurement
y,z = m.Array(m.Var,2,value=0)

# adjustable parameters
a,b,c,d = m.Array(m.FV,4)
a.STATUS=1; b.STATUS=1; c.STATUS=1; d.STATUS=1

# differential equation
#      Original:  x''' = a*x'' + b x' + c x + d
#      Transform: y = x'
#                 z = y'
#                 z' = a*z + b*y + c*x + d
m.Equations([y==x.dt(),z==y.dt()])
m.Equation(z.dt()==a*z+b*y+c*x+d) # differential equation

m.options.IMODE = 5   # dynamic estimation
m.options.NODES = 3   # collocation nodes
m.solve(disp=False)   # display solver output
print(a.value[0],b.value[0],c.value[0],d.value[0])

import matplotlib.pyplot as plt  # plot solution
plt.plot(m.time,x.value,'bo',label='Predicted')
plt.plot(m.time,x_data,'rx',label='Measured')
plt.legend()
plt.xlabel('Time'), plt.ylabel('Value')
plt.show()