Trainer
- class Melodie.trainer.Trainer(config: Config, scenario_cls: Type[Scenario] | None, model_cls: Type[Model] | None, data_loader_cls: Type[DataLoader] | None, processors: int = 1)
Bases:
BaseModellingManager
Trainer trains the agents to update their behavioral parameters for higher payoff.
- 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.
- add_agent_training_property(agent_list_name: str, training_attributes: List[str], agent_ids: Callable[[Scenario], List[int]])
Add a container into the trainer.
- Parameters:
agent_list_name – The name of agent container.
training_attributes – The properties used in training.
agent_ids – The agent with id contained in agent_ids will be trained.
- Returns:
None
- setup()
Setup method, be sure to inherit this method in custom trainer class.
- get_trainer_scenario_cls()
Get the class of trainer scenario.
- Returns:
Trainer parameters
- collect_data()
Set the agent and environment properties to be collected.
- Returns:
- run()
The main method for Trainer.
- Returns:
- run_once_new(scenario: Scenario, trainer_params: GATrainerParams)
Run for one training path
- Parameters:
scenario – The scenario to run
trainer_params – calibration parameters.
- Returns:
None
- utility(agent: Agent) float
The utility is to be maximized. be sure to inherit inside the custom trainer class.
- Parameters:
agent – Agent object.
- Returns:
- target_function(agent: Agent) float
The target function to be minimized.
- Parameters:
agent –
- Returns:
- add_agent_property(agent_list_name: str, prop: str)
Add a property of agent to be recorded.
- Parameters:
agent_list_name – Name of agent list
prop – Property name of agent
- add_environment_property(prop: str)
Add a property of environment to be recorded.
- Parameters:
prop – Property name of environment.
- generate_scenarios()
Generate Scenarios for trainer
- Returns:
A list of scenario objects.
- generate_trainer_params_list(trainer_scenario_cls: Type[GATrainerParams]) List[GATrainerParams]
Generate Trainer Parameters.
- Returns:
A list of trainer parameters.