Utility API
Performance plots
gym_classics2.performance
simple_moving_average
Return a centered simple moving average padded with NaN values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
One-dimensional numeric sequence. |
required | |
window_size
|
Number of observations in the averaging window. |
100
|
Returns:
| Type | Description |
|---|---|
|
NumPy array with the same length as |
Source code in gym_classics2/performance.py
cum_avg
plot_returns
Plot episode returns with a moving average and cumulative average.
Source code in gym_classics2/performance.py
plot_ep_lens
Plot episode lengths with a moving average.
Source code in gym_classics2/performance.py
Gridworld animation
gym_classics2.animation
gridworld_animate
gridworld_animate(env, Vs, policies=None, interval=1000, repeat=False, cmap='coolwarm', clim=None, origin='lower')
Create an animation showing the evolution of value functions in a gridworld.
:param env: The gridworld environment. :param Vs: A list of value functions to animate. :param repeat: Whether the animation should repeat. :param cmap: Colormap to use for the value function. :param origin: 'lower' means (0,0) is at the bottom-left, 'upper' means (0,0) is at the top-left. :return: An animation object.
Source code in gym_classics2/animation.py
General utilities
gym_classics2.utils
get_rng
Return rng as a NumPy random generator.
rng may be a :class:numpy.random.Generator, an integer seed, or
None. Passing a generator lets callers share one reproducible random
stream across an algorithm and all of its helpers.
Source code in gym_classics2/utils.py
clip
random_argmax
Argmax that breaks ties randomly. If axis is None, returns a single index.
If axis is specified, returns an array of indices along that axis. rng
may be a NumPy generator or an integer seed.