Skip to content

Add Thermal Neural Network (TNN) SciML example#18

Open
mmarkows17 wants to merge 1 commit intomatlab-deep-learning:mainfrom
mmarkows17:publish/thermal-neural-network
Open

Add Thermal Neural Network (TNN) SciML example#18
mmarkows17 wants to merge 1 commit intomatlab-deep-learning:mainfrom
mmarkows17:publish/thermal-neural-network

Conversation

@mmarkows17
Copy link
Collaborator

Adds a Thermal Neural Network (TNN) example demonstrating SciML-based virtual temperature sensor modeling.

% This layer holds a TNNCell instance, and performs prediction over
% tbptt_size time steps.
%
% Copyright 2025 The MathWorks, Inc.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We tend to leave the copyright out of the m-help so it doesn't display on help DiffEqLayer

Comment on lines +1 to +2
classdef DiffEqLayer < nnet.layer.Layer & nnet.layer.Formattable
% DiffEqLayer Differential equation layer
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

![image_0.png](README_media/image_0.png)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) $$
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The stuff below the sums didn't render so well on the GitHub diff.


methods

function this = TNNCell(inputStruct)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants