montecarlo¶
Correlated collapse sampling and city-total bands.
quakecascade.montecarlo
¶
Correlated Monte Carlo damage realizations and city-total uncertainty bands.
Independent per-building draws get each building's own distribution right but
average out over a city, so a band on city totals built from them is far too
narrow: in a real event neighbouring buildings are shaken together. The
sampler here is a Gaussian copula on the fragility's own latent variable; it
keeps every building's Hazus marginal exactly and adds only the dependence the
shared shaking creates (PlanX engine/seismic.py, same author, ported). The
band driver city_bands re-implements the city-band stage of the author's earlier
scenario pipeline from its method description.
Also here: summarize_samples, validation_metrics and
tornado (PlanX engine/uncertainty.py, ported).
CORRELATION_MODES
module-attribute
¶
Ground-motion correlation modes. independent draws every building on its
own; between_event shares the between-event residual only (lower bound of
the real correlation); fully_correlated also shares the within-event
residual (upper bound). A distance-decay model sits between the last two and
needs a range parameter from its own paper, which is not supplied here.
BAND_PERCENTILES
module-attribute
¶
Percentiles reported by city_bands.
sample_damage_states_correlated
¶
sample_damage_states_correlated(
rng,
probabilities,
sigma_between,
sigma_within,
mode="between_event",
beta_threshold=HAZUS_PGA_BETA_THRESHOLD,
beta_demand=HAZUS_PGA_BETA_DEMAND,
)
One earthquake realization of damage states, correlated through the shaking.
Hazus splits the fragility dispersion into a building-specific threshold
part (beta_threshold = 0.4) and a ground-motion demand part
(beta_demand = 0.5; FEMA 2024, Section 5.4.3). Only the demand part is
shared between buildings::
g_i = (sigma_between * eta + sigma_within * eps_i) / sigma_total
z_i = sqrt(w) * g_i + sqrt(1 - w) * c_i, w = beta_D^2 / (beta_M^2 + beta_D^2)
with eta one draw per realization, eps_i the within-event draw and
c_i independent per building. u_i = Phi(z_i) picks the state by
inverse transform on the building's own Hazus distribution, so every
building's marginal is exactly the Hazus one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rng
|
Generator
|
Seeded generator; the same generator state reproduces the draw. |
required |
probabilities
|
mapping
|
State name -> array of probabilities (keys of |
required |
sigma_between
|
float
|
Between-event (tau) and within-event (phi) standard deviations of the GMPE's ln PGA residual, e.g. ASB2014 (Akkar et al. 2014). Required: they come from the ground-motion model the scenario used. |
required |
sigma_within
|
float
|
Between-event (tau) and within-event (phi) standard deviations of the GMPE's ln PGA residual, e.g. ASB2014 (Akkar et al. 2014). Required: they come from the ground-motion model the scenario used. |
required |
mode
|
str
|
One of |
'between_event'
|
beta_threshold
|
float
|
Hazus dispersion components (FEMA 2024). |
HAZUS_PGA_BETA_THRESHOLD
|
beta_demand
|
float
|
Hazus dispersion components (FEMA 2024). |
HAZUS_PGA_BETA_THRESHOLD
|
Returns:
| Type | Description |
|---|---|
numpy.ndarray of int
|
Index into |
city_bands
¶
City-total damage bands from correlated earthquake realizations.
Each run samples one damage state per building with
sample_damage_states_correlated and counts the buildings in each
state across the whole stock. The bands are percentiles of those per-run
totals, reported side by side for each correlation mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
damage
|
DataFrame or mapping
|
The frame from |
required |
tau
|
float
|
Between- and within-event standard deviations of ln PGA from the GMPE that produced the ground motion. Required. |
required |
phi
|
float
|
Between- and within-event standard deviations of ln PGA from the GMPE that produced the ground motion. Required. |
required |
runs
|
int
|
Realizations per mode (no default; a few hundred give stable p05/p95). |
required |
seed
|
int
|
Seed. Each (design level, mode) pair draws from its own stream
|
required |
modes
|
iterable of str
|
Subset of |
CORRELATION_MODES
|
percentiles
|
sequence of float
|
Percentiles to report; default (5, 10, 50, 90, 95). |
BAND_PERCENTILES
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per design level x mode x state, with |
summarize_samples
¶
Mean, standard deviation and 5th/50th/95th percentiles along axis.
tornado
¶
One-at-a-time sensitivity rows, largest swing first.
validation_metrics
¶
MAE, RMSE, bias and R^2 over the pairs where both values are finite.
R^2 is 1 - SS_res / SS_tot; it is NaN when the observations have no
variance (PlanX returned 0.0 there, which reads as a real score).