{ "info": { "author": "Alireza Mika", "author_email": "alirezamika@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 2", "Programming Language :: Python :: 3" ], "description": "Evostra: Evolution Strategy for Python\n--------\n\nEvolution Strategy (ES) is an optimization technique based on ideas of adaptation and evolution.\nYou can learn more about it at https://blog.openai.com/evolution-strategies/\n\nInstallation\n--------\nIt's compatible with both python2 and python3.\n\nInstall from source:\n\n.. code-block:: bash\n\n $ python setup.py install\n\n \nInstall latest version from git repository using pip:\n\n.. code-block:: bash\n\n $ pip install git+https://github.com/alirezamika/evostra.git\n \n \nInstall from PyPI:\n\n.. code-block:: bash\n\n $ pip install evostra\n \n(You may need to use python3 or pip3 for python3)\n\n\nSample Usages\n--------\n\n`An AI agent learning to play flappy bird using evostra \n`_\n\n\n`An AI agent learning to walk using evostra \n`_\n\n\nHow to use\n--------\n\nThe input weights of the EvolutionStrategy module is a list of arrays (one array with any shape for each layer of the neural network), so we can use any framework to build the model and just pass the weights to ES.\n\n\nFor example we can use Keras to build the model and pass its weights to ES, but here we use Evostra's built-in model FeedForwardNetwork which is much faster for our use case:\n\n\n.. code:: python\n\n import numpy as np\n from evostra import EvolutionStrategy\n from evostra.models import FeedForwardNetwork\n\n # A feed forward neural network with input size of 5, two hidden layers of size 4 and output of size 3\n model = FeedForwardNetwork(layer_sizes=[5, 4, 4, 3])\n\n\nNow we define our get_reward function:\n\n.. code:: python\n\n solution = np.array([0.1, -0.4, 0.5])\n inp = np.asarray([1, 2, 3, 4, 5])\n\n def get_reward(weights):\n global solution, model, inp\n model.set_weights(weights)\n prediction = model.predict(inp)\n # here our best reward is zero\n reward = -np.sum(np.square(solution - prediction))\n return reward\n\n\nNow we can build the EvolutionStrategy object and run it for some iterations:\n\n.. code:: python\n\n # if your task is computationally expensive, you can use num_threads > 1 to use multiple processes;\n # if you set num_threads=-1, it will use number of cores available on the machine; Here we use 1 process as the\n # task is not computationally expensive and using more processes would decrease the performance due to the IPC overhead.\n es = EvolutionStrategy(model.get_weights(), get_reward, population_size=20, sigma=0.1, learning_rate=0.03, decay=0.995, num_threads=1)\n es.run(1000, print_step=100)\n\n\nHere's the output:\n\n.. code::\n\n iter 100. reward: -68.819312\n iter 200. reward: -0.218466\n iter 300. reward: -0.110204\n iter 400. reward: -0.001901\n iter 500. reward: -0.000459\n iter 600. reward: -0.000287\n iter 700. reward: -0.000939\n iter 800. reward: -0.000504\n iter 900. reward: -0.000522\n iter 1000. reward: -0.000178\n \n \nNow we have the optimized weights and we can update our model:\n\n.. code:: python\n \n optimized_weights = es.get_weights()\n model.set_weights(optimized_weights)\n \n\nTodo\n--------\n- Add distribution support over network\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/alirezamika/evostra", "keywords": "evolution strategy in machine learning - deep reinforcement learning", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "evostra", "package_url": "https://pypi.org/project/evostra/", "platform": "", "project_url": "https://pypi.org/project/evostra/", "project_urls": { "Homepage": "https://github.com/alirezamika/evostra" }, "release_url": "https://pypi.org/project/evostra/2.5.2/", "requires_dist": null, "requires_python": "", "summary": "Evolution Strategy Solver in Python", "version": "2.5.2" }, "last_serial": 3917379, "releases": { "1.0.1": [ { "comment_text": "", "digests": { "md5": "7d476603f452debc84327fcc75f2e043", "sha256": "865c40fe1ea16644676abc0d76af7fb20a5f601271f3f086bbb7bfc8f1d8ac31" }, "downloads": -1, "filename": "evostra-1.0.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "7d476603f452debc84327fcc75f2e043", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 5552, "upload_time": "2017-06-16T16:02:29", "url": "https://files.pythonhosted.org/packages/56/84/57d641e603d6e5e824c9c2bb6b9d91dd9044aad7cd157ec8f37b8f4b46f6/evostra-1.0.1-py2.py3-none-any.whl" } ], "2.0": [ { "comment_text": "", "digests": { "md5": "a56c44ba97cc461f1585e714dc832950", "sha256": "e45619c1379a962a266f505614102a28f3a070f554e4548dd6cf794095bc25ab" }, "downloads": -1, "filename": "evostra-2.0.tar.gz", "has_sig": false, "md5_digest": "a56c44ba97cc461f1585e714dc832950", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4257, "upload_time": "2018-05-10T17:14:02", "url": "https://files.pythonhosted.org/packages/ca/6d/80cd3706adea694ad62d879f82580f1e497046c3a8f901d6ed4a6ab1cc84/evostra-2.0.tar.gz" } ], "2.5.0": [ { "comment_text": "", "digests": { "md5": "4208fa660eb47ae44ff9a2dedfba2287", "sha256": "80402718a43bb7d7051371bee550263cf9ba2286a512843acde6bcea755759e1" }, "downloads": -1, "filename": "evostra-2.5.0.tar.gz", "has_sig": false, "md5_digest": "4208fa660eb47ae44ff9a2dedfba2287", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4665, "upload_time": "2018-05-11T08:32:27", "url": "https://files.pythonhosted.org/packages/65/74/85933a3ce5a15c4e786fd7f212dc4e43d1e054a1666d2215efaba85a39c4/evostra-2.5.0.tar.gz" } ], "2.5.1": [ { "comment_text": "", "digests": { "md5": "e172f7c7bdecea43ad705d64093d69af", "sha256": "b69c9955e6a74923ca740f37cf92cab366862d7321981ca9dcf178c63cb2c451" }, "downloads": -1, "filename": "evostra-2.5.1.tar.gz", "has_sig": false, "md5_digest": "e172f7c7bdecea43ad705d64093d69af", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4668, "upload_time": "2018-05-11T08:48:50", "url": "https://files.pythonhosted.org/packages/e2/aa/334291d135fbd02167e88f96bd5cf2a89477cc61d44d3dab37f46f93d574/evostra-2.5.1.tar.gz" } ], "2.5.2": [ { "comment_text": "", "digests": { "md5": "8a24a167c2a7a8b78621568fa60ad6cc", "sha256": "868b922f7ee00433d1e8373d64e90c01dbdd046d71eb43045658f3863e760105" }, "downloads": -1, "filename": "evostra-2.5.2.tar.gz", "has_sig": false, "md5_digest": "8a24a167c2a7a8b78621568fa60ad6cc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4752, "upload_time": "2018-05-31T15:18:29", "url": "https://files.pythonhosted.org/packages/6f/ec/fd9b77c2b32899b5caf71252e133bc8d9a1daab539c89abb252033c43a3e/evostra-2.5.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "8a24a167c2a7a8b78621568fa60ad6cc", "sha256": "868b922f7ee00433d1e8373d64e90c01dbdd046d71eb43045658f3863e760105" }, "downloads": -1, "filename": "evostra-2.5.2.tar.gz", "has_sig": false, "md5_digest": "8a24a167c2a7a8b78621568fa60ad6cc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4752, "upload_time": "2018-05-31T15:18:29", "url": "https://files.pythonhosted.org/packages/6f/ec/fd9b77c2b32899b5caf71252e133bc8d9a1daab539c89abb252033c43a3e/evostra-2.5.2.tar.gz" } ] }