Kalibrierung (API)¶
Calibrator Facade¶
pyadm1ode_calibration.calibration.Calibrator(plant, verbose=True)
¶
Orchestration layer for calibration workflows.
Provides a simplified interface for running both initial and online calibrations on a plant model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plant
|
Any
|
The PyADM1ODE plant model instance. |
required |
verbose
|
bool
|
Whether to enable verbose logging. Defaults to True. |
True
|
Source code in pyadm1ode_calibration/calibration/__init__.py
Methods:¶
apply_calibration(result)
¶
Apply calibration results to the plant model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
CalibrationResult
|
Result containing new parameters. |
required |
Source code in pyadm1ode_calibration/calibration/__init__.py
run_initial_calibration(measurements, parameters, **kwargs)
¶
Run initial batch calibration from historical data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
measurements
|
MeasurementData
|
Historical measurement data. |
required |
parameters
|
list[str]
|
List of parameter names to calibrate. |
required |
**kwargs
|
Any
|
Additional settings for InitialCalibrator. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
CalibrationResult |
CalibrationResult
|
Results of the calibration. |
Source code in pyadm1ode_calibration/calibration/__init__.py
run_online_calibration(measurements, parameters, **kwargs)
¶
Run online re-calibration for real-time adjustments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
measurements
|
MeasurementData
|
Recent measurement data. |
required |
parameters
|
list[str]
|
List of parameter names to calibrate. |
required |
**kwargs
|
Any
|
Additional settings for OnlineCalibrator. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
CalibrationResult |
CalibrationResult
|
Results of the calibration. |
Source code in pyadm1ode_calibration/calibration/__init__.py
Initial Calibrator¶
pyadm1ode_calibration.calibration.InitialCalibrator(plant, verbose=True, time_varying_feed=False)
¶
Bases: BaseCalibrator
Initial calibrator for ADM1 parameters from historical data.
This calibrator is designed for batch optimization using a window of historical measurement data. It supports multi-objective optimization, sensitivity analysis, and cross-validation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plant
|
Any
|
The PyADM1ODE plant model to calibrate. |
required |
verbose
|
bool
|
Whether to enable verbose output. Defaults to True. |
True
|
Source code in pyadm1ode_calibration/calibration/methods/initial.py
Methods:¶
calibrate(measurements, parameters, bounds=None, method='differential_evolution', objectives=None, weights=None, validation_split=0.2, max_iterations=100, population_size=15, tolerance=0.0001, sensitivity_analysis=True, use_constraints=False, check_identifiability=False, **kwargs)
¶
Run the initial calibration workflow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
measurements
|
MeasurementData
|
Historical measurement data for calibration. |
required |
parameters
|
List[str]
|
Names of parameters to optimize. |
required |
bounds
|
Optional[Dict[str, Tuple[float, float]]]
|
Custom search bounds for parameters. |
None
|
method
|
str
|
Optimization algorithm name. Defaults to 'differential_evolution'. |
'differential_evolution'
|
objectives
|
Optional[List[str]]
|
List of objective variables (e.g., ['Q_ch4', 'pH']). |
None
|
weights
|
Optional[Dict[str, float]]
|
Weights for different objectives in the cost function. |
None
|
validation_split
|
float
|
Fraction of data to use for out-of-sample validation. Defaults to 0.2. |
0.2
|
max_iterations
|
int
|
Maximum number of optimizer iterations. Defaults to 100. |
100
|
population_size
|
int
|
Population size for evolutionary algorithms. Defaults to 15. |
15
|
tolerance
|
float
|
Convergence tolerance. Defaults to 1e-4. |
0.0001
|
sensitivity_analysis
|
bool
|
Whether to perform sensitivity analysis after calibration. |
True
|
use_constraints
|
bool
|
Whether to apply parameter constraints. Defaults to False. |
False
|
check_identifiability
|
bool
|
Screen the parameter set for collinearity before
optimizing and warn when it is unidentifiable as a set. Costs
|
False
|
**kwargs
|
Any
|
Additional keyword arguments passed to the optimizer. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
CalibrationResult |
CalibrationResult
|
The calibration results including optimized parameters and metrics. |
Source code in pyadm1ode_calibration/calibration/methods/initial.py
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 | |
identifiability_analysis(parameters, measurements, optimization_history=None, confidence_level=0.95, correlation_threshold=0.8)
¶
Perform parameter identifiability analysis.
Checks for parameter correlations and information content in the data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parameters
|
Dict[str, float]
|
Parameter set to analyze. |
required |
measurements
|
MeasurementData
|
Data window for simulation. |
required |
optimization_history
|
Optional[List[Dict[str, Any]]]
|
History from a previous optimizer run, used to widen the confidence intervals. |
None
|
confidence_level
|
float
|
Confidence level for the intervals. |
0.95
|
correlation_threshold
|
float
|
Above this, two parameters count as correlated and neither is reported as identifiable on its own. |
0.8
|
Returns:
| Name | Type | Description |
|---|---|---|
IdentifiabilityResult |
dict[str, IdentifiabilityResult]
|
Analysis results including correlation matrix. |
Source code in pyadm1ode_calibration/calibration/methods/initial.py
sensitivity_analysis(parameters, measurements, objectives=None)
¶
Perform local sensitivity analysis for given parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parameters
|
Dict[str, float]
|
Parameter set to analyze. |
required |
measurements
|
MeasurementData
|
Data window for simulation. |
required |
objectives
|
Optional[List[str]]
|
List of objective variables. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, SensitivityResult]
|
Dict[str, SensitivityResult]: Mapping of parameter names to sensitivity indices. |
Source code in pyadm1ode_calibration/calibration/methods/initial.py
Online Calibrator¶
pyadm1ode_calibration.calibration.OnlineCalibrator(plant, verbose=True, parameter_bounds=None, time_varying_feed=False)
¶
Bases: BaseCalibrator
Online calibrator for real-time parameter adjustment.
Performs fast, bounded re-calibration when model predictions deviate from measurements. It is optimized for speed and stability, ensuring that parameters do not drift too far from their physical meanings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plant
|
Any
|
The PyADM1ODE plant model to calibrate. |
required |
verbose
|
bool
|
Whether to enable verbose logging. Defaults to True. |
True
|
parameter_bounds
|
Optional[ParameterBounds]
|
Custom parameter bounds manager. |
None
|
Source code in pyadm1ode_calibration/calibration/methods/online.py
Methods:¶
apply_calibration(result)
¶
Apply calibrated parameters to the underlying plant model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
CalibrationResult
|
The result containing new parameter values. |
required |
Source code in pyadm1ode_calibration/calibration/methods/online.py
calibrate(measurements, parameters=None, current_parameters=None, variance_threshold=0.15, max_parameter_change=0.2, time_window=7, method='nelder_mead', max_iterations=50, objectives=None, weights=None, use_constraints=True, **kwargs)
¶
Perform online re-calibration with bounded parameter adjustments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
measurements
|
MeasurementData
|
Recent measurement data window. |
required |
parameters
|
Optional[List[str]]
|
Parameters to adjust. If None, uses history. |
None
|
current_parameters
|
Optional[Dict[str, float]]
|
Current values. If None, gets from plant. |
None
|
variance_threshold
|
float
|
Variance threshold for triggering (0-1). |
0.15
|
max_parameter_change
|
float
|
Max relative parameter change (0.0 to 1.0). |
0.2
|
time_window
|
int
|
Number of days of recent data to use for optimization. |
7
|
method
|
str
|
Optimization method name. Defaults to 'nelder_mead'. |
'nelder_mead'
|
max_iterations
|
int
|
Maximum optimization iterations. Defaults to 50. |
50
|
objectives
|
Optional[List[str]]
|
List of outputs to match (e.g., ['Q_ch4']). |
None
|
weights
|
Optional[Dict[str, float]]
|
Objective weights for multi-objective cost. |
None
|
use_constraints
|
bool
|
Whether to apply parameter box constraints. |
True
|
**kwargs
|
Any
|
Extra settings passed to the optimizer. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
CalibrationResult |
CalibrationResult
|
Results of the online calibration step. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no parameters are specified and no history is available. |
Source code in pyadm1ode_calibration/calibration/methods/online.py
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 | |
should_recalibrate(recent_measurements, objectives=None)
¶
Check if re-calibration should be triggered based on prediction error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
recent_measurements
|
MeasurementData
|
Recent plant data. |
required |
objectives
|
Optional[List[str]]
|
Variables to monitor for error. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[bool, str]
|
Tuple[bool, str]: (should_recalibrate, reason_string). |
Source code in pyadm1ode_calibration/calibration/methods/online.py
Calibration Result¶
pyadm1ode_calibration.calibration.CalibrationResult(success, parameters, initial_parameters, objective_value, n_iterations, execution_time, method, message, validation_metrics=dict(), sensitivity=dict(), history=list(), timestamp=(lambda: datetime.now(timezone.utc).isoformat())())
dataclass
¶
Result from a calibration run.
Stores the output of an optimization process, including calibrated values, performance metrics, and diagnostic information.
Attributes:
| Name | Type | Description |
|---|---|---|
success |
bool
|
Whether calibration converged successfully. |
parameters |
Dict[str, float]
|
Calibrated parameter values. |
initial_parameters |
Dict[str, float]
|
Initial parameter values before calibration. |
objective_value |
float
|
Final objective function value. |
n_iterations |
int
|
Number of optimization iterations. |
execution_time |
float
|
Wall clock time in seconds. |
method |
str
|
Optimization method used (e.g., 'differential_evolution'). |
message |
str
|
Status message from the optimizer. |
validation_metrics |
Dict[str, float]
|
Metrics on validation data (RMSE, R2, etc.). |
sensitivity |
Dict[str, Any]
|
Parameter sensitivity analysis results. |
history |
List[Dict[str, Any]]
|
Optimization history if tracking was enabled. |
timestamp |
str
|
Calibration timestamp in ISO format. |
Methods:¶
from_dict(data)
classmethod
¶
Create a CalibrationResult instance from a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Dict[str, Any]
|
Dictionary with result attributes. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
CalibrationResult |
CalibrationResult
|
A new instance populated with the data. |
Source code in pyadm1ode_calibration/calibration/core/result.py
to_dict()
¶
Convert the result to a dictionary.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict[str, Any]: Dictionary containing all result data. |
Source code in pyadm1ode_calibration/calibration/core/result.py
to_json(filepath)
¶
Save the result to a JSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str
|
Destination file path. |
required |
Parameter Bounds¶
pyadm1ode_calibration.calibration.parameter_bounds.ParameterBounds()
¶
Manager for parameter bounds in ADM1 calibration.
Provides methods for accessing bounds, validating parameters, and calculating penalties for constraint violations.
Attributes:
| Name | Type | Description |
|---|---|---|
bounds |
dict[str, ParameterBound]
|
Dictionary mapping parameter names to ParameterBound objects |
Example
bounds = ParameterBounds() bounds.add_bound("k_dis", lower=0.3, upper=0.8, default=0.5) is_valid = bounds.is_within_bounds("k_dis", 0.6)
Initialize empty parameter bounds manager.
Source code in pyadm1ode_calibration/calibration/parameter_bounds.py
Methods:¶
add_bound(name, lower, upper, default, bound_type=BoundType.HARD, penalty_weight=1.0, description='', unit='', substrate_dependent=False)
¶
Add parameter bound.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Parameter name |
required |
lower
|
float
|
Lower bound |
required |
upper
|
float
|
Upper bound |
required |
default
|
float
|
Default value |
required |
bound_type
|
BoundType
|
Type of bound |
HARD
|
penalty_weight
|
float
|
Penalty weight for soft constraints |
1.0
|
description
|
str
|
Parameter description |
''
|
unit
|
str
|
Parameter unit |
''
|
substrate_dependent
|
bool
|
Whether bound varies by substrate |
False
|
Source code in pyadm1ode_calibration/calibration/parameter_bounds.py
calculate_penalty(name, value, penalty_type='quadratic')
¶
Calculate penalty for parameter value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Parameter name |
required |
value
|
float
|
Parameter value |
required |
penalty_type
|
str
|
Type of penalty function |
'quadratic'
|
Returns:
| Type | Description |
|---|---|
float
|
Penalty value |
Source code in pyadm1ode_calibration/calibration/parameter_bounds.py
calculate_total_penalty(parameters, penalty_type='quadratic')
¶
Calculate total penalty for all parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parameters
|
dict[str, float]
|
Dictionary of parameter values |
required |
penalty_type
|
str
|
Type of penalty function |
'quadratic'
|
Returns:
| Type | Description |
|---|---|
float
|
Total penalty |
Source code in pyadm1ode_calibration/calibration/parameter_bounds.py
clip_to_bounds(name, value)
¶
Clip parameter value to bounds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Parameter name |
required |
value
|
float
|
Parameter value |
required |
Returns:
| Type | Description |
|---|---|
float
|
Clipped value |
Source code in pyadm1ode_calibration/calibration/parameter_bounds.py
get_bounds(name)
¶
Get bounds for parameter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Parameter name |
required |
Returns:
| Type | Description |
|---|---|
ParameterBound | None
|
ParameterBound object or None if not found |
Source code in pyadm1ode_calibration/calibration/parameter_bounds.py
get_bounds_tuple(name)
¶
Get bounds as tuple (lower, upper).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Parameter name |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float] | None
|
Tuple of (lower, upper) or None |
Source code in pyadm1ode_calibration/calibration/parameter_bounds.py
get_default_values(parameter_names)
¶
Get default values for parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parameter_names
|
list[str]
|
List of parameter names |
required |
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
Dictionary of default values |
Source code in pyadm1ode_calibration/calibration/parameter_bounds.py
is_within_bounds(name, value, tolerance=0.0)
¶
Check if parameter value is within bounds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Parameter name |
required |
value
|
float
|
Parameter value |
required |
tolerance
|
float
|
Tolerance for boundary |
0.0
|
Returns:
| Type | Description |
|---|---|
bool
|
True if within bounds, False otherwise |
Source code in pyadm1ode_calibration/calibration/parameter_bounds.py
scale_to_unit_interval(name, value)
¶
Scale parameter value to unit interval [0, 1].
Useful for optimization algorithms that work better with normalized parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Parameter name |
required |
value
|
float
|
Parameter value |
required |
Returns:
| Type | Description |
|---|---|
float
|
Scaled value in [0, 1] |
Source code in pyadm1ode_calibration/calibration/parameter_bounds.py
unscale_from_unit_interval(name, scaled_value)
¶
Unscale parameter value from unit interval [0, 1].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Parameter name |
required |
scaled_value
|
float
|
Scaled value in [0, 1] |
required |
Returns:
| Type | Description |
|---|---|
float
|
Unscaled parameter value |
Source code in pyadm1ode_calibration/calibration/parameter_bounds.py
validate_parameters(parameters, raise_on_invalid=False)
¶
Validate all parameters against bounds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parameters
|
dict[str, float]
|
Dictionary of parameter values |
required |
raise_on_invalid
|
bool
|
Raise exception if invalid |
False
|
Returns:
| Type | Description |
|---|---|
tuple[bool, list[str]]
|
Tuple of (all_valid, list of error messages) |
Source code in pyadm1ode_calibration/calibration/parameter_bounds.py
pyadm1ode_calibration.calibration.parameter_bounds.create_default_bounds()
¶
Create parameter bounds with default ADM1 values.
Bounds are based on: - Batstone et al. (2002): ADM1 base values - Rosen et al. (2006): BSM2 values - Gaida (2014): Agricultural substrate calibrations - Literature ranges for agricultural biogas plants
Returns:
| Type | Description |
|---|---|
ParameterBounds
|
ParameterBounds with default ADM1 parameter bounds |
Example
bounds = create_default_bounds() k_dis_bounds = bounds.get_bounds("k_dis")
Source code in pyadm1ode_calibration/calibration/parameter_bounds.py
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 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 | |
Simulator¶
pyadm1ode_calibration.calibration.core.simulator.PlantSimulator(plant, verbose=True, time_varying_feed=False)
¶
Handles plant simulation with parameter variations.
This class separates the simulation logic from calibration algorithms, providing a consistent interface for running the ADM1 model with modified parameter sets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plant
|
Any
|
The PyADM1ODE plant model instance. |
required |
verbose
|
bool
|
Whether to enable progress output and logging. Defaults to True. |
True
|
Source code in pyadm1ode_calibration/calibration/core/simulator.py
Methods:¶
simulate_with_parameters(parameters, measurements, restore_params=True, chp_load_setpoints=None, restore_state=True, warmup=None)
¶
Run a plant simulation using a specific set of parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parameters
|
dict[str, float]
|
Parameter values to apply {name: value}. |
required |
measurements
|
MeasurementData
|
Input data for substrate feeds and timing. |
required |
restore_params
|
bool
|
Whether to restore the original plant parameters after the simulation finishes. Defaults to True. |
True
|
restore_state
|
bool
|
Whether to rewind the plant to the state it had before the run. Defaults to True, and calibration depends on it: a plant keeps integrating where the last simulation stopped, so without the rewind the second evaluation of a parameter set starts from a different digester state than the first and returns a different error. The optimizer then sees a landscape that changes under its feet. |
True
|
warmup
|
Optional[MeasurementData]
|
Optional window to run before the scored one, keeping its
end state. Use it when |
None
|
chp_load_setpoints
|
dict[str, ndarray] | None
|
Optional mapping from CHP component ID to an array of load setpoints (one value per simulation step, in [0, 1]). When provided, the simulator drives each CHP from this time series instead of letting the plant engine default to full load. Useful for replaying measured CHP operation so the comparison isolates the gas-production model. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, ndarray]
|
Dict[str, np.ndarray]: Dictionary mapping output names (e.g., 'Q_ch4') to simulated numpy arrays. |
Source code in pyadm1ode_calibration/calibration/core/simulator.py
Analysis¶
pyadm1ode_calibration.calibration.analysis.sensitivity.SensitivityAnalyzer(plant, simulator=None, verbose=True)
¶
Performs local sensitivity analysis on ADM1 plant parameters.
Calculates how changes in input parameters affect specific model outputs, helping to identify which parameters are most influential.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plant
|
The PyADM1ODE plant model instance. |
required | |
simulator
|
Optional[PlantSimulator]
|
Simulator instance to use. |
None
|
verbose
|
bool
|
Whether to enable progress output. Defaults to True. |
True
|
Source code in pyadm1ode_calibration/calibration/analysis/sensitivity.py
Methods:¶
analyze(parameters, measurements, objectives=None, perturbation=0.01)
¶
Perform local sensitivity analysis using finite differences.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parameters
|
Dict[str, float]
|
Baseline parameter set. |
required |
measurements
|
Any
|
Input data for simulation. |
required |
objectives
|
Optional[List[str]]
|
List of objective variables to analyze. |
None
|
perturbation
|
float
|
Relative step size for finite differences. Defaults to 0.01. |
0.01
|
Returns:
| Type | Description |
|---|---|
dict[str, SensitivityResult]
|
Dict[str, SensitivityResult]: Mapping of parameter names to their respective sensitivity analysis results. |
Source code in pyadm1ode_calibration/calibration/analysis/sensitivity.py
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 | |
pyadm1ode_calibration.calibration.analysis.identifiability.IdentifiabilityAnalyzer(plant, sensitivity_analyzer=None, verbose=True)
¶
Assesses parameter identifiability for ADM1 calibration.
Analyzes whether parameters have enough influence on model outputs and whether they are correlated with each other, which can hinder accurate estimation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plant
|
The PyADM1ODE plant model instance. |
required | |
sensitivity_analyzer
|
Optional[SensitivityAnalyzer]
|
Analyzer for calculating gradients. |
None
|
verbose
|
bool
|
Whether to enable verbose output. Defaults to True. |
True
|
Source code in pyadm1ode_calibration/calibration/analysis/identifiability.py
Methods:¶
analyze(parameters, measurements, optimization_history=None, confidence_level=0.95, correlation_threshold=0.8)
¶
Assess parameter identifiability based on sensitivity and correlation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parameters
|
Dict[str, float]
|
Parameter set to analyze. |
required |
measurements
|
Any
|
Measurement data for simulation. |
required |
optimization_history
|
Optional[List[Dict[str, Any]]]
|
History from optimizer. |
None
|
confidence_level
|
float
|
Level for confidence intervals. Defaults to 0.95. |
0.95
|
correlation_threshold
|
float
|
Threshold for identifying high correlations. |
0.8
|
Returns:
| Type | Description |
|---|---|
dict[str, IdentifiabilityResult]
|
Dict[str, IdentifiabilityResult]: Results for each parameter. For whether |
dict[str, IdentifiabilityResult]
|
the parameters can be estimated together, see :meth: |
Source code in pyadm1ode_calibration/calibration/analysis/identifiability.py
analyze_subset(parameters, measurements, objectives=None)
¶
Can this set of parameters be estimated together?
Individual sensitivity is necessary but not sufficient. Two parameters that each move the outputs strongly are still unidentifiable as a pair when one can undo what the other did, which is what the collinearity index measures.
Costs 2 * len(parameters) + 1 simulations, so it is cheap enough to run
before a calibration rather than after it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parameters
|
dict[str, float]
|
The candidate set, name to nominal value. |
required |
measurements
|
Any
|
Data window the sensitivities are evaluated over. |
required |
objectives
|
list[str] | None
|
Channels to score against. Defaults to gas, pH and VFA. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
SubsetIdentifiability |
SubsetIdentifiability
|
The verdict for the set as a whole. |
Source code in pyadm1ode_calibration/calibration/analysis/identifiability.py
subset_verdict(sensitivity, per_parameter)
staticmethod
¶
Judge a parameter set from an existing sensitivity analysis.
Two stages, in the order Brun et al. 2001 prescribe. First each parameter is screened on its own, because one that fails alone cannot be rescued by the company it keeps. The collinearity index is then computed over the survivors only. Doing it the other way round lets a parameter made of solver noise pass as an independent direction, since normalising its column to unit length hides how small it was.
Source code in pyadm1ode_calibration/calibration/analysis/identifiability.py
pyadm1ode_calibration.calibration.analysis.identifiability.IdentifiabilityResult(parameter, is_identifiable, confidence_interval, correlation_with, objective_sensitivity, reason)
dataclass
¶
Result from parameter identifiability analysis.
Determines if a parameter can be reliably estimated from the available data.
Attributes:
| Name | Type | Description |
|---|---|---|
parameter |
str
|
Name of the parameter. |
is_identifiable |
bool
|
Whether the parameter is considered identifiable. |
confidence_interval |
Tuple[float, float]
|
Estimated 95% confidence interval. |
correlation_with |
Dict[str, float]
|
Correlation coefficients with other parameters. |
objective_sensitivity |
float
|
Maximum sensitivity across all objectives. |
reason |
str
|
Explanation for the identifiability status. |
pyadm1ode_calibration.calibration.analysis.identifiability.SubsetIdentifiability(parameters, collinearity_index, is_identifiable, reason)
dataclass
¶
Whether a set of parameters can be estimated together.
Attributes:
| Name | Type | Description |
|---|---|---|
parameters |
List[str]
|
The subset this verdict is about. |
collinearity_index |
float
|
Brun's index, see :func: |
is_identifiable |
bool
|
Whether the index stays below
:data: |
reason |
str
|
Explanation of the verdict. |
pyadm1ode_calibration.calibration.analysis.identifiability.collinearity_index(sensitivity_matrix)
¶
Brun's collinearity index for the given sensitivity matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sensitivity_matrix
|
ndarray
|
One column per parameter, one row per observation. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
|
float
|
1.0 means the parameters act on the outputs in completely independent |
|
float
|
directions, and the value grows without bound as they become linearly |
|
float
|
dependent. |
|
float
|
nothing at all. |
Source code in pyadm1ode_calibration/calibration/analysis/identifiability.py
Validation¶
pyadm1ode_calibration.calibration.validation.CalibrationValidator(plant, verbose=True, time_varying_feed=False)
¶
Validator for calibrated model parameters.
Provides methods to evaluate the goodness-of-fit of calibrated parameters on both training and out-of-sample validation data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plant
|
Any
|
The PyADM1ODE plant model instance. |
required |
verbose
|
bool
|
Whether to enable verbose output. Defaults to True. |
True
|
Source code in pyadm1ode_calibration/calibration/validation.py
Methods:¶
analyze_residuals(measurements, simulated, objectives=None)
¶
Perform detailed residual analysis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
measurements
|
MeasurementData
|
Reference measurements. |
required |
simulated
|
Dict[str, ndarray]
|
Simulated outputs. |
required |
objectives
|
Optional[List[str]]
|
Variables to analyze. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, ResidualAnalysis]
|
Dict[str, ResidualAnalysis]: Analysis results for each objective. |
Source code in pyadm1ode_calibration/calibration/validation.py
cross_validate(parameters, measurements, n_folds=5, objectives=None)
¶
Perform k-fold cross-validation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parameters
|
Dict[str, float]
|
Calibrated parameters. |
required |
measurements
|
MeasurementData
|
Full dataset to split. |
required |
n_folds
|
int
|
Number of folds. Defaults to 5. |
5
|
objectives
|
Optional[List[str]]
|
Variables to validate. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, list[ValidationMetrics]]
|
Dict[str, List[ValidationMetrics]]: List of metrics for each fold. |
Source code in pyadm1ode_calibration/calibration/validation.py
validate(parameters, measurements, objectives=None, simulation_duration=None, warmup=None)
¶
Validate parameters against measurement data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parameters
|
Dict[str, float]
|
Calibrated parameters to test. |
required |
measurements
|
MeasurementData
|
Reference measurement data. |
required |
objectives
|
Optional[List[str]]
|
Variables to validate. |
None
|
simulation_duration
|
Optional[float]
|
Duration in days. |
None
|
warmup
|
Optional[MeasurementData]
|
Window to run before the scored one, so a later stretch of a record is not judged from the plant's initial state. Pass the training window when validating on the test window that follows it; without it the score contains the start-up transient rather than the model error. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, ValidationMetrics]
|
Dict[str, ValidationMetrics]: Metrics for each objective. |