DOE, sensitivity, margins and probabilistic ratings¶
Modules: crashmetrics.doe, crashmetrics.sensitivity,
crashmetrics.margins, crashmetrics.uncertainty (NumPy only).
Four helpers for design studies and machine learning around crash results:
| Task | Functions | Question it answers |
|---|---|---|
| Design of experiments | latin_hypercube, halton, full_factorial, morris_design, lsdyna_parameters |
Which runs should I simulate? |
| Margins as targets | margin, margins, euroncap_margins, margin_features |
How far is each criterion from its limits, as a smooth number a model can learn? |
| Sensitivity | rank_sensitivity, partial_rank_correlation, rank_correlation, regression_coefficients, morris_effects |
Which design variable drives which criterion? |
| Probabilistic rating | monte_carlo, normal, relative, uniform, scale, star_probabilities |
How likely is 5 stars, given test scatter? |
Step 1: sample the design variables¶
from crashmetrics.doe import latin_hypercube, lsdyna_parameters
design = latin_hypercube({"vent": (25.0, 45.0), "limiter": (3.0, 5.5),
"knee_k": (80.0, 200.0)}, n=30, seed=7)
for run in design.rows(): # {"run": "run001", "vent": ..., ...}
folder = Path("doe") / run["run"]
folder.mkdir(parents=True, exist_ok=True)
values = {k: round(run[k], 3) for k in design.names}
(folder / "params.k").write_text(lsdyna_parameters(values, title=run["run"]))
- Latin hypercube: every variable's range is cut into
nstrata, each used once; the default for 10 to a few hundred runs.seedmakes it repeatable. - Halton: deterministic and evenly spread (up to about 10 variables); a run can be added later without breaking the spread.
- Full factorial: every combination of given levels; only for few variables.
- Morris design: trajectories for
morris_effectsscreening,(k + 1)runs per trajectory. lsdyna_parameterswrites*PARAMETERcards (names up to 7 characters, values as reals); include the file in the deck and use&ventin the cards.
Step 2: margins instead of points as targets¶
NCAP points and colour bands jump in steps; regression models learn those badly. The distance to the limits is continuous:
from crashmetrics.margins import euroncap_margins, margin, margin_features
m = euroncap_margins("hybrid3_50", {"hic15": 600.0, "chest_compression": 31.0},
speed=50)
m["chest_compression"].position # 0.5: halfway from HPL (20) to LPL (42)
m["chest_compression"].margin_lpl # 0.26: 26 % of the LPL left
margin("thcc", 30.0, 42.0).margin_lpl # regulation limit (R94 ThCC)
row.update(margin_features(m, prefix="driver.")) # driver.hic15.position, ...
| Field | Definition | Use |
|---|---|---|
position |
(v - HPL) / (LPL - HPL): 0 at the HPL, 1 at the LPL |
Regression target for NCAP criteria |
margin_lpl |
(LPL - v) / LPL |
Safety margin to a regulation limit |
margin_hpl |
(HPL - v) / HPL |
Distance to full points |
sliding |
clip(1 - position, 0, 1) |
Linear sliding-scale fraction (Bharat NCAP style) |
Predict the margins, then apply the scoring functions to the predicted values.
Step 3: which variable drives which criterion¶
from crashmetrics.sensitivity import rank_sensitivity
ranking = rank_sensitivity(rows, ["vent", "limiter", "knee_k"], "chest_compression")
print(ranking.summary())
ranking.ranking # ["limiter", "vent", "knee_k"]
| Measure | Range | Reads as |
|---|---|---|
| PRCC (partial rank correlation, used for the ranking) | -1 to 1 | Effect of one variable with the others held out; finds a weak variable behind a strong one |
| Spearman rank correlation | -1 to 1 | Plain monotonic association |
| SRC (standardised regression coefficient) and R² | about -1 to 1 | Linear share of the variance; trust it when R² is near 1 |
All three miss effects that are not monotonic (an optimum inside the
range, such as an airbag vent size). Morris screening catches
them: a large mu_star means important, a large sigma means
non-linear or interacting.
from crashmetrics.doe import morris_design
from crashmetrics.sensitivity import morris_effects
design = morris_design(bounds, trajectories=12, levels=4, seed=3) # 12 (k + 1) runs
effects = morris_effects(design, hic_of_each_run) # sorted by mu_star
With 30 runs, correlations below about 0.3 are within sampling noise.
Step 4: probabilistic star rating¶
from crashmetrics.uncertainty import monte_carlo, relative, scale, star_probabilities
def rating(v): # any scoring code: inputs -> outputs
...
return {"points": result.points, "stars": result.stars}
result = monte_carlo(rating, nominal, {"hic15": relative(0.10), "chest": relative(0.06),
"neck_scale": scale(0.08)}, n=2000, seed=1)
result.probability("stars", at_least=5) # e.g. 0.68
star_probabilities(result) # {4: 0.32, 5: 0.68, ...}
result.percentiles("points") # 5 / 50 / 95 %
relative(cv)scatters an input by a coefficient of variation,normal(sd)by an absolute standard deviation,uniform(h)by ±h,scale(cv)gives a multiplier around 1 (scale a whole time history). Samples are clipped at zero unlessnonnegative=False.- The scatter should come from your own repeat tests or the dummy certification corridors; 5-10 % is typical for dummy channels.
result.rows()gives every sample as a dict, e.g. forrank_sensitivity(which criteria decide the fifth star?) or a CSV.
Complete examples¶
A 30-run Latin hypercube with LS-DYNA parameters, Euro NCAP margins and the sensitivity of three criteria:
"""Example 20: design of experiments, margins as targets, sensitivity.
A driver restraint study with three design variables: airbag vent
diameter, belt load limiter level and knee bolster stiffness. The
"simulation" is a made-up response model standing in for LS-DYNA runs
(replace `simulate` with reading your runs' results).
1. A Latin hypercube DOE of 30 runs, with LS-DYNA *PARAMETER cards.
2. Each run scored with Euro NCAP 2026 limits; the distance to the
limits (continuous) next to the points (stepped) as ML targets.
3. Which variable drives which criterion: PRCC / Spearman / SRC on the
DOE, and Morris screening.
"""
from crashmetrics.doe import latin_hypercube, lsdyna_parameters, morris_design
from crashmetrics.frontal_scoring import Occupant, score_dummy
from crashmetrics.margins import euroncap_margins, margin_features
from crashmetrics.sensitivity import morris_effects, rank_sensitivity
BOUNDS = {"vent": (25.0, 45.0), # airbag vent diameter, mm
"limiter": (3.0, 5.5), # belt load limiter, kN
"knee_k": (80.0, 200.0)} # knee bolster stiffness, N/mm
def simulate(vent, limiter, knee_k):
"""Made-up Hybrid III 50th driver response (50 km/h) to the design."""
hic15 = 330 + 9.0 * (vent - 35) ** 2 / 10 + 25 * (limiter - 4)
chest = 22 + 4.2 * (limiter - 3) + 0.10 * (vent - 25) # mm
femur = 2200 + 22 * (knee_k - 80) + 150 * (5.5 - limiter) # N
neck_tension = 1500 + 18 * (45 - vent) + 120 * (limiter - 3) # N
return {"hic15": hic15, "head_a3ms": 45 + 0.03 * hic15,
"neck_shear": 900.0, "neck_tension": neck_tension,
"neck_extension": 25.0, "chest_compression": chest,
"viscous_criterion": 0.25 + 0.012 * chest, "femur_force": femur,
"knee_displacement": 4.0, "tibia_index": 0.5, "tibia_force": 2200.0}
# --- 1. Latin hypercube design -------------------------------------------------
design = latin_hypercube(BOUNDS, n=30, seed=7)
print(f"{design.method}: {len(design)} runs of {', '.join(design.names)}")
first = design.rows()[0]
print(lsdyna_parameters({k: round(first[k], 3) for k in design.names},
title=str(first["run"])))
# --- 2. Results, points and margins per run -------------------------------------
rows = []
for run in design.rows():
values = simulate(run["vent"], run["limiter"], run["knee_k"])
score = score_dummy("hybrid3_50", Occupant(values, hard_contact=True),
{"head_neck": 1.25, "chest_abdomen": 1.25,
"knee_femur_pelvis": 1.25, "lower_leg": 1.25})
margins = euroncap_margins("hybrid3_50", values, speed=50)
rows.append({**run, "points": score.points,
**{k: values[k]
for k in ("hic15", "chest_compression", "femur_force")},
**margin_features(margins, fields=("position", "margin_lpl"))})
print("run vent limiter knee_k | HIC15 chest femur | chest position points")
for r in rows[:6]:
print(f"{r['run']} {r['vent']:5.1f} {r['limiter']:5.2f} {r['knee_k']:5.0f} | "
f"{r['hic15']:5.0f} {r['chest_compression']:5.1f} {r['femur_force']:5.0f} | "
f"{r['chest_compression.position']:+14.3f} {r['points']:.2f}")
print("(position: 0 at the HPL, 1 at the LPL; points change in steps, the position"
" does not)")
# --- 3. Sensitivity of each criterion to the design variables ---------------------
for output in ("hic15", "chest_compression", "femur_force"):
print()
print(rank_sensitivity(rows, design.names, output).summary())
# HIC has its minimum near a 35 mm vent: a strong but not monotonic effect,
# which rank measures miss. Morris screening shows it as a large mu* with a
# large sigma (non-linear).
morris = morris_design(BOUNDS, trajectories=12, levels=4, seed=3)
results = [simulate(*run) for run in morris.values]
for output in ("hic15", "chest_compression"):
effects = morris_effects(morris, [r[output] for r in results])
print(f"\nMorris screening of {output} ({len(morris)} runs): " + ", ".join(
f"{e.name} mu* {e.mu_star:.1f} sigma {e.sigma:.1f}" for e in effects))
Output:
latin_hypercube: 30 runs of vent, limiter, knee_k
*KEYWORD
$ run001
*PARAMETER
$# prmr1 val1
R vent 34.75
R limiter 3.075
R knee_k 103.103
*END
run vent limiter knee_k | HIC15 chest femur | chest position points
run001 34.8 3.07 103 | 307 23.3 3072 | +0.150 4.50
run002 27.2 3.78 159 | 380 25.5 4208 | +0.249 4.25
run003 26.3 3.65 91 | 389 24.9 2723 | +0.221 4.50
run004 32.0 3.11 181 | 316 23.2 4783 | +0.143 4.25
run005 40.5 4.20 162 | 362 28.6 4199 | +0.391 4.00
run006 40.0 4.50 151 | 365 29.8 3916 | +0.446 4.00
(position: 0 at the HPL, 1 at the LPL; points change in steps, the position does not)
Sensitivity of hic15 (linear fit R² 0.44):
variable PRCC Spearman SRC
limiter +0.66 +0.67 +0.64
knee_k +0.18 +0.15 +0.16
vent -0.06 -0.09 -0.07
Sensitivity of chest_compression (linear fit R² 1.00):
variable PRCC Spearman SRC
limiter +0.99 +0.98 +1.01
vent +0.80 +0.01 +0.19
knee_k +0.16 +0.10 +0.00
Sensitivity of femur_force (linear fit R² 1.00):
variable PRCC Spearman SRC
knee_k +1.00 +0.99 +0.99
limiter -0.82 -0.07 -0.14
vent -0.34 +0.31 +0.00
Morris screening of hic15 (48 runs): vent mu* 120.0 sigma 123.6, limiter mu* 62.5 sigma 0.0, knee_k mu* 0.0 sigma 0.0
Morris screening of chest_compression (48 runs): limiter mu* 10.5 sigma 0.0, vent mu* 2.0 sigma 0.0, knee_k mu* 0.0 sigma 0.0
A Bharat NCAP design just above the 5-star threshold, with the probability of keeping 5 stars and the criteria that decide it:
"""Example 21: probabilistic Bharat NCAP star rating.
A design scores 27.7 / 32 adult occupant points: 5 stars, but only just
(27 points needed). How likely is it to keep 5 stars in the official
test, given test-to-test scatter of the dummy readings? Each criterion
scatters (relative standard deviation 5-10 %, typical repeatability of
dummy channels); time histories (neck tension, femur) scatter as a
whole. 400 Monte Carlo samples of the complete AIS-197 scoring (use a
few thousand for a decision).
"""
import numpy as np
from crashmetrics.bncap import (
FrontalOccupant,
SideOccupant,
aop_rating,
score_frontal,
score_side,
)
from crashmetrics.sensitivity import rank_sensitivity
from crashmetrics.uncertainty import (
monte_carlo,
relative,
scale,
star_probabilities,
)
t = np.arange(0.0, 0.12, 1e-4) # s
def plateau(level, start_ms, end_ms):
ms = t * 1000.0
up = np.clip((ms - start_ms + 2.0) / 2.0, 0.0, 1.0)
down = np.clip((end_ms + 2.0 - ms) / 2.0, 0.0, 1.0)
return level * np.minimum(up, down)
def rating(v):
"""Adult occupant points and stars for one set of criteria values."""
driver = FrontalOccupant(
hic15=v["hic15"], head_a3ms=v["head_a3ms"],
neck_shear=(t, plateau(-700.0, 20.0, 40.0)),
neck_tension=(t, plateau(1900.0 * v["neck_scale"], 20.0, 45.0)),
neck_extension=18.0,
chest_compression=v["chest"], viscous_criterion=v["vc"],
femur=((t, plateau(-3300.0 * v["femur_scale"], 30.0, 36.0)),
(t, plateau(-3000.0 * v["femur_scale"], 30.0, 36.0))),
knee_displacement=(3.0, 3.5),
tibia_index=(v["tibia_index"], 0.40), tibia_force=(2100.0, 2000.0),
pedal_rearward=60.0,
)
passenger = FrontalOccupant(
hard_contact=False,
neck_shear=(t, plateau(-600.0, 20.0, 40.0)),
neck_tension=(t, plateau(1700.0, 20.0, 45.0)),
neck_extension=15.0,
chest_compression=v["chest_p"], viscous_criterion=0.32,
femur=((t, plateau(-2800.0, 30.0, 36.0)), (t, plateau(-2700.0, 30.0, 36.0))),
knee_displacement=(2.0, 2.5),
tibia_index=(0.42, 0.40), tibia_force=(1900.0, 2000.0),
)
side = SideOccupant(
hic15=300.0, head_a3ms=46.0, rib_deflection=v["rib"], rib_vc=v["rib_vc"],
abdominal_force=v["abdomen"], pubic_force=v["pubic"],
)
result = aop_rating(score_frontal(driver, passenger), score_side(side))
return {"points": result.points, "stars": result.stars}
nominal = {"hic15": 520.0, "head_a3ms": 58.0, "neck_scale": 1.0, "chest": 31.0,
"vc": 0.45, "femur_scale": 1.0, "tibia_index": 0.55, "chest_p": 24.0,
"rib": 27.0, "rib_vc": 0.42, "abdomen": 1150.0, "pubic": 2500.0}
scatter = {"hic15": relative(0.10), "head_a3ms": relative(0.07),
"neck_scale": scale(0.08), "chest": relative(0.06), "vc": relative(0.10),
"femur_scale": scale(0.08), "tibia_index": relative(0.08),
"chest_p": relative(0.06), "rib": relative(0.06), "rib_vc": relative(0.10),
"abdomen": relative(0.10), "pubic": relative(0.10)}
result = monte_carlo(rating, nominal, scatter, n=400, seed=2026)
print(f"Nominal design: {result.nominal['points']:.2f} / 32 points, "
f"{result.nominal['stars']:.0f} stars")
print(result.summary(["points"]))
print("\nStar rating probabilities:")
for stars, p in star_probabilities(result).items():
if p:
print(f" {stars} stars: {p:6.1%}")
print(f"P(5 stars) = {result.probability('stars', at_least=5):.1%}")
# Which criteria decide the fifth star? Rank the inputs by their effect on
# the points (partial rank correlation over the samples).
ranking = rank_sensitivity(result.rows(), list(scatter), "points")
print()
print(ranking.summary())
Output:
Nominal design: 27.73 / 32 points, 5 stars
Monte Carlo, 400 samples
output nominal mean p5 p50 p95
points 27.73 27.41 25.64 27.56 28.84
Star rating probabilities:
4 stars: 31.5%
5 stars: 68.5%
P(5 stars) = 68.5%
Sensitivity of points (linear fit R² 0.90):
variable PRCC Spearman SRC
hic15 -0.91 -0.74 -0.76
chest -0.73 -0.35 -0.37
abdomen -0.69 -0.34 -0.32
rib -0.66 -0.26 -0.28
tibia_index -0.49 -0.20 -0.16
vc +0.06 +0.09 -0.01
femur_scale -0.06 -0.04 -0.03
chest_p -0.04 +0.02 +0.00
rib_vc -0.04 -0.04 +0.00
neck_scale +0.02 +0.04 +0.02
pubic -0.02 -0.06 -0.02
head_a3ms +0.00 -0.04 -0.01
References¶
- M. D. McKay, R. J. Beckman, W. J. Conover (1979). A comparison of three methods for selecting values of input variables in the analysis of output from a computer code. Technometrics 21(2), 239-245.
- M. D. Morris (1991). Factorial sampling plans for preliminary computational experiments. Technometrics 33(2), 161-174.
- F. Campolongo, J. Cariboni, A. Saltelli (2007). An effective screening design for sensitivity analysis of large models. Environmental Modelling & Software 22(10), 1509-1518.
- S. Marino, I. B. Hogue, C. J. Ray, D. E. Kirschner (2008). A methodology for performing global uncertainty and sensitivity analysis in systems biology. Journal of Theoretical Biology 254(1), 178-196 (PRCC).