possible bug involving automatic differentiation

48 views
Skip to first unread message

Simon Barthelmé

unread,
Sep 4, 2013, 2:29:58 AM9/4/13
to stan-...@googlegroups.com
Dear all,

I think I've found a rather strange bug which might have to do with automatic differentiation. The model below just expresses an IID N(0,1) vector x[1] ... x[n] but in the model part the distance matrix d_ij = |x[i] - x[j]| is computed. By definition d_ii = 0, so this part is invariant to the value of x. The distance matrix is *not* used to update the log probability of the model so it should play no role. Sampling fails with:

Error : No acceptably small step size could be found. Perhaps the posterior is not continuous?

which I'm guessing comes from a 0 derivative, but why should that happen?


Here's the code:
-------------------

data {
int<lower=1> n;
}
parameters {
vector[n] x;
}
model {
matrix[n,n] D;
//Prior
for (i in 1:n)
{  
    x[i] ~ normal(0,1);
}

//Compute distance matrix
for (i in 1:n)
{
for (j in i:n) //no error when using j in (i+1):n
 {
 D[i,j] <- sqrt(square(x[i]-x[j]));
 //Note: no error when using fabs instead of sqrt(square(.))
 } 
}

}
-------------

See session info below. Thanks!

Best

Simon Barthelme


R version 3.0.1 (2013-05-16)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=fr_CH.UTF-8       LC_NUMERIC=C             
 [3] LC_TIME=fr_CH.UTF-8        LC_COLLATE=fr_CH.UTF-8   
 [5] LC_MONETARY=fr_CH.UTF-8    LC_MESSAGES=fr_CH.UTF-8  
 [7] LC_PAPER=C                 LC_NAME=C                
 [9] LC_ADDRESS=C               LC_TELEPHONE=C           
[11] LC_MEASUREMENT=fr_CH.UTF-8 LC_IDENTIFICATION=C      

attached base packages:
[1] stats4    grDevices utils     datasets  graphics  stats     methods 
[8] base    

other attached packages:
[1] rstan_1.3.0       inline_0.3.12     Rcpp_0.10.4       mgcv_1.7-24     
[5] numDeriv_2012.9-1 stringr_0.6.2     plyr_1.8          ggplot2_0.9.3.1 

loaded via a namespace (and not attached):
 [1] codetools_0.2-8    colorspace_1.2-2   compiler_3.0.1     dichromat_2.0-0  
 [5] digest_0.6.3       grid_3.0.1         gtable_0.1.2       labeling_0.1     
 [9] lattice_0.20-23    MASS_7.3-29        Matrix_1.0-12      munsell_0.4      
[13] nlme_3.1-111       proto_0.3-10       RColorBrewer_1.0-5 reshape2_1.2.2   
[17] scales_0.2.3       tools_3.0.1   

Bob Carpenter

unread,
Sep 4, 2013, 3:09:50 AM9/4/13
to stan-...@googlegroups.com
Thanks, you're the proud parent of:

https://github.com/stan-dev/stan/issues/203

The issue report above has a stripped down model that
causes the issue and also the diagnoistic from RStan
with stan() called with

test_grad=TRUE

that shows you the NaN values from auto-diff.

- 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/groups/opt_out.

Simon Barthelmé

unread,
Sep 4, 2013, 3:32:30 AM9/4/13
to stan-...@googlegroups.com
All right, thanks for the great work on Stan!


2013/9/4 Bob Carpenter <ca...@alias-i.com>
To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

--
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/dSzC74ZKvWs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to stan-users+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages