import stan
import numpy as np
N = 1000
mu = np.array([-.2, .2])
Z = np.random.binomial(1, .3, N)
Y = np.random.normal(mu[Z])
data = {
'N': Y.size,
'y': Y
}
posterior = stan.build("", data=data, random_seed=1)
This works when pasted into the REPL, but raises a very non-descriptive error message (I guess that's because the script is an empty string?):
Python 3.9.5 (default, May 18 2021, 12:31:01)
[Clang 10.0.0 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import stan
>>> import numpy as np
>>> N = 1000
>>> mu = np.array([-.2, .2])
>>> Z = np.random.binomial(1, .3, N)
>>> Y = np.random.normal(mu[Z])
>>> data = {
... 'N': Y.size,
... 'y': Y
... }
>>> posterior = stan.build("", data=data, random_seed=1)
Building: 56.6s, done.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/forcebru/opt/miniconda3/lib/python3.9/site-packages/stan/model.py", line 512, in build
return asyncio.run(go())
File "/Users/forcebru/opt/miniconda3/lib/python3.9/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/Users/forcebru/opt/miniconda3/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
return future.result()
File "/Users/forcebru/opt/miniconda3/lib/python3.9/site-packages/stan/model.py", line 507, in go
param_names, dims = zip(*((param["name"], param["dims"]) for param in params_list))
ValueError: not enough values to unpack (expected 2, got 0)
>>>
Oh, I even read about getting parameter summary statistics on that same page, but somehow completely missed the part about Jupyter notebooks... Sorry about that
Describe the bug
The error message is the same as here: https://github.com/stan-dev/pystan/issues/280. This comment (https://github.com/stan-dev/pystan/issues/280#issuecomment-828733049) says that "this is not a typical use of pystan", but... isn't a Jupyter notebook literally the most typical use of [insert any data science library, including PyStan]??
Error message:
Describe your system
Code Sample, a copy-pastable example
Code adapted from this STAN case study:
This works when pasted into the REPL, but raises a very non-descriptive error message (I guess that's because the script is an empty string?):