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
Functions¶
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
Initialer Kalibrator¶
pyadm1ode_calibration.calibration.InitialCalibrator(plant, verbose=True)
¶
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
Functions¶
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, **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
|
**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
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 | |
identifiability_analysis(parameters, measurements)
¶
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 |
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 Kalibrator¶
pyadm1ode_calibration.calibration.OnlineCalibrator(plant, verbose=True, parameter_bounds=None)
¶
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
Functions¶
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
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 | |
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
Kalibrierungs-Resultat¶
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().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. |
Functions¶
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 |
Simulator¶
pyadm1ode_calibration.calibration.core.simulator.PlantSimulator(plant, verbose=True)
¶
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
Functions¶
simulate_with_parameters(parameters, measurements, restore_params=True)
¶
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
|
Returns:
| Type | Description |
|---|---|
Dict[str, ndarray]
|
Dict[str, np.ndarray]: Dictionary mapping output names (e.g., 'Q_ch4') to simulated numpy arrays. |