Data-Driven Modeling: Nonlinear System Identification using AI Techniques
Overview
In this webinar we will provide a brief overview of System Identification toolbox and focus on identifying nonlinear models to capture nonlinear system dynamics.
You will learn how to create models of nonlinear system dynamics from data for system simulation, reduced order modeling, and control design workflows. You will learn how to combine your knowledge and intuition about system dynamics with AI techniques.
The webinar will cover identification of nonlinear ARX and Hammerstein-Wiener models that leverage machine learning methods such as Support Vector Machines (SVM), Gaussian Processes (GP), and other representations. You will see how you can choose regressors that best capture your system dynamics, and how you can develop nonlinear dynamics models by first identifying linear models and then adding nonlinear effects.
You will also learn how to identify neural state space models that describe system dynamics in the familiar state-space form, but with nonlinear state and output update functions that are represented by neural networks learned from data.
Highlights
In this webinar you will learn about:
- Overview of system Identification
- Nonlinear system identification using Nonlinear ARX, Hammerstein-Wiener, and Neural ODE models
- Available AI techniques to describe nonlinearities in your model
- Use of nonlinear models for system simulation, control design, and reduced order modeling
About the Presenter
Kishen Mahadevan is a Product Manager for Fuzzy Logic Toolbox, System Identification Toolbox, and Simulink Design Optimization at MathWorks. Kishen has an M.S. in Electrical Engineering with specialization in Control Systems from Arizona State University, and a B.E. in Electrical and Electronics Engineering from Visvesvaraya Technological University in India. He joined MathWorks in 2018 as an Application Support Engineer helping customers resolve issues related to Simulink products before moving into product marketing.
Recorded: 14 Nov 2022
Hello, everyone. Welcome to the session on nonlinear system identification using AI techniques. My name is Kishen Mahadevan. I'm a Product Manager at MathWorks, focusing on the area of system identification. I've been with MathWorks for a little over 4 years now, and I work closely with the development team to help guide the roadmap of our controls tools. I also have a background in electrical engineering, with specialization in control systems.
Before I start this webinar today, I want to give you a quick peek into what you will be seeing over the next 30 to 35 minutes. In this webinar, you'll see how to create accurate nonlinear models of physical systems using different techniques available from System Identification Toolbox, and how to leverage AI techniques to create these models. And as one of the applications of nonlinear models, you'll then see how you can import these models into Simulink, and use the estimated models as reduced order models for speeding up simulations of high-fidelity systems, where you'll see that this reduced order model simulates faster while still capturing essential dynamics.
And as I highlight the capabilities of the product and go through the demonstration, the goal of the session is for you to walk away with these two points-- one, that is you can use System Identification Toolbox to create accurate linear and nonlinear models of physical systems from data, and that you can now leverage AI techniques without actually being experts in the field of machine learning and deep learning.
With that said, I want to start by providing a quick overview of system identification. So system identification is the process of creating mathematical representation or models of physical systems from measured experimental data. There are multiple approaches to modeling dynamic systems, and system identification is one of them. So let's now see where System Identification Toolbox or system identification fits in the overall spectrum.
There are three ways of modeling dynamic systems. If you know the physics or math behind your system, you can use that knowledge to form the model, and that is called first principles modeling. And on the other end of the spectrum is, if you don't know the physics or if you have no knowledge about your system but you have some measured data from the system, you can use that data to construct a model of your system. And we call this data-driven modeling or black box modeling.
And in between is a combination of both. That is, if you use both the knowledge of your system and in terms of equations, and then use measured data to identify physically meaningful parameters, then we call this gray box modeling. And system identification as an area covers the gray box and black box modeling approaches.
And MathWorks offers several different products for modeling dynamic systems. If we are to look at MathWorks tools from MATLAB users' point of view, we have Control System Toolbox as one of the tools for modeling dynamic systems, and this is an addition to the functionalities that we have in base MATLAB. And then we have System Identification Toolbox as a data-driven product for gray box and black box modeling approaches.
If we were to look at it from a Simulink user's point of view, we have Simulink and Simscape as physical modeling tools for first principles modeling. We have Simulink Design Optimization as a tool for gray box modeling in Simulink, and System Identification Toolbox for black box data-driven modeling. So now we know where System Identification Toolbox fits in the overall spectrum. Let's now take a brief look at what System Identification Toolbox has to offer.
The toolbox provides capabilities through which you can use functions to estimate and validate a variety of linear, nonlinear, and even gray box models. You can use the System Identification app that comes with the toolbox to perform interactive workflows, again to estimate, validate, and compare a variety of models and to quickly get started with the design.
You can use popular machine learning algorithms, such as support vector machines, Gaussian process from Statistics and Machine Learning Toolbox and Deep Learning Toolbox to capture nonlinearities in nonlinear systems. You can bring the estimated models into Simulink using built-in blocks to perform integrated workflows and for system-level simulations. You can deploy estimated models using our various Coder tools. And, finally, you can use the reference examples that come with the product to quickly get started.
With that, let's now look at a workflow that you can follow to create models of dynamic systems using System identification Toolbox. So regardless of the type of system you are trying to estimate-- that is, it could either be linear models, nonlinear models, or even gray box models-- you can pretty much follow this workflow where you start by gathering experimental data. You then estimate model from data, and then validate the model with independent data set.
The first step, where you gather data, the data can either be in time or frequency domain. And this step often involves a process called design of experiments, where you use appropriate input signals to excite the essential dynamics of your system, and then capture the associated output. Here, the system can be the actual physical system or the hardware or a high-fidelity simulation model. And this step often also involves data preparation, such as removing means, filtering out the noise, resampling, et cetera.
And then, once you have the data ready, you can then use the input and output data with functionalities from System Identification Toolbox to estimate linear or nonlinear models. And the graphical user interface helps you with this process, including the data preparation steps, and helps you quickly get started with your design, and also helps you select the model that works best for your data and application.
And once you have estimated this model, you can also validate the model, validate the estimated model with an independent data set, where you compare the real output from your system with the estimated output. And once you finalize your identified model, you can then bring it into Simulink for system-level simulation or code generation, or perform workflows in MATLAB for your applications.
Historically, System Identification Toolbox was majorly used for identifying linear models for the purpose of control design applications. But recently, as planned models and controllers are becoming more complex, nonlinear models are becoming more popular, and they are opening up for a variety of applications, such as system simulation, reduced order modeling, virtual sensor modeling, or even nonlinear control design. And there is a need to create better nonlinear models for supporting these applications. And that is an area that we will take a deeper look at today, and we will see the different techniques we have from System Identification Toolbox to model nonlinear systems.
The different structures and models that we provide for modeling nonlinear systems are neural state-space models, which is a new addition where you can create deep learning based nonlinear state-space models. And then we have nonlinear ARX, and Hammerstein-Wiener models, which allowed you to extend linear models, and then have variety of nonlinear functions-- and provide a variety of nonlinear functions to capture nonlinearities.
And, finally, we have nonlinear gray box models, where if you already know the equations of your system but not the values of parameters, then this type of model helps you find physically meaningful parameters from data. We won't be talking much about the gray box identification today, but this is definitely a good technique to keep in mind.
So nonlinear modeling in general can mean use of many different structures, and most commonly used ones are these models that I just mentioned, and System Identification Toolbox provides all of these. So let's take a deeper look at neural state-space, nonlinear ARX, and Hammerstein-Wiener techniques, and see how to create these nonlinear models.
Let's start with the neural state-space model. Using neural state-space models, you can now leverage deep learning architectures and training methods for identifying dynamic systems. This model structure is also popularly known as neural ODE in the deep learning community. The neural state-space model is in the familiar state-space form, where the nonlinear state function f and the nonlinear output function g in the state-space equations are now neural networks which you will learn from data.
The type of network that this neutral state-space supports is multilayered perceptron or feedforward networks, and that requires Deep Learning Toolbox. One quick thing I want to mention here or point out here is that, while we believe that these multilayer perceptron networks will be sufficient for most of the use cases, if your specific use case requires more customized representation of other networks, such as LSTMs, you can use neural ODE functionality from Deep Learning Toolbox. But coming back to neural state-space, with the overall neural state-space model, we have made it easier for controls and simulation engineers who might not be experts in the field of AI to still leverage AI techniques and create these neural state-space models.
Let's now take a look at a demo. In this exercise, we'll see how you can replace a portion of a complex vehicle model with a data-driven nonlinear model created using System Identification Toolbox. In the first case, we'll specifically look at neural state-space models. The reason we want to replace it is because the complex model takes a very long time to simulate, and we want a proxy model that runs faster with a smaller memory footprint.
While there are many inputs and outputs to internal combustion engine model, for this exercise the inputs that we identified are engine speed, ignition timing, throttle position, and wastegate valve. And the output that we identified for this exercise was engine torque. And at the end of the day, we measure these inputs and outputs using first principle model, and then we estimate a model to match the simulation results to a good level of accuracy. So that is what we want to achieve. We want to achieve a very good level of accuracy using the estimated system ID model.
And one thing to note here is that the system identification model will coexist with first principles model for other components of vehicle in Simulink. And another quick note is that this demo is going to be common across the different techniques I will be highlighting today. Let's now see how you can create and train a neural state-space model.
The workflow will follow to train a neural state-space model is we'll start with the data preparation step. That is, we'll prepare the data that we load from a high-fidelity simulation model. We'll then design and train the neural state-space model using the prepared data. We'll then validate the model in MATLAB using an independent validation set. And we'll also show you how to validate the model in Simulink.
So let's start with the data preparation step. The first step is to load the high-fidelity simulation model, after which we extract the input and the output data from the loaded file. We then create input and output vectors, and then we go into preparing the training and validation data.
In this case, we start by removing the initial set of points to remove startup transients. We downsample the data for training. We'll normalize the data. We'll then split the data into training and validation. And we'll then reformat the data as cells of timetable so that we prepare the data for training a neural state-space model.
Now we can quickly take a look at how the data looks. So this plot here shows the training data and the validation data for four inputs and the output, which is the engine torque. The plots in blue-- the data points in blue show the training data, whereas the plot in red shows the split of validation data, which we will use for validating the trained neural state-space model at a later stage.
Once the data is ready, the next step is defining and training a neural state-space model. The first step is to define a neural state-space model. In our case, we have one state, which is the engine torque, and four inputs. We then configure the state network. In our case, the output is equal to the state, so we are not learning the output network. And this state network gets created by default when you create a neural state-space object, but in this case I've created this line, or I've added this line, specifically to show you that you have the flexibility to change the layer sizes, or the number of layers, in a multilayer perceptron network.
After configuring the state network, we can then specify training options, and then train using the nonlinear state-space or neural state-space estimation command. In the interest of time, I'm not going to be training it right now, but I'm going to load a pre-trained neural state-space model. But to give you a quick idea of how the training process looks like, once the training is in progress, a progress plot appears where you can see the cost on the state network. And you also have the flexibility to stop training early if you feel the training has reached a good state. But this is how the training process looks like.
So getting back to the live script, here I've loaded the pre-trained neural state-space object. Once we have the trained neural state-space model, the next step is to validate the model. First, let's do an exercise where we compare it with the training data that we used. So the compare command here, what it's doing is that it is simulating the model. That is set to simulating a trained neural state-space object with the input signal you train, and it is comparing the output of that object with the actual output, which is YTrain. And as you can see, you see that the neutral state-space object, the output of it is pretty close to the actual output of the training data.
Let us do a similar workflow with the validation set so we can see how well the neural state-space object works well on an independent validation data set. If I were to quickly pop this figure out in a separate window-- right here. So here you can see that the output of the neutral state-space object is pretty close to the actual output of the high-fidelity simulation. And in this case, this is the validation output when compared with an independent data set. So we see that the model is doing a pretty good job.
What if there is a requirement that you want to deploy the neural state-space model with the original sample time? To validate that, I'm going to load another set of data with the original sample time, and I'm going to open a Simulink model where I bring in those-- where I bring in those input and output data with the original sample time. And I also load the trained neural state-space object using this neural state-space built-in block, which lets you quickly bring in the trained object into Simulink. And on simulating this model with the original high-fidelity sample time, you can see that the reduced order model using neutral state-space is able to match the simulation results from high-fidelity model for the same input data at the original sample time.
In the previous case, we used data directly to create a neural state-space model, and that worked well. But in few cases, when you have some knowledge, say, from physical insights or knowledge that you might have gained from prior modeling effort, and you want to use this knowledge to influence the design process of nonlinear models, what would you do? So in that case, you can use another structure of nonlinear model we offer that is called nonlinear ARX model, where the concept of nonlinear ARX model is that it offers estimation in two steps. One is selection of features, or regressors, and the other is mapping of these regressors to the output through an output function.
You have different options to specify regressors, such as linear regressors, polynomial regressors, periodic regressors, or even custom regressors. What we mean by custom regressors is that you can enter user-defined custom formula, say to include insights such as saturation. And that is the example equation that you see on the screen. So this is one way you can incorporate your insights.
The other component is the output function, which has multiple mapping objects. One is an offset component, the other is the nonlinear function, and the other one is a linear component. Here, another important detail about nonlinear ARX model is that you have the flexibility to extend linear models, or start with the linear model that you understand really well, and then model the complex nonlinear behavior using an array of nonlinear functions that this model provides.
And the array of nonlinear functions are just popped up on the screen, where these functions are a variety of them where you can choose from, say, general-purpose nonlinear function estimators, such as wavelet network or sigmoid networks. Or you can use state-of-the-art machine learning algorithms, such as Gaussian process, support vector machine, or regression tree ensemble, to represent these nonlinearities or nonlinear functions.
So with the addition of these newer machine learning techniques, we have now brought the power of machine learning to modeling nonlinear dynamic systems. So through the flexibility of choosing, say, either the regressors or through the flexibility of starting with a linear model, you can now include insights about your system and influence the design process. Let's now look at a demo where we see how to use a few of the highlighted functionalities.
So the workflow we'll follow to showcase the training of nonlinear ARX model, where nonlinear ARX model serves as a reduced order model of an internal combustion engine, is going to be very similar to the workflow that we followed for the neural state-space model, where the data preparation part is going to be exactly identical, where we'll use the same data to use-- for training a nonlinear ARX model, after which we will validate the model in MATLAB as well as Simulink. So let's jump to training nonlinear ARX model directly.
In this example, for identifying nonlinear ARX model, we start by specifying the structure. In this case, we'll use linear regressors-- here-- to specify one delayed input variable, and this is just to give you an idea of how to add a feature. And as we saw in the slide earlier, this regressor could be linear, polynomial, periodic, or custom.
Next, we'll specify the output function. This output function here maps the regressors to the model output, and here we use the popular machine learning algorithm of support vector machine as the nonlinear function. So we go about specifying the hyperparameters for the SVM algorithm, such as Kernel, BoxConstraint, and EpsilonMargin.
We then specify the training options for the nonlinear ARX command, and we call the training command for nonlinear ARX. Here, the first argument to this nonlinear ARX command is the estimation data. The second argument is the linear regressors that we specified. And the third and the fourth arguments are the SVM hyperparameters and the training options, respectively. Again, in this case, I'm not going to be training the model, but I'm going to load a trained nonlinear ARX model.
One thing to note here is that when you do not know which regressors to use, you can use the SparsifyRegressors option here to automatically select an optimal subset of regressors, which is nothing but a feature selection option. So one way to go about it is you can start by including linear and polynomial regressors up to large lag to give the sparsify option enough flexibility to choose a subset of regressors. And on specifying the SparsifyRegressors option to true, during the training process the SparsifyRegressors selects an optimal subset of regressors during training. That's one thing I wanted to mention.
But coming back to our example, once we have the trained model, we can validate the model with the estimation data as well as the validation data, as we did with the neural state-space model. And here, on popping this simulated output with the validation data set, we can see that the output of the nonlinear model is in agreement with the actual output from the high-fidelity model.
We can load the high-fidelity simulation data with the original sample time and validate this model in Simulink as well. Here, we bring the trained nonlinear ARX model using the nonlinear ARX built-in block, where we enter the nlarxSVM object here as the pre-trained-- we load the pre-trained object in this block dialog. And on running the simulation, we see that output from the reduced order model of nonlinear ARX is very close to the high-fidelity simulation output for the same inputs. They show that the reduced order model was able to capture the essential dynamics well.
In the previous case with nonlinear ARX models, we took a simple approach, highlighting how to specify regressors and how to go about estimating your nonlinear model using AI technique. Now let's look at how you can start with the linear model and include physical insights. For that, I want to bring up another type of model called Hammerstein-Wiener model, where the concept is similar to nonlinear ARX in a way that the idea is to extend linear models to nonlinear case, with the exception that, in this case, the linear system is in series with nonlinear static modifications at the input and output.
And as we saw with nonlinear ARX, Hammerstein-Wiener also provides an array of nonlinear functions for capturing nonlinearities. And these nonlinear functions include general-purpose nonlinear function estimators, such as wavelet network and sigmoid networks. And with Hammerstein-Wiener, we also have physics-inspired nonlinear estimators, such as saturation or dead zone, where you can directly enter insights, such as saturation or dead zone of your system, directly using these estimators. And we also have a machine learning algorithm of Gaussian process to capture nonlinearities. And the use of this machine learning algorithm requires Statistics and Machine Learning Toolbox.
Now let's take a look at the demo. So the workflow we'll follow for training a Hammerstein-Wiener model to serve as a reduced order model for an internal combustion engine is going to be the same as the workflow we followed with the neural state-space model as well as the nonlinear ARX model, where the data preparation parts remain identical. So we'll directly jump into training our Hammerstein-Wiener model.
The approach we use in this case is that we start with the linear model. And this linear model can be something that you understand really well, or a linear model that is a product of your prior modeling effort that you want to use for modeling nonlinear system. So in such cases where you already have a linear model, you can directly use that for modeling nonlinear systems with Hammerstein-Wiener model.
In this example, I start with a very simple linear model, where I ask my state-space estimation command to suggest a model order. Here, I'm providing the command with the range of orders between 1 to 10, and I'm asking the tool to suggest the right model order for this data. And on running this command, you can see that our model order selection window pops up, and it suggests the model order of 5 for this particular system for the estimation data that we passed on.
And on selecting this model order, and on continuing with estimating this linear model, the linear model gets estimated, linear state-space model with order 5 gets estimated. And with this compare command, we compare the output of the linear model with the data, and we see the results in this plot. So though the output of the linear model is not a great fit with the output of the high-fidelity model, this still serves as a good starting point for nonlinear modeling. Just a quick note here that this linear model can also be used with nonlinear ARX model in a similar manner that I will be showing here.
So what we do next is that, unlike a complete black box technique, here I say that I want to use this linear model to form a part of my nonlinear model to improve the overall fit. With Hammerstein-Wiener models, as we saw in the slide earlier, you can attach static input, and output nonlinearities to this linear model.
So here what I do is I create a Hammerstein-Wiener model where I attach a piecewise-linear nonlinear function with 7 units-- but this is nothing but a piecewise-linear code with 7 breakpoints-- as the input nonlinearity here. And I do the same for the output nonlinearity. And I attach these input and output nonlinearities to the linear model here, which is specified as m0. And I create this Hammerstein-Wiener model with this structure.
And here, with these two lines, I'm also freezing the linear parameters. So what that means is that we will only be identifying or training nonlinear parameters of this model. And, through this, what we're trying to ensure or guarantee is that the nonlinear model we identify is going to be better than the linear one.
And then we go about estimating the Hammerstein-Wiener model. And on running the estimation command, we see the training progress plot, where it trains for 50 epochs according to the training options. And we see that the training is completed.
And once we have the trained agent, we can now validate the model with the estimation data as well as the validation data. And here we see that the nonlinear Hammerstein-Wiener model has provided an improvement over the linear model that we started with. The result that we see here can further be improved by trying different nonlinear functions or by trying different training parameters.
And as we did with prior modeling techniques of neural state-space and nonlinear ARX, we can validate the nonlinear Hammerstein-Wiener model in Simulink in a similar manner by loading the Hammerstein-Wiener object using the built-in Hammerstein-Wiener model block and running the simulation. And here we see that the output of the reduced order model is reasonably fit with the high-fidelity model, and that this can be improved by using different training options or trying out different configurations. But this was just to give you a quick idea of how to start from a linear model and estimate a complex nonlinear model.
Now that we have estimated different types of nonlinear models, we can now use our estimated model in the full vehicle model, where we edit it as one of the variants for modeling engine dynamics. And in this case, I am loading the trained neutral state-space model that we estimated as the reduced order model of the internal combustion engine, and I'm adding that to this closed loop setup.
And on running the simulation, we see that the target creates velocity, and the velocity of the vehicle in this closed-loop setup match in the target subplot, which is the bottom plot here. And you also see the engine torque, which is the output of the reduced order neutral state-space model, in the top subplot. And this model simulates faster than the original high-fidelity simulation model.
To summarize the different techniques we've seen so far, we created and trained a neutral state-space model, where we saw that you can leverage deep learning framework and training methods for dynamic systems without being experts in the field of deep learning. We also saw how you can create and estimate nonlinear ARX and Hammerstein-Wiener models, through which you can include your intuition and knowledge of physics of your system through regressors or through linear models, and combine them with AI techniques offered through nonlinear functions.
So, overall, with these model types, we offer a variety of different configurations through choices of parameters, nonlinear functions, or even regressors that you can try out, and see which of these model types works well for your application. And talking specifically about applications, few of the application areas where we see these nonlinear models created using System Identificaion Toolbox being used are, one, desktop and hardware-in-the-loop simulation.
In this scenario, assume that, where you don't have knowledge of equations of the system or the component you want to model, or if the model you want-- or if the system you want to model is too difficult or impractical, in that case, if you have data from your hardware, you can use the data, and then create nonlinear models to represent those components. So having those components in a way enable you to perform system-level desktop simulation, and also helps you perform hardware-in-the-loop testing through the code generation capabilities. Alternatively, if you have no hardware or lab data, but you have a high-fidelity simulation model but that takes too long to simulate, you can create a reduced order model, like we saw in today's example, that captures essential dynamics with a smaller memory footprint and simulates faster.
And another application is these nonlinear models are also used for virtual sensor modeling, that is, when you want to create models to estimate important signals when sensor is too expensive or when there are no sensors available to measure the signal of interest. Additionally, you can also use the neural state-space model that we looked at in today's webinar as an internal prediction model with Kalman filters for virtual sensor applications.
And extending similar use case for nonlinear control design, you can use the neutral state-space model as an internal prediction model with nonlinear model predictive controllers when the equations of your system of the model that is required as an internal prediction model are too difficult to derive or if the model is computationally expensive. So these are the different application areas where you can look to apply these nonlinear models to.
One thing I want to mention here is that our customers have been successful using our tools and have used it for different applications Ather used the System Identification Toolbox for component modeling of battery cells, which enabled them to perform system-level simulation and control design. B&R Industrial Automation, on the other hand, used System Identification Toolbox for virtual sensor modeling to approximate a motor load from measured input/output data. And Airbus used System Identification Toolbox to tune their plant model parameters using measured flight test data. I have added links to these user stories for your reference. Please feel free to take a look at them to learn more.
So that brings us to the end of this webinar, and I hope I was able to address these key takeaways. And, lastly, I want to leave you all with some additional resources. We have Tech Talks from Brian Douglas on system identification. We also have a good list of nonlinear identification reference examples and a good number of demo videos. Please check them out to learn more about System Identification Toolbox and to get started. This concludes the webinar. Thank you.