Giter VIP home page Giter VIP logo

matlabstan's People

Contributors

brian-lau avatar jpiironen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

matlabstan's Issues

Robustness to spaces in paths ?

Hello,

I'm just trying to have matlabstan working on a Mac, but I have spaces in the folder names of my matlab working directory paths, which seems cause major problems here... Is there a way to make MatlabStan robust to that ?

programmatically obtain stats

Hi Brian
Another feature request, sorry...

Currently, it seems that doing output = stanFit.print(); outputs all the raw text as a cell array.

I wondered if it was possible to obtain selected stats for particular variables using some command of the form: selectedStats = fit.getStats({'mu','tau'}, {'mean','R_hat','50%'}); Which could return mean, 50% and R_hat for the variables listed.

Alternatively, the entire table of stats could be returned in a matlab table format.

This would be really great. I have a toolbox released alongside a paper last year, and I am trying to convert it from using JAGS to STAN. I think this is one of my last stumbling blocks to getting it all working. I tried to look into the code to see if it was easy to do myself, but it doesn't immediately obvious to me.

Ben

error extracting samples

line 57: temp{j} = length(self.(s)(i).(fn{i}));

throws "Index exceeds matrix dimensions." in some cases.
i is an index into self.samples but is used here to index fn, if i > length(fn) this is an error. In any case j seems like it should be the index into self.samples(i).(fn{j});

Help in setting home directory mac os x

I obtain the following error:
%%%%%%%%%%
fit = stan('model_code',schools_code,'data',schools_dat);
Error using StanModel/set.stan_home (line 305)
Can't parse stan_home. Is it set correctly?

Error in StanModel (line 185)
self.stan_home = p.Results.stan_home;

Error in stan (line 108)
model = StanModel();
%%%%%%%%%%%%%%%

This is probably because of my ignorance. I don't know how to set the directory for cmdstan
My file structure is as follows:
ignorantuser_macpro/CmdStanParent/cmdstan

In stan_home.m I have

d = 'CmdStanParent/';

What should I type in instead?

Return Hessian when using optimisation

RStan also returns the Hessian matrix when you add the optional parameter "hessian = TRUE" for optimisation. Can this be done in MatlabStan currently?

Thanks

Matlab 2014b error

Hi Brian,

I tried installing and running matlab stan in Matlab 2014b. I tested the installation on the schools_code example provided in the README file and Matlab threw the following error:

Error using processManager/start (line 362)
Java exception occurred:
java.io.IOException: Cannot run program "make" (in directory
"C:\Users\Garren\Dropbox\cmdstan-2.5.0\cmdstan"): CreateProcess error=2, The system cannot find the file
specified

at java.lang.ProcessBuilder.start(Unknown Source)

at java.lang.Runtime.exec(Unknown Source)

at java.lang.Runtime.exec(Unknown Source)

Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified

at java.lang.ProcessImpl.create(Native Method)

at java.lang.ProcessImpl.<init>(Unknown Source)

at java.lang.ProcessImpl.start(Unknown Source)

... 3 more

Error in processManager/set.command (line 212)
self.start();

Error in processManager (line 179)
self.command = p.Results.command;

Error in StanModel/compile (line 842)
p = processManager('id','compile',...

Error in StanModel/sampling (line 715)
self.compile();

Error in stan (line 137)
fit = model.sampling(p.Unmatched);

I ran the same example in Matlab 2014a and it worked fine. I'm also able to run the make program directly from the command line in the specified directory.

I'm happy to use 2014a, but I thought I'd let you know about the issue and would appreciate advice for getting it working on 2014b if you have any. As a disclaimer, I'm fairly inexperienced at using the command line and installing packages from source, so there's probably something I'm missing.

Thanks,

Garren

Using the .exe from cmdstan in MatlabStan

Is it possible to use the .exe file resulting from compilation in MatlabStan? The help page on avoiding recompilation of Stan models refers to reusing a StanFit object. But suppose you forgot to save the fit, it seems like one ought be able to use the .exe.

Thanks,

  • Ariel

Rdump code

Sorry if this is obvious, but I'm not very familiar yet with github. When I look at the 'rdump' file in the github repository the code is different than when I download it zipped (from here: https://github.com/brian-lau/MatlabStan/releases/tag/v2.15.1.0 ). In the file on github, it uses 'deal':
elseif isnumeric(data{i})
39 fprintf(fid,'%s <- structure(c(%s), .Dim=c(',vars{i},num_list);
40 [sz(:)] = deal(size(data{i}));
(and Matlab 2016 has problems with 'deal')
while the 'elseif isnumeric' does not feature in the .zip file.

Running MatlabStan

I tried to run the rats example but I get the following error message:

Undefined variable "mstan" or class "mstan.stan_home".

Error in StanModel (line 170)
p.addParamValue('stan_home',mstan.stan_home);

Error in stan (line 108)
model = StanModel();

Error in rats (line 20)
fit = stan('file','rats.stan','data',rats_dat,'verbose',true);

Anyone know how to get it to run? I know cmdStan is working as I was able to run the Bernoulli example.
Thanks

Octave compatibility

Some notes from Aki:

If you happen to test MatlabStan with Octave: Our GPstuff package works in Matlab and Octave. Here's example how InputParser syntax differs (and Octave syntax does not work in Matlab). This difference comes from the limited object system implementation. At that time there seemed to be no-one working on necessary changes to object system implementation to get it work as in Matlab.

Matlab
ip=inputParser;
ip.FunctionName = 'GP_SET';
ip.addOptional('gp', [], @isstruct);
ip.addParamValue('cf',[], @(x) isempty(x) || isstruct(x) || iscell(x));
...
ip.parse(varargin{:});
gp=ip.Results.gp;

Octave
ip=inputParser;
ip.FunctionName = 'GP_SET';
ip=iparser(ip,'addOptional','gp', [], @isstruct);
ip=iparser(ip,'addParamValue','cf',[], @(x) isempty(x) || isstruct(x) || iscell(x));
...
ip=iparser(ip,'parse',varargin{:});
gp=ip.Results.gp;

To get all things to work we also made some changes to InputParser code, but due to difficulties in the process to get changes into Octave, it's possible that some of the changes are not in the official distribution. So if you get some errors I might know where the problem is

"Name Stan Model" pop up for simply runs

Hi,

I'm just starting working with matlabstan and I tried running the basic school model from the getting started page. The problem is whenever I run:
fit = stan('model_code',schools_code,'data',schools_dat);
I get a save as window that pops up with the title "Name stan model." If I save it I get the following error:

Error using StanModel/compile (line 852)
uname: not found
uname: not found
cygwin warning:
MS-DOS style path detected: C:/Users/bermads1/Documents/Daniel
Preferred POSIX equivalent is: /cygdrive/c/Users/bermads1/Documents/Daniel
CYGWIN environment variable option "nodosfilewarning" turns off this warning.
Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
make: *** No rule to make target `C:/Users/bermads1/Documents/Daniel/quantum'. Stop.
Error in StanModel/sampling (line 715)
self.compile();

Error in stan (line 137)
fit = model.sampling(p.Unmatched);

If I don't save it and press cancel, I get this error:

Error using fileparts (line 34)
Input must be a row vector of characters.

Error in StanModel/update_model (line 1026)
[~,name] = fileparts(filename);

Error in StanModel/update_model (line 1003)
self.update_model('write',arg);

Error in StanModel/set.model_code (line 416)
self.update_model('model_code',model);

Error in StanModel/set (line 269)
self.model_code = p.Results.model_code;

Error in StanModel/sampling (line 709)
self.set(varargin{:});

Error in stan (line 137)
fit = model.sampling(p.Unmatched);

I'm really not sure what's going on and how to fix it.

All Stan processes finished, but it is still working

fit.check
returns
"All Stan processes finished."

fit.stop
returns
Stan is already finished.

but
fit.peek
gives
"Stan is still working. You can either:

  1. Use the peek method to get partial samples
  2. Come back later, or
  3. Attach a listener to the StanFit object."

how is that possible ?

Progress indication

It would be nice to have some indication of progress. I currently keep fit.process(1, 1).stdout open in the variable explorer, but an ETA on the StanFit object could be nice, so e.g. I can refill my coffee if it's going to be a while.

I can try this and send a PR if you like (since I'm anyhow waiting for the sampling...)

clarification on .extract() method

Hi. Thanks for this great piece of software.
Can I request a specific and expanded wiki section on the extract() method? At the moment there is just a small bit of info on the Getting Started page and I was left with a few questions.

For example, I can tell that the fit.extract('permuted',true); command flattens samples over chains, but I am not 100% sure if it also randomises the ordering of the samples.

Problem with Getting started example

I downloaded from the Stan website all the packages mentioned in Matlabstan - Getting Started according to the instructions. However, my Matlab2015b gives me this error message gives me this error message when I try to run the given script by copy-pasteing it or when downloading the eight_schools.stan -file and running the code line below it:

Error using StanModel/set.stan_home (line 311)
Does not look like a proper stan setup

Error in StanModel (line 184)
self.stan_home = p.Results.stan_home;

Error in stan (line 108)
model = StanModel();

I checked with path-command that all the necessary folders (below MatlabStan-2.7.0.0 and MatlabProcessManager folder's two .m-files) are in the path. In the Matlab workspace I have those same folders and files. I have put the path to MatlabStan-2.7.0.0 in stan_home.m with this exact line:

d = '/Users/sebastiansilfverberg/Documents/MATLAB/BDA/MatlabStan-2.7.0.0/cmdstan-2.9.0';

+mstan -folder is directly below MatlabStan-2.7.0.0.

Can you tell me what seems to be the problem? I'm using Max with OSX 10.11.2

Test Case Failure

I ran the test cases in the provided directory and upon completion, I get the following:


FAILED in 1412.983 seconds.

===== Test Case Failure =====
Location: C:\Users\BLAH\Documents\Bayesian_Analysis\STAN\MatlabStan\Tests\TestBernoulli.m
Name: test_bernoulli_constructor

C:\Users\BLAH\Documents\Bayesian_Analysis\STAN\MatlabStan\Tests\TestBernoulli.m at line 53

CPP file not generated

===== Test Case Failure =====
Location: C:\Users\BLAH\Documents\Bayesian_Analysis\STAN\MatlabStan\Tests\TestStanModel.m
Name: testSet

C:\Users\BLAH\Documents\Bayesian_Analysis\STAN\MatlabStan\StanModel.m at line 329
C:\Users\BLAH\Documents\Bayesian_Analysis\STAN\MatlabStan\StanModel.m at line 273
C:\Users\BLAH\Documents\Bayesian_Analysis\STAN\MatlabStan\Tests\TestStanModel.m at line 96

File does not exist

===== Test Case Failure =====
Location: C:\Users\BLAH\Documents\Bayesian_Analysis\STAN\MatlabStan\Tests\TestStanModel.m
Name: testContructorArgs

C:\Users\BLAH\Documents\Bayesian_Analysis\STAN\MatlabStan\StanModel.m at line 329
C:\Users\BLAH\Documents\Bayesian_Analysis\STAN\MatlabStan\StanModel.m at line 219
C:\Users\BLAH\Documents\Bayesian_Analysis\STAN\MatlabStan\Tests\TestStanModel.m at line 47

File does not exist


I'm not sure what to make of this? I've just recently downloaded everything following the wiki: https://github.com/brian-lau/MatlabStan/wiki/Getting-Started I should have the latest versions of everything. I'm also using Matlab 2013a on a Windows7 32bit with MinGW/msys compiler. I'm brand new to stan and need it for a class. I just want to be sure I actually have a fully functioning program to begin with. Thanks.

When the address to the working directory has spaces

Hi all,

I am new to stan and I am using it in a Mac with MATLAB R2014b. I have gotten Matlab to work from the folder 'User/Marina/Documents/Stan_matlab' but I cannot get Stan to work from a working directory that has spaces it its address:

Error using StanModel/compile (line 852)
make: *** No rule to make target `/Users/Marina/Google'. Stop.

The issue is that I keep all of my schoolwork in Google Drive, which is provided by my school (and which has an address with a space in it). There are a number of spaces in some of my directories (suboptimal, I know, but I also share these with some people) and I wanted to see if there was a way to change the matlab interface to stan so that stan may run from any directory in my computer.

If this is not possible, I can run stan from some other directory, but I would prefer to have all items regarding a project in one place (which sometimes means having them in folders that have spaces in their name.

Thanks,
Marina

Matlab (2018a) crashes when trying to save fit

Stan program runs without any issues. I can see the results, do plots with them etc. Matlab crashes if I try to save the structural matrix created by Stan. I'm wondering if anyone else has a similar problem or solution. Thanks

Issue: print, consistency in the number of saved iterations, inc_warmup

Thanks Brian for the amazing work!

  • I suggest to update in StanFit:
         if ischar(file)
            command = [self.model.stan_home filesep 'bin/print --sig_figs='...
               num2str(p.Results.sig_figs) ' ' file];
         elseif iscell(file)
            command = [self.model.stan_home filesep 'bin/print --sig_figs='...
               num2str(p.Results.sig_figs) ' ' sprintf('%s ',file{:})];

to

         if ischar(file)
            command = [self.model.stan_home filesep 'bin/stansummary --sig_figs='...
               num2str(p.Results.sig_figs) ' ' file];
         elseif iscell(file)
            command = [self.model.stan_home filesep 'bin/stansummary --sig_figs='...
               num2str(p.Results.sig_figs) ' ' sprintf('%s ',file{:})];
  • Also, it would be good to make consistent the number of iterations saved. For example if you have iter = 3000 and you do not specify the warmup, and takes its default to floor(iter/2) = 1500, the total nr of iterations = 3000, and the saved samples are 1500.
    Instead, if you specify the warmup, and have iter = 3000, warmup = 1000, you have a total number of iterations = 4000 and saved samples 3000.
    I hope that this should be solved by changing in the code stan.m the following:
  if isempty(p.Results.warmup)
      total_iters = max(round(p.Results.iter),2);
      model.warmup = max(floor(total_iters/2),1);
      model.iter = total_iters - model.warmup;
   else
      model.warmup = p.Results.warmup;
      model.iter = p.Results.iter;
   end

to:

  if isempty(p.Results.warmup)
      total_iters = max(round(p.Results.iter),2);
      model.warmup = max(floor(total_iters/2),1);
      model.iter = total_iters - model.warmup;
   else
      model.warmup = p.Results.warmup;
      model.iter = p.Results.iter - model.warmup;
   end
  • Last, but not least, in my pc the parameter-value pairs 'inc_warmup', true or 'inc_warmup', false do not make any difference. I cannot get the full trajectory of the sampler...

Best,
Umberto

Why a model converges using the meanfield algorithm but does not using the fullrank?

Hi,

I am using MatlabStan to infer parameters of the following model:

data {
int<lower=1> N; //number of time intervals
int<lower=1> J; //number of sections
real<lower=0> y[N,J]; //data points for corrosion model
real<lower=0> t[N]; //time intervals for data points
}
transformed data {
real<lower=0> sigma;

sigma = 7.8; //uncertainty in corrosion model

}
parameters {
real<lower=0> beta[J]; //scale parameters corrosion growths
real<lower=0> theta_1[J]; //multiplication parameter corrosion growths
real<lower=0> theta_2; //exponent parameter corrosion growths
real<lower=0> delta_x[N,J]; //estimated corrosion growths
}
transformed parameters {
real<lower=0> mu[J]; //to transform parameter from Stan distribution
real<lower=0> alpha[N,J]; //shape parameter corrosion growths
real<lower=0> x[N,J]; //corrosion depths

for (j in 1:J){
mu[j] <- 1/beta[j]; //transformation for Stan Gamma Distribution
alpha[1,j] <- theta_1[j] * pow(t[1],theta_2); //shape parameter corrosion growths
x[1,j] <- delta_x[1,j]; //corrosion depths

for (n in 2:N){ 
                alpha[n,j] <- theta_1[j] * (pow(t[n],theta_2)-pow(t[n-1],theta_2));
                x[n,j] <- delta_x[n,j] + x[n-1,j]; 
               }
            }

}
model {
theta_2 ~ gamma(0.001,0.001); //prior
for (j in 1:J){
theta_1[j] ~ gamma(0.001, 0.001); //prior
beta[j] ~ gamma(0.001, 0.001); //prior

    delta_x[1,j] ~ gamma(alpha[1,j], mu[j]); //corrosion growths
    y[1,j] ~ normal (x[1,j], sigma);    //likelihood

    for (n in 2:N){ 
                    delta_x[n,j] ~ gamma(alpha[n,j], mu[j]);
                    y[n,j] ~ normal(x[n,j], sigma);
                  }
            }

}

The inferences converges when I use the meanfield algorithm:
Stan is performing variational inference ...
nhg_j_mfvi_c.csv: method = variational
nhg_j_mfvi_c.csv: variational
nhg_j_mfvi_c.csv: algorithm = meanfield (Default)
nhg_j_mfvi_c.csv: meanfield
nhg_j_mfvi_c.csv: iter = 10000 (Default)
nhg_j_mfvi_c.csv: grad_samples = 1 (Default)
nhg_j_mfvi_c.csv: elbo_samples = 100 (Default)
nhg_j_mfvi_c.csv: eta = 1 (Default)
nhg_j_mfvi_c.csv: adapt
nhg_j_mfvi_c.csv: engaged = 1 (Default)
nhg_j_mfvi_c.csv: iter = 50 (Default)
nhg_j_mfvi_c.csv: tol_rel_obj = 0.01 (Default)
nhg_j_mfvi_c.csv: eval_elbo = 100 (Default)
nhg_j_mfvi_c.csv: output_samples = 1000 (Default)
nhg_j_mfvi_c.csv: id = 1
nhg_j_mfvi_c.csv: data
nhg_j_mfvi_c.csv: file = C:\MatlabStan-2.15.1.0\temp.data.R
nhg_j_mfvi_c.csv: init = 1
nhg_j_mfvi_c.csv: random
nhg_j_mfvi_c.csv: seed = 213197
nhg_j_mfvi_c.csv: output
nhg_j_mfvi_c.csv: file = nhg_j_mfvi_c.csv
nhg_j_mfvi_c.csv: diagnostic_file = (Default)
nhg_j_mfvi_c.csv: refresh = 100 (Default)
nhg_j_mfvi_c.csv: ------------------------------------------------------------
nhg_j_mfvi_c.csv: EXPERIMENTAL ALGORITHM:
nhg_j_mfvi_c.csv: This procedure has not been thoroughly tested and may be unstable
nhg_j_mfvi_c.csv: or buggy. The interface is subject to change.
nhg_j_mfvi_c.csv: ------------------------------------------------------------
nhg_j_mfvi_c.csv: Gradient evaluation took 0.009 seconds
nhg_j_mfvi_c.csv: 1000 transitions using 10 leapfrog steps per transition would take 90 seconds.
nhg_j_mfvi_c.csv: Adjust your expectations accordingly!
nhg_j_mfvi_c.csv: Begin eta adaptation.
nhg_j_mfvi_c.csv: Iteration: 1 / 250 [ 0%] (Adaptation)
nhg_j_mfvi_c.csv: Iteration: 50 / 250 [ 20%] (Adaptation)
nhg_j_mfvi_c.csv: Iteration: 100 / 250 [ 40%] (Adaptation)
nhg_j_mfvi_c.csv: Iteration: 150 / 250 [ 60%] (Adaptation)
nhg_j_mfvi_c.csv: Iteration: 200 / 250 [ 80%] (Adaptation)
nhg_j_mfvi_c.csv: Iteration: 250 / 250 [100%] (Adaptation)
nhg_j_mfvi_c.csv: Success! Found best value [eta = 0.1].
nhg_j_mfvi_c.csv: Begin stochastic gradient ascent.
nhg_j_mfvi_c.csv: iter ELBO delta_ELBO_mean delta_ELBO_med notes
nhg_j_mfvi_c.csv: 100 -1e+004 1.000 1.000
nhg_j_mfvi_c.csv: 200 -1e+004 0.598 1.000
nhg_j_mfvi_c.csv: 300 -4e+003 1.059 1.000
nhg_j_mfvi_c.csv: 400 -5e+003 0.830 1.000
nhg_j_mfvi_c.csv: 500 -7e+003 0.727 0.316
nhg_j_mfvi_c.csv: 600 -4e+003 0.746 0.841
nhg_j_mfvi_c.csv: 700 -4e+003 0.648 0.316
nhg_j_mfvi_c.csv: 800 -4e+003 0.569 0.316
nhg_j_mfvi_c.csv: 900 -3e+003 0.512 0.195
nhg_j_mfvi_c.csv: 1000 -3e+003 0.461 0.195
nhg_j_mfvi_c.csv: 1100 -3e+003 0.364 0.143
nhg_j_mfvi_c.csv: 1200 -3e+003 0.344 0.057
nhg_j_mfvi_c.csv: 1300 -3e+003 0.149 0.057
nhg_j_mfvi_c.csv: 1400 -3e+003 0.135 0.030
nhg_j_mfvi_c.csv: 1500 -3e+003 0.105 0.028
nhg_j_mfvi_c.csv: 1600 -3e+003 0.022 0.016
nhg_j_mfvi_c.csv: 1700 -3e+003 0.019 0.016
nhg_j_mfvi_c.csv: 1800 -3e+003 0.018 0.016
nhg_j_mfvi_c.csv: 1900 -3e+003 0.012 0.007 MEDIAN ELBO CONVERGED
nhg_j_mfvi_c.csv: Drawing a sample of size 1000 from the approximate posterior...
nhg_j_mfvi_c.csv: COMPLETED.
stan started processing nhg_j_mfvi_c.csv
stan finished processing nhg_j_mfvi_c.csv

But it does not converge using the fullrank:

Stan is performing variational inference ...
nhg_j_frvi_c.csv: method = variational
nhg_j_frvi_c.csv: variational
nhg_j_frvi_c.csv: algorithm = fullrank
nhg_j_frvi_c.csv: fullrank
nhg_j_frvi_c.csv: iter = 10000 (Default)
nhg_j_frvi_c.csv: grad_samples = 1 (Default)
nhg_j_frvi_c.csv: elbo_samples = 100 (Default)
nhg_j_frvi_c.csv: eta = 1 (Default)
nhg_j_frvi_c.csv: adapt
nhg_j_frvi_c.csv: engaged = 1 (Default)
nhg_j_frvi_c.csv: iter = 50 (Default)
nhg_j_frvi_c.csv: tol_rel_obj = 0.01 (Default)
nhg_j_frvi_c.csv: eval_elbo = 100 (Default)
nhg_j_frvi_c.csv: output_samples = 1000 (Default)
nhg_j_frvi_c.csv: id = 1
nhg_j_frvi_c.csv: data
nhg_j_frvi_c.csv: file = C:\MatlabStan-2.15.1.0\temp.data.R
nhg_j_frvi_c.csv: init = 0
nhg_j_frvi_c.csv: random
nhg_j_frvi_c.csv: seed = 208765
nhg_j_frvi_c.csv: output
nhg_j_frvi_c.csv: file = nhg_j_frvi_c.csv
nhg_j_frvi_c.csv: diagnostic_file = (Default)
nhg_j_frvi_c.csv: refresh = 100 (Default)
nhg_j_frvi_c.csv: ------------------------------------------------------------
nhg_j_frvi_c.csv: EXPERIMENTAL ALGORITHM:
nhg_j_frvi_c.csv: This procedure has not been thoroughly tested and may be unstable
nhg_j_frvi_c.csv: or buggy. The interface is subject to change.
nhg_j_frvi_c.csv: ------------------------------------------------------------
nhg_j_frvi_c.csv: Gradient evaluation took 0.01 seconds
nhg_j_frvi_c.csv: 1000 transitions using 10 leapfrog steps per transition would take 100 seconds.
nhg_j_frvi_c.csv: Adjust your expectations accordingly!
nhg_j_frvi_c.csv: Begin eta adaptation.
nhg_j_frvi_c.csv: Iteration: 1 / 250 [ 0%] (Adaptation)
nhg_j_frvi_c.csv: Iteration: 50 / 250 [ 20%] (Adaptation)
nhg_j_frvi_c.csv: Iteration: 100 / 250 [ 40%] (Adaptation)
nhg_j_frvi_c.csv: Iteration: 150 / 250 [ 60%] (Adaptation)
nhg_j_frvi_c.csv: Iteration: 200 / 250 [ 80%] (Adaptation)
nhg_j_frvi_c.csv: Iteration: 250 / 250 [100%] (Adaptation)
nhg_j_frvi_c.csv: Success! Found best value [eta = 0.1].
nhg_j_frvi_c.csv: Begin stochastic gradient ascent.
nhg_j_frvi_c.csv: iter ELBO delta_ELBO_mean delta_ELBO_med notes
nhg_j_frvi_c.csv: 100 -2e+016 1.000 1.000
nhg_j_frvi_c.csv: 200 -7e+005 15347098109.650 30694196218.300
nhg_j_frvi_c.csv: 300 -1e+010 10231398740.100 1.000
nhg_j_frvi_c.csv: 400 -3e+009 7673549055.734 2.635
nhg_j_frvi_c.csv: 500 -1e+019 6138839244.787 1.000
nhg_j_frvi_c.csv: 600 -8e+009 5327331060.280 2.635
nhg_j_frvi_c.csv: 700 -4e+008 4566283768.690 2.635
nhg_j_frvi_c.csv: 800 -3e+008 3995498297.651 2.635
nhg_j_frvi_c.csv: 900 -2e+008 3551554042.413 1.000
nhg_j_frvi_c.csv: 1000 -2e+008 3196398638.182 1.000
nhg_j_frvi_c.csv: 1100 -2e+006 3196398646.930 2.635 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 1200 -8e+007 126979025.198 1.000 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 1300 -2e+017 126979025.198 1.000 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 1400 -2e+006 6824645585.104 1.000 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 1500 -3e+005 6824645585.574 5.702 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 1600 -3e+012 6697666571.900 1.000 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 1700 -4e+008 6697667389.690 1.000 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 1800 -1e+008 6697667389.868 2.153 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 1900 -1e+030 6697667389.916 2.153 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 2000 -7e+008 138428288275062816768.000 5.702 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 2100 -6e+005 138428288275062816768.000 5.702 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 2200 -1e+006 138428288275062816768.000 5.702 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 2300 -4e+008 138428288275062816768.000 5.702 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 2400 -8e+004 138428288268365152256.000 5.702 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 2500 -4e+013 138428288268365152256.000 2.153 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 2600 -8e+005 138428288268370575360.000 1197.049 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 2700 -6e+013 138428288268370575360.000 2.153 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 2800 -3e+007 138428288268370804736.000 1197.049 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 2900 -3e+006 138428288268370804736.000 1197.049 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 3000 -4e+007 5670310.277 8.807 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 3100 -5e+010 5670190.672 1.000 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 3200 -2e+011 5670190.697 1.000 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 3300 -9e+009 5670192.523 8.807 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 3400 -6e+007 5669752.134 8.807 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 3500 -3e+008 5669752.111 8.807 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 3600 -6e+015 243923.504 1.000 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 3700 -1e+005 4952164014.952 8.807 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 3800 -2e+005 4951920109.652 1.000 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 3900 -9e+007 4951920108.871 0.999 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 4000 -4e+004 4951920356.556 1.000 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 4100 -7e+007 4951920356.556 1.000 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 4200 -4e+008 4951920356.567 1.000 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 4300 -3e+007 4951920355.957 1.000 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 4400 -1e+014 4951920341.236 1.000 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 4500 -6e+006 4954227150.505 1.000 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 4600 -6e+007 4954227150.493 1.000 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 4700 -3e+007 2307059.029 0.999 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 4800 -8e+007 2307059.060 0.999 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 4900 -2e+009 2307059.056 0.999 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 5000 -1e+007 2306825.270 0.999 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 5100 -2e+013 2306825.270 1.000 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 5200 -3e+007 2364327.745 1.000 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 5300 -3e+005 2364336.287 1.000 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 5400 -5e+007 2364336.287 1.000 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 5500 -1e+005 57579.169 1.000 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 5600 -2e+010 57579.181 1.000 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 5700 -7e+007 57606.564 98.578 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 5800 -1e+013 57606.601 98.578 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 5900 -4e+007 93719.428 139.917 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 6000 -3e+012 93705.536 98.578 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 6100 -1e+008 96406.442 274.685 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 6200 -4e+006 38907.379 98.578 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 6300 -1e+025 38897.621 34.959 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 6400 -2e+006 462832721509558784.000 274.685 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 6500 -4e+005 462832721509558656.000 34.959 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 6600 -3e+008 462832721509558656.000 34.959 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 6700 -1e+007 462832721509558656.000 29.902 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 6800 -2e+008 462832721509558656.000 29.902 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 6900 -1e+010 462832721509522560.000 4.660 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 7000 -2e+008 462832721509522560.000 29.902 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 7100 -3e+009 462832721509519872.000 4.660 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 7200 -9e+005 462832721509520192.000 4.660 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 7300 -2e+008 462832721509520192.000 4.660 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 7400 -4e+007 347.135 4.433 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 7500 -6e+010 346.769 0.999 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 7600 -6e+004 97230.302 4.433 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 7700 -3e+007 97227.411 0.999 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 7800 -3e+008 97227.408 0.999 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 7900 -6e+007 97227.721 4.113 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 8000 -6e+013 97220.010 1.000 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 8100 -1e+005 63999119.456 4.113 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 8200 -3e+005 63998784.580 1.000 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 8300 -2e+008 63998784.580 1.000 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 8400 -9e+008 63998784.210 0.999 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 8500 -7e+004 64000156.003 1.000 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 8600 -1e+016 63903272.471 1.000 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 8700 -3e+007 118157050.418 1.000 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 8800 -1e+018 118157050.426 1.000 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 8900 -8e+006 15081991457.983 1.000 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 9000 -2e+010 15081991457.983 1.000 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 9100 -1e+005 15018104049.825 1.000 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 9200 -5e+006 15018104049.861 1.000 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 9300 -7e+008 15018104049.861 1.000 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 9400 -4e+010 15018104049.886 1.000 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 9500 -6e+011 15018102678.087 1.000 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 9600 -2e+005 15018342644.502 1.000 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 9700 -2e+005 14964088866.498 0.999 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 9800 -5e+004 14964088866.662 0.999 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 9900 -8e+006 254458.793 0.994 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: 10000 -1e+010 254458.793 0.994 MAY BE DIVERGING... INSPECT ELBO
nhg_j_frvi_c.csv: Informational Message: The maximum number of iterations is reached! The algorithm may not have converged.
nhg_j_frvi_c.csv: This variational approximation is not guaranteed to be meaningful.
nhg_j_frvi_c.csv: Drawing a sample of size 1000 from the approximate posterior...
nhg_j_frvi_c.csv: COMPLETED.
stan started processing nhg_j_frvi_c.csv
stan finished processing nhg_j_frvi_c.csv

I am not sure if using the converged meanfield results is accurate enough. I tried to run the model using the NUTS algorithm but used 2.5 hours just with 1000 samples, 1 chain. I also tried before running the model in OPENBUGS for more than 12 hours but never got a result. Your feedback is more than welcome.

Large double values in data can cause an error

If data has large double values which should be represented using scientific notation, rdump.m may write them as integers which are larger than maxint('int32'), causing Stan to give an error, e.g.,

| Exception: data y value 10683812715190712 beyond int range

The problem is in the rdump.m
fprintf(fid,'%d, ',data{i}(1:end-1))
where %d is used for reals, too. If the floating point representation of a large value happens to be an integer and in 64bit Matlab smaller than max('int64') then Matlab prints the value as an integer. Stan uses int32 and gives an error if an integer is larger than intmax('int32').

MatlabStan crashes

Hi,

I have installed all the required tools for the MatlabStan and I could execute some examples from the wiki. However, I could not execute the real problem I had in mind. I really do not know what the problem is since no error is shown. But I get the windows error "stansummary.exe has stopped working". There are some warnings in the command prompt of Matlab as well. I attached an screenshot of the error along with the model I want to execute.

Any help would be appreciated.

Best,
Majid
stanerror

Problem with java runtime or make, Matlab R2015b Windows

Hej,
I am trying to run Stan through Matlab R2015R on my Windows 64bit machine.
There are no white spaces in my directory paths.
I am getting the following problem:

>> school
Having a problem getting stan version.
This is likely a problem with Java running out of file descriptors
Trying again. Trying again. Trying again. Trying again. Trying again. Trying again.
Giving up.
Output argument "ver" (and maybe others) not assigned during call to "StanModel/stan_version".

Error in StanModel (line 194)
               ver = self.stan_version();

Error in stan (line 108)
   model = StanModel();

Error in school (line 4)
fit1 = stan('file','school.stan','data',schools_dat,'iter',1000,'chains',4);

school.m

schools_dat = struct('J',8,...
                     'y',[28 8 -3 7 -1 1 18 12],...
                     'sigma',[15 10 16 11 9 11 10 18]);
fit1 = stan('file','school.stan','data',schools_dat,'iter',1000,'chains',4);

school.stan

data {
  int<lower=0> J;          // number of schools
  real y[J];               // estimated treatment effect (school j)
  real<lower=0> sigma[J];  // std err of effect estimate (school j)
}
parameters {
  real mu;
  real theta[J];
  real<lower=0> tau;
}
model {
  theta ~ normal(mu, tau); 
  y ~ normal(theta,sigma);
}

I started debugging a bit and found that this is my problem:
StanModel.m

 % FIXME, occasionally stanc does not return version?

Instead of fixing it, I decided to run
C:/Users/HIDEME/Documents/PhD/Courses/BayesianDataAnalysis/cmdstan/bin/stanc --version
manually with this as results: stanc version 2.9.0. I ran this in cygwin (my windows command line tool of choice). I also compiled cmdstan within cygwin using their devel package.

So, with a bit of understanding your code, in StanModel.m I changed ver = self.stan_version(); to ver = [2 9 0];

Now I am running my school.m script again with the following output:

>> school
Error using processManager/start (line 362)
Java exception occurred:
java.io.IOException: Cannot run program "make" (in directory "C:\Users\HIDEME\Documents\PhD\Courses\BayesianDataAnalysis\cmdstan"): CreateProcess error=2, The system
cannot find the file specified
    at java.lang.ProcessBuilder.start(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)
    at java.lang.Runtime.exec(Unknown Source)

Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
    at java.lang.ProcessImpl.create(Native Method)
    at java.lang.ProcessImpl.<init>(Unknown Source)
    at java.lang.ProcessImpl.start(Unknown Source)
    ... 3 more

Error in processManager/set.command (line 212)
            self.start();

Error in processManager (line 179)
         self.command = p.Results.command;

Error in StanModel/compile (line 847)
         p = processManager('id','compile',...

Error in StanModel/sampling (line 719)
            self.compile();

Error in stan (line 137)
   fit = model.sampling(p.Unmatched);

Error in school (line 4)
fit1 = stan('file','school.stan','data',schools_dat,'iter',1000,'chains',4);

So back to debugging.
Inside the function start(self) of processManager.m I set a breakpoint at

self(i).process = runtime.exec(self(i).command, self(i).envp, java.io.File(self(i).workingDir));

Manually extracting self(i).command, self(i).envp and java.io.File(self(i).workingDir) gave me make C:/Users/HIDEME/Documents/PhD/Courses/BayesianDataAnalysis/111/ex4/school.exe, [] and C:\Users\HIDEME\Documents\PhD\Courses\BayesianDataAnalysis\cmdstan, respectively.

Back to cygwin (my windows command line tool of choice), I cd into C:\Users\HIDEME\Documents\PhD\Courses\BayesianDataAnalysis\cmdstan and run make C:/Users/HIDEME/Documents/PhD/Courses/BayesianDataAnalysis/111/ex4/school.exe with the following output:


--- Linking C++ model ---
g++ -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -I src -I stan_2.9.0/src -isystem stan_2.9.0/lib/stan_math_2.9.0/ -isystem stan_2.9.0/lib/stan_math_2.9.0/lib/eigen_3.2.4 -isystem stan_2.9.0/lib/stan_math_2.9.0/lib/boost_1.58.0 -Wall -pipe -DEIGEN_NO_DEBUG -m64 -Wno-unused-function -Wno-uninitialized    -O3 -o C:/Users/HIDEME/Documents/PhD/Courses/BayesianDataAnalysis/111/ex4/school.exe src/cmdstan/main.cpp -include C:/Users/HIDEME/Documents/PhD/Courses/BayesianDataAnalysis/111/ex4/school.hpp  -static-libgcc -static-libstdc++
/usr/lib/gcc/x86_64-pc-cygwin/5.3.0/libstdc++.a(cow-stdexcept.o): In function `std::logic_error::logic_error(std::logic_error const&)':
/usr/src/debug/gcc-5.3.0-3/libstdc++-v3/src/c++11/cow-stdexcept.cc:44: multiple definition of `std::logic_error::logic_error(std::logic_error const&)'
/tmp/cc1PMwpv.o:main.cpp:(.text$_ZNSt11logic_errorC2ERKS_[_ZNSt11logic_errorC2ERKS_]+0x0): first defined here
/usr/lib/gcc/x86_64-pc-cygwin/5.3.0/libstdc++.a(cow-stdexcept.o): In function `std::logic_error::logic_error(std::logic_error const&)':
/usr/src/debug/gcc-5.3.0-3/libstdc++-v3/src/c++11/cow-stdexcept.cc:44: multiple definition of `std::runtime_error::runtime_error(std::runtime_error const&)'
/tmp/cc1PMwpv.o:main.cpp:(.text$_ZNSt13runtime_errorC2ERKS_[_ZNSt13runtime_errorC2ERKS_]+0x0): first defined here
collect2: error: ld returned 1 exit status
makefile:72: recipe for target 'C:/Users/HIDEME/Documents/PhD/Courses/BayesianDataAnalysis/111/ex4/school.exe' failed
make: *** [C:/Users/HIDEME/Documents/PhD/Courses/BayesianDataAnalysis/111/ex4/school.exe] Error 1

I'd love to debug this. But its beyond my comprehension.. Further, I don't know whether I messed something up beforehand.
Thank you for your time.
Rasmus

"extract" fails when dimensionality of a param is greater than number of samples drawn

Hi Brian,

I've been playing around with MatlabStan for a few weeks now, and it's a wonderful tool! Thanks for building it! I ran into an issue this afternoon where the "extract" function was failing, giving error:

Index exceeds matrix dimensions. 
Error in mcmc/extract (line 175)
               temp = temp(self.permute_index(1:max(sz)),:);

This was happening specifically when max(sz) was not equal to the number of samples drawn, due to a transformed parameter in my model with very large dimensionality. I was able to fix the problem in my case by replacing "max(sz)" with "sz(1)" in the offending line of code.

Thanks!

Kevin

nansum not defined

Torben on the Stan Discourse forum post reported:

I just installed and tested MatlabStan and encountered a minor problem that I want to report.
MatlabStan makes use of the function nansum in StanFit.m, which isn’t included in Matlab (anymore?). This is easily solved by writing your own nansum function.

  • write the necessary nansum function

struct array assignment problem using MatlabStan output

Inconsistent Matlab (2016b) behavior when using the Stan output file.
This is the relevant part of the code:
fit = stan('file','linreg.stan','data',data);
print(fit);
beta0=fit.sim.samples.beta0;

Print(fit) displays the Stan results properly but the script crashes on the next line. Displayed error is Struct contents reference from a non-struct array object, meaning that Matlab does not always recognize fit as a proper structured matrix. I'm saying not always because this code crashes only when run from a script (will run from the command window or in debug mode), and it does not crash every time it is run from a script. I've never seen a problem like this in Matlab before. Running the 64-bit Mac version of Matlab 2016b.

"Having a problem getting stan version" Matlab 2015a error

(Moved from the Stan email list. Thanks Brian for your reply, and it's good to know that MatlabStan and OS X can get along!)

Hi,
I’ve attempted to install and run MatlabStan (v. 2.7.0; cmdstan 2.8.0; operating system Mac OS X 10.10.5), but am unsuccessful for reasons I can’t figure out. Running, for example, the eight-schools example gives the following error:

Having a problem getting stan version.
This is likely a problem with Java running out of file descriptors
Trying again. [repeated 6 times]
Giving up.
Error using processManager/start (line 402)
Looks like command doesn't exist. Check spelling or path?
Error in processManager/set.command (line 212)
self.start();
Error in processManager (line 179)
self.command = p.Results.command;
Error in StanModel/stan_version (line 789)
p = processManager('id','stanc version','command',command,...
Error in StanModel (line 194)
ver = self.stan_version();
Error in stan (line 108)
model = StanModel();
Error in school_test (line 27)
fit = stan('model_code',schools_code,'data',schools_dat);

This error & message seems very similar to an issue reported elsewhere, caused by MATLAB not using the appropriate libraries, using its own rather than those in /usr/lib . See e.g. items 13-18 at https://www.mathworks.com/matlabcentral/newsreader/view_thread/162466, or http://sgpsproject.sourceforge.net/JavierVGomez/index.php/Solving_issues_with_GLIBCXX_and_libstdc%2B%2B . However, trying the solutions posted at these places does not work. (Essentially, many of the solutions involve setting the LD_PRELOAD variable to, for example, /usr/lib/libstdc++.so.6 to redirect to the proper libraries.) I think this fails for me because in Mac OS X there is no LD_LIBRARY_PATH variable; the prior discussion of solutions is all for Unix. Also, I don't see libstdc++... in Matlab's binary directories, and don't know what other things I should be looking for. It’s very non-obvious (to me) how to direct Matlab to the proper libraries. (I tried “setenv('DYLD_LIBRARY_PATH', '/usr/lib’);” — this also fails. It is also, of course, possible that the problem is something completely different!

Has anyone used MatlabStan with OS X ? If so, is there some necessary step I’m missing?

(Running Stan from the command line, not through Matlab, works, by the way.)

Any thoughts are very much appreciated!

best wishes,

Raghu

Raghuveer Parthasarathy
Group web page: http://physics.uoregon.edu/~raghu/
Blog: http://eighteenthelephant.wordpress.com/

Associate Professor
Department of Physics
1274 University of Oregon
Eugene, OR 97403-1274
(541) 346-2933 -- office

Test script missing

There is no function "runtests" found in the "run_all_tests.m". I'd like to do so and ensure I have a proper install. Where can I find this file?

MATLABStan with parfor

I am failing to get MATLAB Stan to run with parallelized loop "parfor" ...
Things work with regular "for", work with parfor when workers pool is not started (meaning the parser swallows the syntax and types variables, etc), but as soon as I turn on the worker's pool it breaks with the following error.

Not sure yet what caused exact error I mention below, but there are seem to be a few issues with StanModel.m which would prevent multi-worker execution with "parfor" in MATLAB, since
fname = fullfile(self.working_dir,'temp.data.R');
fname = fullfile(self.working_dir,'temp.init.R');
always saves temporary data into the same file, overwriting it across workers
same issue is hidden someplace with the sample_file which would be by default
output-1.csv
same for all workers.

Also "cores" option does not seem to have been made available within MATLAB.

THANK YOU

 -Leon

ERROR:
Error using StanModel/set.control (line 600)
Too many input arguments.

Error in StanModel/set (line 293)
self.control = p.Results.control;

Error in StanModel/sampling (line 709)
self.set(varargin{:});

Error in P3v2parfor>(parfor body) (line 90)
fit = model.sampling( 'data', peps_dat, 'iter', P.BTnum, 'warmup', round(.1
* P.BTnum), 'chains', P.numChains) ;

Error in P3v2parfor (line 82)
parfor nd =1:NndxActual % parfor % process multi-peptide proteins

Remove dependence on Statistics or Finance toolbox

Hi,

I noticed that in StanFit.m, the nansum function is used on lines 272 and 366. nansum is a function in the Statistics toolbox and in the finance toolbox.

nansum can be replaced with sum(x,'omitnan'), which would circumvent the user needing the two abovementioned toolboxes and serves the same purpose as nansum. I can't find any other functions that require the toolboxes in the MatlabStan scripts.

I know most people probably have one of these toolboxes, but it might make life easier on a few.

Hope it helps :)
Peter

Compiling for 64 bits windows 7

Dear all,

I have installed CmdStan using MinGW (64 bits) on Cygwin on 64 bits Windows 7. This worked fine and the Bernoulli example compiled and executed without errors. Now, I tried to use the schools example in Matlab, but this gives the following error(s):

Error using StanModel/compile (line 852)
File not found - *_inst.cpp
File not found - *_def.cpp
File not found - *.stan
File not found - *.hpp
FIND: Parameter format not correct
Assembler messages:
Fatal error: No compiled in support for x86_64
src/cmdstan/main.cpp:1:0: sorry, unimplemented: 64-bit mode not compiled in
src/cmdstan/main.cpp:13:1: fatal error: error closing -: Invalid argument
compilation terminated.

Apparently, something goes wrong with the compilation, but as the Bernoulli example worked fine, I'm unsure what went wrong.

Would anyone have a clue? :-)

Thanks!

Add option for ADVI

Please, add option to make it possible to use ADVI algorithm available in CmdStan.

MatlabStan version number in downloaded files

This is actually just a simple request 😄 I was wondering whether it would be possible to include the version number of the release of MatlabStan in the downloaded files somewhere.

When I run models, I like to record the versions of cmdstan, matlabstan, and matlabprocessmanager that were used for the models. I have code that pulls the information programmatically for cmdstan and matlabprocessmanager, but I wasn't able to find the release version in any of the downloaded files for MatlabStan. Right now, I pull it from the folder name of the directory that contains the code, but my collaborators don't always include that information in the folder name.

Of course, not a big deal if you don't like the idea. I figured it wouldn't hurt to ask though. Thanks!

Problem if number of observations exceeds number of chains x number of samples

Hi Brian,

Thanks for the amazing code. MatlabStan has been absolutely wonderful to use.

I discovered (and solved) a very minor bug. I deal with fairly large data sets. If my number of observations exceeds number of chains x number of samples, then the fit.extract method fails.

I tracked down the issue, and it is an easy fix. in mcmc.m you set a size variable (sz) as:

           sz = size(temp);

you then use this in the subsequent line:

            temp = temp(self.permute_index(1:max(sz)),:);

But, when nobservations>nchains*nsamples, this crashes since max(sz) no longer applies to the proper index.

The trivially easy fix is to replace max(sz) with sz(1).

          temp = temp(self.permute_index(1:sz(1)),:);

Probably very few people run into this bug. However, if/when you release an update, it is an easy change to make.

Stan exits badly

Dear Brian/team,

I'm a novice Stan user, using Matlab Stan 2.15 1.0 with Matlab 2015b on Windows 10 64bit. I can get the 'rats' and 'schools' model to work fine, but having an issue getting a survival model to work (adapted from an example at https://www.bioconductor.org/help/course-materials/2016/BioC2016/ConcurrentWorkshops4/Buros/weibull-survival-model.html).

The error is:
Warning: Stan seems to have exited badly.

In StanFit/process_exit_failure (line 290)
In StanFit/process_exit (line 170)
In StanFit>@(src,evnt)process_exit(self,src,evnt)
In processState/set.exitValue (line 30)
In processManager.pollTimerStop (line 508)
In timer/timercb (line 30)
In timercb (line 13)

As far as I can see, output files have all been set-up but all are empty. I'm not sure how to de-bug this?

Many thanks for you help,
Ash

Not sure if it will help but here is some output:

fit.processes.exitValue=70

fit.processes.command=E:\Code\Matlab_Code\Neuro_onc\Stan\anon_model.exe sample num_samples=1000 num_warmup=1000 save_warmup=0 thin=1 adapt engaged=1 gamma=0.05 delta=0.8 kappa=0.75 t0=10 init_buffer=75 term_buffer=50 window=25 algorithm=hmc engine=nuts max_depth=10 metric=diag_e stepsize=1 stepsize_jitter=0 id=1 data file=E:\Code\Matlab_Code\Neuro_onc\Stan\temp.data.R init=2 random seed=210873 output file=output-1.csv diagnostic_file= refresh=100

Example with user-defined initial values

How does one define initial values per chain per parameter in MatlabStan? I could not find an example on the wiki. Defining initial values incorrectly causes an "Warning: Stan seems to have exited badly." error.

problem defining N x 1 matrices

I looked to see if this issue was already posted, but didn't find it. Sorry if I missed it.

I'm trying to write a generic stan program that can handle any mixed linear model (y = X_b + Z_u + e) and have a solution that mostly works. The trouble is that my design matrix (X) or random variable matrix (Z) can have zero, one or many columns. This creates a problem for my stan program because X and Z are declared as matrices and the heuristics inside rdump do not detect the desired data types.

I'd like to make a feature request to declare variable types.

If there is a work-around please let me know. If not, my solution was to create an RData object that keeps track of variable names, values and types and includes its own rdump routine. I then modified StanModel.set.data to detect whether the input is an RData object. If it is, then it calls RData.dump. Simple enough and it should be backward compatible. You are welcome to use my code for RData if you think it would be useful. Just email me.

Variational inference

CmdStan recently added variational inference method. Can this be accessed from MatlabStan currently?

Undefined variable in mcmc.m

When I call stan as...

RL_data = struct('n_s',ns,'n_t',nt,'Choice',choices,'Correct',outcomes,...
                 'Reward',rewards,'Subject',subj_nums,'Init',inits);

fitRL = stan('file','opzet_stan_kort_anne_2.stan','data',RL_data,'iter',1000,...
             'chains',4,'refresh',100,'warmup',500,'thin',10);

I get the following error:

??? Undefined function or variable 'rng'.

Error in ==> mcmc>mcmc.mcmc at 37
            self.rng_state = rng;

Error in ==> StanFit>StanFit.StanFit at 94
            self.sim_ = mcmc();

Error in ==> StanModel>StanModel.sampling at 744
         fit = StanFit('model',copy(self),'processes',p,...

Error in ==> stan at 137
   fit = model.sampling(p.Unmatched);

Error in ==> testRL_stan2 at 59
fitRL = stan('file','opzet_stan_kort_anne_2.stan','data',RL_data,'iter',1000,...

As far as I can tell right now it is not an issue with my call to STAN, but I may be wrong about this. Does anyone know what may be wrong? I wasn't planning on being a MatlabSTAN contributor, just a user, but I guess I might need to fix this if it isn't just operator-error.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.