nnrl/utils.py
def fake_space_samples(space: spaces.Space, batch_size: int) -> Tensor:
    """Create fake samples from a Gym space."""
    if isinstance(space, spaces.Box):
        shape = (batch_size,) + space.shape
        randn = np.random.randn(*shape)
        array = np.clip(randn, space.low, space.high).astype(space.dtype)
    elif isinstance(space, spaces.Discrete):
        randint = np.random.randint(space.n, size=batch_size)
        array = randint.astype(space.dtype)
    else:
        raise ValueError(f"Unsupported space type {type(space)}")
    return torch.as_tensor(array)
Create fake samples from a Gym space.
Create fake samples from a Gym space.
Create fake samples from a Gym space .
def fake_space_samples(space: spaces.Space, batch_size: int) -> Tensor:
    if isinstance(space, spaces.Box):
        shape = (batch_size,) + space.shape
        randn = np.random.randn(*shape)
        array = np.clip(randn, space.low, space.high).astype(space.dtype)
    elif isinstance(space, spaces.Discrete):
        randint = np.random.randint(space.n, size=batch_size)
        array = randint.astype(space.dtype)
    else:
        raise ValueError(f"Unsupported space type {type(space)}")
    return torch.as_tensor(array)
def fake_space_samples ( space : spaces . Space , batch_size : int ) -> Tensor : if isinstance ( space , spaces . Box ) : shape = ( batch_size , ) + space . shape randn = np . random . randn ( * shape ) array = np . clip ( randn , space . low , space . high ) . astype ( space . dtype ) elif isinstance ( space , spaces . Discrete ) : randint = np . random . randint ( space . n , size = batch_size ) array = randint . astype ( space . dtype ) else : raise ValueError ( f"Unsupported space type {type(space)}" ) return torch . as_tensor ( array )
Create fake samples from a Gym space.
Create fake samples from a Gym space .
"""Create fake samples from a Gym space."""
space
spaces.Space
batch_size
int