DQNAgent
python
DQNAgent(model: DQNModel | ThreadSafeModel, device: torch.device | None = None, observation_batch_shape_hint: tuple[int, ...] | None = None) -> NoneAgent responsible for greedy action selection and Q-value computation.
Exploration logic (epsilon-greedy, noisy nets) is handled separately by ExplorationStrategy classes in the Actor.
Initialize the DQNAgent.
Parameters:
model(DQNModel | ThreadSafeModel) – The DQN model or a ThreadSafeModel container.device(device | None) – The device to run inference on.observation_batch_shape_hint(tuple[int, ...] | None) – Optional maximum batch shape for the reusable CUDA observation buffer.
Methods
get_action
python
get_action(state: torch.Tensor | np.ndarray, action_masker: ActionMasker | None = None) -> intChoose the greedy action based on Q-values.
Parameters:
state(Tensor | ndarray) – The current environment state.action_masker(ActionMasker | None) – Optional ActionMasker for filtering allowed actions.
Returns:
int– The chosen action (greedy).
get_actions
python
get_actions(states: np.ndarray, action_masker: ActionMasker | None = None) -> list[int]Choose greedy actions for a batch of states.
Parameters:
states(ndarray) – A batch of state observations with shape(N, *state_shape).action_masker(ActionMasker | None) – Optional ActionMasker for filtering allowed actions.
Returns:
list[int]– A list of selected actions (greedy).
get_q_values
python
get_q_values(states: torch.Tensor | np.ndarray) -> torch.TensorCompute Q-values for the given states.
Parameters:
states(Tensor | ndarray) – A batch of states.
Returns:
Tensor– The computed Q-values.
Values
device
python
device = device if device is not None else torch.device('cpu')model
python
model = model