VariationalPINN<T>
Models & Types · AiDotNet.PhysicsInformed.PINNs
Implements Variational Physics-Informed Neural Networks (VPINNs).
Inheritance: NeuralNetworkBase<T> → VariationalPINN<T>
How It Works
For Beginners: Variational PINNs (VPINNs) use the weak (variational) formulation of PDEs instead of the strong form. This is similar to finite element methods (FEM).
Strong vs. Weak Formulation:
Strong Form (standard PINN):
- PDE must hold pointwise: PDE(u) = 0 at every point
- Example: -∇²u = f everywhere
- Requires computing second derivatives
- Solution must be twice differentiable
Weak Form (VPINN):
- PDE holds “on average” against test functions
- ∫∇u·∇v dx = ∫fv dx for all test functions v
- Integration by parts reduces derivative order
- Solution only needs to be once differentiable
- More stable numerically
Key Advantages:
- Lower derivative requirements (better numerical stability)
- Natural incorporation of boundary conditions (through integration by parts)
- Can handle discontinuities and rough solutions better
- Closer to FEM (well-understood mathematical theory)
- Often better convergence properties
How VPINNs Work:
- Choose test functions (often neural networks themselves)
- Multiply PDE by test function and integrate
- Use integration by parts to reduce derivative order
- Minimize the residual in the weak sense
Example - Poisson Equation: Strong: -∇²u = f Weak: ∫∇u·∇v dx = ∫fv dx (after integration by parts)
VPINNs train the network u(x) to satisfy the weak form for all test functions v.
Applications:
- Same as PINNs, but particularly useful for:
- Problems with rough solutions
- Conservation laws
- Problems where weak solutions are more natural
- High-order PDEs (where reducing derivative order helps)
Comparison with Standard PINNs:
- VPINN: More stable, lower derivative requirements, closer to FEM
- Standard PINN: Simpler to implement, direct enforcement of PDE
The variational formulation often provides better training dynamics and accuracy.
Example
var architecture = new NeuralNetworkArchitecture<float>(
inputType: InputType.OneDimensional,
taskType: NeuralNetworkTaskType.Regression,
inputSize: 2, outputSize: 1);
var vpinn = new VariationalPINN<float>(architecture, VariationalWeakForm<float>.Poisson(1.0f));
Constructors
| Constructor | Summary |
|---|---|
VariationalPINN(NeuralNetworkArchitecture<T> architecture, Func<Tensor<T>, Tensor<T>, Tensor<T>, Tensor<T>, Tensor<T>, Tensor<T>> weakFormResidual, VariationalPINNOptions options) |
Initializes a new instance of the Variational PINN. |
Properties
| Property | Summary |
|---|---|
bool SupportsTraining { get; } |
Serializes VPINN-specific data. |
Methods
| Method | Summary |
|---|---|
ModelMetadata<T> GetModelMetadata() |
Gets metadata about the VPINN model. |
T ComputeWeakResidual(int testFunctionIndex) |
Computes the weak form residual R_k = int R(x, u, grad u, v_k, grad v_k) dx by quadrature. |
Tensor<T> Forward(Tensor<T> input) |
Performs a forward pass through the network. |
Vector<T> GetSolution(Vector<T> point) |
Gets the solution at a specific point. |