PhysicsInformedLoss<T>

Models & Types · AiDotNet.PhysicsInformed

Loss function for Physics-Informed Neural Networks (PINNs). Combines data loss, PDE residual loss, boundary condition loss, and initial condition loss.

Inheritance: LossFunctionBase<T> → PhysicsInformedLoss<T>

How It Works

For Beginners: Traditional neural networks learn from data alone. Physics-Informed Neural Networks (PINNs) additionally enforce that the solution satisfies physical laws (PDEs) and constraints.

This loss function has multiple components:

  1. Data Loss: Measures how well predictions match observed data points
  2. PDE Residual Loss: Measures how much the PDE is violated at collocation points
  3. Boundary Loss: Ensures boundary conditions are satisfied
  4. Initial Condition Loss: Ensures initial conditions are satisfied (for time-dependent problems)

The total loss is a weighted sum: L_total = λ_data * L_data + λ_pde * L_pde + λ_bc * L_bc + λ_ic * L_ic

Why This Works: By minimizing this loss, the network learns to:

  • Fit the available data
  • Obey physical laws everywhere (not just at data points)
  • Satisfy boundary and initial conditions

This often requires far less data than traditional deep learning!

Key Innovation: PINNs can solve PDEs in regions where we have NO data, as long as the physics is known.

Constructors

Constructor Summary
PhysicsInformedLoss(IPDESpecification<T> pdeSpecification, IBoundaryCondition<T>[] boundaryConditions, IInitialCondition<T> initialCondition, double? dataWeight, double? pdeWeight, double? boundaryWeight, double? initialWeight) Initializes a new instance of the Physics-Informed loss function.

Properties

Property Summary
string Name { get; } Gets the name of the loss function.

Methods

Method Summary
PhysicsLossGradient<T> ComputePhysicsLossGradients(Vector<T> predictions, Vector<T> targets, PDEDerivatives<T> derivatives, Vector<T> inputs) Computes the physics-informed loss and its gradients with respect to outputs and derivatives.
T CalculateLoss(Vector<T> predicted, Vector<T> actual)
T ComputeLoss(Vector<T> predictions, Vector<T> targets, PDEDerivatives<T> derivatives, Vector<T> inputs) Computes the total physics-informed loss (compatibility wrapper).
T ComputePhysicsLoss(Vector<T> predictions, Vector<T> targets, PDEDerivatives<T> derivatives, Vector<T> inputs) Computes the total physics-informed loss for PINN training.
Tensor<T> ComputeTapeLoss(Tensor<T> predicted, Tensor<T> target)
Tensor<T> ComputeTapePdeLoss(Tensor<T> inputs, Tensor<T> outputs, PDEDerivatives<T> derivatives) The weighted PDE term pde_weight * mean(f^2) over a batch of collocation points, on the gradient tape.