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.
Adds a Thermal Neural Network (TNN) example demonstrating SciML-based virtual temperature sensor modeling.