Table of Contents

Class ToyTextUtils

Namespace
Gym.Environments.Envs.ToyText
Assembly
Gym.Environments.dll

Gymnasium's gymnasium.envs.toy_text.utils (CategoricalSample(IReadOnlyList<double>, Generator)) and the character maps the toy_text envs build their worlds from (CharMap(IReadOnlyList<string>)).

public static class ToyTextUtils
Inheritance
ToyTextUtils
Inherited Members

Remarks

Methods

CategoricalSample(IReadOnlyList<double>, Generator)

Gymnasium's categorical_sample(prob_n, np_random): one draw from npRandom (np_random.random()), then the first index whose running total of probN exceeds it; 0 when none does (NumPy's argmax of an all-false array).

public static long CategoricalSample(IReadOnlyList<double> probN, Generator npRandom)

Parameters

probN IReadOnlyList<double>

The probabilities, in order; they need not sum to 1 (a total below the draw gives 0).

npRandom Generator

The generator; exactly one float64 is drawn from it, as in Gymnasium.

Returns

long

The sampled index.

Remarks

The running total is NumPy's cumsum: float64 additions in order, each rounded, so a total that should be 1 can fall just short of it, which this reproduces. Reference: gymnasium/envs/toy_text/utils.py.

Exceptions

ArgumentNullException

Thrown when an argument is null.

ValueError

Thrown for no probabilities, as NumPy's argmax of an empty sequence raises (after the draw).

CharMap(IReadOnlyList<string>)

NumPy's np.asarray(rows, dtype="c"): a (len(rows), len(row)) array of one-byte strings (S1), one character per element, which is how FrozenLake and Taxi hold their maps.

public static NDArray CharMap(IReadOnlyList<string> rows)

Parameters

rows IReadOnlyList<string>

The map's rows, all of one length, in ASCII.

Returns

NDArray

A new S1 array; the caller owns it.

Remarks

It builds the two-dimensional array of one-character strings NumPy builds for np.asarray(rows, "c"), through NumSharp's own 'c' dtype: same shape, dtype (|S1) and bytes. It was written while NumSharp 0.80.0's np.array(string[], "c") kept one element per string (open item N-2); NumSharp 0.81.0 splits the strings itself (N-2 closed, DR-76, guarded by NumSharpGapTests), and this stays the toy_text envs' one place that builds and validates their maps.

Exceptions

ArgumentNullException

Thrown when rows or a row is null.

ValueError

Thrown for rows of different lengths, with NumPy's message.