{ "info": { "author": "Guillaume Baudart, Martin Hirzel, Kiran Kate, Louis Mandel, Avraham Shinnar", "author_email": "", "bugtrack_url": null, "classifiers": [], "description": "[![Build Status](https://travis-ci.org/IBM/yaps.svg?branch=master)](https://travis-ci.org/IBM/yaps) [![PyPI version](https://badge.fury.io/py/yaps.svg)](https://badge.fury.io/py/yaps) [![Documentation Status](https://readthedocs.org/projects/yaps/badge/?version=latest)](https://yaps.readthedocs.io/en/latest/?badge=latest)\n\n# YAPS\n\nYaps is a new surface language for [Stan](http://mc-stan.org/). It lets\nusers write Stan programs using Python syntax. For example, consider the\nfollowing Stan program, which models tosses `x` of a coin with bias `theta`:\n```stan\ndata {\n int x[10];\n}\nparameters {\n real theta;\n}\nmodel {\n theta ~ uniform(0,1);\n for (i in 1:10)\n x[i] ~ bernoulli(theta);\n}\n```\nIt can be rewritten in Python has follows:\n```python\nimport yaps\nfrom yaps.lib import int, real, uniform, bernoulli\n\n@yaps.model\ndef coin(x: int(lower=0, upper=1)[10]):\n theta: real(lower=0, upper=1) <~ uniform(0, 1)\n for i in range(1,11):\n x[i] <~ bernoulli(theta)\n```\n\nThe `@yaps.model` decorator indicates that the function following it\nis a Stan program. While being syntactically Python, it is\nsemantically reinterpreted as Stan.\n\nThe argument of the function corresponds to the `data` block. The\ntype of the data must be declared. Here, you can see that `x` is an\narray of 10 integers between `0` and `1` (`int(lower=0, upper=1)[10]`).\n\nParameters are declared as variables with their type in the body of\nthe function. Their prior can be defined using the sampling operator\n`<~` (or `is`).\n\nThe body of the function corresponds to the Stan model. Python syntax\nis used for the imperative constructs of the model, like the `for`\nloop in the example. The operator `<~` is used to represent sampling\nand `x.T[a,b]` for truncated distribution.\n\nNote that Stan array are 1-based. The range of the loop is thus `range(1, 11)`,\nthat is 1,2, ... 10.\n\nOther Stan blocks can be introduced using the `with` syntax of Python.\nFor example, the previous program could also be written as follows:\n```python\n@yaps.model\ndef coin(x: int(lower=0, upper=1)[10]):\n with parameters:\n theta: real(lower=0, upper=1)\n with model:\n theta <~ uniform(0, 1)\n for i in range(1,11):\n x[i] <~ bernoulli(theta)\n```\n\nThe corresponding Stan program can be displayed using the `print` function:\n```python\nprint(coin)\n```\n\nFinally, it is possible to launch Bayesian inference on the defined model applied to some data.\nThe communication with the Stan inference engine is based on on [PyCmdStan](https://pycmdstan.readthedocs.io/en/latest/).\n```python\nflips = np.array([0, 1, 0, 0, 0, 0, 0, 0, 0, 1])\nconstrained_coin = coin(x=flips)\nconstrained_coin.sample(data=constrained_coin.data)\n```\nNote that arrays must be cast into numpy arrays (see pycmdstan documentation).\n\nAfter the inference the attribute `posterior` of the constrained model is an object with fields for the latent model parameters:\n```python\ntheta_mean = constrained_coin.posterior.theta.mean()\nprint(\"mean of theta: {:.3f}\".format(theta_mean))\n```\n\nYaps provides a lighter syntax to Stan programs. Since Yaps uses Python syntax, users can take advantage of Python tooling\nfor syntax highlighting, indentation, error reporting, ...\n\n## Install\n\nYaps depends on the following python packages:\n- astor\n- graphviz\n- antlr4-python3-runtime\n- pycmdstan\n\nTo install Yaps and all its dependencies run:\n```\npip install yaps\n```\n\nTo install from source, first clone the repo, then:\n```\npip install .\n```\n\nBy default, communication with the Stan inference engine is based on [PyCmdStan](https://pycmdstan.readthedocs.io/en/latest/). To run inference, you first need to install [CmdStan](http://mc-stan.org/users/interfaces/cmdstan) and set the CMDSTAN environment variable to point to your CmdStan directory.\n\n```\nexport CMDSTAN=/path/to/cmdstan\n```\n\n## Tools\n\nWe provide a tool to compile Stan files to Yaps syntax.\nFor instance, if `path/to/coin.stan` contain the Stan model presented at the beginning, then:\n```\nstan2yaps path/to/coin.stan\n```\noutputs:\n```\n# -------------\n# tests/stan/coin.stan\n# -------------\n@yaps.model\ndef stan_model(x: int(lower=0, upper=1)[10]):\n theta: real\n theta is uniform(0.0, 1.0)\n for i in range(1, 10 + 1):\n x[(i),] is bernoulli(theta)\n print(x)\n```\n\nCompilers from Yaps to Stan and from Stan to Yaps can also be invoked programmatically using the following functions:\n```python\nyaps.from_stan(code_string=None, code_file=None) # Compile a Stan model to Yaps\nyaps.to_stan(code_string=None, code_file=None) # Compile a Yaps model to Stan\n```\n\n## Documentation\n\nThe full documentation is available at https://yaps.readthedocs.io. You can find more details in the following [article](https://arxiv.org/abs/1812.04125):\n```\n@article{2018-yaps-stan,\n author = {Baudart, Guillaume and Hirzel, Martin and Kate, Kiran and Mandel, Louis and Shinnar, Avraham},\n title = \"{Yaps: Python Frontend to Stan}\",\n journal = {arXiv e-prints},\n year = 2018,\n month = Dec,\n url = {https://arxiv.org/abs/1812.04125},\n}\n```\n\n\n## License\n\nYaps is distributed under the terms of the Apache 2.0 License, see\n[LICENSE.txt](LICENSE.txt)\n\n\n\n## Contributions\n\nYaps is still at an early phase of development and we welcome\ncontributions. Contributors are expected to submit a 'Developer's\nCertificate of Origin', which can be found in [DCO1.1.txt](DCO1.1.txt).\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/IBM/yaps", "keywords": "", "license": "Apache License 2.0", "maintainer": "", "maintainer_email": "", "name": "yaps", "package_url": "https://pypi.org/project/yaps/", "platform": "", "project_url": "https://pypi.org/project/yaps/", "project_urls": { "Homepage": "https://github.com/IBM/yaps" }, "release_url": "https://pypi.org/project/yaps/0.1.4/", "requires_dist": [ "astor", "graphviz", "antlr4-python3-runtime", "pycmdstan" ], "requires_python": "", "summary": "A surface language for programming Stan models using python syntax", "version": "0.1.4" }, "last_serial": 4609703, "releases": { "0.1.1": [ { "comment_text": "", "digests": { "md5": "1bda5459196c02071fa49a21ab00ec90", "sha256": "6292ceaa14b5b49caab67ff9372fd2a387517d38d5485db441924aa99b0f7177" }, "downloads": -1, "filename": "yaps-0.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "1bda5459196c02071fa49a21ab00ec90", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 62001, "upload_time": "2018-10-19T18:39:28", "url": "https://files.pythonhosted.org/packages/20/00/9ad74ad3ee562f5c6144544b76a812401cb70d5d74af1ada46dd1a603bc2/yaps-0.1.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "1363490b5a6784079c434fd0b5b84a9c", "sha256": "34b77e0bda20303cdc03d8a333ea2389c7c7414eef231d9a9169ebb4572c7a28" }, "downloads": -1, "filename": "yaps-0.1.1.tar.gz", "has_sig": false, "md5_digest": "1363490b5a6784079c434fd0b5b84a9c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 54339, "upload_time": "2018-10-19T18:39:29", "url": "https://files.pythonhosted.org/packages/cf/50/11028712b550e6ab8107f916b8c9bc2a67077517aa9408297b98715e8e3d/yaps-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "c0d3a08d6d38d93ef6162bed8731c1f5", "sha256": "78e540e316693d0d219a0de7e997b0fbb2b3d4aa9c35c6f7e30f17837f35c3e1" }, "downloads": -1, "filename": "yaps-0.1.2-py3-none-any.whl", "has_sig": false, "md5_digest": "c0d3a08d6d38d93ef6162bed8731c1f5", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 61772, "upload_time": "2018-11-08T22:32:51", "url": "https://files.pythonhosted.org/packages/93/9d/a96ca6ea0433e90941fa59708632632f64876db65d9080ef8f9f4ad6f143/yaps-0.1.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "410ddcf41e1ed9391efda989d992234e", "sha256": "86e294c6d196982edd1480e2b2f88ed25e0bcbb2b250ceeef15392f339f5f435" }, "downloads": -1, "filename": "yaps-0.1.2.tar.gz", "has_sig": false, "md5_digest": "410ddcf41e1ed9391efda989d992234e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 54018, "upload_time": "2018-11-08T22:32:53", "url": "https://files.pythonhosted.org/packages/06/f3/5c9abff5d3e7646175787e9c19fd9386a53ce3cf308349015f463d5e447d/yaps-0.1.2.tar.gz" } ], "0.1.3": [ { "comment_text": "", "digests": { "md5": "c76693a5f7d4354f4d4a0a2552103384", "sha256": "ff4ed3c26cd4885b6b793b1e8c332292f915e820c31edadd8cd90aa7b613d10e" }, "downloads": -1, "filename": "yaps-0.1.3-py3-none-any.whl", "has_sig": false, "md5_digest": "c76693a5f7d4354f4d4a0a2552103384", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 62014, "upload_time": "2018-11-16T22:09:22", "url": "https://files.pythonhosted.org/packages/15/49/7ea8b90316ab97f82c77fba59c671a24ed9f63bb50e990421478301605ee/yaps-0.1.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "c43ee9eaedcd894faa2ef7545ba11fe0", "sha256": "e67f3d00ea1112e074f1db3597f487f4f67ee1a30f535f5e6ce809636ac54dd9" }, "downloads": -1, "filename": "yaps-0.1.3.tar.gz", "has_sig": false, "md5_digest": "c43ee9eaedcd894faa2ef7545ba11fe0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 54286, "upload_time": "2018-11-16T22:09:24", "url": "https://files.pythonhosted.org/packages/1f/93/d5a8b139b91321268688c828cd1f8c81ccd3ab00bc6d799cd7fa84708238/yaps-0.1.3.tar.gz" } ], "0.1.4": [ { "comment_text": "", "digests": { "md5": "4944819b8d43fd78d5375b31e2b49de1", "sha256": "7759bfbf3986290e147ff345c10980556e1129fe3d92e8e74b5593f7d35c6e89" }, "downloads": -1, "filename": "yaps-0.1.4-py3-none-any.whl", "has_sig": false, "md5_digest": "4944819b8d43fd78d5375b31e2b49de1", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 59666, "upload_time": "2018-12-17T21:45:42", "url": "https://files.pythonhosted.org/packages/81/2c/d197e46e5a3c4f5cb4e0cf7bd064e7f344a3ec35f5ba0e6f5157eae22ed5/yaps-0.1.4-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "eb0f734d3f3d2a5474786087827c943b", "sha256": "ab34249dfa0242e7bbe006b2110db66f8b5a5715c8b61ecc3b811c2fc0718dd2" }, "downloads": -1, "filename": "yaps-0.1.4.tar.gz", "has_sig": false, "md5_digest": "eb0f734d3f3d2a5474786087827c943b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 55557, "upload_time": "2018-12-17T21:45:43", "url": "https://files.pythonhosted.org/packages/e1/ec/730e3cbfd11c21d6970325af24ebbdf10c1d7868bb76fedb3a65642af616/yaps-0.1.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "4944819b8d43fd78d5375b31e2b49de1", "sha256": "7759bfbf3986290e147ff345c10980556e1129fe3d92e8e74b5593f7d35c6e89" }, "downloads": -1, "filename": "yaps-0.1.4-py3-none-any.whl", "has_sig": false, "md5_digest": "4944819b8d43fd78d5375b31e2b49de1", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 59666, "upload_time": "2018-12-17T21:45:42", "url": "https://files.pythonhosted.org/packages/81/2c/d197e46e5a3c4f5cb4e0cf7bd064e7f344a3ec35f5ba0e6f5157eae22ed5/yaps-0.1.4-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "eb0f734d3f3d2a5474786087827c943b", "sha256": "ab34249dfa0242e7bbe006b2110db66f8b5a5715c8b61ecc3b811c2fc0718dd2" }, "downloads": -1, "filename": "yaps-0.1.4.tar.gz", "has_sig": false, "md5_digest": "eb0f734d3f3d2a5474786087827c943b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 55557, "upload_time": "2018-12-17T21:45:43", "url": "https://files.pythonhosted.org/packages/e1/ec/730e3cbfd11c21d6970325af24ebbdf10c1d7868bb76fedb3a65642af616/yaps-0.1.4.tar.gz" } ] }