-
-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathexample_script.py
More file actions
33 lines (25 loc) · 932 Bytes
/
Copy pathexample_script.py
File metadata and controls
33 lines (25 loc) · 932 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""Example script to be runned after tests, tqdm installed."""
import os
import sys
# explicit import to test if it is installed
# pylint: disable=E0401,W0611,C0411
import tqdm # noqa
from cmdstanpy import CmdStanModel, cmdstan_path
def run_bernoulli_fit():
# specify Stan file, create, compile CmdStanModel object
bernoulli_path = os.path.join(
cmdstan_path(), 'examples', 'bernoulli', 'bernoulli.stan'
)
bernoulli_model = CmdStanModel(stan_file=bernoulli_path)
# specify data, fit the model
bernoulli_data = {'N': 10, 'y': [0, 1, 0, 0, 0, 0, 0, 0, 0, 1]}
# Show progress
bernoulli_fit = bernoulli_model.sample(
chains=4, parallel_chains=2, data=bernoulli_data, show_progress=True
)
# summarize the results (wraps CmdStan `bin/stansummary`):
print(bernoulli_fit.summary())
if __name__ == '__main__':
run_bernoulli_fit()
# exit explicitly
sys.exit(0)