PyStan traceplot and other issues

357 views
Skip to first unread message

Nathan Lemoine

unread,
Jan 19, 2014, 12:25:24 PM1/19/14
to stan-...@googlegroups.com
Hi everyone,

I just started working with PyStan, as I plan to slowly move my workload over from R to Python as much as possible. One of the big barriers to this was Python's relatively nascient statistical abilities, but PyStan removes that barrier almost entirely, so thanks!

I have two questions:
1) Is it possible in Python to see a traceplot of just one parameter? If I have a fitted object, I can see a traceplot of all parameters using fit.traceplot(). However, this is incredibly cumbersome if you have lots of parameters (including things like predicted values). In R, I can use a command traceplot(posteriors, pars = 'beta') to see a traceplot of JUST beta, but this capability is missing so far as I know. Is this something that can be added to PyStan or am I just doing it wrong? I can do it myself using the following lines:

# traceplot plots for each parameter
beta = fit.extract(permuted=True)['beta']
# stan_args gives one list per chain
n_chains = len(fit.stan_args)


# assumes that the beta array is just one chain tacked onto the end of another
bSplit = np.array_split(beta, n_chains)

# plot
for i in range(n_chains):
    py.plot(bSplit[i])
py.show()

but I'd prefer a parameter argument like in R.

2) This issue is a little more quirky than anything. I can run PyStan fine most times. My code runs fine from the Terminal and as well as the interactive interpreter in Spyder (an IDE). But when I try to run it in an interactive interpreter in PyCharm (a better IDE), the model appears to compile in to C++ just fine but then spits about an error message for what appears to be at every iteration of the model (10,000 or so)

Process PoolWorker-5827:
Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/process.py", line 249, in _bootstrap
    sys.stdin.close()
AttributeError: StdIn instance has no attribute 'close'

I don't know what this means, and it appears to be fairly specific to PyCharm. But I just wanted to report it so that you all are aware that PyStan may not work in some interactive interpreters.

Thanks!

Nate

Allen Riddell

unread,
Jan 19, 2014, 7:03:43 PM1/19/14
to stan-...@googlegroups.com
Hi Nate,

1. plotting a single parameter:

You just need to pass the parameter(s) in a list.

fit.plot(['tau'])


2. PyCharm IDE

We fixed a problem like this for IPython notebook very early on:
https://github.com/stan-dev/pystan/issues/3

It's hard to say if the error is PyCharm specific. You might try disabling
multiprocessing (i.e., set n_jobs=1) and see if it works. My first guess is that
PyCharm is capturing stdout somehow and there's a conflict with PyStan's attempt
to control stdout. Perhaps the PyCharm folks have an idea?

Best wishes,

-a
> --
> You received this message because you are subscribed to the Google Groups "stan users mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Nathan Lemoine

unread,
Jan 20, 2014, 2:27:49 PM1/20/14
to stan-...@googlegroups.com
Hi Allen, 

Thanks for the help!

For what it’s worth, there’s an easy workaround to the PyCharm issue. PyCharm 3 includes a local terminal. I open python in that terminal and it runs fine, which allows me to debug and work interactively. This makes me thing it’s a problem specific to the way PyCharm runs its interactive interpreter. But since the workaround is so easy, it’s not really an issue.

Again, thanks for everything and all the work you all have put into STAN and PyStan.

Nate

You received this message because you are subscribed to a topic in the Google Groups "stan users mailing list" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/stan-users/sWzMACAPLjQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to stan-users+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages