Noises

Definition of the noises used by the agents during the exploration stage.



Implemented noises

The following table lists the implemented noises and their support for different frameworks.

Noises

    pytorch    

    jax    

    warp    

Gaussian noise

\(\blacksquare\)

\(\blacksquare\)

\(\blacksquare\)

Ornstein-Uhlenbeck noise  

\(\blacksquare\)

\(\blacksquare\)

\(\blacksquare\)



Base class

Base class for noises.

API


PyTorch

Noise

Base noise class for implementing custom noises.

class skrl.resources.noises.torch.Noise(*, device: str | torch.device | None = None)[source]

Bases: ABC

Base noise class for implementing custom noises.

Parameters:

device – Data allocation and computation device. If not specified, the default device will be used.

Methods:

sample(size)

Sample noise.

sample_like(tensor)

Sample noise with the same size (shape) as the input tensor.

abstractmethod sample(size: list[int] | torch.Size) torch.Tensor[source]

Sample noise.

Parameters:

size – Noise shape.

Returns:

Sampled noise.

Raises:

NotImplementedError – This method must be implemented by subclasses.

sample_like(tensor: torch.Tensor) torch.Tensor[source]

Sample noise with the same size (shape) as the input tensor.

This method will call the sampling method as follows .sample(tensor.shape).

Parameters:

tensor – Input tensor used to determine output tensor size (shape).

Returns:

Sampled noise.

Example:

>>> x = torch.rand(3, 2, device="cuda:0")
>>> noise.sample_like(x)
tensor([[-0.0423, -0.1325],
        [-0.0639, -0.0957],
        [-0.1367,  0.1031]], device='cuda:0')

JAX

Noise

Base noise class for implementing custom noises.

class skrl.resources.noises.jax.Noise(*, device: str | jax.Device | None = None)[source]

Bases: ABC

Base noise class for implementing custom noises.

Parameters:

device – Data allocation and computation device. If not specified, the default device will be used.

Methods:

sample(size)

Sample noise.

sample_like(tensor)

Sample noise with the same size (shape) as the input tensor.

abstractmethod sample(size: list[int]) jax.Array[source]

Sample noise.

Parameters:

size – Noise shape.

Returns:

Sampled noise.

Raises:

NotImplementedError – This method must be implemented by subclasses.

sample_like(tensor: jax.Array) jax.Array[source]

Sample noise with the same size (shape) as the input tensor.

This method will call the sampling method as follows .sample(tensor.shape).

Parameters:

tensor – Input tensor used to determine output tensor size (shape).

Returns:

Sampled noise.

Example:

>>> x = jax.random.uniform(jax.random.PRNGKey(0), (3, 2))
>>> noise.sample_like(x)
Array([[0.57450044, 0.09968603],
       [0.7419659 , 0.8941783 ],
       [0.59656656, 0.45325184]], dtype=float32)

Warp

Noise

Base noise class for implementing custom noises.

class skrl.resources.noises.warp.Noise(*, device: str | wp.Device | None = None)[source]

Bases: ABC

Base noise class for implementing custom noises.

Parameters:

device – Data allocation and computation device. If not specified, the default device will be used.

Methods:

sample(size)

Sample noise.

sample_like(tensor)

Sample noise with the same size (shape) as the input tensor.

abstractmethod sample(size: list[int]) warp.array[source]

Sample noise.

Parameters:

size – Noise shape.

Returns:

Sampled noise.

Raises:

NotImplementedError – This method must be implemented by subclasses.

sample_like(tensor: warp.array) warp.array[source]

Sample noise with the same size (shape) as the input tensor.

This method will call the sampling method as follows .sample(tensor.shape).

Parameters:

tensor – Input tensor used to determine output tensor size (shape).

Returns:

Sampled noise.

Example:

>>> x = jax.random.uniform(jax.random.PRNGKey(0), (3, 2))
>>> noise.sample_like(x)
Array([[0.57450044, 0.09968603],
       [0.7419659 , 0.8941783 ],
       [0.59656656, 0.45325184]], dtype=float32)