Magics for defining and running stan code in Jupyter.
Project description
CmdStanJupyter
CmdStanJupyter
is a package to help development of Stan models (using CmdStanPy
)
in jupyter notebooks.
Use it with jupyterlab-stan-highlight to recieve
highlighting for your %%stan
blocks in python notebooks!
The package is heavily based on Arvinds-ds
jupyterstan package, but provides an
interface that simply returns a cmdstanpy.CmdStanModel
object.
Features
- Compile a stan model and save it as a cmdstanpy variable by running a
%%stan
cell - Display and load an existing stan file with
%stanf
Installation
To install the library:
pip install cmdstanjupyter
This does not install cmdstanpy by default, as the recommended installation for that package is via conda. If you want to install cmdstanpy via pip alongside this package, use
pip install cmdstanjupyter[all]
Usage
To use the magic
in your notebook, you need to lead the extension:
%load_ext cmdstanjupyter
To define a stan model inside a jupyter notebook, start a cell with the %%stan
magic. You can also provide a variable name, which is the variable name that
the cmdstanpy.CmdStanModel
object will be assigned to. For example:
%%stan paris_female_births
data {
int male;
int female;
}
parameters {
real<lower=0, upper=1> p;
}
model {
female ~ binomial(male + female, p);
}
When you run this cell, cmdstanjupyter
will create a cmdstanpy CmdStanModel object,
which will compile your model and allow you to sample from it.
If the above code was stored in a file births.stan
, the following is also possible:
%stanf paris_female_births births.stan
data {
int male;
int female;
}
parameters {
real<lower=0, upper=1> p;
}
model {
female ~ binomial(male + female, p);
}
To use your compiled model:
fit = paris_female_births.sample(
data={'male': 251527, 'female': 241945},
)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file cmdstanjupyter-0.5.0.tar.gz
.
File metadata
- Download URL: cmdstanjupyter-0.5.0.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8682f848da20f206188db576662115a5171c723c57297de3f93b48170fb62a9b |
|
MD5 | b4eafcfa02e60787fca36f27255626fa |
|
BLAKE2b-256 | fbe8cabc6e67b98cc208577271a310cbd2ceae7a1532f4bd974cbdbf689b8bcb |
File details
Details for the file cmdstanjupyter-0.5.0-py2.py3-none-any.whl
.
File metadata
- Download URL: cmdstanjupyter-0.5.0-py2.py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91de601efd05aba98c1a217483c62eb3822f7f330ec6057ee4e38a5aa962c4c1 |
|
MD5 | b7de4b9bbec04a2998bac3d5038cf7c2 |
|
BLAKE2b-256 | 44fec300119f44a611a3057a4aa66d39ad816fdfba50ac2420e3e8f67c4e353f |