Class Sequence
Sequences of any length whose items belong to one feature space: every element is a tuple (an object?[]) of feature-space elements, or, with Stack, those elements stacked into one batch (an array, or a tuple or dict of arrays).
public class Sequence : Space<object?>, IDisposable, IEquatable<Sequence>
- Inheritance
-
Sequence
- Implements
- Inherited Members
- Extension Methods
Remarks
The length of an unmasked sample is geometric with p = 0.25 (Gymnasium's arbitrary choice), so a sample is
empty one time in four and rarely long.
The space owns its feature space. Reference: gymnasium/spaces/sequence.py.
Constructors
Sequence(Space, SpaceSeed?, bool)
Sequences of space's elements (Gymnasium's Sequence(space, seed=seed, stack=stack)).
public Sequence(Space space, SpaceSeed? seed = null, bool stack = false)
Parameters
spaceSpaceThe feature space; the sequence space owns it from now on.
seedSpaceSeed?An integer seed (it seeds the sequence's generator, which draws the feature space's seed, then is seeded again with the same value), a generator to share, or null.
stackboolWhether samples are the items stacked into one batch rather than a tuple of them.
Remarks
A stacked space batches the feature space once (batch_space(space, 1)), which reads the feature space's
generator and so creates it from entropy when it was not seeded, as in Gymnasium.
Exceptions
- TypeError
Thrown for a null feature space, with Gymnasium's message.
- Error
Thrown when an integer
seedis negative.
Properties
FeatureSpace
The space every item belongs to (Gymnasium's feature_space).
public Space FeatureSpace { get; }
Property Value
IsNpFlattenable
A sequence never flattens to a box: its length varies.
public override bool IsNpFlattenable { get; }
Property Value
Stack
Whether samples are stacked (Gymnasium's stack).
public bool Stack { get; }
Property Value
StackedFeatureSpace
The feature space batched once, for a stacked space's membership and JSON (Gymnasium's stacked_feature_space); null otherwise.
public Space? StackedFeatureSpace { get; }
Property Value
Methods
Contains(object?)
Whether x is an element (Gymnasium's contains): a tuple of feature-space members, or for
a stacked space a batch whose every item is one.
public override bool Contains(object? x)
Parameters
xobjectThe candidate.
Returns
Exceptions
- TypeError
Thrown by a stacked space for a candidate that cannot be iterated (
Unable to iterate over the following elements: …), as Gymnasium's does: unlike the other spaces, its membership test raises rather than answering false.- CustomSpaceError
Thrown by a stacked space whose feature space has no batched iteration.
Dispose(bool)
protected override void Dispose(bool disposing)
Parameters
Equals(Sequence?)
Gymnasium's ==: an equal feature space and the same stacking.
public bool Equals(Sequence? other)
Parameters
otherSequenceThe 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 Gymnasium's JSON form back to sequences (Gymnasium's from_jsonable).
public override IList<object?> FromJsonable(object jsonable)
Parameters
jsonableobjectThe JSON data.
Returns
GetHashCode()
Serves as the default hash function.
public override int GetHashCode()
Returns
- int
A hash code for the current object.
Sample(object?, object?)
Draws a sequence (Gymnasium's sample): a length (geometric, fixed, or drawn from an array of lengths), then
that many feature-space samples, stacked when Stack is on.
public override object? Sample(object? mask = null, object? probability = null)
Parameters
maskobjectnull, or a pair
(length_mask, sample_mask)(an object?[] or tuple): the length mask is null (geometric), a non-negative integer (fixed), or a 1-D integer array of lengths to choose from; the sample mask goes to every feature-space sample.probabilityobjectnull, or the same pair with a probability mask for the feature space.
Returns
- object
A tuple of samples, or the stacked batch; arrays are owned by the caller.
Exceptions
- ValueError
Thrown when both masks are given.
- AssertionError
Thrown for a negative or malformed length mask, with Gymnasium's messages.
- TypeError
Thrown for a length mask that is neither an integer nor an array.
SeedCore(BigInteger?)
Gymnasium's Sequence.seed for an integer or null: null seeds both
generators from entropy; an integer seeds the sequence's generator, draws the feature space's seed from it, and
seeds it again with the same value, so integer and list seeding leave the sequence's generator alike.
protected override object SeedCore(BigInteger? seed)
Parameters
seedBigInteger?The seed, or null.
Returns
- object
The pair of seeds used, as a list.
Exceptions
- Error
Thrown for a negative seed.
SeedListCore(IReadOnlyList<object?>)
Gymnasium's Sequence.seed for a pair: the sequence's seed and the feature space's.
protected override object SeedListCore(IReadOnlyList<object?> seeds)
Parameters
seedsIReadOnlyList<object>Two seeds.
Returns
- object
The pair of seeds used.
Exceptions
- ValueError
Thrown when the list does not have two items.
- Error
Thrown when the sequence's own seed is negative or not a Python
int.
SeedTypeError(object?)
Gymnasium's Sequence.seed error for a seed that is not an integer, a pair or null.
protected override Exception SeedTypeError(object? seed)
Parameters
seedobjectThe refused seed.
Returns
- Exception
TypeError: Expected None, int, tuple of ints, actual type: <class 'dict'>.
ToJsonable(IEnumerable<object?>)
Converts samples to Gymnasium's JSON form: the stacked space's, or one feature-space list per sample.
public override object ToJsonable(IEnumerable<object?> samples)
Parameters
samplesIEnumerable<object>Samples of this space.
Returns
- object
The JSON data.
ToString()
Gymnasium's repr: Sequence(Discrete(4), stack=False).
public override string ToString()
Returns
- string
The text.