mdp_playground.spaces.image_multi_discrete.ImageMultiDiscrete

class mdp_playground.spaces.image_multi_discrete.ImageMultiDiscrete(state_space_sizes, width=100, height=100, circle_radius=20, transforms='rotate, flip, scale, shift', sh_quant=1, scale_range=(0.5, 1.5), ro_quant=1, seed=None, use_custom_images=None, cust_path=None, dtype=<class 'numpy.uint8'>)[source]

Bases: gym.spaces.box.Box

A space that maps a (multi-)discrete space 1-to-1 to images so that the images may be used as representations for corresponding (multi-)discrete states. A MultiDiscrete space will have multiple dimensions. For each of these dimensions, there is a size that represents the number of categorical states that correspond to that dimension. For size = n, each of these categorical states is numbered from 0 to n-1. For each categorical state numbered n, we associate a polygon with n + 3 sides. This polygon is present in the image associated with this dimension. The images generated for all the dimensions are concatenated together by placing them side by side in the order of the dimensions in Space. Any of the transforms - rotate, flip, scale, shift - can be associated with an object of this class, to apply at random to polygons in the images whenever they are generated.

get_concatenated_image(multi_discrete_state)[source]

Gets an image representation for a given multi_discrete_state

Parameters
  • state_space_sizes (list) – The underlying (multi-)discrete state space sizes to which this class associates images as external observations

  • width (int) – The width of the image

  • height (int) – The height of the image

  • circle_radius (int) – The radius of the circle in which the associated polygons are inscribed

  • transforms (str) – Comma separated string specifiying which transforms are applied to images. (Commas are not actually needed, but are recommended for readability, since it’s only the presence of the string representing the corresponding transform that is checked for.)

  • sh_quant (int) – An int to quantise the shift transforms.

  • scale_range (tuple of floats with length = 2) – A tuple of real numbers to specify (min_scaling, max_scaling) for the scale transform.

  • ro_quant (int) – An int to quantise the rotation transforms.

  • seed (int) – seed for randomly applied transformations and NOT for the underlying state space

  • use_custom_images (str or None) – If None, then default setting of no custom textures or images. If this value is “textures” or “images”, then all images in the cust_path directories are loaded in alphabetical order and correspond 1-to-1 with discrete states which are in numeric order. If this value is “textures”, the textures are applied to the polygons that would have been generated for the default setting (of no custom textures or images). If this value is “images”, then the custom images are drawn in a square (with side length = circle_radius * sqrt(2)) in the centre of the polygon when no transforms are applied. When the underlying state space sizes are multi-discrete, the 1-to-1 state number to image mapping is the same for all discrete sub-spaces.

  • cust_path (str or None) – The directory containing the custom images to be loaded

__init__(state_space_sizes, width=100, height=100, circle_radius=20, transforms='rotate, flip, scale, shift', sh_quant=1, scale_range=(0.5, 1.5), ro_quant=1, seed=None, use_custom_images=None, cust_path=None, dtype=<class 'numpy.uint8'>)[source]
Parameters
  • state_space_sizes (list) – The underlying (multi-)discrete state space sizes to which this class associates images as external observations

  • width (int) – The width of the image

  • height (int) – The height of the image

  • circle_radius (int) – The radius of the circle in which the associated polygons are inscribed

  • transforms (str) – Comma separated string specifiying which transforms are applied to images. (Commas are not actually needed, but are recommended for readability, since it’s only the presence of the string representing the corresponding transform that is checked for.)

  • sh_quant (int) – An int to quantise the shift transforms.

  • scale_range (tuple of floats with length = 2) – A tuple of real numbers to specify (min_scaling, max_scaling) for the scale transform.

  • ro_quant (int) – An int to quantise the rotation transforms.

  • seed (int) – seed for randomly applied transformations and NOT for the underlying state space

  • use_custom_images (str or None) – If None, then default setting of no custom textures or images. If this value is “textures” or “images”, then all images in the cust_path directories are loaded in alphabetical order and correspond 1-to-1 with discrete states which are in numeric order. If this value is “textures”, the textures are applied to the polygons that would have been generated for the default setting (of no custom textures or images). If this value is “images”, then the custom images are drawn in a square (with side length = circle_radius * sqrt(2)) in the centre of the polygon when no transforms are applied. When the underlying state space sizes are multi-discrete, the 1-to-1 state number to image mapping is the same for all discrete sub-spaces.

  • cust_path (str or None) – The directory containing the custom images to be loaded

Methods

__init__(state_space_sizes[, width, height, …])

param state_space_sizes

The underlying (multi-)discrete state space sizes to which this class associates images as external observations

contains(x)

Return boolean specifying if x is a valid member of this space

from_jsonable(sample_n)

Convert a JSONable data type to a batch of samples from this space.

generate_image(discrete_state)

get_concatenated_image(multi_discrete_state)

Gets the “stitched together” image made from images corresponding to each discrete sub-space within the multidiscrete space, concatenated along the X-axis

is_bounded([manner])

sample()

Generates a single random sample inside of the Box.

seed([seed])

Seed the PRNG of this space.

to_jsonable(sample_n)

Convert a batch of samples from this space to a JSONable data type.

contains(x)[source]

Return boolean specifying if x is a valid member of this space

from_jsonable(sample_n)[source]

Convert a JSONable data type to a batch of samples from this space.

get_concatenated_image(multi_discrete_state)[source]

Gets the “stitched together” image made from images corresponding to each discrete sub-space within the multidiscrete space, concatenated along the X-axis

sample()[source]

Generates a single random sample inside of the Box.

In creating a sample of the box, each coordinate is sampled according to the form of the interval:

  • [a, b] : uniform distribution

  • [a, oo) : shifted exponential distribution

  • (-oo, b] : shifted negative exponential distribution

  • (-oo, oo) : normal distribution

seed(seed=None)

Seed the PRNG of this space.

to_jsonable(sample_n)[source]

Convert a batch of samples from this space to a JSONable data type.