Sensitivity Analysis#

In this tutorial we demonstrate how to perform sensitivity analysis as part of the AutoEmulate workflow. The tutorial covers:

  1. Setting up an example simulation: here we use our “FlowProblem” simulator. This is a cardiovascular modelling example, simulating a blood vessel divided into 10 compartments. This allows for the study of the pressure and flow rate at various points in the tube. See “The Flow Problem” below for more details.

  2. Running the simulation for 100 sets of parameters sampled from the parameter space.

  3. Using Autoemulate to find the best emulator for this simulation

  4. Performing sensitivity analysis.

The Flow Problem

In the field of cardiovascular modeling, capturing the dynamics of blood flow and the associated pressures and volumes within the vascular system is crucial for understanding heart function and disease. This simulator simulates a vessel divided to 10 compartments.

Parameters#

The simulation parameters include :

  1. R (Resistance): Represents the resistance to blood flow in blood vessels, akin to the hydraulic resistance caused by vessel diameter and blood viscosity (Analogous to electrical resistor).

  2. L (Inductance): Represents the inertial effects of blood flow, capturing how blood resists changes in its velocity (Analogous to electrical inductor).

  3. C (Capacitance): Represents the compliance or elasticity of blood vessels, primarily large arteries, which store and release blood volume with changes in pressure (Analogous to a capacitor).

Boundary conditions#

  1. Neumann boundary condition : Specifies the derivative of the variable at the boundary.

  2. Dirichlet Boundary condition : Specifies the value of the variable directly at the boundary.

The setup#

The input flow rate in each compartment is \(Q_i(t)\) for the \(i^{th}\) compartment and the output flow rate is \(Q_{i+1}(t)\).

\(Q_0(t) = \begin{cases} A \cdot \sin^2\left(\frac{\pi}{t_d} t\right), & \text{if } 0 \leq t < T, \\ 0, & \text{otherwise}. \end{cases}\)

Where:

  • \(Q_0(t)\) is the input pulse function (flow rate) at time t

  • A is the amplitude of the pulse

  • \(t_d\) is the pulse duration.

Solve#

Pressure in Each Compartment (\(P_i\)): This determines how the pressure in each compartment evolves over time, based on the inflow (\(Q_i(t)\)) and the outflow (\(Q_{i+1}(t)\)). where \(i\) is the number of compartment.

Circuit Diagram

\(\frac{dP_i}{dt} = \frac{1}{C_n} \left( Q_i(t) - Q_{i+1}(t) \right)\) where, \(C_n = \frac{C}{n_\text{comp}}\)

Flow rate equation (\(Q_i\)): This governs how the flow in each compartment changes over time, depending on the pressures in the neighboring compartments and the resistance and inertance properties of each compartment.

\(\frac{dQ_i}{dt} = \frac{1}{L_n} \left( P_i - P_{10} - R_n Q_i(t) \right)\), where \(L_n = \frac{L}{n_\text{comp}}, \quad R_n = \frac{R}{n_\text{comp}}\)

from autoemulate.core.compare import AutoEmulate
from autoemulate.core.sensitivity_analysis import SensitivityAnalysis
from autoemulate.simulations.flow_problem import FlowProblem

figsize = (9, 5)

Set up the simulation parameters and ranges:

parameters_range = {
    "T": (0.5, 2.0), # Cardiac cycle period (s)
    "td": (0.1, 0.5), # Pulse duration (s)
    "amp": (100.0, 1000.0), # Amplitude (e.g., pressure or flow rate)
    "dt": (0.0001, 0.01), # Time step (s)
    "C": (20.0, 60.0), # Compliance (unit varies based on context)
    "R": (0.01, 0.1), # Resistance (unit varies based on context)
    "L": (0.001, 0.005), # Inductance (unit varies based on context)
    "R_o": (0.01, 0.05), # Outflow resistance (unit varies based on context)
    "p_o": (5.0, 15.0) # Initial pressure (unit varies based on context)
}
output_names = ["pressure"]

simulator = FlowProblem(
    parameters_range=parameters_range,
    output_names=output_names,
    show_progress_bar=False
)

Run the simulation for 100 sets of parameters sampled from the parameter space:

x = simulator.sample_inputs(100)
y, _ = simulator.forward_batch(x)
print(x.shape, y.shape)
torch.Size([100, 9]) torch.Size([100, 1])

Use AutoEmulate to find the best emulator for this simulation:

ae = AutoEmulate(x, y, models=["MLP", "GaussianProcessRBF"], show_progress_bar=False)  # remove models argument to use all models
best = ae.best_result()
print(best.model_name)
GaussianProcessRBF

Sensitivity Analysis#

  1. Define the problem by creating a dictionary which contains the names and the boundaries of the parameters

  2. Evaluate the contribution of each parameter via the Sobol and Morris methods.

problem = {
    'num_vars': simulator.in_dim,
    'names': simulator.param_names,
    'bounds': simulator.param_bounds,
    'output_names': simulator.output_names,
}
sa = SensitivityAnalysis(best.model, problem=problem)

Sobol metrics:

  • \(S_1\): First-order sensitivity index.

  • \(S_2\): Second-order sensitivity index.

  • \(S_t\): Total sensitivity index.

Sobol interpretation:

  • \(S_1\) values sum to ≤ 1.0 (exact fraction of variance explained)

  • \(S_t - S_1\) = interaction effects involving that parameter

  • Large \(S_t - S_1\) gap indicates strong interactions

sobol_df = sa.run("sobol")
sobol_df
/home/runner/work/autoemulate/autoemulate/.venv/lib/python3.12/site-packages/SALib/util/__init__.py:274: FutureWarning: unique with argument that is not not a Series, Index, ExtensionArray, or np.ndarray is deprecated and will raise in a future version.
  names = list(pd.unique(groups))
output parameter index value confidence
0 pressure T S1 4.109527e-05 0.001006
1 pressure td S1 1.262631e-02 0.013203
2 pressure amp S1 9.300964e-01 0.070756
3 pressure dt S1 8.598584e-05 0.001554
4 pressure C S1 9.463330e-03 0.008897
5 pressure R S1 3.315130e-02 0.014197
6 pressure L S1 1.470405e-04 0.002599
7 pressure R_o S1 1.055000e-04 0.001200
8 pressure p_o S1 1.915383e-03 0.001100
0 pressure T ST 1.365446e-04 0.000016
1 pressure td ST 2.230119e-02 0.003278
2 pressure amp ST 9.438004e-01 0.062153
3 pressure dt ST 2.772057e-04 0.000037
4 pressure C ST 9.965166e-03 0.001264
5 pressure R ST 3.821518e-02 0.004584
6 pressure L ST 9.576940e-04 0.000116
7 pressure R_o ST 1.933691e-04 0.000023
8 pressure p_o ST 2.045754e-04 0.000026
0 pressure (T, td) S2 1.242719e-04 0.001554
1 pressure (T, amp) S2 7.300999e-05 0.001782
2 pressure (T, dt) S2 6.842994e-05 0.001540
3 pressure (T, C) S2 9.365318e-05 0.001551
4 pressure (T, R) S2 1.194106e-04 0.001538
5 pressure (T, L) S2 1.209668e-04 0.001534
6 pressure (T, R_o) S2 7.609545e-05 0.001532
7 pressure (T, p_o) S2 6.797760e-05 0.001537
8 pressure (td, amp) S2 4.344766e-03 0.021921
9 pressure (td, dt) S2 1.614057e-03 0.018558
10 pressure (td, C) S2 2.724602e-03 0.018643
11 pressure (td, R) S2 1.849184e-03 0.018382
12 pressure (td, L) S2 2.084225e-03 0.018583
13 pressure (td, R_o) S2 1.642837e-03 0.018563
14 pressure (td, p_o) S2 1.748894e-03 0.018601
15 pressure (amp, dt) S2 9.716417e-04 0.067872
16 pressure (amp, C) S2 3.500558e-04 0.068837
17 pressure (amp, R) S2 4.314816e-03 0.068407
18 pressure (amp, L) S2 1.421588e-03 0.068267
19 pressure (amp, R_o) S2 5.910491e-04 0.067955
20 pressure (amp, p_o) S2 -1.346729e-03 0.067871
21 pressure (dt, C) S2 9.026492e-05 0.002695
22 pressure (dt, R) S2 2.149776e-04 0.002634
23 pressure (dt, L) S2 1.238691e-04 0.002695
24 pressure (dt, R_o) S2 1.263649e-04 0.002696
25 pressure (dt, p_o) S2 9.280092e-05 0.002696
26 pressure (C, R) S2 -2.250949e-03 0.013761
27 pressure (C, L) S2 -2.487180e-03 0.013844
28 pressure (C, R_o) S2 -2.564382e-03 0.013840
29 pressure (C, p_o) S2 -2.475380e-03 0.013856
30 pressure (R, L) S2 -3.063185e-03 0.021544
31 pressure (R, R_o) S2 -3.067368e-03 0.021596
32 pressure (R, p_o) S2 -3.062206e-03 0.021537
33 pressure (L, R_o) S2 5.494106e-07 0.004015
34 pressure (L, p_o) S2 3.583328e-05 0.004019
35 pressure (R_o, p_o) S2 1.216417e-04 0.001614
sa.plot_sobol(sobol_df, index="ST", figsize=figsize) 
../../_images/e2837bfd03248b396bdec9af354d6d4e2d50f610bc7e50df7885fb5e892bf6c3.png

You can also save the plot directly to a file by passing the fname argument to the plotting function.

sa.plot_sobol(sobol_df, index="ST", figsize=figsize, fname="sobol_plot.png") 

Morris Interpretation:

  • High \(\mu^*\), Low \(\sigma\): Important parameter with linear/monotonic effects

  • High \(\mu^*\), High \(\sigma\): Important parameter with non-linear effects or interactions

  • Low \(\mu^*\), High \(\sigma\): Parameter involved in interactions but not individually important

  • Low \(\mu^*\), Low \(\sigma\): Unimportant parameter

morris_df = sa.run("morris")
morris_df
output parameter mu mu_star sigma mu_star_conf
0 pressure T -5.402066 6.929348 5.794508 0.244131
1 pressure td 80.173599 90.406357 88.250572 4.553330
2 pressure amp 667.403076 667.403076 96.851250 6.429606
3 pressure dt -5.752673 11.505016 12.926661 0.493690
4 pressure C -63.766251 63.795982 37.419270 2.006932
5 pressure R -127.209656 131.110626 83.995995 4.861785
6 pressure L 7.432716 19.155983 21.385103 0.784358
7 pressure R_o -8.413643 8.964589 6.749642 0.334195
8 pressure p_o -1.780217 9.988790 11.688455 0.391052
sa.plot_morris(morris_df, figsize=figsize)
../../_images/76568a2d4d7e0d3d86ac87b4d413429c1d416cc73cf920c7d69c4e61160d2d4d.png