MStan?

465 views
Skip to first unread message

Aki Vehtari

unread,
Jan 10, 2014, 3:54:30 AM1/10/14
to stan-...@googlegroups.com
Hi,

Do you have any useful estimate when MStan (Matlab/Octave interface) might be available? Or how should I proceed if I would like to help implement that?

Aki

Bob Carpenter

unread,
Jan 10, 2014, 5:20:01 AM1/10/14
to stan-...@googlegroups.com


On 1/10/14, 9:54 AM, Aki Vehtari wrote:
> Hi,
>
> Do you have any useful estimate when MStan (Matlab/Octave interface) might be available?

When we find a volunteer who knows MATLAB and wants to do it :-)

> Or how should I proceed if I would like to help implement that?

There are two ways to create an interface.

1. Process-level wrapper
Just write code in MATLAB to dump the data in a format we can read,
call Stan in a separate process(es) to write samples out, then write
code to read back in the results into MATLAB and ideally do some posterior
analysis.

2. In-memory wrapper
This is what we've done for PyStan and RStan. It's a lot more work,
but potentially much faster and definitely more flexible (e.g., it
makes it easy to expose the log prob functions and gradients/Hessians.
MATLAB has a package (whose name I forget) that makes that possible.

One of the things we're going to try to do over the next 12 months
is clean up the underlying C++ code to make approach (2) easier
and more consistent across our interfaces. Right now, everything
that's in stan/gm/command.hpp needs to be reimplemented in each
interface.

- Bob


Joachim Vandekerckhove

unread,
Jan 10, 2014, 12:47:51 PM1/10/14
to stan-...@googlegroups.com
I'm almost done with #1.

Brian Lau

unread,
Jan 11, 2014, 7:28:40 AM1/11/14
to
I've got a process-level wrapper here:

https://github.com/brian-lau/MatlabStan

I'll get some better docs up in the next week, although some effort went into following Pystan/Rstan conventions, so some of those docs could be useful.

Joachim, maybe it's worth merging?

-b

Aki Vehtari

unread,
Jan 12, 2014, 6:40:06 AM1/12/14
to stan-...@googlegroups.com
Joachim and Brian,

Great! I can help you with testing (Linux).

Aki


lauantai, 11. tammikuuta 2014 14.21.34 UTC+2 Brian Lau kirjoitti:
I've got a process-level wrapper here:

https://github.com/brian-lau/MatlabStan

I'll get some better docs up in the next week, although some effort went into following Pystan/Rstan conventions, so some of those docs could be useful.

Joachim, maybe it's worth merging?

-b

On Friday, January 10, 2014 11:20:01 AM UTC+1, Bob Carpenter wrote:

Brian Lau

unread,
Jan 13, 2014, 11:00:44 AM1/13/14
to stan-...@googlegroups.com
Testing would be great! Some basic docs are up:


And things are updated to work with Stan 2.1.0.

-b

Aki Vehtari

unread,
Feb 17, 2014, 9:18:43 AM2/17/14
to stan-...@googlegroups.com
Hi,
I finally had time to test MatlabStan. Sometimes print(fit) gives an error
---clip---
print: lib/eigen_3.2.0/Eigen/src/Core/DenseCoeffsBase.h:173: Eigen::DenseCoeffsBase<Derived,
0>::CoeffReturnType Eigen::DenseCoeffsBase<Derived, 0>::operator()(Eigen::DenseCoeffsBase<Derived,
0>::Index) const [with Derived = Eigen::Matrix<Eigen::Matrix<double, -0x00000000000000001, 1>,
-0x00000000000000001, 1>, Eigen::DenseCoeffsBase<Derived, 0>::CoeffReturnType = const
Eigen::Matrix<double, -0x00000000000000001, 1>&, Eigen::DenseCoeffsBase<Derived, 0>::Index = long
int]: Assertion `index >= 0 && index < size()' failed.
Warning: non-fatal error reading adapation data
Warning: non-fatal error reading samples
Warning: non-fatal error reading adapation data
Warning: non-fatal error reading samples
Warning: non-fatal error reading adapation data
Warning: non-fatal error reading samples
Warning: non-fatal error reading adapation data
Warning: non-fatal error reading samples
ans = 
    [1x92 char]
    [1x98 char]
    [1x94 char]
    [1x85 char]
    [1x97 char]
    'int]: Assertion `index >= 0 && index < size()' failed.'
---clip---
but retrying gives sensible result. I guess it's possible that Stan was still writing logs, but MatlabStan does not realize it and gives strange error...

Aki

Brian Lau

unread,
Feb 17, 2014, 1:00:57 PM2/17/14
to stan-...@googlegroups.com, stan-...@googlegroups.com
Yup, the print method calls down to Stan's print, and it looks like there's no check to see if Stan finished. I'll make sure this is the problem, and fix it this week. Thanks for testing. You're running on Linux, right?

-b
--
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.

Aki Vehtari

unread,
Feb 18, 2014, 9:54:33 AM2/18/14
to stan-...@googlegroups.com
Yes, I'm running Linux. I'm going to use MatlabStan on a course starting in two weeks. I'm really glad you have made MatlabStan. Thanks!

Btw. how do I make Matlab to wait that Stan is finished (all chains)? I think it is possible with MatlabProcessManager, but could not find an example.

Aki

Brian Lau

unread,
Feb 23, 2014, 12:35:29 PM2/23/14
to stan-users
On Tue, Feb 18, 2014 at 3:54 PM, Aki Vehtari <aki.v...@aalto.fi> wrote:
Yes, I'm running Linux. I'm going to use MatlabStan on a course starting in two weeks. I'm really glad you have made MatlabStan. Thanks!

Great! Keep me posted if you or your students have any problems. I'll be incorporating some of your code for MCMC diagnostics in the next few weeks.
 
Btw. how do I make Matlab to wait that Stan is finished (all chains)? I think it is possible with MatlabProcessManager, but could not find an example.

There's a StanFit method for blocking the command line. Another alternative is to use a listener. I've added examples here:


I prefer the latter as it lets me keep working in Matlab.

Regarding the print(fit) message, the latest MatlabStan version on github now issues a warning when print() is called before any samples are written.

-b

Aki Vehtari

unread,
Feb 24, 2014, 8:57:03 AM2/24/14
to stan-...@googlegroups.com
> I'll be incorporating some of your code for MCMC diagnostics in the next few weeks.

Cool. Note that in BDA3 there is improved method for computing potential scale reduction. I had updated psrf.m in GPstuff earlier, and now remembered to update that also in MCMCdiag toolbox. Check that you have the latest version.


> There's a StanFit method for blocking the command line. Another alternative is to use a listener. I've added examples here:

Thanks!

Aki

Brian Lau

unread,
Sep 28, 2014, 7:40:15 AM9/28/14
to stan-...@googlegroups.com
I updated the process-level Matlab wrapper for Stan
  * exposes some new parameters from Stan 2.4.0 (optimization)
  * changes so that it runs on Windows
  * function for calculating WAIC (based on R code from Vehtari & Gelman)

More details here:



On Saturday, January 11, 2014 1:21:34 PM UTC+1, Brian Lau wrote:
I've got a process-level wrapper here:

https://github.com/brian-lau/MatlabStan

I'll get some better docs up in the next week, although some effort went into following Pystan/Rstan conventions, so some of those docs could be useful.

Joachim, maybe it's worth merging?

-b

On Friday, January 10, 2014 11:20:01 AM UTC+1, Bob Carpenter wrote:

Bob Carpenter

unread,
Sep 30, 2014, 10:32:01 PM9/30/14
to stan-...@googlegroups.com
Awesome --- this looks great. Thanks for letting
everyone know.

Would you mind if we linked that from our top-level
web site, mc-stan.org? I'd create a page mirroring this
one and include a navbar:

http://mc-stan.org/pystan.html

Presumably I should call it "MatlabStan" instead of
"MStan"?

Thanks for including clear licensing terms (BSD, to boot).
And some full working examples.

I also take it this is Matlab-only and won't work in Octave?
I'm not a user of either one, I just want to know how to describe
it on the web page.

You're also welcome to move the repo to stan-dev if you'd
prefer. Otherwise, I can just create links to your repo.

- Bob
> --
> 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/d/optout.

Brian Lau

unread,
Oct 1, 2014, 2:01:26 AM10/1/14
to stan-users
On Wed, Oct 1, 2014 at 4:31 AM, Bob Carpenter <ca...@alias-i.com> wrote:
Awesome --- this looks great.  Thanks for letting
everyone know.

Would you mind if we linked that from our top-level
web site, mc-stan.org?  I'd create a page mirroring this
one and include a navbar:

  http://mc-stan.org/pystan.html

Presumably I should call it "MatlabStan" instead of
"MStan"?

Sure sounds good. Feel free to call it MStan, I chose MatlabStan in case a more official package was in the works. If we move the repo to stan-dev, might as well call it whatever you guys were going to call the Matlab wrapper. 
 
I also take it this is Matlab-only and won't work in Octave?
I'm not a user of either one, I just want to know how to describe
it on the web page.

I have no idea if it would work in Octave. 
 
You're also welcome to move the repo to stan-dev if you'd
prefer.  Otherwise, I can just create links to your repo.

Sounds good. I have no experience doing this, so can you fill me in (by email if you wish).

-b

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/Lj-LmCw8KPU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to stan-users+...@googlegroups.com.

Aki Vehtari

unread,
Oct 1, 2014, 5:30:33 AM10/1/14
to stan-...@googlegroups.com
I have tested that it with Octave and it doesn't work without modifications. Unfortunately InputParser in Octave has slightly incompatible syntax compared to Matlab's InputParser. Fixing that is not difficult. If I remember correctly, I did test quick fix for InputParser syntax, but then there was other problems with object class definition syntax in MatlabProcessManager (required by MatlabStan) and I did not have time to investigate further. So it is unclear how much work it would require to get it work in Octave.

Aki

Brian Lau

unread,
Oct 1, 2014, 6:14:23 AM10/1/14
to stan-...@googlegroups.com
On Wednesday, October 1, 2014 11:30:33 AM UTC+2, Aki Vehtari wrote:
I have tested that it with Octave and it doesn't work without modifications. Unfortunately InputParser in Octave has slightly incompatible syntax compared to Matlab's InputParser. Fixing that is not difficult. If I remember correctly, I did test quick fix for InputParser syntax, but then there was other problems with object class definition syntax in MatlabProcessManager (required by MatlabStan) and I did not have time to investigate further. So it is unclear how much work it would require to get it work in Octave.

Good to know. I see that there are some differences in how Matlab and Octave call Java, so I will set up a branch to try and track this down. Thanks for investigating!

-b
Reply all
Reply to author
Forward
0 new messages