{ "info": { "author": "Bernhard Raml", "author_email": "pypi-reinforcment@googlegroups.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", "Topic :: Scientific/Engineering :: Artificial Intelligence" ], "description": "[![Build Status](https://travis-ci.org/SwamyDev/reinforcement.svg?branch=master)](https://travis-ci.org/SwamyDev/reinforcement) [![Coverage Status](https://coveralls.io/repos/github/SwamyDev/reinforcement/badge.svg?branch=master)](https://coveralls.io/github/SwamyDev/reinforcement?branch=master) [![PyPI version](https://badge.fury.io/py/reinforcement.svg)](https://badge.fury.io/py/reinforcement)\n\n# Reinforcement\nThe reinforcement package aims to provide simple implementations for basic reinforcement learning algorithms, using Test Driven Development and other principles of Software Engineering in an attempt to minimize defects and improve reproducibility. \n\n## Installation\nThe library can be installed using pip:\n```bash\npip install reinforcement\n```\n\n## Example Implementation\nThis section demonstrates how to implement a REINFORCE agent and benchmark it on the 'CartPole' gym environment.\n\nYou can find the full implementation in [examples/reinforce.py](example/reinforce.py). The [example folder](example/) also contains some additional utility classes and functions that are used in the implementation.\n\n[embedmd]:# (example/reinforce.py python /def run_reinforce/ /env.close\\(\\)/)\n```python\ndef run_reinforce(config):\n reporter, env, rewards = Reporter(config), gym.make('CartPole-v0'), []\n with tf1.Session() as session:\n agent = _make_agent(config, session, env)\n for episode in range(1, config.episodes + 1):\n reward = _run_episode(env, episode, agent, reporter)\n rewards.append(reward)\n if reporter.should_log(episode):\n logger.info(reporter.report(episode, rewards))\n env.close()\n```\nThis is the main function setting up the boiler plate code. It creates the tensorflow session, logs the progress, and creats the agent. The `Reporter` class is just a helper to make logging at a certain frequency more convenient\n\n[embedmd]:# (example/reinforce.py python /def _make_agent/ /return BatchAgent\\(alg\\)/)\n```python\ndef _make_agent(config, session, env):\n p = ParameterizedPolicy(session, env.observation_space.shape[0], env.action_space.n, NoLog(), config.lr_policy)\n b = ValueBaseline(session, env.observation_space.shape[0], NoLog(), config.lr_baseline)\n alg = Reinforce(p, config.gamma, b, config.num_trajectories)\n return BatchAgent(alg)\n```\n\nThe factory function `_make_agent` creates the REINFORCE agent object. It uses a parameterized policy and baseline to learn and estimate proper actions. In this case, both parameterizations are straightforward artificial neural networks with no hidden layer. Both have the same input layer, but the output layer of the policy is a softmax function, whereas the baseline outputs a single linear value. The `BatchAgent` type records trajectories (states, actions, rewards) which are then used to optimize the policy and the baseline. The `NoLog` class is a Null-Object implementing the TensorBoard `FileWriter` interface.\n\n[embedmd]:# (example/reinforce.py python /def _run_episode/ /return reward/)\n```python\ndef _run_episode(env, episode, agent, report):\n obs = env.reset()\n done, reward = False, 0\n while not done:\n if report.should_render(episode):\n env.render()\n obs, r, done, _ = env.step(agent.next_action(obs))\n agent.signal(r)\n reward += r\n\n agent.train()\n return reward\n```\n\nThis function performs a run through a single episode of the environment. Observations of the environment are passed to the agent's `next_action` interface function. The resulting estimated actions are passed again to the environment, leading to the next observation and a reward signal. The agent is then trained at the end of the episode because we want to train it on whole trajectories. It also contains a call to `env.render()` to visualize some runs. \n\n## Running an Example\nRunning the REINFORCE agent example with default settings:\n```bash\npython example/reinforce.py\n```\n\nAfter a few 1000 episodes it should get very close to the highest achievable reward:\n```\n...\nINFO:__main__:Episode 2800: reward=200.0; mean reward of last 100 episodes: 199.71\nINFO:__main__:Episode 2900: reward=200.0; mean reward of last 100 episodes: 199.36\nINFO:__main__:Episode 3000: reward=200.0; mean reward of last 100 episodes: 198.09\n```\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/SwamyDev/reinforcement", "keywords": "AI reinforcement learning", "license": "", "maintainer": "", "maintainer_email": "", "name": "reinforcement", "package_url": "https://pypi.org/project/reinforcement/", "platform": "", "project_url": "https://pypi.org/project/reinforcement/", "project_urls": { "Bug Reports": "https://github.com/SwamyDev/reinforcement/issues", "Homepage": "https://github.com/SwamyDev/reinforcement", "Source": "https://github.com/SwamyDev/reinforcement/" }, "release_url": "https://pypi.org/project/reinforcement/1.2.0/", "requires_dist": [ "numpy (<1.17) ; extra == 'test'", "tensorflow (==1.14) ; extra == 'test'", "pytest ; extra == 'test'", "pytest-rerunfailures ; extra == 'test'", "matplotlib ; extra == 'test'", "gym ; extra == 'test'", "numpy (<1.17) ; extra == 'tf_cpu'", "tensorflow (==1.14) ; extra == 'tf_cpu'", "numpy (<1.17) ; extra == 'tf_gpu'", "tensorflow-gpu (==1.14) ; extra == 'tf_gpu'" ], "requires_python": "", "summary": "A reinforcement learning module", "version": "1.2.0" }, "last_serial": 5905788, "releases": { "1.0.5": [ { "comment_text": "", "digests": { "md5": "aa6cc5f3de432a4f687229dad0a13b90", "sha256": "20def6c426a5520fdda32e999fe443440029e581bebe584f50f40cda360e24b5" }, "downloads": -1, "filename": "reinforcement-1.0.5-py3-none-any.whl", "has_sig": false, "md5_digest": "aa6cc5f3de432a4f687229dad0a13b90", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11076, "upload_time": "2018-04-07T16:31:20", "url": "https://files.pythonhosted.org/packages/96/18/1c638eff2ea9a5afdb89de526b95620079bb6a7a43d7a4799c2e678f97bd/reinforcement-1.0.5-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "89ed01a3d5348df1b916e9df5df64b55", "sha256": "610f73516ed6ab9655a836bb27a70e7610212f96dc8a5187c519d6b82639fbaf" }, "downloads": -1, "filename": "reinforcement-1.0.5.tar.gz", "has_sig": false, "md5_digest": "89ed01a3d5348df1b916e9df5df64b55", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7538, "upload_time": "2018-04-07T16:31:20", "url": "https://files.pythonhosted.org/packages/63/61/19d011b58b503c3e69b360e5437d594c7ce0d3eaa69995bc6ea65534a138/reinforcement-1.0.5.tar.gz" } ], "1.0.6": [ { "comment_text": "", "digests": { "md5": "dc45dbc4e94bdc74ad9723f22cdc3be0", "sha256": "67dec6b6a212dcfc6d502c386263e88d8a4861de86fd21983303368c93e664fe" }, "downloads": -1, "filename": "reinforcement-1.0.6-py3-none-any.whl", "has_sig": false, "md5_digest": "dc45dbc4e94bdc74ad9723f22cdc3be0", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11104, "upload_time": "2018-04-07T16:39:07", "url": "https://files.pythonhosted.org/packages/ef/ae/aa0d951325e0b04082042307b4dd1bc509350af11b7ff497bb6229627350/reinforcement-1.0.6-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "041cb8e4fc3c9adb907d9d5cf85125c3", "sha256": "9a5e00980723275414761027f90c655ef626fa65b2546a19bc5959b6221f1d52" }, "downloads": -1, "filename": "reinforcement-1.0.6.tar.gz", "has_sig": false, "md5_digest": "041cb8e4fc3c9adb907d9d5cf85125c3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7558, "upload_time": "2018-04-07T16:39:08", "url": "https://files.pythonhosted.org/packages/0c/1c/131c6cf4cae50b3e1b4a49b261520434fa6b9c0616ed7ff5cf2bf56610f6/reinforcement-1.0.6.tar.gz" } ], "1.1.2": [ { "comment_text": "", "digests": { "md5": "a40c1886a435900bb4c2e01e43286e5f", "sha256": "2279ddf6af0cbe126330a36e2947f32f01876aaa07b9f5a35c8133eefc7272a9" }, "downloads": -1, "filename": "reinforcement-1.1.2-py3-none-any.whl", "has_sig": false, "md5_digest": "a40c1886a435900bb4c2e01e43286e5f", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11758, "upload_time": "2019-08-25T09:08:37", "url": "https://files.pythonhosted.org/packages/6f/c8/0c5c261cafa0791729e62632e40cc72ca8716fe10ccae5a3a18bdb4a58df/reinforcement-1.1.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "50367a078e0b6723c995df2bc29db408", "sha256": "9e3189184c79a95bde5d642b1915c86fba817bbeed3287edfe88237a46fc2470" }, "downloads": -1, "filename": "reinforcement-1.1.2.tar.gz", "has_sig": false, "md5_digest": "50367a078e0b6723c995df2bc29db408", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7829, "upload_time": "2019-08-25T09:08:39", "url": "https://files.pythonhosted.org/packages/1b/59/d205e8e15a3416f3201cba152f308047ed7723031c17970eea5536ff848e/reinforcement-1.1.2.tar.gz" } ], "1.2.0": [ { "comment_text": "", "digests": { "md5": "0bde5b15d09e604eec05bb4d4669133a", "sha256": "f21e299b5467a5d73f7293d0c72ea75648671e3590bb284ff69699a96d41ecdc" }, "downloads": -1, "filename": "reinforcement-1.2.0-py3-none-any.whl", "has_sig": false, "md5_digest": "0bde5b15d09e604eec05bb4d4669133a", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 23563, "upload_time": "2019-09-30T09:11:59", "url": "https://files.pythonhosted.org/packages/8c/2d/dec9f01534257eb7edde9c51c44a62dfa329de5875c8aec965863ae0e2ec/reinforcement-1.2.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "d5d627ca6caa55d0aa6c6b1d2f4a2698", "sha256": "ed2c9ff0a8b6f902abaa3bb39f589d0a8c17995cca0a01bf7a77f57497fcdbc8" }, "downloads": -1, "filename": "reinforcement-1.2.0.tar.gz", "has_sig": false, "md5_digest": "d5d627ca6caa55d0aa6c6b1d2f4a2698", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14410, "upload_time": "2019-09-30T09:12:01", "url": "https://files.pythonhosted.org/packages/2d/00/9799ba20fb1276da5c5c3e1308f4ea2e33be95030868100c6dbc282dba44/reinforcement-1.2.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "0bde5b15d09e604eec05bb4d4669133a", "sha256": "f21e299b5467a5d73f7293d0c72ea75648671e3590bb284ff69699a96d41ecdc" }, "downloads": -1, "filename": "reinforcement-1.2.0-py3-none-any.whl", "has_sig": false, "md5_digest": "0bde5b15d09e604eec05bb4d4669133a", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 23563, "upload_time": "2019-09-30T09:11:59", "url": "https://files.pythonhosted.org/packages/8c/2d/dec9f01534257eb7edde9c51c44a62dfa329de5875c8aec965863ae0e2ec/reinforcement-1.2.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "d5d627ca6caa55d0aa6c6b1d2f4a2698", "sha256": "ed2c9ff0a8b6f902abaa3bb39f589d0a8c17995cca0a01bf7a77f57497fcdbc8" }, "downloads": -1, "filename": "reinforcement-1.2.0.tar.gz", "has_sig": false, "md5_digest": "d5d627ca6caa55d0aa6c6b1d2f4a2698", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14410, "upload_time": "2019-09-30T09:12:01", "url": "https://files.pythonhosted.org/packages/2d/00/9799ba20fb1276da5c5c3e1308f4ea2e33be95030868100c6dbc282dba44/reinforcement-1.2.0.tar.gz" } ] }