NeuralFMU: Presenting a Workflow for Integrating Hybrid NeuralODEs into Real-World Applications
Abstract
:1. Introduction
1.1. State of the Art: Hybrid Modeling
- Real-world models from common modeling tools are in general not available as symbolic ODEs;
- NeuralODE training tends to converge in local minima;
- NeuralODE training often takes a considerable amount of calculation time.
1.2. Preliminary Work: NeuralFMUs
- Real measurement data: Training on real data raises challenges, such as noise and drifts. Whereas (small) uniformly distributed measurement noise may even improve the hybrid model’s quality by reducing overfitting, static sensor drifts must be identified and corrected. This can be completed with a state-correcting ANN, as highlighted later.
- Closed-loop controllers: Controlled systems may behave unexpectedly if the state dynamics are modified. Manipulating the dynamics of a controlled quantity forces the controller to compensate for these manipulations. On the other hand, this also offers possibilities. In the example of a velocity-controlled system introduced later, additional forces can be injected without changing the control value (velocity), as long the controller is robust enough to respond to the changes.
- Unknown system states: Dynamic systems in the industry often count many states. If a real demonstrator is used for data generation, usually not every state can be measured. This is a problem because the initial values of the system state are needed to solve the ODE inside of the FMU. If the data from computer simulations are sufficient, this is not an issue because, in general, simulation tools provide the capability to save every needed computation value.
- High-frequency discontinuities: As further introduced in Section 2.1, it is common to model ultra-fast continuous effects as discrete events. This way, instead of forcing the ODE solver to perform very small time steps, the solver is re-initialized after the event instance. This reset must be taken into account for the sensitivity determination. If the amount of time to reset the solver is smaller than the time to solve the original continuous system part, computation time can be saved. On the other hand, the excessive use of discontinuities, as in high-frequency sample-and-hold blocks, leads to long simulation times. Even if this can be avoided in many cases, it is a common modeling practice and needs to be taken into account.
2. Materials and Methods
2.1. Functional Mock-Up Interface (FMI)
2.2. NeuralODEs & NeuralFMUs
2.3. Software
2.3.1. Julia Programming Language
2.3.2. FMI in Julia: FMI.jl
Listing 1. Simulating FMUs with FMI.jl. |
2.3.3. NeuralFMUs in Julia: FMIFlux.jl
Listing 2. Setup and training of an ME-NeuralFMU as in Figure 3 with n states in Julia. |
- The FMU variables used as the layer inputs and outputs. Any variable that is accessible via fmi2SetReal or fmi2SetContinuousStates is a potential layer input, and any variable that can be obtained by fmi2GetReal or fmi2GetDerivatives can serve as a layer output;
- The number and positions of the FMUs inside the ANN topology as long as the signal traceability via AD is given.
2.4. Workflow
- The FPM is designed by a domain expert inside a familiar modeling tool that supports FMIs (export and import).
- After modeling, the FPM is exported as the FMU.
- The FPM–FMU is imported into Julia using FMI.jl.
- The FPM is extended to a hybrid model and trained on data, for example, of a real system or a high-resolution and high-fidelity simulation, using FMIFlux.jl. Simulation of the trained hybrid model and export of the simulation data is possible directly in Julia.
- The following steps are optional. The trained hybrid model may be exported as an FMU using FMI.jl.
- The hybrid model FMU may be imported into the original modeling environment or another simulation tool with FMI support.
- The improved hybrid model FMU may further be used as a stand-alone or as part of larger co-simulations, such as for example the distributed simulation framework in [27].
2.5. Data Pre- and Post-Processing
2.6. Initialization (Pre-Training)
2.6.1. Neutral Initialization Pre-Training (NIPT)
2.6.2. Collocation Pre-Training (CCPT)
2.6.3. FPM/ANN Gates
2.7. Batching & Training
3. Results
3.1. Example Model: Vehicle Longitudinal Dynamics Model (VLDM)
- the PI-controller state (integrated error) for the throttle pedal (Driver);
- the PI-controller state (integrated error) for the brake pedal (Driver);
- the integrated driving cycle speed and the cycle position (Driving cycle);
- the vehicle position (Vehicle dynamics);
- the vehicle velocity (Vehicle dynamics);
- the cumulative consumption (energy).
- the PI-controller error/deviation for the throttle pedal (Driver);
- the PI-controller error/deviation for the brake pedal (Driver);
- the driving cycle speed (Driving cycle);
- the vehicle velocity (Vehicle dynamics);
- the vehicle acceleration (Vehicle dynamics);
- the current consumption (power).
- The system is highly discontinuous, meaning it has a significant amount of explicitly time-dependent events (100 events per second). This further limits the maximum time step size for the numerical solver and therefore worsens the simulation and training performance;
- The simulation contains a closed-loop over multiple subsystems with two controllers running at 100 Hz (the source of the high-frequency time events);
- The system contains a large amount of state-dependent events, triggered by 22 event indicators;
- Measurements of the real system are not equidistant in time (even if it was saved this way, which introduces a typical measurement error);
- Only a subpart of the system state vector is part of the measurements, the remaining parts are estimated;
- The measurements are not exact and contain typical, sensor- and filter-specific errors (such as noise and oscillation);
- There is a hysteresis loop for the activation of the throttle and brake pedal. The PI-controller states are initialized at corresponding edges of the hysteresis loop;
- The system is highly non-linear, e.g., multiple quantities are saturated;
- Characteristic maps (data models) for the electric power, inverted electric power and the electric power losses are used.
3.2. Topology
- corresponds to the vehicle speed, acceleration and power (current consumption). These are the inputs for the ANN;
- corresponds to the estimated vehicle acceleration by the ANN. This is the output of the ANN (technically, it is the only output because the other five dynamics are assumed always to be zero and are neglected);
- . Only the influence of the vehicle acceleration from the ANN can be controlled via (this is the only ANN output);
- . Only the influence of the vehicle acceleration from the FMU can be controlled via (all other derivatives contribute 100%).
3.3. Consumption Prediction
3.3.1. Training
3.3.2. Testing (Validation)
4. Conclusions
Author Contributions
Funding
Institutional Review Board Statement
Informed Consent Statement
Data Availability Statement
Acknowledgments
Conflicts of Interest
Abbreviations
AD | Automatic Differentiation |
ANN | Artifical Neural Networks |
BNSDE | Bayesian Neural Stochastic Differential Equations |
CADC | Common Artemis Driving Cycles |
CCPT | Collocation Pre-Training |
CS | Co-Simulations |
DAE | Differential-Algebraic Systems of Equations |
DARN | Deep Auto-Regressive Networks |
FMI | Functional Mock-up Interface |
FMU | Functional Mock-up Unit |
FPM | First-Principle Models |
HiL | Hardware in the Loop |
ME | Model Exchange |
ML | Machine Learning |
MSE | Mean Squared Error |
NEDC | New European Driving Cycle |
NIPT | Neutral Initialization Pre-Training |
ODE | Ordinary Differential Equation |
PAC | Probably Approximately Correct |
PDE | Partial Differential Equations |
PINN | Physics-Informed Neural Network |
RNN | Recurrent Neural Network |
SE | Scheduled Execution |
SSP | System Structure and Parameterization |
VLDM | Vehicle Longitudinal Dynamics Model |
WLTC | Worldwide Harmonized Light-Duty Vehicles Test Cycle |
References
- Raissi, M.; Perdikaris, P.; Karniadakis, G. Physics-informed neural networks: A deep learning framework for solving forward and inverse problems involving nonlinear partial differential equations. J. Comput. Phys. 2019, 378, 686–707. [Google Scholar] [CrossRef]
- Haussmann, M.; Gerwinn, S.; Look, A.; Rakitsch, B.; Kandemir, M. Learning Partially Known Stochastic Dynamics with Empirical PAC Bayes. arXiv 2021, arXiv:cs.LG/2006.09914. [Google Scholar]
- Gregor, K.; Danihelka, I.; Mnih, A.; Blundell, C.; Wierstra, D. Deep AutoRegressive Networks. ACM Digit. Libr. 2013, 32, 242–250. [Google Scholar] [CrossRef]
- Bruder, F.; Mikelsons, L. Modia and Julia for Grey Box Modeling. In Proceedings of the 14th Modelica Conference 2021, Linköping, Sweden, 20–24 September 2021; pp. 87–95. [Google Scholar] [CrossRef]
- Rai, R.; Sahu, C.K. Driven by Data or Derived Through Physics? A Review of Hybrid Physics Guided Machine Learning Techniques With Cyber-Physical System (CPS) Focus. IEEE Access 2020, 8, 71050–71073. [Google Scholar] [CrossRef]
- Willard, J.; Jia, X.; Xu, S.; Steinbach, M.; Kumar, V. Integrating Physics-Based Modeling with Machine Learning: A Survey. arXiv 2020, arXiv:physics.comp-ph/2003.04919. [Google Scholar]
- Chen, T.Q.; Rubanova, Y.; Bettencourt, J.; Duvenaud, D. Neural Ordinary Differential Equations. arXiv 2018, arXiv:1911.07532. [Google Scholar]
- Innes, M.; Edelman, A.; Fischer, K.; Rackauckas, C.; Saba, E.; Shah, V.B.; Tebbutt, W. A Differentiable Programming System to Bridge Machine Learning and Scientific Computing. arXiv 2019, arXiv:1907.07587. [Google Scholar]
- Thummerer, T.; Mikelsons, L.; Kircher, J. NeuralFMU: Towards structural integration of FMUs into neural networks. In Proceedings of the 14th Modelica Conference 2021, Linköping, Sweden, 20–24 September 2021. [Google Scholar] [CrossRef]
- Thummerer, T.; Tintenherr, J.; Mikelsons, L. Hybrid modeling of the human cardiovascular system using NeuralFMUs. J. Phys. Conf. Ser. 2021, 2090, 012155. [Google Scholar] [CrossRef]
- Modelica Association. Homepage of the FMI-Standard. Available online: https://fmi-standard.org/ (accessed on 28 September 2022).
- Modelica Association. Functional Mock-Up Interface for Model Exchange and Co-Simulation, Document Version: 2.0.2; Technical Report; Modelica Association: Linköping, Sweden, 2020. [Google Scholar]
- Modelica Association. Functional Mock-Up Interface Specification, Document Version: 3.0; Technical Report; Modelica Association: Linköping, Sweden, 2022. [Google Scholar]
- Modelica Association. System Structure and Parameterization, Document Version: 1.0; Technical Report; Modelica Association: Linköping, Sweden, 2019. [Google Scholar]
- SciML, Julia Computing. DiffEqFlux.jl Repository on GitHub. Available online: https://github.com/SciML/DiffEqFlux.jl (accessed on 28 September 2022).
- Rackauckas, C.; Innes, M.; Ma, Y.; Bettencourt, J.; White, L.; Dixit, V. DiffEqFlux.jl-A Julia Library for Neural Differential Equations. arXiv 2019, arXiv:1902.02376. [Google Scholar]
- Bezanson, J.; Edelman, A.; Karpinski, S.; Shah, V.B. Julia: A Fresh Approach to Numerical Computing. arXiv 2015, arXiv:1411.1607. [Google Scholar] [CrossRef] [Green Version]
- Revels, J.; Lubin, M.; Papamarkou, T. Forward-Mode Automatic Differentiation in Julia. arXiv 2016, arXiv:1607.07892. [Google Scholar]
- Revels, J.; Papamarkou, T.; Lubin, L.; Other Contributors. Available online: https://github.com/JuliaDiff/ForwardDiff.jl (accessed on 28 September 2022).
- Innes, M. Don’t Unroll Adjoint: Differentiating SSA-Form Programs. arXiv 2018, arXiv:1810.07951. [Google Scholar]
- Julia Computing, Inc.; Innes, M.J.; Other Contributors. Zygote.jl Repository on GitHub. Available online: https://github.com/FluxML/Zygote.jl (accessed on 28 September 2022).
- Elmqvist, H.; Neumayr, A.; Otter, M. Modia-Dynamic Modeling and Simulation with Julia. In Proceedings of the Juliacon 2018, London, UK, 26 November 2018; Available online: https://elib.dlr.de/124133/ (accessed on 28 September 2022).
- Elmqvist, H.; DLR Institute of System Dynamics and Control. Modia.jl Repository on GitHub. Available online: https://github.com/ModiaSim/Modia.jl (accessed on 28 September 2022).
- Thummerer, T.; Mikelsons, L.; Kircher, J.; Other Contributors. FMI.jl Repository on GitHub. Available online: https://github.com/ThummeTo/FMI.jl (accessed on 28 September 2022).
- Thummerer, T.; Mikelsons, L. FMIFlux.jl Repository on GitHub. Available online: https://github.com/ThummeTo/FMIFlux.jl (accessed on 28 September 2022).
- Julia Computing, Inc.; Innes, M.J.; Other Contributors. Flux.jl Repository on GitHub. Available online: https://github.com/FluxML/Flux.jl (accessed on 28 September 2022).
- Gorecki, S.; Possik, J.; Zacharewicz, G.; Ducq, Y.; Perry, N. A Multicomponent Distributed Framework for Smart Production System Modeling and Simulation. Sustainability 2020, 12, 6969. [Google Scholar] [CrossRef]
- Roesch, E.; Rackauckas, C.; Stumpf, M. Collocation based training of neural ordinary differential equations. Stat. Appl. Genet. Mol. Biol. 2021, 20, 25. [Google Scholar] [CrossRef]
- Kalman, R.E. A New Approach to Linear Filtering and Prediction Problems. J. Basic Eng. 1960, 82, 35–45. [Google Scholar] [CrossRef]
- Turan, E.M.; Jäschke, J. Multiple Shooting for Training Neural Differential Equations on Time Series. IEEE Control Syst. Lett. 2022, 6, 1897–1902. [Google Scholar] [CrossRef]
- Danquah, B.; Koch, A.; Weis, T.; Lienkamp, M.; Pinnel, A. Modular, Open Source Simulation Approach: Application to Design and Analyze Electric Vehicles. In Proceedings of the IEEE 2019 Fourteenth International Conference on Ecological Vehicles and Renewable Energies (EVER), Monte Carlo, Monaco, 8–10 May 2019; pp. 1–8. [Google Scholar] [CrossRef]
- Guzzella, L.; Sciarretta, A. Vehicle Propulsion Systems: Introduction to Modeling and Optimization, 3rd ed.; Springer: Berlin/Heidelberg, Germany, 2013. [Google Scholar]
- Danquah, B. Component Library for Full Vehicle Simulations Repository on GitHub. Available online: https://github.com/TUMFTM/Component_Library_for_Full_Vehicle_Simulations (accessed on 28 September 2022).
- Kingma, D.P.; Ba, J. Adam: A Method for Stochastic Optimization. arXiv 2014, arXiv:1412.6980. [Google Scholar]
Index | Type | Activation | Inputs | Outputs | Bias | Parameters |
---|---|---|---|---|---|---|
1 | Pre-process | none | 3 | 3 | 0 | 6 |
2 | Dense | tanh | 3 | 32 | 32 | 128 |
3 | Dense | tanh | 32 | 1 | 1 | 33 |
4 | Post-process | none | 1 | 1 | 0 | 0 |
5 | Gates | none | 1 | 1 | 0 | 2 |
Sum: 169 |
Model | Cycle | MSE (W2s2) | Max. Error (Ws) | Final Error (Ws) | Sim. Time (s) | Solver Steps | Triggered Events |
---|---|---|---|---|---|---|---|
FMU | CADC Road | 460,185.79 | −453.614.80 | 10.29 | 110,294 | 110,247 | |
NeuralFMU | CADC Road | 63,558.61 | −55,610.81 | 110,301 | 110,247 | ||
FMU | WLTC Class 2 | 249,693.13 | −248,286.71 | 144,569 | 144,519 | ||
NeuralFMU | WLTC Class 2 | 79,822.16 | 15,463.58 | 144,590 | 144,519 |
Publisher’s Note: MDPI stays neutral with regard to jurisdictional claims in published maps and institutional affiliations. |
© 2022 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).
Share and Cite
Thummerer, T.; Stoljar, J.; Mikelsons, L. NeuralFMU: Presenting a Workflow for Integrating Hybrid NeuralODEs into Real-World Applications. Electronics 2022, 11, 3202. https://doi.org/10.3390/electronics11193202
Thummerer T, Stoljar J, Mikelsons L. NeuralFMU: Presenting a Workflow for Integrating Hybrid NeuralODEs into Real-World Applications. Electronics. 2022; 11(19):3202. https://doi.org/10.3390/electronics11193202
Chicago/Turabian StyleThummerer, Tobias, Johannes Stoljar, and Lars Mikelsons. 2022. "NeuralFMU: Presenting a Workflow for Integrating Hybrid NeuralODEs into Real-World Applications" Electronics 11, no. 19: 3202. https://doi.org/10.3390/electronics11193202
APA StyleThummerer, T., Stoljar, J., & Mikelsons, L. (2022). NeuralFMU: Presenting a Workflow for Integrating Hybrid NeuralODEs into Real-World Applications. Electronics, 11(19), 3202. https://doi.org/10.3390/electronics11193202