Initialisations of vectors and arrays

24 views
Skip to first unread message

John Reid

unread,
Oct 18, 2014, 6:51:07 AM10/18/14
to stan-...@googlegroups.com
Hi,

Can I assume vectors, arrays, matrices, etc... are initialised to 0 or are their values undefined at initialisation?

Thanks,
John.

Michael Betancourt

unread,
Oct 18, 2014, 7:24:27 AM10/18/14
to stan-...@googlegroups.com
Assume that they are undefined and should be explicitly initialized to values 
(rep_vector and rep_matrix come in handy here).

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

Daniel Lee

unread,
Oct 18, 2014, 8:03:10 AM10/18/14
to stan-...@googlegroups.com
+1 for Michael's response. That's the best way to deal with it.

In Stan, real variables declared in transformed data, transformed parameters, and local variables are initialized to NaN, not a number. See http://en.m.wikipedia.org/wiki/NaN. Since real variables in Stan are implemented using double and Stan's automatic differentiation types, which use doubles, these can be set as NaN.

int variables are initialized to 0, I believe. The C++ int type can't represent NaN.



Daniel
Reply all
Reply to author
Forward
0 new messages