{ "info": { "author": "", "author_email": "", "bugtrack_url": null, "classifiers": [], "description": "# Question Programs & Expected Information Gain\n\nThis is a package for parsing/executing questions and calculating Expected Information Gain (EIG) for question programs defined on the Battleship Dataset in the paper \"[Question Asking as Program Generation](https://arxiv.org/abs/1711.06351)\".\n\nThis package provide a Pure python version (slow) and a Python/C++ hybrid version (fast). Both versions have the same API but different implementations.\n\n## Installation\n\nThis package can be installed using pip\n```\npip install expected-information-gain\n```\n\n## Basic Usage\n\nThe following example shows how to execute a program on a given board\n```python\n# define a board using BattleshipHypothesis\nfrom eig.battleship import Ship, BattleshipHypothesis, Parser, Executor\nships = [Ship(ship_label=1, topleft=(0, 0), size=2, orientation='V'),\n Ship(ship_label=2, topleft=(1, 2), size=2, orientation='V')\nhypothesis = BattleshipHypothesis(grid_size=3, ships=ships)\n# the board looks like this\n# B W W\n# B W R\n# W W R\n\n# parse and execute the program\nquestion = Parser.parse(\"(bottomright (coloredTiles Red))\")\nexecutor = Executor(question)\nexecutor.execute(hypothesis) # (2, 2)\n\n# we can also evaluate general arithmic and logical expressions, with whatever hypothesis provided\nquestion2 = Parser.parse(\"(and (not (< 4 9)) (== (+ 1 3) 4))\")\nexecutor2 = Executor(question)\nexecutor.execute(hypothesis) # False\n```\n\nThe next example shows how to calculate Expected Information Gain on a partly revealed board\n```python\n# first we need to construct a hypothesis space \n# We suggest to do this as an initialization step, and use this instance every time\n# Because this step is time consuming, and may take several seconds to finish.\nfrom eig.battleship import BattleshipHypothesisSpace\nhypotheses = BattleshipHypothesisSpace(grid_size=6, ship_labels=[1, 2, 3], \n ship_sizes=[2, 3, 4], orientations=['V', 'H'])\n\n# suppose we have a program and a partly revealed board\nimport numpy as np\nprogram = \"...\"\nboard = np.array([...])\n\n# next we can calculate EIG as follows\nfrom eig import compute_eig_basic\nfrom eig.battleship.program import ProgramSyntaxError\ntry:\n score = compute_eig_basic(hypotheses, program, board)\nexcept ProgramSyntaxError: # if the program is invalid, a ProgramSyntaxError will be raised\n # do something\nexcept RuntimeError: # if error happens during execution, a RuntimeError will be raised\n # do something\n```\n\n## Advanced Usage\n\nWe also provide some advanced interfaces, which are more efficient when the users need to calculate EIG for many \nprograms on one given board, and they also allows users to incorporate more complicated distributions.\n\n```python\n# construct the hypothesis space\nfrom eig.battleship import BattleshipHypothesisSpace\nhypotheses = BattleshipHypothesisSpace(grid_size=6, ship_labels=[1, 2, 3], \n ship_sizes=[2, 3, 4], orientations=['V', 'H'])\n\n# calculate EIG as follows\nfrom eig import compute_eig, Bayes, Context\nfrom eig.battleship import Parser, Executor\nfrom eig.battleship.program import ProgramSyntaxError\ntry:\n ast = Parser.parse(program) # parse the program into abstract syntax tree\n executor = Executor(ast) # obtain an executor to execute the program\n prior = EqualSizesDistribution(ship_labels=[1, 2, 3]) # a more cognitive inspired prior distribution\n belief = eig.Bayes(hypotheses, prior) # a prior belief given the hypothesis space\n context = eig.Context(hypotheses, belief) # context stores the posterior belief\n context.observe(board) # update posterior belief given the board\n score = eig.compute_eig(executor, context) # compute EIG given program and posterior belief\nexcept ProgramSyntaxError: # if the program is invalid, a ProgramSyntaxError will be raised\n # do something\nexcept RuntimeError: # if error happens during execution, a RuntimeError will be raised\n # do something\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/anselmrothe/EIG", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "expected-information-gain", "package_url": "https://pypi.org/project/expected-information-gain/", "platform": "", "project_url": "https://pypi.org/project/expected-information-gain/", "project_urls": { "Homepage": "https://github.com/anselmrothe/EIG" }, "release_url": "https://pypi.org/project/expected-information-gain/1.0.3/", "requires_dist": [ "numpy", "cython" ], "requires_python": "", "summary": "Parsing, executing, and calculating expected information gain for program-form questions.", "version": "1.0.3" }, "last_serial": 4977129, "releases": { "1.0.2": [ { "comment_text": "", "digests": { "md5": "d38b115f2c1dc9c512ae5aa9fb3f296c", "sha256": "5ff17322ee2ddca27cfea06c73b9e223528850c48f10c14124e18e5cd54e1d61" }, "downloads": -1, "filename": "expected_information_gain-1.0.2-cp36-cp36m-macosx_10_7_x86_64.whl", "has_sig": false, "md5_digest": "d38b115f2c1dc9c512ae5aa9fb3f296c", "packagetype": "bdist_wheel", "python_version": "cp36", "requires_python": null, "size": 211155, "upload_time": "2019-03-01T20:41:27", "url": "https://files.pythonhosted.org/packages/92/e5/604ffa7c8292dab9e3459074fb3ba89bc1e0cf09e9d2dbe82fa1bb241fd9/expected_information_gain-1.0.2-cp36-cp36m-macosx_10_7_x86_64.whl" }, { "comment_text": "", "digests": { "md5": "151151a7ac77f7196278f0c057dfb308", "sha256": "13db70aa3141419386a380d070d8bd76e4f44d42a81a3efa68a9d0952902ba9c" }, "downloads": -1, "filename": "expected-information-gain-1.0.2.tar.gz", "has_sig": false, "md5_digest": "151151a7ac77f7196278f0c057dfb308", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 22698, "upload_time": "2019-03-01T20:41:30", "url": "https://files.pythonhosted.org/packages/83/3b/970a6f2b2185b310794de4db2d7b41dfd732802d2771a1b00e0f7f01586b/expected-information-gain-1.0.2.tar.gz" } ], "1.0.3": [ { "comment_text": "", "digests": { "md5": "f4838cc76c37cc2f60070d88abbd2b91", "sha256": "c3e3e6128fbe92515accaac0f5aa6594f4a952b352a4e033bea46ef7543db3fd" }, "downloads": -1, "filename": "expected_information_gain-1.0.3-cp36-cp36m-macosx_10_7_x86_64.whl", "has_sig": false, "md5_digest": "f4838cc76c37cc2f60070d88abbd2b91", "packagetype": "bdist_wheel", "python_version": "cp36", "requires_python": null, "size": 213021, "upload_time": "2019-03-24T01:09:10", "url": "https://files.pythonhosted.org/packages/28/4f/f82a52e6d3fe3dd56d6d6620348872df324e8ecfeb13857898a9c7044898/expected_information_gain-1.0.3-cp36-cp36m-macosx_10_7_x86_64.whl" }, { "comment_text": "", "digests": { "md5": "2e0d0bd311e9925f21bf7168c6d22611", "sha256": "fa5b660959b3d5fdf0b361256071dda69f6b5af1ec8d17328b35368d9cb60bfe" }, "downloads": -1, "filename": "expected-information-gain-1.0.3.tar.gz", "has_sig": false, "md5_digest": "2e0d0bd311e9925f21bf7168c6d22611", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 23860, "upload_time": "2019-03-24T01:09:11", "url": "https://files.pythonhosted.org/packages/3f/41/7f07b274124896f1e79bcbef306990992e0ac83acc131285f4cef36133c8/expected-information-gain-1.0.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "f4838cc76c37cc2f60070d88abbd2b91", "sha256": "c3e3e6128fbe92515accaac0f5aa6594f4a952b352a4e033bea46ef7543db3fd" }, "downloads": -1, "filename": "expected_information_gain-1.0.3-cp36-cp36m-macosx_10_7_x86_64.whl", "has_sig": false, "md5_digest": "f4838cc76c37cc2f60070d88abbd2b91", "packagetype": "bdist_wheel", "python_version": "cp36", "requires_python": null, "size": 213021, "upload_time": "2019-03-24T01:09:10", "url": "https://files.pythonhosted.org/packages/28/4f/f82a52e6d3fe3dd56d6d6620348872df324e8ecfeb13857898a9c7044898/expected_information_gain-1.0.3-cp36-cp36m-macosx_10_7_x86_64.whl" }, { "comment_text": "", "digests": { "md5": "2e0d0bd311e9925f21bf7168c6d22611", "sha256": "fa5b660959b3d5fdf0b361256071dda69f6b5af1ec8d17328b35368d9cb60bfe" }, "downloads": -1, "filename": "expected-information-gain-1.0.3.tar.gz", "has_sig": false, "md5_digest": "2e0d0bd311e9925f21bf7168c6d22611", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 23860, "upload_time": "2019-03-24T01:09:11", "url": "https://files.pythonhosted.org/packages/3f/41/7f07b274124896f1e79bcbef306990992e0ac83acc131285f4cef36133c8/expected-information-gain-1.0.3.tar.gz" } ] }