Gaussian noise

Noise generated by normal distribution.



Usage

The noise usage is defined in each agent’s configuration.

# import the noise class
from skrl.resources.noises.torch import GaussianNoise

cfg = AGENT_CFG()
# ...
cfg.exploration_noise = GaussianNoise
cfg.exploration_noise_kwargs = {"mean": 0.0, "std": 0.1, "device": device}

API


PyTorch

GaussianNoise

Gaussian noise.

class skrl.resources.noises.torch.gaussian.GaussianNoise(*, mean: float, std: float, device: str | torch.device | None = None)[source]

Bases: Noise

Gaussian noise.

Parameters:
  • mean – Mean of the normal distribution.

  • std – Standard deviation of the normal distribution.

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

Example:

>>> noise = GaussianNoise(mean=0, std=1)

Methods:

sample(size)

Sample a Gaussian noise.

sample_like(tensor)

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

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

Sample a Gaussian noise.

Parameters:

size – Noise shape.

Returns:

Sampled noise.

Example:

>>> noise.sample((3, 2))
tensor([[-0.4901,  1.3357],
        [-1.2141,  0.3323],
        [-0.0889, -1.1651]], device='cuda:0')

>>> x = torch.rand(3, 2, device="cuda:0")
>>> noise.sample(x.shape)
tensor([[0.5398, 1.2009],
        [0.0307, 1.3065],
        [0.2082, 0.6116]], device='cuda:0')
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

GaussianNoise

Gaussian noise.

class skrl.resources.noises.jax.gaussian.GaussianNoise(*, mean: float, std: float, device: str | jax.Device | None = None)[source]

Bases: Noise

Gaussian noise.

Parameters:
  • mean – Mean of the normal distribution.

  • std – Standard deviation of the normal distribution.

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

Example:

>>> noise = GaussianNoise(mean=0, std=1)

Methods:

sample(size)

Sample a Gaussian noise.

sample_like(tensor)

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

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

Sample a Gaussian noise.

Parameters:

size – Noise shape.

Returns:

Sampled noise.

Example:

>>> noise.sample((3, 2))
Array([[ 0.01878439, -0.12833427],
       [ 0.06494182,  0.12490594],
       [ 0.024447  , -0.01174496]], dtype=float32)

>>> x = jax.random.uniform(jax.random.PRNGKey(0), (3, 2))
>>> noise.sample(x.shape)
Array([[ 0.17988093, -1.2289404 ],
       [ 0.6218886 ,  1.1961104 ],
       [ 0.23410667, -0.11247082]], dtype=float32)
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

GaussianNoise

Gaussian noise.

class skrl.resources.noises.warp.gaussian.GaussianNoise(*, mean: float, std: float, device: str | wp.Device | None = None)[source]

Bases: Noise

Gaussian noise.

Parameters:
  • mean – Mean of the normal distribution.

  • std – Standard deviation of the normal distribution.

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

Example:

>>> noise = GaussianNoise(mean=0, std=1)

Methods:

sample(size)

Sample a Gaussian noise.

sample_like(tensor)

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

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

Sample a Gaussian noise.

Parameters:

size – Noise shape.

Returns:

Sampled noise.

Example:

>>> noise.sample((3, 2))
Array([[ 0.01878439, -0.12833427],
       [ 0.06494182,  0.12490594],
       [ 0.024447  , -0.01174496]], dtype=float32)

>>> x = jax.random.uniform(jax.random.PRNGKey(0), (3, 2))
>>> noise.sample(x.shape)
Array([[ 0.17988093, -1.2289404 ],
       [ 0.6218886 ,  1.1961104 ],
       [ 0.23410667, -0.11247082]], dtype=float32)
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)