Supplying initial values in matlabStan

33 views
Skip to first unread message

Daniel Lewis

unread,
Apr 12, 2017, 10:18:25 PM4/12/17
to Stan users mailing list
I'm pretty new to Stan - pushed through the learning process using the documentation and posts here (very helpful resource!), but I'm stuck on getting MatlabStan to accept user-supplied initial values. My model fits fine without supplied initial values, but when I try to fit with them, I get:

Warning: Stan seems to have exited badly.
> In StanFit/process_exit_failure (line 280)
 
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 504)
 
In timer/timercb (line 30)
 
In timercb (line 13)
 
In timer/start (line 39)
 
In processManager/start (line 399)
 
In StanModel/sampling (line 747)
 
In stan (line 137)

I'm entering 

fit1 = stan( 'model_code',SV_code,'data',SV_data,'warmup',1000,'iter',10000,'chains',1,'init',inits)

where inits is given by

inits=struct('H21',.64,'H31',-2.11,'H12',-2.36,'H32',-1.69,'H13',-2.69,'H23',-.27)

As far as I can tell, this should be right, as according to the help file, init can be "a struct, with fields corresponding to parameters to be initialized". I assume I'm mistaken, and that's what's causing the error.

My model is below:

SV_code= {


'data {'


 ' int<lower=0> T;   // # time points (equally spaced)'


  'matrix[T,3] y;      // observed shocks'


'}'


'transformed data {'


'vector[3] zeros; //means are zeros'


'vector[T] yzeros;'


'yzeros = rep_vector(0, T);'


'zeros = rep_vector(0, 3);'


'}'


'parameters {'


 'corr_matrix[3] Omega;'


 'vector<lower=-1,upper=1>[3] phi;'


 'vector<lower=0>[3] sigma; '


 ' matrix[T,3] h_innov;             // std log volatility time t'


  'real H21;'


 ' real H31;'


 ' real H12;'


 ' real H32;'


 ' real H13;'


 ' real H23;'


'}'


'transformed parameters {'


 ' matrix[T,3] h;                 // log volatility at time t'


  'matrix[3,3] H;'


 'cov_matrix[3] Sigma; '


  'Sigma = quad_form_diag(Omega, sigma); '


 'H[1, 1] = 1; H[1, 2] = H12; H[1, 3] = H13; '


 'H[2, 1] = H21; H[2, 2] = 1; H[2, 3] = H23;'


 'H[3, 1] = H31; H[3, 2] = H32; H[3, 3] = 1; '


 ' h = h_innov;'


 ' h[1,1] = h[1,1] ./ sqrt(1 - phi[1] * phi[1]);'


 ' h[1,2] = h[1,2] ./ sqrt(1 - phi[2] * phi[2]);'


 ' h[1,3] = h[1,3] ./ sqrt(1 - phi[3] * phi[3]);'


 ' for (t in 2:T)'


 '   h[t] = h[t] + h[t-1] * diag_matrix(phi);'


'}'


'model {'


'vector[3] vol_t;'


 'Omega ~ lkj_corr(1); // LKJ prior on the correlation matrix ;'


 'sigma ~ cauchy(0, 2);'


  'for (t in 1:T){'


  'h_innov[t] ~ multi_normal(zeros,Sigma);'


  'vol_t=h[t]'' ;'


  'y[t] ~ multi_normal(zeros, H*diag_matrix(exp(vol_t))*H'');'


  '}'


  'phi ~ uniform(-1,1);'


  'H21 ~ normal(0,1);'


  'H31 ~ normal(0,1);'


  'H12 ~ normal(0,1);'


  'H32 ~ normal(0,1);'


  'H13 ~ normal(0,1);'


  'H23 ~ normal(0,1);'


'}'


};


Thanks so much!

Daniel

Bob Carpenter

unread,
Apr 13, 2017, 2:49:33 PM4/13/17
to stan-...@googlegroups.com
I don't think Brian Lau, the MatlabStan dev, reads this list,
so you're probably better off filing an issue directly on
the MatlabStan repo:

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

Hopefully you won't need to supply your own inits---Stan is
pretty good at getting from diffuse inits to the typical
set.

- 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.
> To post to this group, send email to stan-...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Daniel Lewis

unread,
Apr 14, 2017, 7:14:27 PM4/14/17
to Stan users mailing list
Thanks for the reply - I'll ask over there. I'm really happy with stan's inits, I'm just trying to explore a local minima I another algorithm is stuck in.

Daniel
Reply all
Reply to author
Forward
0 new messages