Magics for defining stan code in notebooks.
Project description
# jupyterstan
`jupyterstan` is a package to help development of Stan models (using `pystan`)
in jupyter notebooks.
The package is heavily based on Arvinds-ds
[stanmagic](https://github.com/Arvinds-ds/stanmagic) package, but provides an
interface that simply returns a `pystan.Model` object.
In addition, it bundles Arvinds-ds `stan_code_helper` package to improve
syntax highlighting for stan cells.
## Installation
To install the library:
```
pip install git+https://github.com/janfreyberg/jupyterstan.git
```
To enable the syntax highlighting:
```
jupyter nbextension install --py stan_syntax --sys-prefix
jupyter nbextension enable stan_syntax --py --sys-prefix
```
## Usage
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 `pystan.Model` 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);
}
```
Then, to use your defined model:
```
fit = paris_female_births.sampling(
data={'male': 251527, 'female': 241945},
iter=1000,
chains=4
)
```
`jupyterstan` is a package to help development of Stan models (using `pystan`)
in jupyter notebooks.
The package is heavily based on Arvinds-ds
[stanmagic](https://github.com/Arvinds-ds/stanmagic) package, but provides an
interface that simply returns a `pystan.Model` object.
In addition, it bundles Arvinds-ds `stan_code_helper` package to improve
syntax highlighting for stan cells.
## Installation
To install the library:
```
pip install git+https://github.com/janfreyberg/jupyterstan.git
```
To enable the syntax highlighting:
```
jupyter nbextension install --py stan_syntax --sys-prefix
jupyter nbextension enable stan_syntax --py --sys-prefix
```
## Usage
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 `pystan.Model` 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);
}
```
Then, to use your defined model:
```
fit = paris_female_births.sampling(
data={'male': 251527, 'female': 241945},
iter=1000,
chains=4
)
```
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
jupyterstan-0.0.1.tar.gz
(11.4 kB
view hashes)
Built Distribution
Close
Hashes for jupyterstan-0.0.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | baf6ed9921c099bd2b06a2032575121540245284f7974d87c9e32a6ec22cc617 |
|
MD5 | 209eadf1261937a69f466675b61120b8 |
|
BLAKE2b-256 | 7dd697d076f4b104ac7ab8aa7858d9e7f4b2a8bf2f961b76a48323733c05de71 |