gyx v0.1.1 Gyx.Core.Spaces protocol

This protocol defines basic functions to interact with action and observation spaces.

Link to this section Summary

Functions

Verifies if a particular action or observation point lies inside a given space

Samples a random point from a space. Note that sampled points are very different in nature depending on the underlying space. This sampling is pretty important for an agent, as it is the way the agent might decide which actions to take from an action space defined on the environment the agent is interacting with.

Parameters

Sets the random generator used by sample/1 with the space defined seed

Link to this section Types

Link to this type

box_point()
box_point() :: [[float()]]

Link to this type

discrete_point()
discrete_point() :: integer()

Link to this type

tuple_point()
tuple_point() :: [discrete_point() | box_point()]

Link to this section Functions

Link to this function

contains?(space, point)
contains?(space(), point()) :: bool()

Verifies if a particular action or observation point lies inside a given space.

Examples

iex> box_space = %Box{shape: {1, 2}}
iex> {:ok, box_point} = Spaces.sample(box_space)
iex> Spaces.contains(box_space, box_point)
true
Link to this function

sample(space)
sample(space()) :: {atom(), point()}

Samples a random point from a space. Note that sampled points are very different in nature depending on the underlying space. This sampling is pretty important for an agent, as it is the way the agent might decide which actions to take from an action space defined on the environment the agent is interacting with.

Parameters

  • space: Any module representing a space.

Examples

iex> discrete_space = %Gyx.Core.Spaces.Discrete{n: 42}
%Gyx.Core.Spaces.Discrete{n: 42, random_algorithm: :exsplus, seed: {1,2,3}}

iex> Gyx.Core.Spaces.set_seed(discrete_space)
{%{
  jump: #Function<16.10897371/1 in :rand.ml_alg/1>
  max: 288230376151711743,
  next: #Function<15.1089737/1 in :rand.mk_alg/1>
  type: :explus
}, [72022415603679006 | 144185572652843231]}

iex> Gyx.Core.Spaces.sample(discrete_space)
{:ok, 35}

iex> Gyx.Core.Spaces.sample(%Gyx.Core.Spaces.Box{shape: {2}, high: 7}
{:ok, [[3.173570417347619, 0.286615818442874]]}
Link to this function

set_seed(space)

Sets the random generator used by sample/1 with the space defined seed.