Physics-Informed Neural Network for Motor Thermal Prediction
ThermoPINN combines data-driven sequence modeling with first-principles thermal physics to predict stator winding temperatures of electric machines. It merges an LSTM-based temporal network with an RC thermal model constraint, creating a hybrid model that respects both data and physics.
This approach enables:
- Accurate long-term temperature prediction
- Consistency with energy conservation and thermal dynamics
- Reduced need for labeled data
- Robust generalization across operating conditions
git clone https://github.com/yourusername/ThermoPINN.git
cd ThermoPINN
pip install -r requirements.txtThis project uses the Electric Motor Temperature Dataset:
Wilhelm Kirchgässner, Oliver Wallscheid, and Joachim Böcker. (2021).
Electric Motor Temperature [Data set]. Kaggle.
https://doi.org/10.34740/KAGGLE/DSV/2161054
You can download the dataset directly from Kaggle and place it into the data/ folder of the repository.
Electric motor thermal behavior is typically modeled using lumped-parameter RC networks, where heat flow between nodes (stator, housing, coolant, etc.) follows differential equations derived from the heat balance law. However, these models rely on difficult-to-identify parameters (thermal resistances and capacitances), limiting accuracy in varying conditions.
Pure neural networks, in contrast, capture nonlinear relationships but often violate physical constraints and generalize poorly outside training regimes. ThermoPINN bridges this gap by embedding the RC-model physics directly into the learning objective.
A standard first-order RC model for the temperature hotspot
where:
-
$C_{th}$ : thermal capacitance [J/K] -
$R_{th}$ : thermal resistance [K/W] -
$P_{loss}$ : power loss input [W] -
$T_{amb}$ : ambient or coolant temperature [°C]
Rearranging gives the temperature dynamics, this ODE defines the governing physics constraint
The LSTM network learns to approximate the mapping:
where:
-
$X_t = [P_{loss}(t), T_{amb}(t), \dots]$ is the multivariate input sequence -
$f_\theta$ denotes the LSTM with parameters$\theta$
The model predicts the temperature trajectory over time using sequential dependencies.
The total loss combines data-driven and physics-informed components:
Supervised error between predicted and measured temperatures:
Enforces the ODE constraint using automatic differentiation:
The derivative torch.autograd.grad) or
approximated via temperature gradients using Euler Forward/Backward or trapezoidal rule.
Input features are normalized and fed to the network using a sliding window approach:
$$
X_t = [x_{t-w+1}, \dots, x_t]
$$
where
class LSTM_PINN(nn.Module):
def __init__(self, input_dim, output_dim, hidden_dim=128, num_layers=2, dropout=0.2):
super().__init__()
self.lstm = nn.LSTM(input_dim, hidden_dim, num_layers, batch_first=True, dropout=dropout)
self.fc = nn.Linear(hidden_dim, output_dim)
def forward(self, x):
out, _ = self.lstm(x)
out = self.fc(out)
return outTable I: Results for NN and PINN models on the generalization set (ID60, ID62, ID74) in terms of MSE / MAE / MAX error.
| Test ID | MSE (NN / PINN) | MAE (NN / PINN) | MAX (NN / PINN) |
|---|---|---|---|
| 60 | 9.70 / 3.59 | 2.02 / 1.09 | 17.7 / 14.6 |
| 62 | 5.04 / 2.08 | 1.63 / 0.77 | 17.6 / 12.8 |
| 74 | 2.78 / 2.07 | 1.35 / 1.06 | 5.78 / 9.31 |
| Avg | 5.26 / 2.41 | 1.61 / 0.95 | 17.7 / 14.6 |
| NN Result | PINN Result |
|---|---|
![]() |
![]() |
Performing 10-fold cross-validation by training ten models, after removing IDs 60, 62, 74 as a hold-out generalisation test set, the following performance is obtained for each of the ten models (left PINN/ right NN):
Fold 0: MSE=2.6824, MAE=1.0193, R2=0.9964, MAX=13.2819 / MSE=4.3614, MAE=1.3816, R2=0.9941, MAX=17.7026
Fold 1: MSE=2.5699, MAE=1.0912, R2=0.9965, MAX=15.3820 / MSE=5.7220, MAE=1.7847, R2=0.9922, MAX=16.8528
Fold 2: MSE=4.2839, MAE=1.5628, R2=0.9942, MAX=12.8137 / MSE=5.9230, MAE=1.6849, R2=0.9919, MAX=19.4199
Fold 3: MSE=2.5640, MAE=1.1065, R2=0.9965, MAX=14.0120 / MSE=4.8526, MAE=1.5688, R2=0.9934, MAX=20.1742
Fold 4: MSE=7.5126, MAE=2.1228, R2=0.9898, MAX=12.7229 / MSE=5.1198, MAE=1.4844, R2=0.9930, MAX=19.0554
Fold 5: MSE=3.3325, MAE=1.3359, R2=0.9955, MAX=13.3533 / MSE=5.2259, MAE=1.5350, R2=0.9929, MAX=15.9624
Fold 6: MSE=2.7120, MAE=1.2651, R2=0.9963, MAX=12.2236 / MSE=12.099, MAE=2.4498, R2=0.9835, MAX=15.2632
Fold 7: MSE=2.5097, MAE=1.1276, R2=0.9966, MAX=15.1577 / MSE=4.1078, MAE=1.4594, R2=0.9944, MAX=19.3918
Fold 8: MSE=2.6025, MAE=1.1967, R2=0.9965, MAX=13.4628 / MSE=4.3721, MAE=1.3362, R2=0.9941, MAX=20.0484
Fold 9: MSE=2.2765, MAE=1.1289, R2=0.9969, MAX=15.8944 / MSE=4.3797, MAE=1.4280, R2=0.9940, MAX=18.5930Averaging these results leads to the following average performance for the generalisation test set (ID 60, 62, 74) including the standard deviation (left PINN/ right NN):
MSE = 3.3046 ± 1.5873 / MSE = 5.6164 ± 2.3580
MAE = 1.2957 ± 0.3296 / MAE = 1.6113 ± 0.3245
R2 = 0.9955 ± 0.0022 / R2 = 0.9924 ± 0.0032
MAX = 13.830 ± 1.2458 / MAX = 18.246 ± 1.7250The results demonstrate that incorporating physical constraints through the PINN formulation yields a consistent performance improvement over the purely data-driven neural network:
-
Lower MSE and MAE across all test cases:
The PINN achieves roughly 50–60 % lower MSE and ~40 % lower MAE, indicating a smoother and more physically consistent temperature trajectory. -
Reduced generalization gap:
Even when trained on limited operating conditions, the PINN generalizes better to unseen load and speed profiles. This is attributed to the physics residual acting as a regularization term, discouraging unrealistic temperature fluctuations. -
Interpretation of MAX errors:
While both models can occasionally produce larger instantaneous deviations (e.g., rapid transients), the PINN consistently limits overshooting due to its adherence to the RC heat balance constraint. The slightly higher MAX error for test ID 74 (9.31 °C vs 5.78 °C) likely results from the RC simplification, which cannot fully capture spatially distributed effects under fast thermal gradients.
- The NN model follows the data closely but sometimes violates thermal time-constant behavior, producing short-term oscillations or unrealistically fast cooling.
- The PINN model enforces the first-order RC dynamics, resulting in monotonic heating and cooling consistent with physical laws.
- This not only improves accuracy, but also enhances interpretability and robustness — an essential aspect for deployment in embedded thermal monitoring systems.
To improve the maximum error during the session we can try to learn the initial state at the beginning of a session
and capture it in
| Metric | NN | PINN | PINN + Init |
|---|---|---|---|
| MSE | 5.6164 ± 2.3580 | 3.3046 ± 1.5873 | 2.8894 ± 0.4656 |
| MAE | 1.6113 ± 0.3245 | 1.2957 ± 0.3296 | 1.2298 ± 0.1428 |
| R2 | 0.9924 ± 0.0032 | 0.9955 ± 0.0022 | 0.9961 ± 0.0006 |
| MAX | 18.246 ± 1.7250 | 13.830 ± 1.2458 | 12.020 ± 1.2282 |
The Physics-Informed Neural Network effectively bridges data-driven learning and first-principles modeling.
By constraining the network with thermal dynamics, ThermoPINN achieves higher generalization performance while maintaining physically meaningful predictions.

