Calibrator
- class Melodie.calibrator.Calibrator(config: Config, scenario_cls: Type[Scenario] | None, model_cls: Type[Model] | None, data_loader_cls: Type[DataLoader], processors=1)
Bases:
BaseModellingManager
Calibrator calibrates the parameters of the scenario by minimizing the distance between model output and empirical evidence.
- Parameters:
config – Config instance for current project.
scenario_cls – Scenario class for current project.
model_cls – Model class in current project.
data_loader_cls – DataLoader class in current project.
processors – Each path in current iteration will be computed parallelly, this parameter stands for processor cores used in parallel computation.
- setup()
Setup method, be sure to inherit this method in custom calibrator class.
- collect_data()
Set the agent and environment properties to be collected.
- generate_scenarios() List[Scenario]
Generate scenario objects by the parameter from static tables or scenarios_dataframe.
- Returns:
A list of generated scenarios.
- get_params_scenarios() List
Get the parameters of calibrator parameters from the registered dataframe.
- Returns:
A list of dict, and each dict contains parameters.
- run()
The main method for calibrator.
- run_once_new(scenario: Scenario, calibration_params: GACalibratorParams)
Run for one calibration path
- Parameters:
scenario – The scenario to run.
calibration_params – calibration parameters.
- Returns:
None
- target_function(model: Model) float | int
The target function to be minimized
- Parameters:
env – Environment of the current model.
- Returns:
- distance(model: Model) float
The optimization of calibrator is to minimize the distance.
Be sure to inherit this function in custom calibrator, and return a float value.
- Parameters:
model – The current model after running the current parameter set.
- Returns:
None
- add_scenario_calibrating_property(prop: str)
Add a property to be tuned in the calibration, and
prop
should be a name of property in the environment.- Parameters:
prop – Property name
- Returns:
None
- add_environment_property(prop: str)
Add a property of environment to be recorded in the calibration voyage.
- Parameters:
prop – Property name
- Returns:
None