Skip to content

Commit 14e0191

Browse files
Merge pull request #191 from matthiaskoenig/sbmlsim2
Fix #176, documentation sensitivity analysis
2 parents f07259c + efaa1c6 commit 14e0191

File tree

91 files changed

+19555
-2311
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+19555
-2311
lines changed

_docs/api/index.qmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Sensitivity functionality.
77
| | |
88
| --- | --- |
99
| [sensitivity](sensitivity.qmd#sbmlsim.sensitivity) | Sensitivity analysis. |
10-
| [sensitivity.sensitivity_local](sensitivity.sensitivity_local.qmd#sbmlsim.sensitivity.sensitivity_local) | Local sensitivity analysis based on finite differences. |
10+
| [sensitivity.sensitivity_local](sensitivity.sensitivity_local.qmd#sbmlsim.sensitivity.sensitivity_local) | Local sensitivity analysis using finite differences. |
1111
| [sensitivity.sensitivity_fast](sensitivity.sensitivity_fast.qmd#sbmlsim.sensitivity.sensitivity_fast) | Global sensitivity analysis using FAST (Fourier Amplitude Sensitivity Test). |
1212
| [sensitivity.sensitivity_sobol](sensitivity.sensitivity_sobol.qmd#sbmlsim.sensitivity.sensitivity_sobol) | Global sensitivity analysis using Sobol indices. |
1313
| [sensitivity.sensitivity_morris](sensitivity.sensitivity_morris.qmd#sbmlsim.sensitivity.sensitivity_morris) | Morris sensitivity analysis. |

_docs/api/sensitivity.sensitivity_local.qmd

Lines changed: 50 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,34 @@
22

33
`sensitivity.sensitivity_local`
44

5-
Local sensitivity analysis based on finite differences.
5+
Local sensitivity analysis using finite differences.
66

7-
This module implements a local (derivative-based) sensitivity analysis using
8-
two-sided finite differences around a reference parameter set. Each model
9-
parameter is perturbed individually by a small relative amount, and the
10-
resulting change in model outputs is used to approximate local sensitivities.
7+
This module implements a local, derivative-based sensitivity analysis using
8+
symmetric finite differences around a reference parameter set. Each model
9+
parameter is perturbed individually while all other parameters are kept
10+
constant.
1111

12-
The analysis is designed for deterministic simulation models and is
13-
particularly suited for:
12+
The method is intended for deterministic simulation models and is useful for:
1413
- Identifying locally influential parameters
15-
- Debugging and model inspection
16-
- Complementing global sensitivity analyses
17-
- Supporting parameter screening prior to optimization or uncertainty analysis
18-
19-
Sensitivities are computed for each analysis group and output variable, and
20-
can be reported both as raw sensitivities and as normalized, dimensionless
21-
sensitivities.
22-
23-
The implementation builds on the sbmlsim sensitivity framework and integrates
24-
with existing simulation, caching, and plotting utilities.
25-
14+
- Debugging and inspecting model behavior
15+
- Screening parameters prior to optimization or uncertainty analysis
16+
- Complementing global sensitivity analysis methods
2617

18+
Sensitivities are computed per analysis group and output variable and are
19+
reported as both raw and normalized (dimensionless) sensitivities.
2720

2821
## Notes {.doc-section .doc-section-notes}
2922

30-
For each parameter p_i with reference value p_{i,0}, two perturbed simulations
31-
are generated:
32-
p_i_plus = p_{i,0} * (1 + difference)
33-
p_i_minus = p_{i,0} * (1 - difference)
23+
For a parameter p with reference value p0, sensitivities are computed as:
3424

35-
## Raw sensitivities are computed using a symmetric finite-difference scheme {.doc-section .doc-section-raw-sensitivities-are-computed-using-a-symmetric-finite-difference-scheme}
25+
p_plus = p0 * (1 + difference)
26+
p_minus = p0 * (1 - difference)
3627

37-
S(q_k, p_i) = (q_k(p_i_plus) - q_k(p_i_minus)) / (p_i_plus - p_i_minus)
28+
S = (q(p_plus) - q(p_minus)) / (p_plus - p_minus)
3829

39-
Normalized sensitivities represent the relative change in output per relative
40-
change in parameter:
41-
S_norm(q_k, p_i) = S(q_k, p_i) * (p_{i,0} / q_k(p_{i,0}))
30+
Normalized sensitivities are defined as:
31+
32+
S_norm = S * (p0 / q(p0))
4233

4334
## Classes
4435

@@ -63,34 +54,25 @@ sensitivity.sensitivity_local.LocalSensitivityAnalysis(
6354

6455
Local sensitivity analysis based on symmetric finite differences.
6556

66-
This class implements a local sensitivity analysis in which each model
67-
parameter is perturbed individually by a small relative amount while all
68-
other parameters are kept at their reference values.
69-
70-
For each parameter, two simulations are performed (increase and decrease),
71-
in addition to a reference simulation. Sensitivities are computed for each
72-
output variable and analysis group.
73-
74-
57+
Each model parameter is perturbed individually by a small relative amount
58+
around a reference parameter set, while all other parameters are held
59+
constant. For each parameter, two perturbed simulations (increase and
60+
decrease) are evaluated in addition to a reference simulation.
7561

7662
#### Attributes {.doc-section .doc-section-attributes}
7763

78-
difference : float
79-
Relative parameter perturbation used for the finite-difference
80-
approximation (e.g., 0.01 corresponds to ±1% changes).
81-
82-
#### Attributes
83-
84-
| Name | Description |
85-
| --- | --- |
86-
| [num_samples](#sbmlsim.sensitivity.sensitivity_local.LocalSensitivityAnalysis.num_samples) | Return the number of samples required for the analysis. |
64+
| Name | Type | Description |
65+
|------------|------------------|---------------------------------------------------------------------------------------------------------------|
66+
| difference | [float](`float`) | Relative parameter perturbation used for the finite-difference approximation (e.g., 0.01 corresponds to ±1%). |
67+
| prefix | [str](`str`) | Prefix used for naming result files. |
8768

8869
#### Methods
8970

9071
| Name | Description |
9172
| --- | --- |
92-
| [calculate_sensitivity](#sbmlsim.sensitivity.sensitivity_local.LocalSensitivityAnalysis.calculate_sensitivity) | Compute raw and normalized local sensitivity matrices. |
93-
| [create_samples](#sbmlsim.sensitivity.sensitivity_local.LocalSensitivityAnalysis.create_samples) | Create parameter samples for the local sensitivity analysis. |
73+
| [calculate_sensitivity](#sbmlsim.sensitivity.sensitivity_local.LocalSensitivityAnalysis.calculate_sensitivity) | Compute raw and normalized local sensitivities. |
74+
| [create_samples](#sbmlsim.sensitivity.sensitivity_local.LocalSensitivityAnalysis.create_samples) | Create parameter samples for local sensitivity analysis. |
75+
| [plot](#sbmlsim.sensitivity.sensitivity_local.LocalSensitivityAnalysis.plot) | Generate plots for normalized local sensitivities. |
9476

9577
##### calculate_sensitivity { #sbmlsim.sensitivity.sensitivity_local.LocalSensitivityAnalysis.calculate_sensitivity }
9678

@@ -101,35 +83,41 @@ sensitivity.sensitivity_local.LocalSensitivityAnalysis.calculate_sensitivity(
10183
)
10284
```
10385

104-
Compute raw and normalized local sensitivity matrices.
105-
106-
This method calculates two-sided finite-difference sensitivities for
107-
each parameter–output combination and stores both raw and normalized
108-
sensitivity matrices.
109-
110-
Optionally, results can be read from or written to a cache file.
111-
86+
Compute raw and normalized local sensitivities.
11287

88+
Sensitivities are calculated using a symmetric finite-difference scheme
89+
for each parameter–output combination.
11390

11491
###### Parameters {.doc-section .doc-section-parameters}
11592

116-
cache_filename : str, optional
117-
Filename for caching sensitivity results.
118-
cache : bool, optional
119-
Whether to read from and/or write to the cache.
93+
| Name | Type | Description | Default |
94+
|----------------|----------------|---------------------------------------------------------|-----------|
95+
| cache_filename | [str](`str`) | Filename used to read/write cached sensitivity results. | `None` |
96+
| cache | [bool](`bool`) | Whether cached results should be used. | `False` |
12097

12198
##### create_samples { #sbmlsim.sensitivity.sensitivity_local.LocalSensitivityAnalysis.create_samples }
12299

123100
```python
124101
sensitivity.sensitivity_local.LocalSensitivityAnalysis.create_samples()
125102
```
126103

127-
Create parameter samples for the local sensitivity analysis.
104+
Create parameter samples for local sensitivity analysis.
128105

129106
For each analysis group, this method constructs a sample matrix
130107
containing:
131108
- One reference parameter vector
132109
- Two perturbed parameter vectors per parameter (±difference)
133110

134-
The samples are stored as xarray.DataArray objects and indexed by
135-
sample and parameter identifiers.
111+
Samples are stored as an ``xarray.DataArray`` indexed by sample and
112+
parameter identifiers.
113+
114+
##### plot { #sbmlsim.sensitivity.sensitivity_local.LocalSensitivityAnalysis.plot }
115+
116+
```python
117+
sensitivity.sensitivity_local.LocalSensitivityAnalysis.plot()
118+
```
119+
120+
Generate plots for normalized local sensitivities.
121+
122+
Produces heatmaps of normalized sensitivities for each analysis group
123+
and saves the figures to the results directory.

_docs/api/sensitivity.sensitivity_morris.qmd

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,30 @@
44

55
Morris sensitivity analysis.
66

7-
Method of Morris, including groups and optimal trajectories (Morris 1991, Campolongo et al. 2007)
7+
This module implements the Method of Morris for global screening-based
8+
sensitivity analysis. The Morris method estimates *elementary effects* by
9+
sampling trajectories through the parameter space and provides qualitative
10+
and semi-quantitative measures of parameter importance.
11+
12+
The implementation supports:
13+
14+
- Classical Morris sampling (Morris, 1991)
15+
- Optimized trajectories (Campolongo et al., 2007)
16+
- Local optimization of trajectories (Ruano et al., 2012)
17+
18+
For each output variable, the following Morris indices are computed:
19+
20+
- mu: Mean of elementary effects
21+
- mu_star: Mean of absolute elementary effects
22+
- sigma: Standard deviation of elementary effects
23+
- mu_star_conf: Confidence interval of mu_star
24+
- r: Combined importance measure
25+
26+
## References {.doc-section .doc-section-references}
27+
28+
- Morris, M.D., 1991. Factorial Sampling Plans for Preliminary Computational Experiments. Technometrics 33, 161-174. https://doi.org/10.1080/00401706.1991.10484804
29+
- Campolongo, F., Cariboni, J., & Saltelli, A. 2007. An effective screening design for sensitivity analysis of large models. Environmental Modelling & Software, 22(10), 1509-1518. https://doi.org/10.1016/j.envsoft.2006.10.004
30+
- Ruano, M.V., Ribes, J., Seco, A., Ferrer, J., 2012. An improved sampling strategy based on trajectory design for application of the Morris method to systems with many input factors. Environmental Modelling & Software 37, 103-109. https://doi.org/10.1016/j.envsoft.2012.03.008
831

932
## Classes
1033

@@ -33,15 +56,11 @@ sensitivity.sensitivity_morris.MorrisSensitivityAnalysis(
3356

3457
Morris sensitivity analysis.
3558

36-
Campolongo et al., [2] introduces an optimal trajectories approach which attempts to maximize the parameter space scanned for a given number of trajectories (where optimal_trajectories). The approach accomplishes this aim by randomly generating a high number of possible trajectories (500 to 1000 in [2]) and selecting a subset of r trajectories which have the highest spread in parameter space. The r variable in [2] corresponds to the optimal_trajectories parameter here.
59+
Campolongo et al., introduces an optimal trajectories approach which attempts to maximize the parameter space scanned for a given number of trajectories (where optimal_trajectories). The approach accomplishes this aim by randomly generating a high number of possible trajectories (500 to 1000) and selecting a subset of r trajectories which have the highest spread in parameter space. The r variable in corresponds to the optimal_trajectories parameter here.
3760

3861
Calculating all possible combinations of trajectories can be computationally expensive. The number of factors makes little difference, but the ratio between number of optimal trajectories and the sample size results in an exponentially increasing number of scores that must be computed to find the optimal combination of trajectories. We suggest going no higher than 4 levels from a pool of 100 samples with this “brute force” approach.
3962

40-
Ruano et al., [3] proposed an alternative approach with an iterative process that maximizes the distance between subgroups of generated trajectories, from which the final set of trajectories are selected, again maximizing the distance between each. The approach is not guaranteed to produce the most optimal spread of trajectories, but are at least locally maximized and significantly reduce the time taken to select trajectories. With local_optimization = True (which is default), it is possible to go higher than the previously suggested 4 levels from a pool of 100 samples.
41-
42-
[1] Morris, M.D., 1991. Factorial Sampling Plans for Preliminary Computational Experiments. Technometrics 33, 161-174. https://doi.org/10.1080/00401706.1991.10484804
43-
[2] Campolongo, F., Cariboni, J., & Saltelli, A. 2007. An effective screening design for sensitivity analysis of large models. Environmental Modelling & Software, 22(10), 1509-1518. https://doi.org/10.1016/j.envsoft.2006.10.004
44-
[3] Ruano, M.V., Ribes, J., Seco, A., Ferrer, J., 2012. An improved sampling strategy based on trajectory design for application of the Morris method to systems with many input factors. Environmental Modelling & Software 37, 103-109. https://doi.org/10.1016/j.envsoft.2012.03.008
63+
Ruano et al., proposed an alternative approach with an iterative process that maximizes the distance between subgroups of generated trajectories, from which the final set of trajectories are selected, again maximizing the distance between each. The approach is not guaranteed to produce the most optimal spread of trajectories, but are at least locally maximized and significantly reduce the time taken to select trajectories. With local_optimization = True (which is default), it is possible to go higher than the previously suggested 4 levels from a pool of 100 samples.
4564

4665
#### Methods
4766

@@ -81,12 +100,12 @@ sensitivity.sensitivity_morris.MorrisSensitivityAnalysis.create_samples()
81100
Create samples using the Method of Morris.
82101
Three variants of Morris' sampling for elementary effects is supported:
83102

84-
- Vanilla Morris (see [1])
103+
- Vanilla Morris
85104
when ``optimal_trajectories`` is ``None``/``False`` and
86105
``local_optimization`` is ``False``
87106
- Optimised trajectories when ``optimal_trajectories=True`` using
88-
Campolongo's enhancements (see [2]) and optionally Ruano's enhancement
89-
(see [3]) when ``local_optimization=True``
107+
Campolongo's enhancements and optionally Ruano's enhancement
108+
when ``local_optimization=True``
90109
- Morris with groups when the problem definition specifies groups of
91110
parameters
92111

@@ -97,19 +116,3 @@ sensitivity.sensitivity_morris.MorrisSensitivityAnalysis.plot()
97116
```
98117

99118
Morris plot.
100-
101-
["mu", "mu_star", "sigma", "mu_star_conf"]
102-
103-
## Functions
104-
105-
| Name | Description |
106-
| --- | --- |
107-
| [plot_morris_indices](#sbmlsim.sensitivity.sensitivity_morris.plot_morris_indices) | Barplots and scatterplots of Morris indices. |
108-
109-
### plot_morris_indices { #sbmlsim.sensitivity.sensitivity_morris.plot_morris_indices }
110-
111-
```python
112-
sensitivity.sensitivity_morris.plot_morris_indices(sa, fig_path)
113-
```
114-
115-
Barplots and scatterplots of Morris indices.

_docs/api/sensitivity.sensitivity_sampling.qmd

Lines changed: 11 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,51 +4,24 @@
44

55
Sampling-based sensitivity and uncertainty analysis.
66

7-
This module implements a sampling-based sensitivity analysis in which model
8-
parameters are varied simultaneously according to predefined bounds and
9-
probability assumptions, and the resulting distribution of model outputs is
10-
analyzed statistically.
7+
This module implements a sampling-based sensitivity and uncertainty analysis
8+
approach. Model parameters are varied simultaneously within their bounds, and
9+
the resulting distribution of model outputs is analyzed statistically.
1110

12-
The primary purpose of this approach is to quantify output uncertainty and
13-
variability induced by parameter uncertainty, rather than to compute
14-
variance-decomposition sensitivity indices. It is therefore complementary to
15-
local (derivative-based) and global (variance-based) sensitivity analyses.
16-
17-
Parameter samples are generated using Latin Hypercube Sampling (LHS), a
18-
stratified Monte Carlo method that ensures efficient coverage of the
19-
multidimensional parameter space. In the current implementation, parameters
20-
are sampled independently assuming uniform distributions within their bounds.
11+
Parameter samples are generated using Latin Hypercube Sampling (LHS), assuming
12+
independent and uniformly distributed parameters.
2113

2214
For each analysis group and output variable, descriptive statistics are
23-
computed from the simulated sample ensemble, including:
15+
computed, including:
16+
2417
- mean and median
2518
- standard deviation and coefficient of variation
2619
- minimum and maximum
27-
- selected quantiles (5% and 95%)
28-
29-
These statistics provide a compact summary of output uncertainty and enable
30-
comparisons across model outputs and experimental or physiological conditions.
31-
32-
The module is intended for:
33-
- uncertainty propagation analyses
34-
- robustness and variability assessments
35-
- exploratory model analysis and screening
36-
- reporting uncertainty ranges in computational modeling studies
37-
38-
It integrates with the sbmlsim sensitivity framework and supports result
39-
caching, tabular export, and visualization of output distributions.
40-
20+
- lower and upper quantiles (5% and 95%)
4121

42-
43-
## Notes {.doc-section .doc-section-notes}
44-
45-
This method does not compute sensitivity indices in the strict variance-based
46-
sense (e.g., Sobol indices). Instead, it characterizes how uncertainty in
47-
parameters propagates to uncertainty in model outputs via sampling.
48-
49-
Typical workflows combine this approach with local or global sensitivity
50-
analysis to obtain both quantitative sensitivity measures and uncertainty
51-
estimates.
22+
This approach focuses on uncertainty propagation rather than variance-based
23+
sensitivity indices and is therefore complementary to local and Sobol-based
24+
methods.
5225

5326
## Classes
5427

@@ -73,11 +46,6 @@ sensitivity.sensitivity_sampling.SamplingSensitivityAnalysis(
7346

7447
Sensitivity/uncertainty analysis based on sampling.
7548

76-
#### more control on sampling {.doc-section .doc-section-more-control-on-sampling}
77-
78-
cv: float = 0.1,
79-
distribution: DistributionType = DistributionType.NORMAL_DISTRIBUTION,
80-
8149
#### Methods
8250

8351
| Name | Description |

0 commit comments

Comments
 (0)