Git Product home page Git Product logo

simple-q's Introduction

Q-Learning

A low learning curve implementation of Q-learning.

PyPI License.

Q-learning is a reinforcement learning algorithm that allows an agent to learn an optimal policy for sequential decision-making problems. This implementation provides an easy-to-use and beginner-friendly approach to Q-learning, making it accessible to users with varying levels of experience. This implementation is build to work with "GYM" environments from the Gymnasium Project.

Features

  • Provides flexibility to work with either integer or custom objects for states and actions.
  • Offers customizable learning rate and exploration-exploitation trade-off parameters.
  • Implements epsilon-greedy strategy for action selection.
  • Supports polynomial and power decay functions for learning rate and exploration parameter respecitively. The learning rate decay is based on the research in Even-Dar et al. (2003). When lambda is in (0,1) this implementation of Q-learning satisfies the conditions for probability one convergence in Watkins and Dayan (1992).

Installation

Install the Simple_Q package from PyPI:

pip install Simple_Q
from Simple_Q import Qlearning

## Usage

```python
from Simple_Q import Qlearning

# Create the Q-learning agent
agent = Qlearning(states=10, actions = ['forward', 'left', 'right' 'stop'])

# Use the Q-learning agent in your reinforcement learning loop
state = env.reset()
N = 100
for n in range(N):
    action = agent.get_action(state)
    next_state, reward, done, _ = env.step(action)
    agent.update_q_table(state, action, reward, next_state)
    state = next_state
    agent.update_epsilon()

See also the Savings Problem example in the GitHub repository.

Documentation

The Q-Learning class provides the following parameters:

Parameter Description
states Number of states or a list of immutable objects representing states. If a list is passed, the states are mapped to integers starting from 0, and the immutable objects (not indices) are expected as input for the other methods.
actions Number of actions or a list of immutable objects representing actions. If a list is passed, the actions are mapped to integers starting from 0, and the immutable objects (not indices) are expected as input for the other methods.
alpha Learning rate parameter. If 'polynomial', a polynomial decay is used. If int or float, a fixed value is used.
w Decay exponent for the polynomial decay. Only applicable when alpha='polynomial'.
gamma Discount factor for future rewards.
epsilon_decay Epsilon decay function. If 'power', a power decay is used.
epsilon Initial value for the exploration-exploitation trade-off parameter.
epsilon_decay_factor Decay factor for epsilon. Determines how it decays over time.
epsilon_min Minimum value for epsilon.

The Q-Learning class provides the following attributes:

Attribute Description
q_table Q-table storing the learned Q-values for state-action pairs.

Contributing

Contributions are welcome! If you find any issues or have suggestions for improvement, please feel free to open an issue or submit a pull request.

License

This project is licensed under the MIT License.

Acknowledgements

This code is originally based upon the Q-Learning implementation from the book: "Advanced Deep Learning with TensorFlow 2 and Keras" by Rowel Atienza. However many changes have been made to the original code, including the addition of the polynomial learning rate decay as well as the ability to work with custom objects for states and actions.

References

Even-Dar, E., Y. Mansour, and P. Bartlett (2003). Learning rates for q-learning. Journal of machine learning Research 5(1).

Watkins, C. J. and P. Dayan (1992, May). Technical note: Q-learning. Machine Learning 8(3), 279โ€“292

simple-q's People

Contributors

nesta-gitu avatar

Stargazers

Diego avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.