Analysis¶
Conditioning and identifiability diagnostics for identified parameters (pinnrl.analysis). Two questions are kept apart: how well the data determine the parameters (sensitivities, Fisher information, the Cramér–Rao bound; exact from a closed form or from the trained surrogate by the implicit-function theorem) and how well-conditioned training is (loss-Hessian and tangent-kernel spectra).
exact_sensitivities ¶
du/dtheta of a closed-form solution at (x, t), shape (N, k, p).
The compiled expression is evaluated with a per-point copy of each
parameter that requires grad, so the derivative comes from autograd and
works for every function the expression language accepts (abs,
heaviside, sigmoid, ...). It is computed in double precision.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pde
|
Any
|
A |
required |
parameters
|
Sequence[str]
|
Names of the parameters to differentiate with respect to. |
required |
x
|
Tensor
|
Spatial coordinates, |
required |
t
|
Tensor | None
|
Time, |
None
|
values
|
dict[str, float] | None
|
Parameter values to evaluate at; defaults to the PDE's true
values ( |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the PDE has no expression-valued exact solution, or a name is not one of its parameters. |
Source code in pinnrl/analysis/sensitivity.py
fisher_information ¶
Fisher information J^T Sigma^{-1} J for Gaussian noise and its Cramér–Rao bound.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
jacobian
|
Tensor
|
Sensitivities, |
required |
sigma
|
float | Tensor
|
Noise standard deviation: a scalar, one value per observation
point |
required |
parameters
|
Sequence[str]
|
Names for the |
required |
rank_tol
|
float | None
|
Eigenvalues of |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in pinnrl/analysis/sensitivity.py
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 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | |
closed_form_bound ¶
The Cramér–Rao bound for parameters from observations at (x, t) with noise sigma.
A convenience around :func:exact_sensitivities and :func:fisher_information.
Source code in pinnrl/analysis/sensitivity.py
FisherSummary
dataclass
¶
FisherSummary(
parameters,
information,
covariance,
std,
correlation,
identifiable,
eigenvalues,
eigenvectors,
condition_number,
)
Fisher information for a parameter set and what it implies.
Attributes:
| Name | Type | Description |
|---|---|---|
parameters |
tuple[str, ...]
|
Parameter names, in the order of every matrix axis. |
information |
Tensor
|
The Fisher matrix |
covariance |
Tensor
|
The Cramér–Rao bound |
std |
Tensor
|
Lower bound on the standard deviation of each parameter ( |
correlation |
Tensor
|
Correlation matrix of the bound ( |
identifiable |
Tensor
|
Per parameter, whether it lies outside the null space of |
eigenvalues |
Tensor
|
Eigenvalues of |
eigenvectors |
Tensor
|
Columns are the corresponding parameter directions. |
condition_number |
float
|
Ratio of the largest to the smallest eigenvalue
( |
relative_std ¶
std / |true value| per parameter (inf when not identifiable).
Source code in pinnrl/analysis/sensitivity.py
surrogate_sensitivities ¶
surrogate_sensitivities(
pde,
model,
parameters,
x,
t,
*,
n_collocation=2048,
damping=0.001,
cg_iterations=300,
cg_tol=1e-05,
seed=0,
)
du/dtheta at (x, t) from the trained surrogate, by the implicit-function theorem.
Pass the same pde the model was trained with: the Hessian is taken of
that object's physics loss (its loss weights, boundary and initial point
counts, loss function and device), at the current values of its
parameters. Parameters that are not registered as trainable are made
trainable for the duration of the call, so a forward-trained problem works
as it is.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pde
|
Any
|
The problem the model was trained on. |
required |
model
|
Module
|
The trained network, a minimum of the physics loss for the parameters' current values. |
required |
parameters
|
Sequence[str]
|
Names of the PDE parameters to differentiate with respect to. |
required |
x
|
Tensor
|
Spatial coordinates of the observation points, |
required |
t
|
Tensor | None
|
Time, |
required |
n_collocation
|
int
|
Collocation points on which the Hessian is evaluated. |
2048
|
damping
|
float
|
Tikhonov damping |
0.001
|
cg_iterations
|
int
|
Maximum conjugate-gradient iterations per parameter. |
300
|
cg_tol
|
float
|
Relative residual at which the solve stops. |
1e-05
|
seed
|
int
|
Seed of the collocation sample (drawn in a forked RNG, so the caller's random state is untouched). |
0
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If a name is not a parameter of |
Source code in pinnrl/analysis/surrogate.py
SurrogateSensitivity
dataclass
¶
The Jacobian du/dtheta of a trained surrogate and how the solve went.
Attributes:
| Name | Type | Description |
|---|---|---|
jacobian |
Tensor
|
|
parameters |
tuple[str, ...]
|
The parameter names along the last axis. |
cg_iterations |
list[int]
|
Conjugate-gradient iterations used per parameter. |
cg_residuals |
list[float]
|
Relative residual of each solve. |
damping |
list[float]
|
Damping each solve ended with (raised from the requested value when the damped Hessian showed negative curvature). |
physics_loss |
float
|
The physics loss at which the Hessian was taken. |
loss_hessian_spectrum ¶
Extreme eigenvalues of d^2 loss / d parameters^2 by Lanczos with full reorthogonalization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
loss_fn
|
Callable[[], Tensor]
|
Returns the scalar loss as a function of |
required |
parameters
|
list[Parameter]
|
The tensors to differentiate with respect to. |
required |
iterations
|
int
|
Lanczos steps, hence the number of Ritz values. With 50 steps the few largest and smallest eigenvalues are converged to several digits for typical PINN Hessians. |
50
|
seed
|
int
|
Seed of the starting vector (a forked RNG, so the caller's state is untouched). |
0
|
Source code in pinnrl/analysis/spectrum.py
HessianSpectrum
dataclass
¶
Ritz values of the loss Hessian from Lanczos iteration.
Attributes:
| Name | Type | Description |
|---|---|---|
eigenvalues |
Tensor
|
Ritz values, descending; the extremes converge first. |
iterations |
int
|
Lanczos steps taken. |
loss |
float
|
The loss the Hessian belongs to. |
condition_number ¶
Largest over smallest positive Ritz value.
tangent_kernel_spectrum ¶
Spectrum of the tangent kernel of a per-point quantity of the network.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module
|
The network. |
required |
values_fn
|
Callable[[Module], Tensor]
|
Maps the network to the per-point values of the term, shape
|
required |
The kernel is K = J J^T with J = d values / d weights of shape
(N k, P), assembled row by row with one backward pass per value, so
keep N k in the hundreds.
Source code in pinnrl/analysis/spectrum.py
KernelSpectrum
dataclass
¶
Eigenvalues of the neural tangent kernel of a loss term on a batch.
Attributes:
| Name | Type | Description |
|---|---|---|
eigenvalues |
Tensor
|
Descending eigenvalues of |
trace |
float
|
Their sum, the total rate at which the term is fitted. |
condition_number ¶
Largest over smallest eigenvalue above floor.
Source code in pinnrl/analysis/spectrum.py
perturb_observations ¶
A disturbed copy of {"x", "t", "u"} observations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obs
|
Observations
|
Observation tensors of shape |
required |
kind
|
str
|
One of
|
required |
magnitude
|
float
|
Size of the disturbance, in the units the kind names. |
required |
seed
|
int
|
Seed of the random draws. |
0
|
sensors
|
Tensor | None
|
Optional boolean mask |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
For an unknown kind. |
Source code in pinnrl/analysis/disturbance.py
linear_response ¶
First-order parameter shift for a data disturbance delta_y.
delta_theta = (J^T Sigma^-1 J)^-1 J^T Sigma^-1 delta_y with
Sigma = sigma^2 I, the response of a weighted least-squares estimate.
A (N, k, p) Jacobian is flattened over k; delta_y is (N,)
or (N, k). Returns (p,).
Source code in pinnrl/analysis/disturbance.py
stability_ratio ¶
error / residual of a trained surrogate on a dense independent sample of the domain.
The residual is the equation applied to the network at fresh uniform
points (not the training points), so it includes the quadrature gap;
the error is against the closed form. Requires pde.has_exact_solution.
Source code in pinnrl/analysis/disturbance.py
StabilityRatio
dataclass
¶
Error, residual and their ratio on a dense independent grid.
Attributes:
| Name | Type | Description |
|---|---|---|
error |
float
|
Relative L2 error of the field against the closed form. |
residual |
float
|
Root-mean-square residual on the grid (all equations). |
boundary_error |
float
|
RMS mismatch of the field against the closed form on the spatial boundary (zero when the exact solution is unavailable there). |
initial_error |
float
|
RMS mismatch against the initial condition at |
ratio |
float
|
|
points |
int
|
Grid points used. |
field_response ¶
Change of the trained field between a base and a perturbed problem, on (x, t).
Returns the relative L2 norm of u_perturbed - u_base and, when the
reference solution's change reference_delta is given, the
amplification ratio ||delta u_PINN|| / ||delta u_ref|| and the
relative error of the PINN's response.