A modular, high-precision scientific machine learning repository implementing Artificial Neural Networks (ANNs) and Deep Feed-Forward Neural Networks (FFNNs) in PyTorch for solving linear, non-linear, oscillatory, higher-order, and coupled Ordinary Differential Equations (ODEs).
This repository is built upon the foundational mathematical framework introduced by I. E. Lagaris, A. Likas, and D. I. Fotiadis (IEEE Transactions on Neural Networks, 1998).
While soft-constrained neural solvers often enforce boundary and initial conditions as penalty terms in the objective function:
This soft formulation introduces hyperparameter sensitivity (
In contrast, the Lagaris formulation parametrizes the approximate solution as an analytically constructed trial solution:
where:
-
$A(x)$ satisfies the initial/boundary conditions unconditionally (contains no trainable weights). -
$B(x)$ is an algebraic envelope designed such that$B(x_0) = 0$ (and$B'(x_0) = 0$ for derivative initial conditions). -
$N(x, \mathbf{p})$ is the output of a feed-forward neural network parameterized by trainable weights and biases$\mathbf{p}$ .
Key Theoretical Advantage: Because
$B(x_0) = 0$ , the initial condition$\Psi_t(x_0) = A(x_0) = \Psi_0$ is strictly and analytically satisfied for ANY arbitrary network parameters$\mathbf{p}$ . Boundary error is mathematically zero throughout the entire optimization process.
The network is trained on a discrete collocation grid
Derivatives torch.autograd.grad(..., create_graph=True)), avoiding truncation errors associated with finite difference approximations.
| File | Problem Type | Mathematical Equation | Domain & Conditions | Exact Solution |
|---|---|---|---|---|
problem1_first_order.py |
1st-Order Rational ODE (Lagaris #1) | |||
problem2_oscillatory.py |
1st-Order Oscillatory ODE (Lagaris #2) | |||
problem3_second_order.py |
2nd-Order Damped Oscillator (Lagaris #3) | |||
problem4_coupled_system.py |
Coupled Non-Linear System (Lagaris #4) |
|
|
|
euler_vs_pinn.py |
Numerical Integration Comparison | |||
ode_decay_single_layer.py |
Single-Layer MLP Decay Solver | |||
ode_decay_deep.py |
Deep MLP Decay Solver |
ANN-ODE-Solver/
├── figures/ # Exported publication-quality figures (300 DPI)
├── src/ # Modular package components
│ ├── __init__.py # Package exports
│ ├── models.py # FeedForwardNN & MultiOutputDNN architectures
│ └── utils.py # Error metrics (L_inf, MSE, Rel L2) & plotting tools
├── problem1_first_order.py # Lagaris Problem 1 (1st-Order Rational ODE)
├── problem2_oscillatory.py # Lagaris Problem 2 (Oscillatory ODE)
├── problem3_second_order.py # Lagaris Problem 3 (2nd-Order Damped ODE)
├── problem4_coupled_system.py # Lagaris Problem 4 (Coupled Non-Linear System)
├── euler_vs_pinn.py # Forward Euler vs ANN comparison
├── ode_decay_single_layer.py # Single-hidden-layer decay solver
├── ode_decay_deep.py # Multi-hidden-layer deep decay solver
├── benchmark_all.py # Automated benchmark execution suite
├── pytorch_problem1.py # Backward-compatible entrypoint
├── pytorch_problem2.py # Backward-compatible entrypoint
├── pytorch_problem3.py # Backward-compatible entrypoint
├── pytorch_problem4.py # Backward-compatible entrypoint
├── pytorch_euler.py # Backward-compatible entrypoint
├── pytorch_ode_solver_1hidden.py # Backward-compatible entrypoint
├── pytorch_ode_solver_n_hidden.py # Backward-compatible entrypoint
├── requirements.txt # Dependency specifications
└── README.md # Comprehensive documentation
Results obtained on standard CPU runtime using the trial solution formulation:
| Benchmark Problem | Domain | Max Absolute Error ( |
Root Mean Squared Error (RMSE) | Relative |
|---|---|---|---|---|
| Problem 1 (Rational 1st-Order) | ||||
| Problem 2 (Oscillatory 1st-Order) | ||||
| Problem 3 (Damped 2nd-Order) | ||||
| Problem 4 (Coupled System: |
||||
| Exponential Decay ( |
When comparing the continuous neural network solution against standard discrete Euler stepping on
-
Forward Euler (
$O(\Delta x)$ error): Accumulates step-by-step local truncation error, yielding maximum absolute error$\approx 3.4 \times 10^{-2}$ . -
ANN (
$C^\infty$ trial function): Optimizes a globally continuous representation, achieving maximum absolute error$\approx 1.9 \times 10^{-4}$ (over 100x lower error on the same grid density). - Furthermore, the neural solution provides instant closed-form evaluation and continuous derivatives at any arbitrary point
$x \in [0, 1]$ without interpolation.
If you use this codebase or benchmark suite in your research, please cite the foundational paper:
@article{lagaris1998artificial,
title={Artificial neural networks for solving ordinary and partial differential equations},
author={Lagaris, Isaac E and Likas, Aristidis and Fotiadis, Dimitrios I},
journal={IEEE Transactions on Neural Networks},
volume={9},
number={5},
pages={987--1000},
year={1998},
publisher={IEEE},
doi={10.1109/72.712178}
}This repository is made available for academic research and educational purposes. All rights reserved. Commercial redistribution or reproduction without explicit permission is prohibited.