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
.
- on_train_start()[source]#
Hook method called at the beginning of training.
- Raises:
NotImplementedError – If the batch size is not
None
.
- loss_phys(samples, equation)[source]#
Computes the physics loss for the physics-informed solver based on the provided samples and equation.
- Parameters:
samples (LabelTensor) – The samples to evaluate the physics loss.
equation (EquationInterface) – The governing equation.
- Returns:
The computed physics loss.
- Return type: