Probabilistic Calibration API¶
Unified API
Probabilistic calibration is accessed through the Calibrator class using the run_probabilistic() method. See the Calibrator API for the complete API reference.
Quick Reference¶
from commol import Calibrator, CalibrationProblem, ProbabilisticCalibrationConfig
# Configure probabilistic calibration in the problem
problem = CalibrationProblem(
observed_data=observed_data,
parameters=parameters,
loss_function="sse",
optimization_config=pso_config,
probabilistic_config=ProbabilisticCalibrationConfig(n_runs=20),
)
# Use the unified Calibrator with run_probabilistic()
calibrator = Calibrator(simulation, problem)
result = calibrator.run_probabilistic()
Related Classes¶
ProbabilisticCalibrationConfig¶
ProbabilisticCalibrationConfig ¶
Bases: BaseModel
Unified configuration for probabilistic calibration.
This configuration groups all settings for the probabilistic calibration workflow, which finds an ensemble of parameter sets with uncertainty quantification instead of a single optimal solution.
The workflow consists of: 1. Run: Multiple independent calibration runs 2. Evaluation Processing: Deduplication and filtering 3. Clustering: Group similar solutions 4. Representative Selection: Pick diverse solutions from clusters 5. Ensemble Selection: NSGA-II multi-objective optimization 6. Statistics: Calculate confidence intervals and coverage
Attributes:
| Name | Type | Description |
|---|---|---|
n_runs |
int
|
Number of independent calibration runs to perform (default: 50). More runs provide better parameter space exploration but take longer. |
evaluation_processing |
ProbEvaluationFilterConfig
|
Configuration for evaluation deduplication and filtering |
clustering |
ProbClusteringConfig
|
Configuration for clustering parameter space |
representative_selection |
ProbRepresentativeConfig
|
Configuration for selecting representatives from clusters |
ensemble_selection |
ProbEnsembleConfig
|
Configuration for NSGA-II ensemble selection |
confidence_level |
float
|
Confidence interval level (default: 0.95 for 95% CI). Must be in range (0.0, 1.0). |
Source code in commol/context/probabilistic_calibration.py
options: show_root_heading: true show_source: false heading_level: 3 show_docstring_attributes: true
ProbabilisticCalibrationResult¶
ProbabilisticCalibrationResult ¶
Bases: BaseModel
Complete result from probabilistic calibration with ensemble analysis.
Contains the selected optimal ensemble solution, all Pareto-optimal solutions from multi-objective optimization, and metadata about the calibration process.
Attributes:
| Name | Type | Description |
|---|---|---|
selected_ensemble |
ParetoSolution
|
The optimal ensemble solution selected based on pareto_preference |
pareto_front |
list[ParetoSolution]
|
All Pareto-optimal ensemble solutions from NSGA-II optimization These represent different trade-offs between CI width and coverage |
selected_pareto_index |
int
|
Index in pareto_front of the selected solution |
n_runs_performed |
int
|
Number of calibration runs performed |
n_unique_evaluations |
int
|
Number of unique parameter evaluations after deduplication |
n_clusters_used |
int
|
Number of clusters identified in parameter space |
confidence_level |
float
|
Confidence level used for interval calculation (e.g., 0.95 for 95% CI) |
Source code in commol/context/probabilistic_calibration.py
options: show_root_heading: true show_source: false heading_level: 3 show_docstring_attributes: true
ParetoSolution¶
ParetoSolution ¶
Bases: BaseModel
A complete ensemble solution with statistics and predictions.
Represents a single ensemble of parameter sets, containing the ensemble composition, parameter statistics, model predictions with confidence intervals, and performance metrics.
Attributes:
| Name | Type | Description |
|---|---|---|
ensemble_size |
int
|
Number of parameter sets in this ensemble |
selected_indices |
list[int]
|
Indices of parameter sets selected for this ensemble |
ensemble_parameters |
list[dict[str, float]]
|
List of parameter dictionaries in this ensemble |
parameter_statistics |
dict[str, ParameterSetStatistics]
|
Statistics for each parameter across the ensemble |
prediction_median |
dict[str, list[float]]
|
Median predictions for each compartment over time |
prediction_ci_lower |
dict[str, list[float]]
|
Lower bound of confidence interval for each compartment over time |
prediction_ci_upper |
dict[str, list[float]]
|
Upper bound of confidence interval for each compartment over time |
coverage_percentage |
float
|
Percentage of observed data points within the confidence intervals |
average_ci_width |
float
|
Average width of confidence intervals across time and compartments |
ci_width |
float
|
Normalized confidence interval width objective [0, 1] used in optimization |
coverage |
float
|
Normalized coverage objective [0, 1] used in optimization |
size_penalty |
float
|
Size constraint penalty applied during optimization [0, infinity] |
Source code in commol/context/probabilistic_calibration.py
options: show_root_heading: true show_source: false heading_level: 3 show_docstring_attributes: true
ParameterSetStatistics¶
ParameterSetStatistics ¶
Bases: BaseModel
Statistics for a parameter across the ensemble.
Attributes:
| Name | Type | Description |
|---|---|---|
mean |
float
|
Mean value across ensemble |
median |
float
|
Median value across ensemble |
std |
float
|
Standard deviation across ensemble |
percentile_lower |
float
|
Lower percentile bound (e.g., 2.5th for 95% CI) |
percentile_upper |
float
|
Upper percentile bound (e.g., 97.5th for 95% CI) |
min |
float
|
Minimum value in ensemble |
max |
float
|
Maximum value in ensemble |
Source code in commol/context/probabilistic_calibration.py
options: show_root_heading: true show_source: false heading_level: 3 show_docstring_attributes: true
CalibrationEvaluation¶
CalibrationEvaluation
dataclass
¶
A single calibration evaluation result.
This dataclass represents a parameter set evaluation from calibration, including the parameters, loss value, and optionally predictions.
Attributes:
| Name | Type | Description |
|---|---|---|
parameters |
list[float]
|
Parameter values for this evaluation |
loss |
float
|
Loss/objective function value |
parameter_names |
list[str]
|
Names of the parameters (in same order as parameters list) |
predictions |
list[list[float]] | None
|
Optional predictions matrix with shape (time_steps, compartments) |
Source code in commol/context/probabilistic_calibration.py
options: show_root_heading: true show_source: false heading_level: 3 show_docstring_attributes: true
Visualization¶
The SimulationPlotter class supports visualization of probabilistic calibration results with confidence intervals.
Plotting with ProbabilisticCalibrationResult¶
When a ProbabilisticCalibrationResult is passed to plot_series or plot_cumulative, the plotter automatically displays:
- Median predictions as the main line
- Confidence interval bands as shaded regions
- Observed data as scatter points
from commol import SimulationPlotter
# Create plotter with median predictions from selected ensemble
plotter = SimulationPlotter(simulation, result.selected_ensemble.prediction_median)
# Plot with confidence intervals
fig = plotter.plot_series(
observed_data=observed_data,
calibration_result=result,
output_file="probabilistic_fit.png",
)
# Access the selected ensemble solution
selected = result.selected_ensemble
print(f"Ensemble size: {selected.ensemble_size}")
print(f"Coverage: {selected.coverage_percentage:.2f}%")
print(f"Parameter estimates: {selected.parameter_statistics}")
# Explore alternative solutions on the Pareto front
for i, solution in enumerate(result.pareto_front):
print(f"Solution {i}: size={solution.ensemble_size}, "
f"coverage={solution.coverage_percentage:.2f}%, "
f"CI width={solution.average_ci_width:.4f}")
SimulationPlotter.plot_series¶
plot_series ¶
plot_series(output_file: str | None = None, observed_data: list[ObservedDataPoint] | None = None, calibration_result: CalibrationResult | ProbabilisticCalibrationResult | None = None, config: PlotConfig | None = None, bins: list[str] | None = None, **kwargs: str | int | float | bool | None) -> Figure
Plot simulation results as time series with one subplot per bin.
Creates a figure with subplots arranged in a grid, where each subplot shows the evolution of one bin over time. Optionally overlays observed data points. If a ProbabilisticCalibrationResult is provided, plots confidence intervals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_file
|
str | None
|
Path to save the figure. If None, figure is not saved (only returned). |
None
|
observed_data
|
list[ObservedDataPoint] | None
|
Optional observed data points to overlay on corresponding bin subplots. Observed data points with a scale_id will be unscaled for plotting using scale values from the calibration_result. |
None
|
calibration_result
|
CalibrationResult | ProbabilisticCalibrationResult | None
|
Optional calibration result. If ProbabilisticCalibrationResult is provided, plots the median prediction with confidence interval bands. Scale values are extracted from best_parameters (CalibrationResult) or parameter_statistics (ProbabilisticCalibrationResult) to unscale observed data for comparison with model predictions. |
None
|
config
|
PlotConfig | None
|
Configuration for plot layout and styling (figsize, dpi, layout, style, palette, context). If None, uses defaults. |
None
|
bins
|
list[str] | None
|
List of bin IDs to plot. If None, plots all bins. |
None
|
**kwargs
|
str | int | float | bool | None
|
Additional keyword arguments passed to seaborn.lineplot(). Common parameters: linewidth, alpha, linestyle, marker, etc. |
{}
|
Returns:
| Type | Description |
|---|---|
Figure
|
The matplotlib Figure object. |
Source code in commol/api/plotter.py
options: show_root_heading: false show_source: false heading_level: 4
SimulationPlotter.plot_cumulative¶
plot_cumulative ¶
plot_cumulative(output_file: str | None = None, observed_data: list[ObservedDataPoint] | None = None, calibration_result: CalibrationResult | ProbabilisticCalibrationResult | None = None, config: PlotConfig | None = None, bins: list[str] | None = None, **kwargs: str | int | float | bool | None) -> Figure
Plot cumulative (accumulated) simulation results with one subplot per bin.
Creates a figure showing the running sum of each bin's values over time. Useful for tracking total infections, deaths, or other accumulated quantities. If a ProbabilisticCalibrationResult is provided, plots confidence intervals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_file
|
str | None
|
Path to save the figure. If None, figure is not saved (only returned). |
None
|
observed_data
|
list[ObservedDataPoint] | None
|
Optional observed data points to overlay (also shown as cumulative). Observed data points with a scale_id will be unscaled for plotting using scale values from the calibration_result. |
None
|
calibration_result
|
CalibrationResult | ProbabilisticCalibrationResult | None
|
Optional calibration result. If ProbabilisticCalibrationResult is provided, plots the median prediction with confidence interval bands. Scale values are extracted from best_parameters (CalibrationResult) or parameter_statistics (ProbabilisticCalibrationResult) to unscale observed data for comparison with model predictions. |
None
|
config
|
PlotConfig | None
|
Configuration for plot layout and styling (figsize, dpi, layout, style, palette, context). If None, uses defaults. |
None
|
bins
|
list[str] | None
|
List of bin IDs to plot. If None, plots all bins. |
None
|
**kwargs
|
str | int | float | bool | None
|
Additional keyword arguments passed to seaborn.lineplot(). Common parameters: linewidth, alpha, linestyle, marker, etc. |
{}
|
Returns:
| Type | Description |
|---|---|
Figure
|
The matplotlib Figure object. |
Source code in commol/api/plotter.py
options: show_root_heading: false show_source: false heading_level: 4
Helper Classes¶
The probabilistic calibration workflow is orchestrated using focused helper classes:
CalibrationRunner¶
Runs multiple calibrations in parallel with different random seeds.
CalibrationRunner ¶
Handles running multiple calibrations in parallel.
This class is responsible for: - Converting Python types to Rust types for the calibration problem - Executing parallel calibration runs via Rust/Rayon - Returning calibration results with evaluation history
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
simulation
|
Simulation
|
A fully initialized Simulation object with the model to calibrate. |
required |
problem
|
CalibrationProblem
|
A fully constructed and validated calibration problem definition. |
required |
seed
|
int
|
Random seed for reproducibility. Each calibration run gets a derived seed (seed + run_index). |
required |
Source code in commol/api/probabilistic/calibration_runner.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | |
Functions¶
run_multiple ¶
Run multiple calibration attempts in parallel using Rust.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_runs
|
int
|
Number of calibration runs to perform. |
required |
Returns:
| Type | Description |
|---|---|
list[CalibrationResultWithHistoryProtocol]
|
List of calibration results with evaluation history. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If all calibration runs fail. |
Source code in commol/api/probabilistic/calibration_runner.py
options: show_root_heading: true show_source: false heading_level: 3 members: - run_multiple
EvaluationProcessor¶
Handles deduplication, filtering, and clustering of calibration evaluations.
EvaluationProcessor ¶
Handles processing of calibration evaluations.
This class is responsible for: - Collecting evaluations from calibration results - Deduplicating similar evaluations - Filtering evaluations by loss percentile - Clustering evaluations using K-means - Selecting cluster representatives
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
deduplication_tolerance
|
float
|
Tolerance for parameter deduplication (default: 1e-6) |
1e-06
|
seed
|
int
|
Random seed for reproducibility (required, must be 32-bit for sklearn compatibility) |
required |
min_evaluations_for_clustering
|
int
|
Minimum number of evaluations required for clustering analysis |
10
|
identical_solutions_atol
|
float
|
Absolute tolerance for checking if all solutions are identical |
1e-10
|
silhouette_threshold
|
float
|
Silhouette score threshold for determining if clustering is beneficial |
0.2
|
silhouette_excellent_threshold
|
float
|
Early stopping threshold for silhouette score search |
0.7
|
kmeans_max_iter
|
int
|
Maximum iterations for K-means clustering |
100
|
kmeans_algorithm
|
str
|
K-means algorithm to use |
'elkan'
|
Source code in commol/api/probabilistic/evaluation_processor.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 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 | |
Functions¶
collect_evaluations ¶
collect_evaluations(results: list[CalibrationResultWithHistoryProtocol]) -> list[CalibrationEvaluation]
Collect all parameter evaluations from calibration results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
list[CalibrationResultWithHistoryProtocol]
|
List of calibration results with evaluation history |
required |
Returns:
| Type | Description |
|---|---|
list[CalibrationEvaluation]
|
List of all evaluations collected from the results |
Source code in commol/api/probabilistic/evaluation_processor.py
deduplicate ¶
deduplicate(evaluations: list[CalibrationEvaluation]) -> list[CalibrationEvaluation]
Remove duplicate evaluations based on parameter similarity using Rust.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
evaluations
|
list[CalibrationEvaluation]
|
List of evaluations to deduplicate |
required |
Returns:
| Type | Description |
|---|---|
list[CalibrationEvaluation]
|
List of unique evaluations |
Source code in commol/api/probabilistic/evaluation_processor.py
filter_by_loss_percentile ¶
filter_by_loss_percentile(evaluations: list[CalibrationEvaluation], percentile: float) -> list[CalibrationEvaluation]
Filter evaluations to keep only the best N% by loss.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
evaluations
|
list[CalibrationEvaluation]
|
List of evaluations to filter |
required |
percentile
|
float
|
Fraction (0.0 - 1.0] of best solutions to keep |
required |
Returns:
| Type | Description |
|---|---|
list[CalibrationEvaluation]
|
Filtered list containing only the best solutions by loss |
Source code in commol/api/probabilistic/evaluation_processor.py
find_optimal_k ¶
find_optimal_k(evaluations: list[CalibrationEvaluation]) -> int
Automatically determine optimal number of clusters using silhouette analysis.
Returns 1 if there's no clear clustering structure (all solutions are similar), otherwise returns the optimal K based on silhouette scores.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
evaluations
|
list[CalibrationEvaluation]
|
List of evaluations to analyze |
required |
Returns:
| Type | Description |
|---|---|
int
|
Optimal number of clusters (1 if no clear structure) |
Source code in commol/api/probabilistic/evaluation_processor.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | |
cluster_evaluations ¶
cluster_evaluations(evaluations: list[CalibrationEvaluation], k: int) -> list[int]
Cluster evaluations using K-means.
If k=1, all evaluations are assigned to a single cluster.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
evaluations
|
list[CalibrationEvaluation]
|
List of evaluations to cluster |
required |
k
|
int
|
Number of clusters |
required |
Returns:
| Type | Description |
|---|---|
list[int]
|
List of cluster labels (one per evaluation) |
Source code in commol/api/probabilistic/evaluation_processor.py
select_representatives ¶
select_representatives(evaluations: list[CalibrationEvaluation], cluster_labels: list[int], max_representatives: int, elite_fraction: float, strategy: str, selection_method: str, quality_temperature: float, k_neighbors_min: int, k_neighbors_max: int, sparsity_weight: float, stratum_fit_weight: float) -> list[int]
Select representative evaluations from clusters using Rust.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
evaluations
|
list[CalibrationEvaluation]
|
List of all evaluations |
required |
cluster_labels
|
list[int]
|
Cluster assignment for each evaluation |
required |
max_representatives
|
int
|
Maximum total representatives to select |
required |
elite_fraction
|
float
|
Fraction of best solutions to always include (0.0-1.0) |
required |
strategy
|
str
|
Distribution strategy ("proportional" or "equal") |
required |
selection_method
|
str
|
Diversity method ("crowding_distance", "maximin_distance", or "latin_hypercube") |
required |
quality_temperature
|
float
|
Temperature for quality weighting in maximin method |
required |
k_neighbors_min
|
int
|
Minimum k for k-nearest neighbors density estimation |
required |
k_neighbors_max
|
int
|
Maximum k for k-nearest neighbors density estimation |
required |
sparsity_weight
|
float
|
Exponential weight for sparsity in density-aware selection |
required |
stratum_fit_weight
|
float
|
Weight for stratum fit quality vs diversity in Latin hypercube |
required |
Returns:
| Type | Description |
|---|---|
list[int]
|
Indices of selected representative evaluations |
Source code in commol/api/probabilistic/evaluation_processor.py
options: show_root_heading: true show_source: false heading_level: 3 members: - collect_evaluations - deduplicate - filter_by_loss_percentile - find_optimal_k - cluster_evaluations - select_representatives
EnsembleSelector¶
Runs NSGA-II multi-objective optimization for ensemble selection.
EnsembleSelector ¶
Handles NSGA-II ensemble selection.
This class is responsible for: - Generating predictions for candidate parameter sets - Running NSGA-II multi-objective optimization - Selecting Pareto-optimal ensemble
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
simulation
|
Simulation
|
A fully initialized Simulation object |
required |
problem
|
CalibrationProblem
|
The calibration problem definition |
required |
seed
|
int
|
Random seed for reproducibility in NSGA-II optimization |
required |
Source code in commol/api/probabilistic/ensemble_selector.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | |
Functions¶
select_ensemble ¶
select_ensemble(representatives: list[CalibrationEvaluation], nsga_population_size: int, nsga_generations: int, confidence_level: float, pareto_preference: float, ensemble_size_mode: str, ensemble_size: int | None, ensemble_size_min: int | None, ensemble_size_max: int | None, ci_margin_factor: float, ci_sample_sizes: list[int], nsga_crossover_probability: float) -> EnsembleSelectionResultProtocol
Run NSGA-II ensemble selection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
representatives
|
list[CalibrationEvaluation]
|
Candidate parameter sets for ensemble selection |
required |
nsga_population_size
|
int
|
NSGA-II population size |
required |
nsga_generations
|
int
|
Number of NSGA-II generations |
required |
confidence_level
|
float
|
Confidence level for CI calculation (e.g., 0.95) |
required |
pareto_preference
|
float
|
Preference for Pareto front selection (0.0-1.0) |
required |
ensemble_size_mode
|
str
|
Mode for determining ensemble size ("fixed", "bounded", "automatic") |
required |
ensemble_size
|
int | None
|
Fixed ensemble size (required if mode='fixed') |
required |
ensemble_size_min
|
int | None
|
Minimum ensemble size (required if mode='bounded') |
required |
ensemble_size_max
|
int | None
|
Maximum ensemble size (required if mode='bounded') |
required |
ci_margin_factor
|
float
|
Margin factor for CI bounds estimation (e.g., 0.1 = 10% margin) |
required |
ci_sample_sizes
|
list[int]
|
Sample sizes used for CI bounds estimation |
required |
nsga_crossover_probability
|
float
|
Crossover probability for NSGA-II (0.0-1.0) |
required |
Returns:
| Type | Description |
|---|---|
object
|
Rust EnsembleSelectionResult object |
Source code in commol/api/probabilistic/ensemble_selector.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | |
options: show_root_heading: true show_source: false heading_level: 3 members: - select_ensemble
StatisticsCalculator¶
Computes ensemble statistics and predictions with confidence intervals.
StatisticsCalculator ¶
Handles calculation of ensemble statistics.
This class is responsible for: - Calculating parameter statistics across the ensemble - Generating ensemble predictions - Computing prediction intervals (median, CI bounds) - Calculating coverage metrics
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
simulation
|
Simulation
|
A fully initialized Simulation object |
required |
problem
|
CalibrationProblem
|
The calibration problem definition |
required |
confidence_level
|
float
|
Confidence level for CI calculation (e.g., 0.95) |
0.95
|
Source code in commol/api/probabilistic/statistics_calculator.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | |
Functions¶
calculate_parameter_statistics ¶
calculate_parameter_statistics(ensemble_params: list[CalibrationEvaluation]) -> dict[str, ParameterSetStatistics]
Calculate statistics for each parameter across the ensemble.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ensemble_params
|
list[CalibrationEvaluation]
|
List of parameter sets in the ensemble |
required |
Returns:
| Type | Description |
|---|---|
dict[str, ParameterSetStatistics]
|
Dictionary mapping parameter names to their statistics |
Source code in commol/api/probabilistic/statistics_calculator.py
generate_ensemble_predictions ¶
generate_ensemble_predictions(ensemble_params: list[CalibrationEvaluation], compartment_ids: list[str], time_steps: int) -> dict[str, list[list[float]]]
Generate predictions for each ensemble member in parallel using Rust.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ensemble_params
|
list[CalibrationEvaluation]
|
List of parameter sets in the ensemble |
required |
compartment_ids
|
list[str]
|
List of compartment IDs to generate predictions for |
required |
time_steps
|
int
|
Number of time steps to simulate |
required |
Returns:
| Type | Description |
|---|---|
dict[str, list[list[float]]]
|
Dictionary mapping compartment IDs to list of prediction trajectories |
Source code in commol/api/probabilistic/statistics_calculator.py
calculate_prediction_intervals ¶
calculate_prediction_intervals(all_predictions: dict[str, list[list[float]]], compartment_ids: list[str]) -> tuple[dict[str, list[float]], dict[str, list[float]], dict[str, list[float]]]
Calculate median and confidence intervals from ensemble predictions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
all_predictions
|
dict[str, list[list[float]]]
|
Dictionary mapping compartment IDs to list of prediction trajectories |
required |
compartment_ids
|
list[str]
|
List of compartment IDs |
required |
Returns:
| Type | Description |
|---|---|
tuple[dict[str, list[float]], dict[str, list[float]], dict[str, list[float]]]
|
Tuple of (median, lower CI, upper CI) dictionaries |
Source code in commol/api/probabilistic/statistics_calculator.py
calculate_coverage_metrics ¶
calculate_coverage_metrics(prediction_ci_lower: dict[str, list[float]], prediction_ci_upper: dict[str, list[float]]) -> tuple[float, float]
Calculate coverage percentage and average CI width.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prediction_ci_lower
|
dict[str, list[float]]
|
Lower CI bounds for each compartment |
required |
prediction_ci_upper
|
dict[str, list[float]]
|
Upper CI bounds for each compartment |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
Tuple of (coverage_percentage, average_ci_width) |
Source code in commol/api/probabilistic/statistics_calculator.py
options: show_root_heading: true show_source: false heading_level: 3 members: - calculate_parameter_statistics - generate_ensemble_predictions - calculate_prediction_intervals - calculate_coverage_metrics