Post-hoc sensitivity¶
sensitivity_from_table() fits a surrogate over completed experiments and
estimates Morris or Sobol sensitivity cheaply through that model. Inspect its
cross-validated accuracy before interpreting importance: this measures the
surrogate's estimated response, not a new set of simulator evaluations.
Use sobol_indices() when you need first-order and total-order indices together;
ST - S1 reveals effects attributable to interactions.
See the complete conditional sensitivity and discrete contrasts workflow for explicit fixed-stratum selection, refusal of varying omitted inputs and explicit configuration/dataset grouped validation and its one-partition boundary.
trade_study.TableSensitivity(importance, surrogate_cv_r2, screened_factors=(), fixed_factors=dict(), conditioning=dict(), omitted_config_keys=(), metadata_keys=(), source_rows=(), sampling_factors=(), surrogate_cv_rmse=dict(), surrogate_row_cv_r2=dict(), surrogate_row_cv_rmse=dict(), cv_group_by=None, cv_group_source='rows', cv_group_labels=None, validation_scheme='unreported', validation_groups=list(), cv_folds_requested=5, support_ranges=dict())
dataclass
¶
Post-hoc sensitivity indices computed via a table-fit surrogate.
Attributes:
| Name | Type | Description |
|---|---|---|
importance |
dict[str, NDArray[floating[Any]]]
|
Mapping from observable name to an array of factor
importances (mu_star for Morris, S1 for Sobol), one value per
varying continuous factor, in |
surrogate_cv_r2 |
dict[str, float]
|
Per-observable cross-validated R^2 of the surrogate the indices were computed from. A low value means the sensitivity indices reflect a poorly learned response surface, not necessarily the true system -- treat such observables' indices as unreliable. Grouped results stay unavailable/NaN when fewer than two groups survive. |
screened_factors |
tuple[str, ...]
|
Ordered varying continuous input names. |
fixed_factors |
dict[str, Any]
|
Observed constants bound during prediction, including continuous factors made constant by conditioning. |
conditioning |
dict[str, Any]
|
Explicit requested discrete/categorical stratum. |
omitted_config_keys |
tuple[str, ...]
|
Non-factor config fields excluded from the surface. |
metadata_keys |
tuple[str, ...]
|
Explicitly declared non-factor bookkeeping fields. |
source_rows |
tuple[int, ...]
|
Selected original row indices, aligned with validation_groups. |
sampling_factors |
tuple[Factor, ...]
|
Factor definitions carrying screened bounds/log scales. Sampling is independent uniform in each declared linear/log coordinate. |
surrogate_cv_rmse |
dict[str, float]
|
Actual held-out RMSE, in observable units. |
surrogate_row_cv_r2 |
dict[str, float]
|
Shuffled row R² retained alongside grouped metrics. |
surrogate_row_cv_rmse |
dict[str, float]
|
Shuffled row RMSE. |
cv_group_by |
tuple[str, ...] | None
|
Factor grouping names, or None for rows/external groups. |
cv_group_source |
str
|
"rows", "configuration" or caller-declared "external". |
cv_group_labels |
tuple[Hashable, ...] | None
|
Validated external labels aligned with selected rows. |
validation_scheme |
str
|
Shuffled rows, held-out designs or named factor groups. External groups are one explicit partition, not automatic crossed CV. |
validation_groups |
list[int]
|
Group ids aligned with source_rows, empty for row CV. |
cv_folds_requested |
int
|
Requested maximum; effective folds depend on finite rows/groups for each observable and can be fewer or unavailable. |
support_ranges |
dict[str, dict[str, tuple[float, float]]]
|
Observed marginal continuous ranges per fitted observable. This does not establish support for joint sampled configurations. |
trade_study.sensitivity_from_table(results, factors, *, method='sobol', surrogate_method='rf', n_trajectories=100, seed=42, n_estimators=200, warn_below_r2=0.0, condition_on=None, metadata_keys=(), cv_group_by=None, cv_groups=None, cv_folds=5)
¶
Compute post-hoc Sobol/Morris sensitivity from a collected table.
Only varying continuous factors are screened. Discrete/categorical factors must be observed constants, optionally after explicit conditioning. All constants are bound in surrogate predictions. Varying unmodeled config keys are refused unless explicitly declared bookkeeping through metadata_keys. This is conditional surface sensitivity under independent uniform sampling in declared linear/log coordinates, not sensitivity to discrete factors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
ResultsTable
|
A :class: |
required |
factors
|
list[Factor]
|
All model factor definitions. At least one continuous factor must vary in the selected rows; observed constants are held fixed. |
required |
method
|
str
|
|
'sobol'
|
surrogate_method
|
str
|
|
'rf'
|
n_trajectories
|
int
|
Forwarded to |
100
|
seed
|
int
|
Random seed for both the surrogate fit and |
42
|
n_estimators
|
int
|
Forwarded to :func: |
200
|
warn_below_r2
|
float | None
|
Forwarded to :func: |
0.0
|
condition_on
|
Mapping[str, Any] | None
|
Discrete/categorical values selecting an observed stratum. Remaining varying noncontinuous factors are refused. |
None
|
metadata_keys
|
Sequence[str]
|
Explicit non-factor config bookkeeping fields; excluded from prediction and reported in omitted_config_keys. |
()
|
cv_group_by
|
str | Sequence[str] | None
|
Forwarded configuration-factor grouping, including "design". |
None
|
cv_groups
|
Sequence[object] | NDArray[Any] | None
|
Explicit dataset/replicate group labels aligned with every original results row, including rows excluded by conditioning. Mutually exclusive with cv_group_by. Values are validated before selection, then filtered by source_rows. No grouping is inferred. |
None
|
cv_folds
|
int
|
Requested CV maximum, forwarded to fit_surrogate. Must be >=2. |
5
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
TableSensitivity
|
class: |
TableSensitivity
|
surrogate validation, input scope, selected rows and marginal support. |
Raises:
| Type | Description |
|---|---|
ValueError
|
Invalid scope/layout/conditioning, unmodeled variation or no varying continuous factor; also propagated from fit_surrogate. |
Source code in src/trade_study/sensitivity.py
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 | |