Competitive Physics-Informed Solver#
Module for the competitive physics-informed multi-model solver.
- class CompetitivePhysicsInformedSolver(problem, model, discriminator=None, optimizer_model=None, optimizer_discriminator=None, scheduler_model=None, scheduler_discriminator=None, weighting=None, loss=None)[source]#
Bases:
PhysicsInformedMixin,MultiModelSolverMulti-model solver for competitive physics-informed learning problems.
This solver approximates the solution of a differential problem using a trainable model together with a discriminator network. 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}).\]The discriminator \(D\) assigns pointwise weights to the residuals, encouraging the model to focus on regions where the approximation performs poorly. The model parameters are optimized by minimizing the loss, while the discriminator parameters are optimized by maximizing it.
For a problem with governing equation operator \(\mathcal{A}\) in the domain \(\Omega\) and boundary operator \(\mathcal{B}\) on the boundary \(\partial\Omega\), the competitive objective can be written as
\[\mathcal{L}_{\mathrm{problem}} = \frac{1}{N_{\Omega}} \sum_{i=1}^{N_{\Omega}} \mathcal{L} \left(D(\mathbf{x}_i)\mathcal{A}[\hat{\mathbf{u}}](\mathbf{x}_i)\right) +\frac{1}{N_{\partial\Omega}} \sum_{i=1}^{N_{\partial\Omega}} \mathcal{L} \left(D(\mathbf{x}_i)\mathcal{B}[\hat{\mathbf{u}}](\mathbf{x}_i)\right),\]where \(D\) is the discriminator network and \(\mathcal{L}\) is the selected loss function, typically the mean squared error.
The model and discriminator are trained through a min-max problem:
\[\min_{\theta} \max_{\phi} \mathcal{L}_{\mathrm{problem}},\]where \(\theta\) denotes the model parameters and \(\phi\) denotes the discriminator parameters.
See also
Original reference: Zeng, Q., Kothari, P., Chou, E., & Masi, G. (2022). Competitive physics informed networks. International Conference on Learning Representations, ICLR 2022. OpenReview Preprint.
Initialization of the
CompetitivePhysicsInformedSolverclass.- Parameters:
problem (BaseProblem) – The problem to be solved.
model (torch.nn.Module) – The model used by the solver.
discriminator (torch.nn.Module) – The discriminator used by the solver. If
None, a deep copy of the model is used as discriminator. Default isNone.optimizer_model (TorchOptimizer) – The optimizer of the main model. If
None, thetorch.optim.Adamoptimizer with a learning rate of0.001is used. Default isNone.optimizer_discriminator (TorchOptimizer) – The optimizer of the discriminator. 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_discriminator (TorchScheduler) – The scheduler of the discriminator. 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 discriminator#
The discriminator used by the solver.
- Returns:
The discriminator 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_discriminator#
The optimizer for the discriminator used by the solver.
- Returns:
The optimizer for the discriminator 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_discriminator#
The scheduler for the discriminator used by the solver.
- Returns:
The scheduler for the discriminator used by the solver.
- Return type: