SymExpTwoHot#
- class torchrl.modules.SymExpTwoHot(num_bins: int = 255)[source]#
DreamerV3 categorical scalar representation.
The support contains
num_binsraw scalar values obtained by applyingsymexpto an evenly spaced grid from -20 to 20. Targets are interpolated between adjacent raw support values, while predictions are decoded as the softmax-weighted raw-value expectation.- Parameters:
num_bins (int, optional) – Number of categorical support values. Defaults to 255.
Examples
>>> import torch >>> from torchrl.modules import SymExpTwoHot >>> two_hot = SymExpTwoHot(num_bins=5) >>> target = torch.tensor([-10.0, 0.0, 10.0]) >>> encoded = two_hot.encode(target) >>> decoded = two_hot.decode(encoded.log()) >>> torch.allclose(decoded, target, atol=1e-3) True