pub trait DiscreteActionMapper<A> {
// Required methods
fn num_actions(&self) -> usize;
fn action_to_index(&self, action: &A) -> usize;
fn index_to_action(&self, index: usize) -> A;
}Expand description
Maps between environment action types and integer indices.
DQN is a discrete-action algorithm. The Q-network outputs one Q-value
per action, indexed 0..N. This trait bridges that integer world and the
environment’s Action type, which may be an enum or something richer.
§Example
use ember_rl::encoding::DiscreteActionMapper;
// CartPole: action is just usize (push left = 0, push right = 1)
struct CartPoleActions;
impl DiscreteActionMapper<usize> for CartPoleActions {
fn num_actions(&self) -> usize { 2 }
fn action_to_index(&self, action: &usize) -> usize { *action }
fn index_to_action(&self, index: usize) -> usize { index }
}Required Methods§
Sourcefn num_actions(&self) -> usize
fn num_actions(&self) -> usize
Total number of discrete actions available.
Determines the Q-network’s output layer size.
Sourcefn action_to_index(&self, action: &A) -> usize
fn action_to_index(&self, action: &A) -> usize
Convert an action to its integer index.
Used when storing experience – we record the index, not the action.
Sourcefn index_to_action(&self, index: usize) -> A
fn index_to_action(&self, index: usize) -> A
Convert an integer index to an action.
Used when the Q-network selects an action – it returns an argmax index that we convert back to the environment’s action type.