Skip to main content

A tiny, teaching-focused reinforcement learning kit (Q-learning, SARSA, Bandits) with toy environments.

Project description

myrlkit

A minimal, lightweight reinforcement learning toolkit — built for quick experimentation, small projects, and clear, dependency-light code.
Includes core RL algorithms and simple toy environments with ready-to-run examples and matplotlib visualizations.

✨ Features

  • Algorithms: Q-learning, SARSA, and Epsilon-Greedy Bandit.
  • Environments: GridWorld and K-armed Bandit.
  • Visualization: Built-in learning curves and policy renderings.
  • No heavy frameworks — just Python + NumPy + Matplotlib.
  • Readable & well-documented — easy to extend and adapt.

Install

pip install myrlkit

If installing from source:

pip install -e .

Quickstart

Q-learning on GridWorld

import numpy as np
from myrlkit.agents import QLearningAgent
from myrlkit.envs import GridWorld

env = GridWorld(width=5, height=5, start=(0,0), goal=(4,4), obstacles=[(1,1), (1,2), (2,1)])
agent = QLearningAgent(state_size=env.n_states, action_size=env.n_actions, alpha=0.5, gamma=0.99, epsilon=0.1)

episodes = 300
rewards = []
for _ in range(episodes):
    s = env.reset()
    done = False
    total = 0.0
    while not done:
        a = agent.choose_action(s)
        ns, r, done, _ = env.step(a)
        agent.update(s, a, r, ns, done)
        s = ns
        total += r
    rewards.append(total)

policy = env.render_policy(agent.q_table)
print(policy)

SARSA on GridWorld

from myrlkit.agents import SARSAAgent
from myrlkit.envs import GridWorld

env = GridWorld(width=4, height=4, start=(0,0), goal=(3,3))
agent = SARSAAgent(state_size=env.n_states, action_size=env.n_actions, alpha=0.5, gamma=0.99, epsilon=0.1)

Epsilon-Greedy Bandit

from myrlkit.agents import EpsilonGreedyBandit
from myrlkit.envs import KArmedBandit

env = KArmedBandit(k=10, means=[0.0]*10, std=1.0, seed=42)
agent = EpsilonGreedyBandit(k=env.k, epsilon=0.1)

rewards = []
for t in range(1000):
    a = agent.select_action()
    r = env.pull(a)
    agent.update(a, r)
    rewards.append(r)

API

  • myrlkit.agents.QLearningAgent
  • myrlkit.agents.SARSAAgent
  • myrlkit.agents.EpsilonGreedyBandit
  • myrlkit.envs.GridWorld
  • myrlkit.envs.KArmedBandit

Examples

See examples/ for runnable scripts (learning curves, policy printouts).

License

MIT


Author

Nihar Lohar
LinkedIn: https://www.linkedin.com/in/nihar-lohar-20234a287/ github: https://github.com/Nihar3453/passport_ocr

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

myrlkit-0.1.2.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

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

myrlkit-0.1.2-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file myrlkit-0.1.2.tar.gz.

File metadata

  • Download URL: myrlkit-0.1.2.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for myrlkit-0.1.2.tar.gz
Algorithm Hash digest
SHA256 96e8c8fe969ed191ab0a16183e6026047226b6e80fa6a4a042b842bb461f8e0d
MD5 ba173bb8be0e675d857100824e6f3455
BLAKE2b-256 7c251de3a48ec29df783e416be5a0a0986b60c86fee4f86e6de125bdd74ca209

See more details on using hashes here.

File details

Details for the file myrlkit-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: myrlkit-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for myrlkit-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 bcf1e7fa9892adc1c369eca36379226a920b829f1691096423279eb43ca1a24e
MD5 d21573c8234f8ee959d52a318b9b699a
BLAKE2b-256 c5f64ce7f913f139ad9c2d0721f763e5c0b3748e04dcfbccdf30836ffc73a608

See more details on using hashes here.

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