nhra_gt.sensitivity¶
Classes¶
Functions¶
generate_sensitivity_summary(morris_path, sobol_path, output_path)
¶
Synthesizes Morris and Sobol results into a Markdown report.
Source code in src/nhra_gt/sensitivity.py
get_parameter_lineage()
¶
Returns a mapping of model parameters to their evidence sources in the context pack.
Source code in src/nhra_gt/sensitivity.py
plot_sobol_indices(si, output_path)
¶
Generates Sobol first-order and total sensitivity plots.
Source code in src/nhra_gt/sensitivity.py
plot_sobol_heatmap(si, output_path)
¶
Generates a heatmap of second-order interaction indices (S2).
Source code in src/nhra_gt/sensitivity.py
plot_morris_tornado(df, output_path)
¶
Generates a Morris Tornado plot (mu_star ranking).
Source code in src/nhra_gt/sensitivity.py
get_salib_problem(param_names, bounds_override=None, default_variation=0.2)
¶
Generates a SALib-compatible problem dictionary from the Params dataclass.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
param_names
|
list[str]
|
List of parameter names to include in the GSA. |
required |
bounds_override
|
dict[str, list[float]] | None
|
Optional dictionary mapping parameter names to [min, max] bounds. |
None
|
default_variation
|
float
|
If no override, bounds are set to [default * (1-var), default * (1+var)]. |
0.2
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dictionary with 'num_vars', 'names', and 'bounds'. |
Source code in src/nhra_gt/sensitivity.py
evaluate_parallel(model_func, param_values, n_procs=4)
¶
Evaluates the model function in parallel across multiple processes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_func
|
Callable[[ndarray[Any, Any]], float]
|
Function that takes a parameter array and returns a scalar result. |
required |
param_values
|
ndarray[Any, Any]
|
2D array of shape (n_samples, n_vars). |
required |
n_procs
|
int
|
Number of worker processes to use. |
4
|
Returns:
| Type | Description |
|---|---|
ndarray[Any, Any]
|
A 1D array of results. |
Source code in src/nhra_gt/sensitivity.py
run_morris_analysis(problem, model_func, n_trajectories=10, n_procs=4, seed=42)
¶
Performs Morris analysis (Elementary Effects screening).
Returns:
| Type | Description |
|---|---|
DataFrame
|
A pandas DataFrame with mu_star and sigma indices. |
Source code in src/nhra_gt/sensitivity.py
run_sobol_analysis(problem, model_func, n_samples=128, n_procs=4, seed=42)
¶
Performs Sobol variance-based sensitivity analysis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_samples
|
int
|
The number of samples to generate (must be a power of 2). |
128
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dictionary containing S1, ST, and S2 indices. |
Source code in src/nhra_gt/sensitivity.py
export_sensitivity_indices(si, output_path)
¶
Exports S1 and ST indices to a CSV file.
Source code in src/nhra_gt/sensitivity.py
export_sobol_s2_to_csv(si, output_path)
¶
Exports the S2 interaction matrix to a CSV file.
Source code in src/nhra_gt/sensitivity.py
run_psa(distributions, model_func, n_samples=1000, n_procs=4)
¶
Performs Probabilistic Sensitivity Analysis (PSA).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
distributions
|
dict[str, Callable[[int], ndarray[Any, Any]]]
|
Dict mapping param name to a sampler function (takes N, returns array). |
required |
model_func
|
Callable[[ndarray[Any, Any]], float]
|
Function taking param array (in order of dict keys) -> scalar result. |
required |
n_samples
|
int
|
Number of MC samples. |
1000
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with parameters and outcome. |