Uncertainty quantification¶
Intervals for identified physics (pinnrl.uq): a Gaussian (Laplace) posterior from the surrogate's Fisher information, the region of equivalence sampled by an exploratory particle swarm, ensembles summarized with a dispersion diagnostic, loss weights from the noise model, and the calibration metrics that judge them. See the theory pages on the Bayesian view and on equivalence regions.
laplace_posterior ¶
Gaussian posterior over parameters at the trained estimate.
The covariance is the inverse Fisher information of the surrogate's
sensitivities at the observation points (pde.observation_data by
default, or x, t). This is the Laplace approximation restricted to the
parameters with the generalized Gauss–Newton curvature; it coincides with
the Cramér–Rao bound at the estimate.
Source code in pinnrl/uq/laplace.py
LaplacePosterior
dataclass
¶
A Gaussian posterior over identified parameters.
Attributes:
| Name | Type | Description |
|---|---|---|
parameters |
tuple[str, ...]
|
Names. |
mean |
Tensor
|
The point estimate (the trained values). |
covariance |
Tensor
|
|
std |
Tensor
|
Marginal standard deviations. |
correlation |
Tensor
|
|
likelihood_weights ¶
likelihood_weights(
n_data,
sigma_data,
n_residual,
sigma_residual=1.0,
*,
boundary=10.0,
initial=10.0,
)
Loss weights that make the mean-squared loss a negative log-likelihood up to scale.
The loss uses means, so a term with n points and noise sigma
contributes n / (2 sigma^2) times its mean square to -log L. With
the residual weight fixed at 1, the data weight is
(n_data / sigma_data^2) / (n_residual / sigma_residual^2), where
sigma_residual is the model-error scale admitted for the equation.
Source code in pinnrl/uq/laplace.py
sample_equivalence_region ¶
sample_equivalence_region(
misfit,
bounds,
tolerance=None,
*,
sigma=None,
level=0.9,
n_particles=40,
n_iterations=100,
seed=0,
exploration=0.9,
stop_on_collapse=0.02,
)
Sample {theta : misfit(theta) <= tolerance} with a cloud particle swarm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
misfit
|
Callable[[ndarray], ndarray]
|
Vectorized misfit, |
required |
bounds
|
Sequence[tuple[float, float]]
|
|
required |
tolerance
|
float | None
|
Accept positions with misfit at or below it. When |
None
|
sigma
|
float | None
|
Noise standard deviation, needed when |
None
|
level
|
float
|
Confidence level of the likelihood-ratio region. |
0.9
|
n_particles
|
int
|
Swarm size. |
40
|
n_iterations
|
int
|
Iterations; every evaluation is a candidate sample. |
100
|
seed
|
int
|
Seed of the initial positions and of the per-particle parameters. |
0
|
exploration
|
float
|
Fraction of the way to the second-order stability border at which each particle's acceleration is drawn (close to 1 is the exploratory setting the papers recommend). |
0.9
|
stop_on_collapse
|
float
|
Stop when the dispersion falls below this fraction of its initial value. |
0.02
|
Source code in pinnrl/uq/swarm.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
SwarmSample
dataclass
¶
The outcome of a swarm run.
Attributes:
| Name | Type | Description |
|---|---|---|
positions |
ndarray
|
Every evaluated position, |
misfits |
ndarray
|
Their misfits. |
accepted |
ndarray
|
Mask of the positions with |
best |
ndarray
|
The lowest-misfit position. |
best_misfit |
float
|
Its misfit. |
dispersion |
ndarray
|
Per iteration, the median distance of the particles to their centre of gravity relative to iteration 0 (1.0 at the start; a value near 0 means the swarm collapsed). |
tolerance |
float
|
The tolerance used. |
interval ¶
Central empirical interval per parameter from the accepted samples, (2, p).
misfit_tolerance ¶
Tolerance on the squared misfit sum (y - u)^2 for Gaussian noise.
The expected squared misfit of the true parameters is N sigma^2; the
region of equivalence is taken as the set within (1 + epsilon) of it.
Source code in pinnrl/uq/swarm.py
second_order_stable ¶
Whether a PSO parameter pair is inside the second-order (variance) stability region.
For the classical PSO with uniformly distributed accelerations the mean
trajectory is stable for |omega| < 1 and 0 < phi < 2 (omega + 1), and
the variance for phi < 12 (1 - omega^2) / (7 - 5 omega) (Poli, 2009;
García-Gonzalo & Fernández-Martínez, 2014, for general distributions).
phi is the mean total acceleration (a_g + a_l) / 2.
Source code in pinnrl/uq/swarm.py
ensemble_summary ¶
Summarize the estimates of an ensemble of independently trained members.
Source code in pinnrl/uq/__init__.py
EnsembleSummary
dataclass
¶
Point estimates of an ensemble and what they imply.
Attributes:
| Name | Type | Description |
|---|---|---|
estimates |
ndarray
|
|
mean |
ndarray
|
Per parameter. |
std |
ndarray
|
Per parameter (the ensemble spread). |
dispersion |
float
|
Median distance of the members to their median, relative to the mean absolute value of the parameters (a collapse diagnostic). |
interval ¶
Central interval per parameter, (2, p): empirical, or Gaussian from mean and std.
Source code in pinnrl/uq/__init__.py
coverage ¶
Fraction of intervals [lower, upper] that contain the truth.
Source code in pinnrl/uq/metrics.py
mean_width ¶
gaussian_interval ¶
Central interval of a Gaussian at the given level.
sample_interval ¶
Central empirical interval of a set of samples at the given level.
Source code in pinnrl/uq/metrics.py
crps_gaussian ¶
Continuous ranked probability score of a Gaussian forecast (Gneiting & Raftery, 2007).
CRPS = sigma [ z (2 Phi(z) - 1) + 2 phi(z) - 1/sqrt(pi) ] with z = (y - mu) / sigma.
Lower is better; it rewards both calibration and sharpness.
Source code in pinnrl/uq/metrics.py
crps_samples ¶
CRPS of an empirical forecast: E|X - y| - E|X - X'| / 2.