Spaces
Space descriptors for an environment's observation, action and
reward arrays - shape, dtype and element-wise bounds, plus a sample
that draws a conforming array. Discrete for integers, Continuous for
floats.
Shape = Tuple[int, ...]
module-attribute
An array shape, i.e. a tuple of ints (() for a scalar).
Continuous
Bases: Space
A floating-point space: every element lies in [minimum, maximum].
navix uses it for reward_space (shape=(), bounds [-1, 1] by
default) and for float observations. Bounds may be infinite
(-jnp.inf / jnp.inf) to express "unbounded"; sample then falls
back to a finite range (see below).
create(shape, minimum, maximum, dtype=jnp.float32)
classmethod
Builds a Continuous space.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
tuple[int, ...]
|
shape of the array the space
describes. |
required |
minimum
|
Array
|
element-wise lower bound (inclusive); a
scalar broadcasts to |
required |
maximum
|
Array
|
element-wise upper bound (inclusive); a
scalar broadcasts to |
required |
dtype
|
floating dtype of the sampled array (default
|
float32
|
Returns:
| Name | Type | Description |
|---|---|---|
Continuous |
Continuous
|
the space. |
sample(key)
Draws values uniformly from [minimum, maximum), independently
per element. Infinite bounds are first mapped to the largest
finite value of dtype (via jnp.nan_to_num), so an unbounded
space still yields a finite draw rather than nan.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Array
|
a |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
shape |
Raises:
| Type | Description |
|---|---|
AssertionError
|
if |
Discrete
Bases: Space
An integer-valued space: every element is one of the n_elements
integers 0, 1, ..., n_elements - 1.
With shape=() it describes a single categorical value - the usual
case for an action index (Environment.action_space). With a
non-empty shape it describes an array of independent categoricals,
e.g. a categorical observation is Discrete over entity tags with
shape=(H, W).
n
property
The number of distinct values, n_elements (i.e.
maximum + 1). For an action space, len(env.action_set).
create(n_elements, shape=(), dtype=jnp.int32)
classmethod
Builds a Discrete space over 0 .. n_elements - 1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_elements
|
int | Array
|
number of distinct values; must be
|
required |
shape
|
tuple[int, ...]
|
shape of the integer array the space
describes. |
()
|
dtype
|
integer dtype of the sampled array (default
|
int32
|
Returns:
| Name | Type | Description |
|---|---|---|
Discrete |
Discrete
|
the space, with |
Discrete
|
|
sample(key)
Draws integers uniformly from 0 .. n_elements - 1,
independently per element.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Array
|
a |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
shape |
Space
Bases: PyTreeNode
Describes one array that flows through an environment: its shape, its dtype, and its element-wise value bounds.
An Environment exposes
three of these - observation_space, action_space and
reward_space - so a caller knows what reset/step will return and
what step expects, without having to run the environment. sample
draws a random array that conforms to the space, which is useful for
smoke tests and for shaping neural-network inputs/outputs.
Use the create classmethod of a concrete subclass
(Discrete or
Continuous) to build one; the bare
constructor does no validation or bound broadcasting.
Attributes:
| Name | Type | Description |
|---|---|---|
shape |
Shape
|
the shape of the array the space describes. |
dtype |
dtype
|
the array's dtype (e.g. |
minimum |
Array
|
element-wise lower bound (inclusive). A scalar array
broadcasts to |
maximum |
Array
|
element-wise upper bound (inclusive). A scalar array
broadcasts to |
sample(key)
Draws one array of shape shape and dtype dtype whose
elements lie within [minimum, maximum].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Array
|
a |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
the sampled array, shape |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
|