Trajectory Recorder
The trajectory_recorder module provides functionality to save and manage game trajectories, which capture the full sequence of states, actions, and rewards during an episode.
netsecgame.utils.trajectory_recorder
TrajectoryRecorder
Manages the recording and storage of agent trajectories.
Initializes the TrajectoryRecorder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_name
|
str
|
The name of the agent. |
required |
agent_role
|
str
|
The role of the agent. |
required |
Source code in netsecgame/utils/trajectory_recorder.py
14 15 16 17 18 19 20 21 22 23 24 25 26 | |
add_initial_state
Adds the initial state to the trajectory history.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
GameState
|
The initial game state. |
required |
Source code in netsecgame/utils/trajectory_recorder.py
62 63 64 65 66 67 68 69 | |
add_step
Adds a single step to the trajectory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action
|
Action
|
The action taken. |
required |
reward
|
float
|
The reward received. |
required |
next_state
|
GameState
|
The resulting state. |
required |
end_reason
|
Optional[str]
|
Reason for episode end, if applicable. |
None
|
Source code in netsecgame/utils/trajectory_recorder.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
get_trajectory
Returns the current trajectory data.
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict[str, Any]: The trajectory dictionary. |
Source code in netsecgame/utils/trajectory_recorder.py
71 72 73 74 75 76 77 78 | |
reset
Resets the trajectory data for a new episode.
Source code in netsecgame/utils/trajectory_recorder.py
28 29 30 31 32 33 34 35 36 37 38 39 40 | |
save_to_file
Saves the recorded trajectory to a JSONL file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
location
|
str
|
Directory to save the file. Defaults to "./logs/trajectories". |
'./logs/trajectories'
|
filename
|
str
|
Name of the file to save. If None, defaults to "{datetime.now():%Y-%m-%d}{self.agent_name}{self.agent_role}". |
None
|
Source code in netsecgame/utils/trajectory_recorder.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |