Table of Contents

Class MultiBinary

Namespace
Gym.Spaces
Assembly
Gym.dll

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

Constructors

MultiBinary(long, SpaceSeed?)

The flat space of n binary values (Gymnasium's MultiBinary(n)).

public MultiBinary(long n, SpaceSeed? seed = null)

Parameters

n long

The number of values; must be positive.

seed SpaceSeed?

An integer seed, a generator to share, or null for a lazy entropy-seeded one.

Exceptions

ValueError

Thrown when n is not positive: n (counts) have to be positive, got 0.

Error

Thrown when an integer seed is 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

n long[]

The shape; every dimension must be positive.

seed SpaceSeed?

An integer seed, a generator to share, or null.

Exceptions

ValueError

Thrown when a dimension is not positive.

ArgumentNullException

Thrown when n is null.

Error

Thrown when an integer seed is negative.

Properties

DType

The element dtype, int8.

public DType DType { get; }

Property Value

DType

IsNpFlattenable

Whether this space flattens to a Box (Gymnasium's is_np_flattenable).

public override bool IsNpFlattenable { get; }

Property Value

bool

N

The shape of the elements, Gymnasium's n (an int or a tuple; ToString() tells which).

public IReadOnlyList<long> N { get; }

Property Value

IReadOnlyList<long>

Shape

The element shape.

public Shape Shape { get; }

Property Value

Shape

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

x object

The candidate.

Returns

bool

true for an element.

Equals(MultiBinary?)

Gymnasium's ==: the same n, an int differing from a one-element tuple.

public bool Equals(MultiBinary? other)

Parameters

other MultiBinary

The other space.

Returns

bool

true when equal.

Equals(object?)

Determines whether the specified object is equal to the current object.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current object.

Returns

bool

true if the specified object is equal to the current object; otherwise, false.

FromJsonable(object)

Converts nested lists back to int8 arrays (Gymnasium's np.asarray(sample, int8)).

public override IList<NDArray> FromJsonable(object jsonable)

Parameters

jsonable object

A list of nested lists.

Returns

IList<NDArray>

New int8 arrays, owned by the caller.

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

mask NDArray

null, or an int8 array of the space's shape holding 0 or 1 (that value) or 2 (a coin toss).

probability NDArray

null, 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

mask object

null, or an int8 array of the space's shape holding 0, 1 or 2.

probability object

null, 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

seed BigInteger?

Any non-negative integer, or null for a fresh generator from OS entropy.

Returns

BigInteger

The seed used: seed itself, 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 seed is 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

samples IEnumerable<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.