CategoricalProjection
python
CategoricalProjection(v_min: float, v_max: float, num_atoms: int, gamma: float, n_step: int, device: torch.device) -> NoneHandles categorical distribution projection (L2-projection) for distributional RL (C51). Extracted from Learner for better separation of concerns.
Initialize the CategoricalProjection.
Parameters:
v_min(float) – Minimum value of the support.v_max(float) – Maximum value of the support.num_atoms(int) – Number of atoms in the distribution.gamma(float) – Discount factor.n_step(int) – Number of steps for n-step returns.device(device) – The device to perform computations on.
Methods
project
python
project(next_dist: torch.Tensor, rewards: torch.Tensor, dones: torch.Tensor, support: torch.Tensor, n_steps: torch.Tensor | int | None = None) -> torch.TensorPerform the categorical projection (L2-projection) of the target distribution.
Parameters:
next_dist(Tensor) – The distribution of the next state's chosen action with shape (batch_size,num_atoms).rewards(Tensor) – The received rewards with shape (batch_size, 1).dones(Tensor) – Whether the episode finished with shape (batch_size, 1).support(Tensor) – The support tensor from the model.n_steps(Tensor | int | None) – Optional number of steps for each transition. If None, uses self.n_step.
Returns:
Tensor– The projected target distribution with shape (batch_size,num_atoms).
Values
delta_z
python
delta_z = (v_max - v_min) / (num_atoms - 1)device
python
device = devicegamma
python
gamma = gamman_step
python
n_step = n_stepnum_atoms
python
num_atoms = num_atomsv_max
python
v_max = v_maxv_min
python
v_min = v_min