{ "info": { "author": "Jacqueline Buros Novik", "author_email": "jackinovik@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Environment :: Console", "Intended Audience :: Science/Research", "License :: OSI Approved :: Apache Software License", "Operating System :: OS Independent", "Programming Language :: Python", "Topic :: Scientific/Engineering :: Bio-Informatics" ], "description": "[![Build Status](https://travis-ci.org/hammerlab/stancache.svg?branch=master)](https://travis-ci.org/hammerlab/stancache) \n[![Coverage Status](https://img.shields.io/coveralls/hammerlab/stancache.svg)](https://coveralls.io/github/hammerlab/stancache?branch=master)\n[![PyPI version](https://img.shields.io/pypi/v/stancache.svg)](https://pypi.python.org/pypi/stancache)\n\nstancache\n===============================\n\nauthor: Jacqueline Buros Novik\n\nOverview\n--------\n\nFilecache for stan models\n\nInstallation\n--------------------\n\nYou can install this package from pypi using pip:\n\n $ pip install stancache\n\nOr clone the repo & run setup.py:\n\n $ git clone https://github.com/hammerlab/stancache.git\n $ python setup.py install\n\nIntroduction\n------------\n\nThis is a filecache for [pystan](https://pystan.readthedocs.io/en/latest/) models fit to data. Each pystan model fit to data is comprised of two parts - the compiled model code & the result of MCMC sampling of that model given data. Both model compilation & model sampling can be time-consuming operations, so both are cached as separate [pickled](https://docs.python.org/3/library/pickle.html) objects on the filesystem. \n\nThis separation allows one to (for example) compile a model once & execute the model several times - caching the result each time. You might be testing the model on different samples of data, or using different initializations or passing in different parameters.\n\nLoading pickled pystan.fit objects into memory is also safer using `cached_stan_fit()` since this will ensure that the compiled model is first unpickled before the fit model.\n\nGetting started\n---------------\n\n### Configuration\n\nThe configuration uses python's [configparser](https://docs.python.org/2/library/configparser.html) module, allowing the user to either load a `config.ini` file from disk or set the configuration in code.\n\n`stancache` looks for a default config file to be located in `'~/.stancache.ini'`. You can modify this using `stancache.config.load_config('/another/config/file.ini')`. \n\nCurrently, the config settings include\n\n* `CACHE_DIR` (defaults to `.cached_models`)\n* `SEED` (seed value passed to `pystan.stan` for reproducible research)\n* `SET_SEED` (boolean, whether to set the random.seed systemwide in addition to stan_seed)\n\nYou can use `config.set_value(NAME=value)` to modify a setting.\n\nFor example, you might want to set up a shared-nfs-mount containing fitted models among your collaborators:\n\n```python\nfrom stancache import config\nconfig.set_value(CACHE_DIR='/mnt/trial-analyses/cohort1/stancache')\n```\n\nAn updated list of configuration defaults is available in [defaults.py](https://github.com/hammerlab/stancache/blob/master/stancache/defaults.py)\n\n### Fitting cached models\n\nOnce you have configured your settings, you would then use `stancache.cached_stan_fit` to fit your model, like so:\n\n```python\nfrom stancache import stancache\nfit1 = stancache.cached_stan_fit(file = '/path/to/model.stan', data=dict(), chains=4, iter=100)\n```\n\nThe options to `cached_stan_fit` are the same as those to `pystan.stan` (see [pystan.stan documentation](https://pystan.readthedocs.io/en/latest/api.html#pystan.stan)).\n\nAlso see `?stancache.cached_stan_fit` for more details.\n\n### Caching other items\n\nThe caching is very sensitive to certain things which would change the returned object, such as the sort order of your data elements within the dictionary. But is not sensitive to other things, such as whether you use a file-based stan code or string-based version of same code. \n\nIn practice, we find that it can be helpful to cache data-preparation steps, especially when simulating data. There is thus a `stancache.cached()` wrapper function for this purpose,. This will save or cache all objects _other_ than `pystan.stan` objects to disk using the same file-cache settings as are used for stancache.\n\n### Avoiding re-executing a model\n\nThere are a number of scenarios where you might want to use a cache of fitted models in read-only mode. You can avoid accidentally re-fitting the model by setting `cache_only=True`.\n\nFor example, you may have fit a set of models which you want to read into a jupyter notebook for model exploration. Or, you may be reviewing a colleague's fitted model objects. Note that this is foolproof so please back up your work. \n\nContributing\n------------\n\nTBD\n\nExamples\n--------\n\nFor example (borrowing from [pystan's docs](https://pystan.readthedocs.io/en/latest/getting_started.html)):\n\n```python\nimport stancache\n\nschools_code = \"\"\"\ndata {\n int J; // number of schools\n real y[J]; // estimated treatment effects\n real sigma[J]; // s.e. of effect estimates\n}\nparameters {\n real mu;\n real tau;\n real eta[J];\n}\ntransformed parameters {\n real theta[J];\n for (j in 1:J)\n theta[j] <- mu + tau * eta[j];\n}\nmodel {\n eta ~ normal(0, 1);\n y ~ normal(theta, sigma);\n}\n\"\"\"\n\nschools_dat = {'J': 8,\n 'y': [28, 8, -3, 7, -1, 1, 18, 12],\n 'sigma': [15, 10, 16, 11, 9, 11, 10, 18]}\n\n# fit model to data\nfit = stancache.cached_stan_fit(model_code=schools_code, data=schools_dat,\n iter=1000, chains=4)\n\n# load fit model from cache\nfit2 = stancache.cached_stan_fit(model_code=schools_code, data=schools_dat,\n iter=1000, chains=4)\n```\n\nIn addition, there are a number of publicly-accessible ipynbs using [stancache](http://github.com/hammerlab/stancache). \n\nThese include:\n\n* [survivalstan-examples](http://github.com/jburos/survivalstan-examples)\n* [immune-infiltrate-explorations](http://github.com/hammerlab/immune-infiltrate-explorations)\n - e.g. [model-single-origin-samples/0.830 model3 by cell_type (n=500).ipynb](http://nbviewer.jupyter.org/github/hammerlab/immune-infiltrate-explorations/blob/master/model-single-origin-samples/0.830%20model3%20by%20cell_type%20%28n%3D500%29.ipynb)\n \nIf you know of other examples, please let us know and we will add them to this list.", "description_content_type": "", "docs_url": "https://pythonhosted.org/stancache/", "download_url": "https://github.com/jburos/stancache/tarball/0.1.64", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/jburos/stancache", "keywords": "", "license": "http://www.apache.org/licenses/LICENSE-2.0.html", "maintainer": "", "maintainer_email": "", "name": "stancache", "package_url": "https://pypi.org/project/stancache/", "platform": "", "project_url": "https://pypi.org/project/stancache/", "project_urls": { "Download": "https://github.com/jburos/stancache/tarball/0.1.64", "Homepage": "https://github.com/jburos/stancache" }, "release_url": "https://pypi.org/project/stancache/0.1.64/", "requires_dist": null, "requires_python": "", "summary": "Filecache for stan models", "version": "0.1.64" }, "last_serial": 4705030, "releases": { "0.1.3": [], "0.1.4": [ { "comment_text": "", "digests": { "md5": "fb77c5cc467ae16ba58f4e6c88c49480", "sha256": "9e31747289cbd6a77faa4b75179990a74d534f4c35d926770a980b8445ad72c8" }, "downloads": -1, "filename": "stancache-0.1.4.tar.gz", "has_sig": false, "md5_digest": "fb77c5cc467ae16ba58f4e6c88c49480", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9925, "upload_time": "2017-03-06T22:05:52", "url": "https://files.pythonhosted.org/packages/00/cd/dd455af2e41653039a73cd34d396c47595b160cacf527c6d1c0efc57d934/stancache-0.1.4.tar.gz" } ], "0.1.5": [ { "comment_text": "", "digests": { "md5": "b006e7056605c85572dba4f43102f0b9", "sha256": "e31ca422f31fe21a0343629489f044a28ea7f0c8ea8c90eec167a7259963d734" }, "downloads": -1, "filename": "stancache-0.1.5.tar.gz", "has_sig": false, "md5_digest": "b006e7056605c85572dba4f43102f0b9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9945, "upload_time": "2017-03-16T19:02:58", "url": "https://files.pythonhosted.org/packages/66/de/cd00fa12ad2c9be2a53eb254c1fdf7095b2a294fcf26263f223af6400aee/stancache-0.1.5.tar.gz" } ], "0.1.6": [ { "comment_text": "", "digests": { "md5": "095aff1def81fe35ee3c29b19bd04132", "sha256": "fe1f1f32d58ef56726e50f1c95a85479112a16c3b0e88aa9ec5417c502dfa26c" }, "downloads": -1, "filename": "stancache-0.1.6.tar.gz", "has_sig": false, "md5_digest": "095aff1def81fe35ee3c29b19bd04132", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9955, "upload_time": "2017-03-16T20:57:39", "url": "https://files.pythonhosted.org/packages/7a/20/6a622a0f266b03db6323cd659fc089c8e632a05f50380a59572e795f2c3d/stancache-0.1.6.tar.gz" } ], "0.1.61": [ { "comment_text": "", "digests": { "md5": "471c09be76005a26a272bbebeeaa98ab", "sha256": "5e1f62664fe4733987f66bb5cde052081daee4b5ee46a9638b99f1121b4f937d" }, "downloads": -1, "filename": "stancache-0.1.61.tar.gz", "has_sig": false, "md5_digest": "471c09be76005a26a272bbebeeaa98ab", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 28051, "upload_time": "2017-03-16T22:34:31", "url": "https://files.pythonhosted.org/packages/a9/0d/d54e683316899904a2afcde3a2642469ab18518eec7cf31f80db6bd0e20f/stancache-0.1.61.tar.gz" } ], "0.1.62": [ { "comment_text": "", "digests": { "md5": "99b96549e398c18c5a65bac894c28939", "sha256": "8489f5cc8fdb46642712c78acec8eeb432fef10129b0fbaf6c4bba03ae7e0db5" }, "downloads": -1, "filename": "stancache-0.1.62.tar.gz", "has_sig": false, "md5_digest": "99b96549e398c18c5a65bac894c28939", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 28086, "upload_time": "2017-03-17T17:10:35", "url": "https://files.pythonhosted.org/packages/f2/4c/b1df0a636f412ea9c582217efe2fa60e409f90943ce0d7b2014322054f53/stancache-0.1.62.tar.gz" } ], "0.1.64": [ { "comment_text": "", "digests": { "md5": "3e3e74911f432077280d2ebc79337d22", "sha256": "74261b8d7e078707c92996668dea40c2ff5854814fd393dc22c09218914cb699" }, "downloads": -1, "filename": "stancache-0.1.64.tar.gz", "has_sig": false, "md5_digest": "3e3e74911f432077280d2ebc79337d22", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 28434, "upload_time": "2019-01-16T20:21:51", "url": "https://files.pythonhosted.org/packages/cf/38/d018944f56d7385490cf815bfb2420d36fc9f2707eea2c14cde4d8e04a17/stancache-0.1.64.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "3e3e74911f432077280d2ebc79337d22", "sha256": "74261b8d7e078707c92996668dea40c2ff5854814fd393dc22c09218914cb699" }, "downloads": -1, "filename": "stancache-0.1.64.tar.gz", "has_sig": false, "md5_digest": "3e3e74911f432077280d2ebc79337d22", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 28434, "upload_time": "2019-01-16T20:21:51", "url": "https://files.pythonhosted.org/packages/cf/38/d018944f56d7385490cf815bfb2420d36fc9f2707eea2c14cde4d8e04a17/stancache-0.1.64.tar.gz" } ] }