rlightning.buffer.utils.preprocessors

Preprocessors for transforming observations and actions.

class rlightning.buffer.utils.preprocessors.BoxFlattenPreprocessor(space: MockModule('gymnasium.Space'))[source]

Bases: Preprocessor

Flatten Box observations into 1D vectors.

batch_transform(batched_data: MockModule('numpy.ndarray') | MockModule('torch.Tensor') | Tuple | Dict) Any[source]

Flatten a batch of observations.

property shape: Sequence[int]

Return the flattened output shape.

transform(data: MockModule('numpy.ndarray') | MockModule('torch.Tensor') | Dict) Any[source]

Flatten a single observation.

class rlightning.buffer.utils.preprocessors.DiscretePreprocessor(space: MockModule('gymnasium.Space'))[source]

Bases: Preprocessor

One-hot encoder for discrete observations.

batch_transform(batched_data: MockModule('numpy.ndarray') | MockModule('torch.Tensor') | Tuple | Dict) Any[source]

One-hot encode a batch of observations.

property shape: Sequence[int]

Return the output shape.

transform(data: MockModule('numpy.ndarray') | MockModule('torch.Tensor') | Dict) Any[source]

One-hot encode a single observation.

class rlightning.buffer.utils.preprocessors.NonPreprocessor(space: MockModule('gymnasium.Space'))[source]

Bases: Preprocessor

No-op preprocessor that returns input unchanged.

batch_transform(batched_data: MockModule('numpy.ndarray') | MockModule('torch.Tensor') | Tuple | Dict) Any[source]

Return the batched input unchanged.

property shape: Sequence[int]

Return the original space shape.

transform(data: MockModule('numpy.ndarray') | MockModule('torch.Tensor') | Dict) Any[source]

Return the input unchanged.

class rlightning.buffer.utils.preprocessors.Preprocessor(space: MockModule('gymnasium.Space'))[source]

Bases: ABC

Transform raw data into vectorized representations.

abstractmethod batch_transform(batched_data: MockModule('numpy.ndarray') | MockModule('torch.Tensor') | Tuple | Dict)[source]

Transform a batched raw data as preprocessed

property shape: Sequence[int]

Return the data shape of preprocessed data.

abstractmethod transform(data: MockModule('numpy.ndarray') | MockModule('torch.Tensor') | Dict)[source]

Transform raw data as preprocessed

rlightning.buffer.utils.preprocessors.default_obs_preprocessor(obs_seq: List[Any]) List[Any][source]

Return observations unchanged.

rlightning.buffer.utils.preprocessors.default_reward_preprocessor(rew_seq: List[Any]) List[Any][source]

Return rewards unchanged.

rlightning.buffer.utils.preprocessors.get_preprocessor_cls(space: MockModule('gymnasium.Space')) Type[Preprocessor][source]

Select an appropriate preprocessor class based on space type.