Add Thermal Neural Network (TNN) SciML example#18
Add Thermal Neural Network (TNN) SciML example#18mmarkows17 wants to merge 1 commit intomatlab-deep-learning:mainfrom
Conversation
| % This layer holds a TNNCell instance, and performs prediction over | ||
| % tbptt_size time steps. | ||
| % | ||
| % Copyright 2025 The MathWorks, Inc. |
There was a problem hiding this comment.
We tend to leave the copyright out of the m-help so it doesn't display on help DiffEqLayer
| classdef DiffEqLayer < nnet.layer.Layer & nnet.layer.Formattable | ||
| % DiffEqLayer Differential equation layer |
There was a problem hiding this comment.
I don't really see a differential equation when I look at the predict implementation - I see either something like recurrence or autoregressive behaviour. I guess in the context of this method it can be seen like an ODE solve.
| % DiffEqLayer Differential equation layer | ||
| % | ||
| % This layer holds a TNNCell instance, and performs prediction over | ||
| % tbptt_size time steps. |
There was a problem hiding this comment.
tbptt_size isn't defined, and it looks like we loop over all steps.
| numSteps = size(input, 3); % Assuming input is [features, batch, time] | ||
|
|
||
| % Preallocate the outputs: | ||
| outputs = dlarray(zeros(size(state,[1 2 3]),'single'),'CBT'); |
There was a problem hiding this comment.
I'd use zeros(sz, like=input) here. Besides taking the precision from the input I think it also helps out the dlarray autodiff system.
| @@ -0,0 +1,37 @@ | |||
| function generatePlots(profileLengths,test_tensor,prediction,scale,targetNames) | |||
There was a problem hiding this comment.
Mix of conventions with test_tensor and targetNames
| mseError = mse(groundTruth,currentPred); | ||
| plot(0:profileLengths(ii)-1,groundTruth, ... | ||
| Color = "green",LineWidth = 1.5) | ||
| hold on |
There was a problem hiding this comment.
Should there be a hold off somewhere too? I think running this function will leave the current figure with a hold on the axes, so any subsequent plot commands by the user would end up on the same axes unless they create a fresh one or turn hold off themselves.
| - Stator tooth | ||
| - Stator winding | ||
|
|
||
|  |
There was a problem hiding this comment.
A descriptive alt text would be better.
|
|
||
| A simplified discrete state equation for each component $i$ of a LPTN model is: | ||
|
|
||
| $$ T_i (k+1)=T_i (k)+t_s \kappa_i (k)\left(\pi_i (k)+\sum_{m\;\in \;components} \gamma_{im} (k)\Delta T_{im} (k)+\sum_{n\;\in \;ancillary} \gamma_{in} (k)\Delta T_{in} (k)\right) $$ |
There was a problem hiding this comment.
The stuff below the sums didn't render so well on the GitHub diff.
|
|
||
| methods | ||
|
|
||
| function this = TNNCell(inputStruct) |
There was a problem hiding this comment.
Using a struct as an input doesn't really tell a user anything about what fields that struct has to contain. This would be clearer with required arguments and optional NVPs with an arguments block.
jess-42
left a comment
There was a problem hiding this comment.
Taken a pass over the repo, focusing on the ReadMe.
|
|
||
| The data set contains various operational measurements from an electric motor, including currents, voltages, torque, speed, and ambient conditions. The TNN model learns to estimate the internal temperatures that would typically require embedded temperature sensors, which are often impractical in production motors. | ||
|
|
||
| This example is intended to be an instructional resource demonstrating how to build and train a TNN in MATLAB. For integration and use with Simulink, see the Github repository [here](https://github.com/wkirgsn/thermal-nn/tree/main/matlab). For video content on this topic, check out this recorded MATLAB Expo talk on [Thermal Neural Network for Temperature Modeling in E-Motors](https://www.mathworks.com/videos/thermal-neural-network-for-temperature-modeling-in-e-motors-1762251869161.html) and this [YouTube video](https://youtu.be/ySRjX9GUiCA?si=s7slG-9Ekt6y9wUe). |
There was a problem hiding this comment.
Can we spell out where the link goes to? I.e.,
For an example showing how to integrate and use this model with Simulink, see the Thermal neural network for electric motor temperature estimation GitHub repository.
|
|
||
| The data set contains various operational measurements from an electric motor, including currents, voltages, torque, speed, and ambient conditions. The TNN model learns to estimate the internal temperatures that would typically require embedded temperature sensors, which are often impractical in production motors. | ||
|
|
||
| This example is intended to be an instructional resource demonstrating how to build and train a TNN in MATLAB. For integration and use with Simulink, see the Github repository [here](https://github.com/wkirgsn/thermal-nn/tree/main/matlab). For video content on this topic, check out this recorded MATLAB Expo talk on [Thermal Neural Network for Temperature Modeling in E-Motors](https://www.mathworks.com/videos/thermal-neural-network-for-temperature-modeling-in-e-motors-1762251869161.html) and this [YouTube video](https://youtu.be/ySRjX9GUiCA?si=s7slG-9Ekt6y9wUe). |
There was a problem hiding this comment.
Similar to other comments, it is good to say where a link is going, rather than just "YouTube video". How about:
For video content on this topic, see the recorded MATLAB Expo talk on Thermal Neural Network for Temperature Modeling in E‑Motors, as well as a related YouTube video.
|
|
||
| # References | ||
| <a id="M_560c"></a> | ||
| 1. Wilhelm Kirchgässner, Oliver Wallscheid, Joachim Böcker, Thermal neural networks: Lumped\-parameter thermal modeling with state\-space machine learning, Engineering Applications of Artificial Intelligence 117 (2023) 105537. [https://doi.org/10.1016/j.engappai.2022.105537](https://doi.org/10.1016/j.engappai.2022.105537) |
There was a problem hiding this comment.
Kirchgässner, Wilhelm, et al. “Thermal Neural Networks: Lumped-Parameter Thermal Modeling with State-Space Machine Learning.” Engineering Applications of Artificial Intelligence, vol. 117, Jan. 2023, p. 105537. DOI.org (Crossref), https://doi.org/10.1016/j.engappai.2022.105537.
|
|
||
|
|
||
|
|
||
| The data set contains measurements from various sensors on an electric motor across multiple test profiles. Each row represents a measurement at a specific time point, and each column represents a different sensor or calculated value. In addition to the measured data the `profile_id` column identifies different test profile. You can use the `profile_id` value to separate the training and testing data. |
There was a problem hiding this comment.
Add comma and plural:
"In addition to the measured data, the profile_id column identifies different test profiles."
| end | ||
| ``` | ||
|
|
||
| Normalize all non\-temperature input columns by dividing by the maximum values. |
| @@ -0,0 +1,142 @@ | |||
| classdef TNNCell < nnet.layer.Layer | |||
There was a problem hiding this comment.
It might be nice throughout to give a 1-line about what each function does, similar to prepareSequenceData.m
| Run the example by running [`ThermalNeuralNetwork.m`](ThermalNeuralNetwork_code.m). | ||
|
|
||
| # **Requirements** | ||
| MATLAB version R2025a is strongly recommended for full functionality. At a minimum, this example requires MATLAB release R2024a or newer as well as Deep Learning Toolbox. |
There was a problem hiding this comment.
What do I miss out out by not having the latest version? Does this example also only require MATLAB + DLT?
|
|
||
| This example is intended to be an instructional resource demonstrating how to build and train a TNN in MATLAB. For integration and use with Simulink, see the Github repository [here](https://github.com/wkirgsn/thermal-nn/tree/main/matlab). For video content on this topic, check out this recorded MATLAB Expo talk on [Thermal Neural Network for Temperature Modeling in E-Motors](https://www.mathworks.com/videos/thermal-neural-network-for-temperature-modeling-in-e-motors-1762251869161.html) and this [YouTube video](https://youtu.be/ySRjX9GUiCA?si=s7slG-9Ekt6y9wUe). | ||
|
|
||
| # **Setup** |
There was a problem hiding this comment.
Consider changing this to "Get Started" as this is all you need to do to get started with the repo.
| <a id="M_560c"></a> | ||
| 1. Wilhelm Kirchgässner, Oliver Wallscheid, Joachim Böcker, Thermal neural networks: Lumped\-parameter thermal modeling with state\-space machine learning, Engineering Applications of Artificial Intelligence 117 (2023) 105537. [https://doi.org/10.1016/j.engappai.2022.105537](https://doi.org/10.1016/j.engappai.2022.105537) | ||
|
|
||
| # **Prepare Data for Training** |
There was a problem hiding this comment.
I'm assuming you have the full example here for discoverability, but it does give a bit of whiplash to suddenly start preparing data after reading the references.
There was a problem hiding this comment.
Consider resizing the plot during training, this will make the text easier to read.
Adds a Thermal Neural Network (TNN) example demonstrating SciML-based virtual temperature sensor modeling.