Class MultiBinary
The binary arrays of a fixed shape: every element is an int8 array of 0s and 1s, such as a set of on/off switches.
public class MultiBinary : Space<NDArray>, IDisposable, IEquatable<MultiBinary>
- Inheritance
-
MultiBinary
- Implements
- Inherited Members
- Extension Methods
Remarks
Reference: gymnasium/spaces/multi_binary.py.
Constructors
MultiBinary(long, SpaceSeed?)
The flat space of n binary values (Gymnasium's MultiBinary(n)).
public MultiBinary(long n, SpaceSeed? seed = null)
Parameters
nlongThe number of values; must be positive.
seedSpaceSeed?An integer seed, a generator to share, or null for a lazy entropy-seeded one.
Exceptions
- ValueError
Thrown when
nis not positive:n (counts) have to be positive, got 0.- Error
Thrown when an integer
seedis negative.
MultiBinary(long[], SpaceSeed?)
The space of binary arrays of shape n (Gymnasium's MultiBinary([3, 2])).
public MultiBinary(long[] n, SpaceSeed? seed = null)
Parameters
nlong[]The shape; every dimension must be positive.
seedSpaceSeed?An integer seed, a generator to share, or null.
Exceptions
- ValueError
Thrown when a dimension is not positive.
- ArgumentNullException
Thrown when
nis null.- Error
Thrown when an integer
seedis negative.
Properties
DType
The element dtype, int8.
public DType DType { get; }
Property Value
IsNpFlattenable
Whether this space flattens to a Box (Gymnasium's is_np_flattenable).
public override bool IsNpFlattenable { get; }
Property Value
N
The shape of the elements, Gymnasium's n (an int or a tuple; ToString() tells which).
public IReadOnlyList<long> N { get; }
Property Value
Shape
The element shape.
public Shape Shape { get; }
Property Value
Methods
Contains(object?)
Whether x is an element (Gymnasium's contains): an array (a .NET array or list is
converted first) of the space's shape whose values are all 0 or 1. The dtype is not checked, as in Gymnasium.
public override bool Contains(object? x)
Parameters
xobjectThe candidate.
Returns
Equals(MultiBinary?)
Gymnasium's ==: the same n, an int differing from a one-element tuple.
public bool Equals(MultiBinary? other)
Parameters
otherMultiBinaryThe other space.
Returns
Equals(object?)
Determines whether the specified object is equal to the current object.
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current object.
Returns
FromJsonable(object)
Converts nested lists back to int8 arrays (Gymnasium's np.asarray(sample, int8)).
public override IList<NDArray> FromJsonable(object jsonable)
Parameters
jsonableobjectA list of nested lists.
Returns
Exceptions
- ArgumentException
Thrown for a value no int8 array can be made from.
GetHashCode()
Serves as the default hash function.
public override int GetHashCode()
Returns
- int
A hash code for the current object.
Sample(NDArray?, NDArray?)
Draws one element, typed (DR-86, DR-97): Gymnasium's sample(mask, probability) with both masks as arrays.
A call on a MultiBinary reference binds this overload unless an argument is typed
object; it draws exactly what Sample(object?, object?) draws.
public NDArray Sample(NDArray? mask = null, NDArray? probability = null)
Parameters
maskNDArraynull, or an int8 array of the space's shape holding 0 or 1 (that value) or 2 (a coin toss).
probabilityNDArraynull, or a float64 array of the space's shape with each value's probability of 1.
Returns
- NDArray
A new int8 array, owned by the caller.
Exceptions
- ValueError
Thrown when both masks are given.
- AssertionError
Thrown for a mask or probability of the wrong dtype, shape or values, with Gymnasium's messages.
Sample(object?, object?)
Draws one element by a fair coin toss per value (Gymnasium's sample), or under a mask that fixes values
(0 or 1) or leaves them random (2), or with a per-value probability of 1.
public override NDArray Sample(object? mask = null, object? probability = null)
Parameters
maskobjectnull, or an int8 array of the space's shape holding 0, 1 or 2.
probabilityobjectnull, or a float64 array of the space's shape with values in
[0, 1].
Returns
- NDArray
A new int8 array, owned by the caller.
Remarks
A mask draws a full array of coin tosses and keeps the ones the mask leaves random (np.where(mask == 2,
integers(0, 2, size=n, dtype=int8), mask)), so the generator moves by the whole shape either way, as in
Gymnasium. Reference: gymnasium/spaces/multi_binary.py.
Exceptions
- ValueError
Thrown when both masks are given.
- AssertionError
Thrown for a mask or probability of the wrong type, dtype, shape or values, with Gymnasium's messages.
Seed(BigInteger?)
Reseeds the space's generator (Gymnasium's seed), typed (DR-86): a simple space's seed is one integer, so
it comes back as a BigInteger where Seed(BigInteger?) returns it boxed.
public BigInteger Seed(BigInteger? seed = null)
Parameters
seedBigInteger?Any non-negative integer, or null for a fresh generator from OS entropy.
Returns
- BigInteger
The seed used:
seeditself, or the 128-bit entropy of an unseeded call, which reproduces it.
Remarks
Footgun: a call through a Space reference binds the untyped base method, which returns the same seed as an object.
Exceptions
- Error
Thrown when
seedis negative, with Gymnasium's message.- InvalidCastException
Thrown by a subclass whose seeding returns something other than one integer.
ToJsonable(IEnumerable<NDArray>)
Converts samples to nested lists of ints (Gymnasium's np.array(list(sample_n)).tolist()).
public override object ToJsonable(IEnumerable<NDArray> samples)
Parameters
samplesIEnumerable<NDArray>Samples of this space.
Returns
- object
One nested list per sample.
ToString()
Gymnasium's repr: MultiBinary(5), or MultiBinary((3, 2)) for a shape.
public override string ToString()
Returns
- string
The text.