Skip to content

MNISTBandit-bsuite

MNISTBandit

MNISTBandit(fraction: float = 1.0)

Bases: Environment[EnvState, EnvParams]

Classify an MNIST digit in a contextual bandit with one step per episode.

JAX port of the bsuite MNIST bandit environment. Constructing the environment loads the MNIST training set with gymnax.utils.load_mnist, which downloads it if it is not cached. Each reset shows an image drawn uniformly at random from the first fraction of the training set.

  • Observation: Box with the shape of one MNIST image, (28, 28). reset returns the sampled image as float32 divided by 255. Every step ends the episode, so step returns the image of the next episode, while info["final_observation"] is an array of zeros.
  • Actions: Discrete(10). The predicted digit.
  • Reward: 1 if the action equals the label of the image and -1 otherwise.
  • Termination: after every step.
  • Truncation: after params.max_steps_in_episode steps (1 by default), so every step is flagged as both terminated and truncated.

Parameters:

  • fraction (float, default: 1.0 ) –

    Fraction of the MNIST training set to sample images from. The first int(fraction * num_images) images are kept.

References

Parameters and state

EnvParams

Bases: EnvParams

Parameters of the MNISTBandit environment.

Attributes:

  • optimal_return (int) –

    Reward of a correct classification, used to compute the regret.

  • max_steps_in_episode (int) –

    Number of steps after which the episode is truncated.

EnvState

Bases: EnvState

State of the MNISTBandit environment.

Attributes:

  • correct_label (Array) –

    Label of the image shown in the current episode.

  • regret (Array) –

    Sum of params.optimal_return - reward over the steps of the current episode.

  • time (int) –

    Number of steps taken in the current episode.