akro package

A library containing types of Spaces.

class akro.Space[source]

Bases: object

Provides a classification state spaces and action spaces.

Allows you to write generic code that applies to any Environment. E.g. to choose a random action.

contains(x)[source]

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

flat_dim

Return the length of the flattened vector of the space.

flatten(x)[source]

Return a flattened observation x.

Returns:
x (flattened)
flatten_n(xs)[source]

Return flattened observations xs.

Returns:
xs (flattened)
new_tensor_variable(name, extra_dims)[source]

Create a tensor variable given the name and extra dimensions.

Parameters:
  • name – name of the variable
  • extra_dims – extra dimensions in the front
Returns:

the created tensor variable

sample(seed=0)[source]

Uniformly randomly sample a random element of this space.

unflatten(x)[source]

Return an unflattened observation x.

Returns:
x (unflattened)
unflatten_n(xs)[source]

Return unflattened observations xs.

Returns:
xs (unflattened)
class akro.Box(low, high, shape=None, dtype=<class 'numpy.float32'>)[source]

Bases: akro.space.Space

A box in R^n.

Each coordinate is bounded above and below.

bounds

Return a 2-tuple containing the lower and upper bounds.

contains(x)[source]

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

dtype

Return the dtype of samples contained in this Space.

flat_dim

Return the length of the flattened vector of the space.

flatten(x)[source]

Return a flattened observation x.

Returns:
x (flattened)
flatten_n(xs)[source]

Return flattened observations xs.

Returns:
xs (flattened)
new_tensor_variable(name, extra_dims)[source]

Create a tensor variable given the name and extra dimensions.

Parameters:
  • name – name of the variable
  • extra_dims – extra dimensions in the front
Returns:

the created tensor variable

sample()[source]

Uniformly randomly sample a random element of this space.

shape

Return the shape of samples contained in this Space.

unflatten(x)[source]

Return an unflattened observation x.

Returns:
x (unflattened)
unflatten_n(xs)[source]

Return unflattened observations xs.

Returns:
xs (unflattened)
class akro.Dict(spaces)[source]

Bases: akro.space.Space

A dictionary of simpler spaces, e.g. Discrete, Box.

Example usage:
self.observation_space = spaces.Dict({“position”: spaces.Discrete(2),
“velocity”: spaces.Discrete(3)})
contains(x)[source]

Check if x is contained within self.spaces.

Returns:
Boolean
flat_dim

Return a flat dimension of the dict space.

Returns:
flat_dim (int)
flatten(x)[source]

Return a flattened observation x.

Returns:
x (flattened)
flatten_n(xs)[source]

Return flattened observations xs.

Returns:
xs (flattened)
from_jsonable(sample_n)[source]

Convert information from a JSON format into a list.

Returns:
ret (list)
new_tensor_variable(name, extra_dims)[source]

Create a tensor variable given the name and extra dimensions.

Parameters:
  • name – name of the variable
  • extra_dims – extra dimensions in the front
Returns:

the created tensor variable

sample()[source]

Return a sample from each space in spaces.

Returns:
OrderedDict
to_jsonable(sample_n)[source]

Serialize as a dict-representation of vectors.

Returns:
JSON (dict)
unflatten(x)[source]

Return an unflattened observation x.

Returns:
x (unflattened)
unflatten_n(xs)[source]

Return unflattened observations xs.

Returns:
xs (unflattened)
class akro.Discrete(n)[source]

Bases: akro.space.Space

{0,1,…,n-1}.

contains(x)[source]

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

default_value

Return the default value of the spaceself.

This is always just 0.

flat_dim

Return the length of the flattened vector of the space.

flatten(x)[source]

Return a flattened observation x.

Returns:
x (flattened)
flatten_n(x)[source]

Return flattened observations xs.

Returns:
xs (flattened)
n

Return the number of elements in the Discrete space.

new_tensor_variable(name, extra_dims)[source]

Create a tensor variable given the name and extra dimensions.

Parameters:
  • name – name of the variable
  • extra_dims – extra dimensions in the front
Returns:

the created tensor variable

sample()[source]

Uniformly randomly sample a random element of this space.

unflatten(x)[source]

Return an unflattened observation x.

Returns:
x (unflattened)
unflatten_n(x)[source]

Return unflattened observations xs.

Returns:
xs (unflattened)
weighted_sample(weights)[source]

Compute a weighted sample of the elements in the Discrete Space.

class akro.Tuple(*components)[source]

Bases: akro.space.Space

A Tuple of Spaces which produces samples which are Tuples of samples.

components

Each of the spaces making up this Tuple space.

contains(x)[source]

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

flat_dim

Return the length of the flattened vector of the space.

flatten(x)[source]

Return a flattened observation x.

Returns:
x (flattened)
flatten_n(xs)[source]

Return flattened observations xs.

Returns:
xs (flattened)
new_tensor_variable(name, extra_dims)[source]

Create a tensor variable given the name and extra dimensions.

Parameters:
  • name – name of the variable
  • extra_dims – extra dimensions in the front
Returns:

the created tensor variable

sample()[source]

Uniformly randomly sample a random element of this space.

unflatten(x)[source]

Return an unflattened observation x.

Returns:
x (unflattened)
unflatten_n(xs)[source]

Return unflattened observations xs.

Returns:
xs (unflattened)

Submodules

akro.box module

A Space representing a rectangular region of space.

class akro.box.Box(low, high, shape=None, dtype=<class 'numpy.float32'>)[source]

Bases: akro.space.Space

A box in R^n.

Each coordinate is bounded above and below.

bounds

Return a 2-tuple containing the lower and upper bounds.

contains(x)[source]

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

dtype

Return the dtype of samples contained in this Space.

flat_dim

Return the length of the flattened vector of the space.

flatten(x)[source]

Return a flattened observation x.

Returns:
x (flattened)
flatten_n(xs)[source]

Return flattened observations xs.

Returns:
xs (flattened)
new_tensor_variable(name, extra_dims)[source]

Create a tensor variable given the name and extra dimensions.

Parameters:
  • name – name of the variable
  • extra_dims – extra dimensions in the front
Returns:

the created tensor variable

sample()[source]

Uniformly randomly sample a random element of this space.

shape

Return the shape of samples contained in this Space.

unflatten(x)[source]

Return an unflattened observation x.

Returns:
x (unflattened)
unflatten_n(xs)[source]

Return unflattened observations xs.

Returns:
xs (unflattened)

akro.dict module

Cartesian product of multiple named Spaces (also known as a dict of Spaces).

This Space produces samples which are dicts, where the values of those dicts are drawn from the values of this Space.

class akro.dict.Dict(spaces)[source]

Bases: akro.space.Space

A dictionary of simpler spaces, e.g. Discrete, Box.

Example usage:
self.observation_space = spaces.Dict({“position”: spaces.Discrete(2),
“velocity”: spaces.Discrete(3)})
contains(x)[source]

Check if x is contained within self.spaces.

Returns:
Boolean
flat_dim

Return a flat dimension of the dict space.

Returns:
flat_dim (int)
flatten(x)[source]

Return a flattened observation x.

Returns:
x (flattened)
flatten_n(xs)[source]

Return flattened observations xs.

Returns:
xs (flattened)
from_jsonable(sample_n)[source]

Convert information from a JSON format into a list.

Returns:
ret (list)
new_tensor_variable(name, extra_dims)[source]

Create a tensor variable given the name and extra dimensions.

Parameters:
  • name – name of the variable
  • extra_dims – extra dimensions in the front
Returns:

the created tensor variable

sample()[source]

Return a sample from each space in spaces.

Returns:
OrderedDict
to_jsonable(sample_n)[source]

Serialize as a dict-representation of vectors.

Returns:
JSON (dict)
unflatten(x)[source]

Return an unflattened observation x.

Returns:
x (unflattened)
unflatten_n(xs)[source]

Return unflattened observations xs.

Returns:
xs (unflattened)

akro.discrete module

A space representing a selection between a finite number of items.

class akro.discrete.Discrete(n)[source]

Bases: akro.space.Space

{0,1,…,n-1}.

contains(x)[source]

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

default_value

Return the default value of the spaceself.

This is always just 0.

flat_dim

Return the length of the flattened vector of the space.

flatten(x)[source]

Return a flattened observation x.

Returns:
x (flattened)
flatten_n(x)[source]

Return flattened observations xs.

Returns:
xs (flattened)
n

Return the number of elements in the Discrete space.

new_tensor_variable(name, extra_dims)[source]

Create a tensor variable given the name and extra dimensions.

Parameters:
  • name – name of the variable
  • extra_dims – extra dimensions in the front
Returns:

the created tensor variable

sample()[source]

Uniformly randomly sample a random element of this space.

unflatten(x)[source]

Return an unflattened observation x.

Returns:
x (unflattened)
unflatten_n(x)[source]

Return unflattened observations xs.

Returns:
xs (unflattened)
weighted_sample(weights)[source]

Compute a weighted sample of the elements in the Discrete Space.

akro.space module

The abstract base class for all Space types.

class akro.space.Space[source]

Bases: object

Provides a classification state spaces and action spaces.

Allows you to write generic code that applies to any Environment. E.g. to choose a random action.

contains(x)[source]

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

flat_dim

Return the length of the flattened vector of the space.

flatten(x)[source]

Return a flattened observation x.

Returns:
x (flattened)
flatten_n(xs)[source]

Return flattened observations xs.

Returns:
xs (flattened)
new_tensor_variable(name, extra_dims)[source]

Create a tensor variable given the name and extra dimensions.

Parameters:
  • name – name of the variable
  • extra_dims – extra dimensions in the front
Returns:

the created tensor variable

sample(seed=0)[source]

Uniformly randomly sample a random element of this space.

unflatten(x)[source]

Return an unflattened observation x.

Returns:
x (unflattened)
unflatten_n(xs)[source]

Return unflattened observations xs.

Returns:
xs (unflattened)

akro.tuple module

Cartesian product of multiple Spaces (also known as a tuple of Spaces).

This Space produces samples which are Tuples, where the elments of those Tuples are drawn from the components of this Space.

class akro.tuple.Tuple(*components)[source]

Bases: akro.space.Space

A Tuple of Spaces which produces samples which are Tuples of samples.

components

Each of the spaces making up this Tuple space.

contains(x)[source]

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

flat_dim

Return the length of the flattened vector of the space.

flatten(x)[source]

Return a flattened observation x.

Returns:
x (flattened)
flatten_n(xs)[source]

Return flattened observations xs.

Returns:
xs (flattened)
new_tensor_variable(name, extra_dims)[source]

Create a tensor variable given the name and extra dimensions.

Parameters:
  • name – name of the variable
  • extra_dims – extra dimensions in the front
Returns:

the created tensor variable

sample()[source]

Uniformly randomly sample a random element of this space.

unflatten(x)[source]

Return an unflattened observation x.

Returns:
x (unflattened)
unflatten_n(xs)[source]

Return unflattened observations xs.

Returns:
xs (unflattened)