coopihc.bundle.BaseBundle.BaseBundle
- class BaseBundle(task, user, assistant, *args, reset_random=False, reset_start_after=- 1, reset_go_to=0, **kwargs)[source]
Bases:
object
Main class for bundles.
Main class for bundles. This class is subclassed by Bundle, which defines the interface with which to interact.
A bundle combines a task with a user and an assistant. The bundle creates the
game_state
by combining the task, user and assistant states with the turn index and both agent’s actions.The bundle takes care of all the messaging between classes, making sure the gamestate and all individual states are synchronized at all times.
The bundle implements a forced reset mechanism, where each state of the bundle can be forced to a particular state via a dictionnary mechanism (see :py:func:reset)
The bundle also takes care of rendering each of the three component in a single place.
- Parameters
task – (
coopihc.interactiontask.InteractionTask.InteractionTask
) A task that inherits fromInteractionTask
user – (
coopihc.agents.BaseAgent.BaseAgent
) a user which inherits fromBaseAgent
assistant – (
coopihc.agents.BaseAgent.BaseAgent
) an assistant which inherits fromBaseAgent
Methods
Close the bundle once the game is finished.
quarter_step
Combines all render methods.
Reset bundle.
Play a round
Attributes
parameters
The round number in the game (0 to N)
state
turn_dict
The turn number in the game (0 to 3)
- render(mode, *args, **kwargs)[source]
Combines all render methods.
- Parameters
mode – “text” or “plot”
type – string
- reset(go_to=None, start_after=None, task=True, user=True, assistant=True, dic={}, random_reset=False)[source]
Reset bundle.
Reset the game and start at a specific turn number.
select which components to reset
forced reset mechanism using dictionnaries
Example:
new_target_value = self.game_state["task_state"]["targets"] new_fixation_value = self.game_state["task_state"]["fixation"] ) reset_dic = {"task_state": {"targets": new_target_value, "fixation": new_fixation_value}} self.reset(dic=reset_dic, turn = 1)
Will set the substates “targets” and “fixation” of state “task_state” to some value.
Note
If subclassing BaseBundle, make sure to call super().reset() in the new reset method.
- Parameters
turn (int, optional) – game turn number. Can also be set globally at the bundle level by passing the “reset_turn” keyword argument, defaults to 0
start_after (int, optional) – which turn to start at (allows skipping some turns during reset), defaults to 0
task (bool, optional) – reset task?, defaults to True
user (bool, optional) – reset user?, defaults to True
assistant (bool, optional) – reset assistant?, defaults to True
dic (dict, optional) – reset_dic, defaults to {}
random_reset (bool, optional) – whether during resetting values should be randomized or not if not set by a reset dic, default to False
- Returns
new game state
- Return type
- property round_number
The round number in the game (0 to N)
- Returns
turn number
- Return type
numpy.ndarray
- step(user_action=None, assistant_action=None, go_to=None, **kwargs)[source]
Play a round
Play a round of the game. A round consists in 4 turns. If go_to is not None, the round is only played until that turn. If a user action and assistant action are passed as arguments, then these are used as actions to play the round. Otherwise, these actions are sampled from each agent’s policy.
- Parameters
action (assistant) – user action
action – assistant action
go_to (int, optional) – turn at which round stops, defaults to None
- Type
any
- Type
any
- Returns
gamestate, reward, game finished flag
- Return type
tuple(
State
, collections.OrderedDict, boolean)
- property turn_number
The turn number in the game (0 to 3)
- Returns
turn number
- Return type
numpy.ndarray