RBAPINN#
- class RBAPINN(problem, model, optimizer=None, scheduler=None, weighting=None, loss=None, eta=0.001, gamma=0.999)[source]#
Bases:
PINN
Residual-based Attention Physics-Informed Neural Network (RBAPINN) solver class. This class implements the Residual-based Attention Physics-Informed Neural Network solver, using a user specified
model
to solve a specificproblem
. It can be used to solve both forward and inverse problems.The Residual-based Attention Physics-Informed Neural Network solver aims to find the solution \(\mathbf{u}:\Omega\rightarrow\mathbb{R}^m\) of a differential problem:
\[\begin{split}\begin{cases} \mathcal{A}[\mathbf{u}](\mathbf{x})=0\quad,\mathbf{x}\in\Omega\\ \mathcal{B}[\mathbf{u}](\mathbf{x})=0\quad, \mathbf{x}\in\partial\Omega \end{cases}\end{split}\]minimizing the loss function:
\[\mathcal{L}_{\rm{problem}} = \frac{1}{N} \sum_{i=1}^{N_\Omega} \lambda_{\Omega}^{i} \mathcal{L} \left( \mathcal{A} [\mathbf{u}](\mathbf{x}) \right) + \frac{1}{N} \sum_{i=1}^{N_{\partial\Omega}} \lambda_{\partial\Omega}^{i} \mathcal{L} \left( \mathcal{B}[\mathbf{u}](\mathbf{x}) \right),\]denoting the weights as: \(\lambda_{\Omega}^1, \dots, \lambda_{\Omega}^{N_\Omega}\) and \(\lambda_{\partial \Omega}^1, \dots, \lambda_{\Omega}^{N_\partial \Omega}\) for \(\Omega\) and \(\partial \Omega\), respectively.
Residual-based Attention Physics-Informed Neural Network updates the weights of the residuals at every epoch as follows:
\[\lambda_i^{k+1} \leftarrow \gamma\lambda_i^{k} + \eta\frac{\lvert r_i\rvert}{\max_j \lvert r_j\rvert},\]where \(r_i\) denotes the residual at point \(i\), \(\gamma\) denotes the decay rate, and \(\eta\) is the learning rate for the weights’ update.
See also
Original reference: Sokratis J. Anagnostopoulos, Juan D. Toscano, Nikolaos Stergiopulos, and George E. Karniadakis. Residual-based attention and connection to information bottleneck theory in PINNs. Computer Methods in Applied Mechanics and Engineering 421 (2024): 116805 DOI: 10.1016/j.cma.2024.116805.
Initialization of the
RBAPINN
class.- Parameters:
problem (AbstractProblem) – The problem to be solved.
model (torch.nn.Module) – The neural network model to be used.
optimizer (Optimizer) – The optimizer to be used. If
None
, thetorch.optim.Adam
optimizer is used. Default isNone
.scheduler (Scheduler) – Learning rate scheduler. If
None
, thetorch.optim.lr_scheduler.ConstantLR
scheduler is used. Default isNone
.weighting (WeightingInterface) – The weighting schema to be used. If
None
, no weighting schema is used. Default isNone
.loss (torch.nn.Module) – The loss function to be minimized. If
None
, thetorch.nn.MSELoss
loss is used. Default isNone
.eta (float | int) – The learning rate for the weights of the residuals. Default is
0.001
.gamma (float) – The decay parameter in the update of the weights of the residuals. Must be between
0
and1
. Default is0.999
.
- Raises:
ValueError if
gamma
is not in the range (0, 1).- Raises:
ValueError if
eta
is not greater than 0.
- on_train_start()[source]#
Ensure that all residual weight buffers registered during initialization are moved to the correct computation device.
- training_step(batch, batch_idx, **kwargs)[source]#
Solver training step. It computes the optimization cycle and aggregates the losses using the
weighting
attribute.- Parameters:
- Returns:
The loss of the training step.
- Return type:
- validation_step(batch, **kwargs)[source]#
The validation step for the PINN solver. It returns the average residual computed with the
loss
function not aggregated.