Self-Adaptive Physics-Informed Solver#
Module for the self-adaptive physics-informed multi-model solver.
- class SelfAdaptivePhysicsInformedSolver(problem, model, weight_function=Sigmoid(), optimizer_model=None, optimizer_weights=None, scheduler_model=None, scheduler_weights=None, weighting=None, loss=None)[source]#
Bases:
PhysicsInformedMixin,MultiModelSolverMulti-model solver for self-adaptive physics-informed learning problems.
This solver approximates the solution of a differential problem using a trainable model together with condition-wise self-adaptive weights. It is intended for problems whose conditions may include supervised data, equation residuals evaluated on input points, and equation residuals sampled from domains.
Given a model \(\mathcal{M}\), the predicted solution is
\[\hat{\mathbf{u}}(\mathbf{x}) = \mathcal{M}(\mathbf{x}).\]For each condition, the solver introduces trainable pointwise weights. These weights are passed through a user-defined weight function \(m\), typically chosen to keep the effective weights bounded or positive. The resulting weighted objective encourages the model to focus on regions where the residual is larger.
For a problem with governing equation operator \(\mathcal{A}\) in the domain \(\Omega\) and boundary operator \(\mathcal{B}\) on the boundary \(\partial\Omega\), the objective can be written as
\[\mathcal{L}_{\mathrm{problem}} = \frac{1}{N_{\Omega}} \sum_{i=1}^{N_{\Omega}} m(\lambda_{\Omega}^{i}) \mathcal{L} \left( \mathcal{A}[\hat{\mathbf{u}}](\mathbf{x}_i) \right) + \frac{1}{N_{\partial\Omega}} \sum_{i=1}^{N_{\partial\Omega}} m(\lambda_{\partial\Omega}^{i}) \mathcal{L} \left( \mathcal{B}[\hat{\mathbf{u}}](\mathbf{x}_i) \right),\]where \(\lambda_{\Omega}^{i}\) and \(\lambda_{\partial\Omega}^{i}\) are the self-adaptive weights associated with points in \(\Omega\) and \(\partial\Omega\), respectively, and \(\mathcal{L}\) is the selected loss function, typically the mean squared error.
The model parameters and the self-adaptive weights are optimized through a min-max problem:
\[\min_{\theta} \max_{\lambda} \mathcal{L}_{\mathrm{problem}},\]where \(\theta\) denotes the model parameters and \(\lambda\) denotes the collection of self-adaptive weights.
See also
Original reference: McClenny, L. D., & Braga-Neto, U. M. (2023). Self-adaptive physics-informed neural networks. Journal of Computational Physics, 474, 111722. DOI: 10.1016/j.jcp.2022.111722.
Initialization of the
SelfAdaptivePhysicsInformedSolverclass.- Parameters:
problem (BaseProblem) – The problem to be solved.
model (torch.nn.Module) – The model used by the solver.
weight_function (torch.nn.Module) – The weight function used to compute self-adaptive weights. Default is
torch.nn.Sigmoid().optimizer_model (TorchOptimizer) – The optimizer of the main model. If
None, thetorch.optim.Adamoptimizer with a learning rate of0.001is used. Default isNone.optimizer_weights (TorchOptimizer) – The optimizer of the self-adaptive weights. If
None, thetorch.optim.Adamoptimizer with a learning rate of0.001is used. Default isNone.scheduler_model (TorchScheduler) – The scheduler of the main model. If
None, thetorch.optim.lr_scheduler.ConstantLRscheduler with a factor of1.0is used. Default isNone.scheduler_weights (TorchScheduler) – The scheduler of the self-adaptive weights. If
None, thetorch.optim.lr_scheduler.ConstantLRscheduler with a factor of1.0is used. Default isNone.weighting (BaseWeighting) – The weighting strategy used to combine condition losses. If
None, no weighting is applied. Default isNone.loss – The loss function used to compute residual losses. If
None,torch.nn.MSELossis used. Default isNone.
- Raises:
ValueError – If
weight_functionis not atorch.nn.Module.ValueError – If not all domains have been discretised.
- forward(x)[source]#
Forward pass through the model.
- Parameters:
x (torch.Tensor | LabelTensor | Data | Graph) – The input data.
- Returns:
The output of the model.
- Return type:
torch.Tensor | LabelTensor | Data | Graph
- property model#
The single model used by the solver.
- Returns:
The single model used by the solver.
- Return type:
- property weights#
The self-adaptive weights used by the solver.
- Returns:
The self-adaptive weights used by the solver.
- Return type:
- property optimizer_model#
The optimizer for the model used by the solver.
- Returns:
The optimizer for the model used by the solver.
- Return type:
- property optimizer_weights#
The optimizer for the weights used by the solver.
- Returns:
The optimizer for the weights used by the solver.
- Return type:
- property scheduler_model#
The scheduler for the model used by the solver.
- Returns:
The scheduler for the model used by the solver.
- Return type:
- property scheduler_weights#
The scheduler for the weights used by the solver.
- Returns:
The scheduler for the weights used by the solver.
- Return type: