# Data-driven control system

Data-driven control systems are a broad family of control systems, in which the identification of the process model and/or the design of the controller are based entirely on experimental data collected from the plant.
In many control applications, trying to write a mathematical model of the plant is considered a hard task, requiring efforts and time to the process and control engineers. This problem is overcome by data-driven methods, which fit a system model to the experimental data collected, choosing it in a specific models class. The control engineer can then exploit this model to design a proper controller for the system. However, it is still difficult to find a simple yet reliable model for a physical system, that includes only those dynamics of the system that are of interest for the control specifications. The direct data-driven methods allow to tune a controller, belonging to a given class, without the need of an identified model of the system. In this way, one can also simply weight process dynamics of interest inside the control cost function, and exclude those dynamics that are out of interest.

## Overview

The standard approach to control systems design is organized in two-steps:
* Model identification aims at estimating a nominal model of the system ${\widehat {G}}=G\left(q;{\widehat {\theta }}_{N}\right)$, where $q$ is the unit-delay operator (for discrete-time transfer functions representation) and ${\widehat {\theta }}_{N}$ is the vector of parameters of $G$ identified on a set of $N$ data. Then, validation consists in constructing the uncertainty set $\Gamma$ that contains the true system $G_{0}$ at a certain probability level.
* Controller design aims at finding a controller $C$ achieving closed-loop stability and meeting the required performance with ${\widehat {G}}$.
Typical objectives of system identification are to have ${\widehat {G}}$ as close as possible to $G_{0}$, and to have $\Gamma$ as small as possible. However, from an identification for control perspective, what really matters is the performance achieved by the controller, not the intrinsic quality of the model.
One way to deal with uncertainty is to design a controller that has an acceptable performance with all models in $\Gamma$, including $G_{0}$. This is the main idea behind robust control design procedure, that aims at building frequency domain uncertainty descriptions of the process. However, being based on worst-case assumptions rather than on the idea of averaging out the noise, this approach typically leads to conservative uncertainty sets. Rather, data-driven techniques deal with uncertainty by working on experimental data, and avoiding excessive conservativism.
In the following, the main classifications of data-driven control systems are presented.

### Indirect and direct methods

There are many methods available to control the systems. The fundamental distinction is between indirect and direct controller design methods. The former group of techniques is still retaining the standard two-step approach, i.e. first a model is identified, then a controller is tuned based on such model. The main issue in doing so is that the controller is computed from the estimated model ${\widehat {G}}$ (according to the certainty equivalence principle), but in practice ${\widehat {G}}\neq G_{0}$. To overcome this problem, the idea behind the latter group of techniques is to map the experimental data directly onto the controller, without any model to be identified in between.

### Iterative and noniterative methods

Another important distinction is between iterative and noniterative (or one-shot) methods. In the former group, repeated iterations are needed to estimate the controller parameters, during which the optimization problem is performed based on the results of the previous iteration, and the estimation is expected to become more and more accurate at each iteration. This approach is also prone to on-line implementations (see below). In the latter group, the (optimal) controller parametrization is provided with a single optimization problem. This is particularly important for those systems in which iterations or repetitions of data collection experiments are limited or even not allowed (for example, due to economic aspects). In such cases, one should select a design technique capable of delivering a controller on a single data set. This approach is often implemented off-line (see below).

### On-line and off-line methods

Since, on practical industrial applications, open-loop or closed-loop data are often available continuously, on-line data-driven techniques use those data to improve the quality of the identified model and/or the performance of the controller each time new information is collected on the plant. Instead, off-line approaches work on batch of data, which may be collected only once, or multiple times at a regular (but rather long) interval of time.

## Iterative feedback tuning

The iterative feedback tuning (IFT) method was introduced in 1994, starting from the observation that, in identification for control, each iteration is based on the (wrong) certainty equivalence principle.
IFT is a model-free technique for the direct iterative optimization of the parameters of a fixed-order controller; such parameters can be successively updated using information coming from standard (closed-loop) system operation.
Let $y^{d}$ be a desired output to the reference signal $r$; the error between the achieved and desired response is ${\tilde {y}}(\rho )=y(\rho )-y^{d}$. The control design objective can be formulated as the minimization of the objective function:
    $J(\rho )={\frac {1}{2N}}\sum _{t=1}^{N}E\left[{\tilde {y}}(t,\rho )^{2}\right].$
Given the objective function to minimize, the quasi-Newton method can be applied, i.e. a gradient-based minimization using a gradient search of the type:
    $\rho _{i+1}=\rho _{i}-\gamma _{i}R_{i}^{-1}{\frac {d{\widehat {J}}}{d\rho }}(\rho _{i}).$
The value $\gamma _{i}$ is the step size, $R_{i}$ is an appropriate positive definite matrix and ${\frac {d{\widehat {J}}}{d\rho }}$ is an approximation of the gradient; the true value of the gradient is given by the following:
    ${\frac {dJ}{d\rho }}(\rho )={\frac {1}{N}}\sum _{t=1}^{N}\left[{\tilde {y}}(t,\rho ){\frac {\delta y}{\delta \rho }}(t,\rho )\right].$
The value of ${\frac {\delta y}{\delta \rho }}(t,\rho )$ is obtained through the following three-step methodology:
* Normal Experiment: Perform an experiment on the closed loop system with $C(\rho )$ as controller and $r$ as reference; collect N measurements of the output $y(\rho )$, denoted as $y^{(1)}(\rho )$.
* Gradient Experiment: Perform an experiment on the closed loop system with $C(\rho )$ as controller and 0 as reference $r$; inject the signal $r-y^{(1)}(\rho )$ such that it is summed to the control variable output by $C(\rho )$, going as input into the plant. Collect the output, denoted as $y^{(2)}(\rho )$.
* Take the following as gradient approximation: ${\frac {\delta {\widehat {y}}}{\delta \rho }}(\rho )={\frac {\delta C}{\delta \rho }}(\rho )y^{(2)}(\rho )$.
A crucial factor for the convergence speed of the algorithm is the choice of $R_{i}$; when ${\tilde {y}}$ is small, a good choice is the approximation given by the Gauss–Newton direction:
    $R_{i}={\frac {1}{N}}\sum _{t=1}^{N}{\frac {\delta {\widehat {y}}}{\delta \rho }}(\rho _{i}){\frac {\delta {\widehat {y}}^{T}}{\delta \rho }}(\rho _{i}).$

## Noniterative correlation-based tuning

Noniterative correlation-based tuning (nCbT) is a noniterative method for data-driven tuning of a fixed-structure controller. It provides a one-shot method to directly synthesize a controller based on a single dataset.
Suppose that $G$ denotes an unknown LTI stable SISO plant, $M$ a user-defined reference model and $F$ a user-defined weighting function. An LTI fixed-order controller is indicated as $K(\rho )=\beta ^{T}\rho$, where $\rho \in \mathbb {R} ^{n}$, and $\beta$ is a vector of LTI basis functions. Finally, $K^{*}$ is an ideal LTI controller of any structure, guaranteeing a closed-loop function $M$ when applied to $G$.
The goal is to minimize the following objective function:
    $J(\rho )=\left\|F{\bigg{\frac {K^{*}G-K(\rho )G}{(1+K^{*}G)^{2}}}{\bigg )}\right\|_{2}^{2}.$
$J(\rho )$ is a convex approximation of the objective function obtained from a model reference problem, supposing that ${\frac {1}{(1+K(\rho )G)}}\approx {\frac {1}{(1+K^{*}G)}}$.
When $G$ is stable and minimum-phase, the approximated model reference problem is equivalent to the minimization of the norm of $\varepsilon (t)$ in the scheme in figure.
The input signal $r(t)$ is supposed to be a persistently exciting input signal and $v(t)$ to be generated by a stable data-generation mechanism. The two signals are thus uncorrelated in an open-loop experiment; hence, the ideal error $\varepsilon (t,\rho ^{*})$ is uncorrelated with $r(t)$. The control objective thus consists in finding $\rho$ such that $r(t)$ and $\varepsilon (t,\rho ^{*})$ are uncorrelated.
The vector of instrumental variables $\zeta (t)$ is defined as:
    $\zeta (t)=[r_{W}(t+\ell _{1}),r_{W}(t+\ell _{1}-1),\ldots ,r_{W}(t),\ldots ,r_{W}(t-\ell _{1})]^{T}$
where $\ell _{1}$ is large enough and $r_{W}(t)=Wr(t)$, where $W$ is an appropriate filter.
The correlation function is:
    $f_{N,\ell _{1}}(\rho )={\frac {1}{N}}\sum _{t=1}^{N}\zeta (t)\varepsilon (t,\rho )$
and the optimization problem becomes:
    ${\widehat {\rho }}={\underset {\rho \in D_{k}}{\operatorname {arg\,min} }}J_{N,\ell _{1}}(\rho )={\underset {\rho \in D_{k}}{\operatorname {arg\,min} }}f_{N,\ell _{1}}^{T}f_{N,\ell _{1}}.$
Denoting with $\phi _{r}(\omega )$ the spectrum of $r(t)$, it can be demonstrated that, under some assumptions, if $W$ is selected as:
    $W(e^{-j\omega })={\frac {F(e^{-j\omega })(1-M(e^{-j\omega }))}{\phi _{r}(\omega )}}$
then, the following holds:
    $\lim _{N,\ell _{1}\to \infty ,\ell _{1}/N\to \infty }{\widehat {\rho }}=\rho ^{*}.$

### Stability constraint

There is no guarantee that the controller $K$ that minimizes $J_{N,\ell _{1}}$ is stable. Instability may occur in the following cases:
* If $G$ is non-minimum phase, $K^{*}$ may lead to cancellations in the right-half complex plane.
* If $K^{*}$ (even if stabilizing) is not achievable, $K(\rho )$ may not be stabilizing.
* Due to measurement noise, even if $K^{*}=K(\rho )$ is stabilizing, data-estimated ${\widehat {K}}(\rho )$ may not be so.
Consider a stabilizing controller $K_{s}$ and the closed loop transfer function $M_{s}={\frac {K_{s}G}{1+K_{s}G}}$. Define:
    $\Delta (\rho ):=M_{s}-K(\rho )G(1-M_{s})$
    $\delta (\rho ):=\left\|\Delta (\rho )\right\|_{\infty }.$
    Theorem
    The controller $K(\rho )$ stabilizes the plant $G$ if
* $\Delta (\rho )$ is stable
* $\exists \delta _{N}\in (0,1)$ s.t. $\delta (\rho )\leq \delta _{N}.$
Condition 1. is enforced when:
* $K(\rho )$ is stable
* $K(\rho )$ contains an integrator (it is canceled).
The model reference design with stability constraint becomes:
    $\rho _{s}={\underset {\rho \in D_{k}}{\operatorname {arg\,min} }}J(\rho )$
    ${\text{s.t. }}\delta (\rho )\leq \delta _{N}.$
A convex data-driven estimation of $\delta (\rho )$ can be obtained through the discrete Fourier transform.
Define the following:
    ${\begin{aligned}&{\widehat {R}}_{r}(\tau )={\frac {1}{N}}\sum _{t=1}^{N}r(t-\tau )r(t){\text{ for }}\tau =-\ell _{2},\ldots ,\ell _{2}\\[4pt]&{\widehat {R}}_{r\varepsilon }(\tau )={\frac {1}{N}}\sum _{t=1}^{N}r(t-\tau )\varepsilon (t,\rho ){\text{ for }}\tau =-\ell _{2},\ldots ,\ell _{2}.\end{aligned}}$
For stable minimum phase plants, the following convex data-driven optimization problem is given:
    ${\begin{aligned}{\widehat {\rho }}&={\underset {\rho \in D_{k}}{\operatorname {arg\,min} }}J_{N,\ell _{1}}(\rho )\\[3pt]&{\text{s.t.}}\\[3pt]&{\bigg |}\sum _{\tau =-\ell _{2}}^{\ell _{2}}{\widehat {R}}_{r\varepsilon }(\tau ,\rho )e^{-j\tau \omega _{k}}{\bigg |}\leq \delta _{N}{\bigg |}\sum _{\tau =-\ell _{2}}^{\ell _{2}}{\widehat {R}}_{r}(\tau ,\rho )e^{-j\tau \omega _{k}}{\bigg |}\\[4pt]\omega _{k}&={\frac {2\pi k}{2\ell _{2}+1}},\qquad k=0,\ldots ,\ell _{2}+1.\end{aligned}}$

## Virtual reference feedback tuning

Virtual Reference Feedback Tuning (VRFT) is a noniterative method for data-driven tuning of a fixed-structure controller. It provides a one-shot method to directly synthesize a controller based on a single dataset.
VRFT was first proposed in and then extended to LPV systems. VRFT also builds on ideas given in as $VRD^{2}$.
The main idea is to define a desired closed loop model $M$ and to use its inverse dynamics to obtain a virtual reference $r_{v}(t)$ from the measured output signal $y(t)$.
The virtual signals are $r_{v}(t)=M^{-1}y(t)$ and $e_{v}(t)=r_{v}(t)-y(t).$
The optimal controller is obtained from noiseless data by solving the following optimization problem:
    ${\widehat {\rho }}_{\infty }={\underset {\rho }{\operatorname {arg\,min} }}\lim _{N\to \infty }J_{vr}(\rho )$
where the optimization function is given as follows:
    $J_{vr}^{N}(\rho )={\frac {1}{N}}\sum _{t=1}^{N}\left(u(t)-K(\rho )e_{v}(t)\right)^{2}.$