Maintaining MatlabStan?

every few months we get a question re MatlabStan - afaik, it’s not being actively maintained.

MatlabStan is a very light wrapper around CmdStan. I don’t know matlab, but as wrappers go, this one is beautiful in its simplicity. my guess is that the problem is here:

so if we have any matlab fans - this bit of code needs to be updated. information about using the CmdStan makefile to compile a model is here: https://mc-stan.org/docs/2_24/cmdstan-guide/compiling-a-stan-program.html#invoking-the-make-utility

@brian-lau - could you comment? are you interested in keeping this project going or helping someone who could?

3 Likes

I’m curious about what made you select this particular issue :) There are 24 open on github issues that need addressing. It is excellent software, but there hasn’t been a release since May 2017. It hasn’t kept up with changes in cmdstan.

The problem with the code you posted is similar to one of the open issues: https://github.com/brian-lau/MatlabStan/issues/57. It mentions how to fix it. This issue also mentions an issue with pulling the version of cmdstan after 2.22.0, which breaks MatlabStan across systems.

It seems that it would be a straightforward fix using ispc to determine whether the user is running Windows. It seems this is a problem elsewhere in the MatlabStan code based on the issue referenced above. I don’t know if this fixes the problem you’re referencing though, because I run MatlabStan on a mac.

I can help address some of the open issues on github to keep it running. (as long as I can do so on mac for the time being) I don’t know if many others out there use MatlabStan though. I only use it for particular things, but I do most other Stan modeling in R .

How can I help? I’m MATLAB savvy but not stan savvy :) I would like to ensure that MatlabStan continues to be maintained, so I’m happy to help.

(also, https://mc-stan.org/docs/2_24/cmdstan-guide/compiling-a-stan-program.html#invoking-the-make-utility says that Mac and Linux use the backslash, but the example given uses forward slashes)

> make examples/bernoulli/bernoulli
5 Likes

in the past few weeks there were two user queries regarding MatlabStan - as I’m very involved in both CmdStan and wrapper interfaces CmdStanPy and CmdStanR, things that touch CmdStan are on my radar. so just a response to recent posts on discourse, that’s all.

that would be awesome. I’m stan savvy but not Matlab savvy, so happy to work together.

and many thanks for catching errors in the CmdStan docs.

3 Likes

Hello,

I was wondering if there was any news concerning the maintenance of Matlab Stan? :)

1 Like

Hi,

as far as I know, no one has been maintaining MatlabStan since, at least that the Stan Development Team is aware of.

1 Like

So since MatlabStan is just a wrapper around cmdstan which is still supported. Is it ok to still use it or I should move my analysis pipeline to python or R?

Edouard

if MatlabStan works with a modern version of CmdStan, fine, but I’m not sure it does.

Thanks. I’ll give it a try next week. :)

Currently, all the wrappers of stan (python, R, Mathematica…) are grouped in the StanDev repository. MatlabStan seems to be the only one not included. Do you think that including a fork of @brian-lau repository in the StanDev GitHub might increase its visibility and increase the number of contribution to it?

Edouard

I think it’s the other way around - if MatlabStan has one or two active developers or maintainers, then it would make sense to make it part of the StanDev repo. the last repo that got added was GitHub - stan-dev/posteriordb: Database with posteriors of interest for Bayesian inference, and there was a long discussion and then some kind of vote before adding it.

another way to go might be to look at the CmdStanX wrappers - currently CmdStanPy and CmdStanR. they’re designed to be as similar as possible, modulo the difference between Python classes and R6 classes, plus available libraries. I know nothing about Matlab - would it be possible to conform to the CmdStanX workflow? cf: https://mc-stan.org/cmdstanpy/workflow.html

4 Likes

Hello, small update on MatlabStan. I downloaded MatlabStan with CmdStan v2.28.2 (stan v3.1)

Following code seems to be working:

% Import dependencies 
addpath( genpath('/Users/edelaire1/Documents/software/MatlabStan/'))
addpath( genpath('/Users/edelaire1/Documents/software/MatlabProcessManager/'))

%% Define data and model 
data = struct('N',10,...
              'y',[0,1,0,0,0,0,0,0,0,1]);

model_path = '/Users/edelaire1/Documents/software/MatlabStan/Examples/bernoulli/';
model = StanModel('file',fullfile(model_path,'bernoulli.stan'), 'method','sample','algorithm','NUTS','verbose',true, ...
    'working_dir',model_path);
model.compile();
model_fit = model.sampling('data', data);


%% 
model_fit.print()
figure;
model_fit.traceplot()

model_fit.print

Inference for Stan model: bernoulli_model
4 chains: each with iter=(1000,1000,1000,1000); warmup=(0,0,0,0); thin=(1,1,1,1); 4000 iterations saved.
Warmup took (0.024, 0.031, 0.041, 0.033) seconds, 0.13 seconds total
Sampling took (0.10, 0.12, 0.11, 0.084) seconds, 0.42 seconds total
                Mean     MCSE  StdDev     5%   50%   95%    N_Eff  N_Eff/s    R_hat
lp__            -7.3  1.8e-02    0.69   -8.7  -7.0  -6.8     1451     3487      1.0
accept_stat__   0.93  3.2e-03    0.11   0.68  0.97   1.0  1.3e+03  3.0e+03  1.0e+00
stepsize__      0.90  5.5e-02   0.078   0.83  0.88   1.0  2.0e+00  4.8e+00  1.9e+13
treedepth__      1.4  2.0e-02    0.55    1.0   1.0   2.0  7.8e+02  1.9e+03  1.0e+00
n_leapfrog__     2.7  2.4e-01     1.5    1.0   3.0   7.0  4.1e+01  9.9e+01  1.0e+00
divergent__     0.00      nan    0.00   0.00  0.00  0.00      nan      nan      nan
energy__         7.8  2.5e-02    0.97    6.8   7.5   9.6  1.5e+03  3.6e+03  1.0e+00
theta           0.26  3.2e-03    0.12  0.083  0.24  0.48     1414     3398      1.0
Samples were drawn using hmc with nuts.
For each parameter, N_Eff is a crude measure of effective sample size,
and R_hat is the potential scale reduction factor on split chains (at 
convergence, R_hat=1).

In the future changes, I will

Edit: fork can be found here: GitHub - Edouard2laire/MatlabStan: Matlab interface to Stan, a package for Bayesian inference

7 Likes