Skip to main content

Information-theoretic metrics for Gymnasium environments

Project description

gym_info

Information-theoretic diagnostics for Gymnasium environments.

gym_info helps you inspect state and action entropies in RL environments with minimal changes to your existing Gymnasium code. You wrap an environment once, run your usual interaction loop, and then query global or per-episode entropy metrics, tables, and simple reports.


Installation

pip install gym_info
# or, with uv:
# uv add gym_info

Requirements:

  • Python: $\geq$ 3.10
  • Gymnasium: $\geq$ 1.2.2

Quick Start

import gymnasium as gym
import gym_info as gi

# 1. Create and wrap the environment
env = gym.make("CartPole-v1")
env = gi.attach(env, preset="classic_control", run_id="demo-run")

# 2. Run your usual interaction loop
obs, info = env.reset(seed=0)
for _ in range(200):
    action = env.action_space.sample()
    obs, reward, terminated, truncated, info = env.step(action)
    if terminated or truncated:
        obs, info = env.reset()

# 3. Global entropies for the whole run (in bits)
metrics = gi.entropies(env)
print(metrics.H_S, metrics.H_A, metrics.H_A_given_S)

# 4. High-level summary
summ = gi.summary(env)
gi.print_table(summ)         # text table
gi.plot_entropies(summ)      # matplotlib figure

Per-episode Analysis

You can inspect entropies for each completed episode separately.

from gym_info import entropies_per_episode, episode_entropy_series, episode_entropy_dataframe

episode_metrics = entropies_per_episode(env)
for i, m in enumerate(episode_metrics):
    print(f"Episode {i}: H(S)={m.H_S:.3f}, H(A)={m.H_A:.3f}, H(A|S)={m.H_A_given_S:.3f}")

series = episode_entropy_series(env)
df = episode_entropy_dataframe(env)

Discretization

gym_info works by discretizing continuous observations and actions into bins and then computing histogram-based entropies.

  • A preset encapsulates reasonable default binning strategies for a family of environments.

  • Currently, the main preset is:

    • preset="classic_control": designed for standard classic control environments such as CartPole-v1 and MountainCar-v0.

You can override discretization globally by passing obs_bins and action_bins to attach:

env = gi.attach(
    env,
    preset="classic_control",
    run_id="demo-run",
    obs_bins=20,    # here
    action_bins=5,  # here
)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gym_info-0.1.1.tar.gz (106.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gym_info-0.1.1-py3-none-any.whl (22.2 kB view details)

Uploaded Python 3

File details

Details for the file gym_info-0.1.1.tar.gz.

File metadata

  • Download URL: gym_info-0.1.1.tar.gz
  • Upload date:
  • Size: 106.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for gym_info-0.1.1.tar.gz
Algorithm Hash digest
SHA256 6fc05ef2cbd1a6205317c79f9476b71b71214498b7e1ae62f9145f73de9a5aca
MD5 ef567005652463efe7d3569039e88564
BLAKE2b-256 422ecdcbba36cb3f5b3eae3f5da35cfb30c225b1c9a9526090876d604968c035

See more details on using hashes here.

Provenance

The following attestation bundles were made for gym_info-0.1.1.tar.gz:

Publisher: release.yaml on RafaStutz/gym_info

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gym_info-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: gym_info-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 22.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for gym_info-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6860a188f9744bee4c5ed0961207e69fa83fc9dc877ce4dc8625f92096559ae4
MD5 4fb43beba90aca338f5499d3e8465ad0
BLAKE2b-256 d997dfb47267697a3c99898834ed0a5350d1ffda5666e95598e513e3754203d6

See more details on using hashes here.

Provenance

The following attestation bundles were made for gym_info-0.1.1-py3-none-any.whl:

Publisher: release.yaml on RafaStutz/gym_info

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page