grid#

gym_socks.utils.grid.boxgrid(space, resolution, out=None)[source]#

Returns a coarse grid from a bounded Box space.

Constructs a coarse grid from a bounded box in \(\mathbb{R}^n\). A Box is the Cartesian product of \(n\) intervals, and we create a coarse grid of those intervals using a specified resolution.

Parameters
  • space (gym.spaces.box.Box) – The Box space to create a grid over. Must be bounded.

  • resolution (tuple) – The grid resolution. Can either be a single integer (applies to all dimensions) or a tuple of integers, which is of length \(n\).

Returns

Grid of points (the product of all points in ranges).

Example

>>> import numpy as np
>>> from gym.spaces import Box
>>> from gym_socks.utils.grid import boxgrid
>>> space = Box(low=-1, high=1, shape=(2,), dtype=np.float32)
>>> boxgrid(space, (3, 5))
array([[-1. , -1. ],
       [-1. , -0.5],
       [-1. ,  0. ],
       [-1. ,  0.5],
       [-1. ,  1. ],
       [ 0. , -1. ],
       [ 0. , -0.5],
       [ 0. ,  0. ],
       [ 0. ,  0.5],
       [ 0. ,  1. ],
       [ 1. , -1. ],
       [ 1. , -0.5],
       [ 1. ,  0. ],
       [ 1. ,  0.5],
       [ 1. ,  1. ]])
gym_socks.utils.grid.cartesian(*xi, out=None)[source]#

Create a grid of points from ranges.

Parameters

xi – Ranges.

Returns

Grid of points (the product of all points in ranges).

Example

>>> import numpy as np
>>> from gym_socks.utils.grid import cartesian
>>> grid = cartesian(np.linspace(1, 3, 3), np.linspace(4, 6, 3))
array([[1.0, 4.0],
       [1.0, 5.0],
       [1.0, 6.0],
       [2.0, 4.0],
       [2.0, 5.0],
       [2.0, 6.0],
       [3.0, 4.0],
       [3.0, 5.0],
       [3.0, 6.0]])