stan变量声明:var_type var_name [length]和vector [length] var_name之间使用差异
我是Stan的新手,我正在努力了解如何使用不同的变量声明样式的区别。特别是,我对何时应该在变量类型之后放置方括号以及何时将它们放在变量名称之后感到困惑。例如,给定int< lower = 0> l; //我的数据长度
,让我们考虑:
real n [l]; //我的变量
vers
vector [l] n; //我的变量
我从我的理解中都声明了变量n为长度L的向量。 第一种方式指定变量类型的两个方法之间的唯一区别是吗?它们可以互换使用吗?他们应该属于stan代码的不同部分(例如, data vs 参数
或model
)?
感谢您的解释!
I am new at Stan and I'm struggling to understand the difference in how different variable declaration styles are used. In particular, I am confused about when I should put square brackets after the variable type and when I should put them after the variable name. For example, given int<lower = 0> L; // length of my data
, let's consider:
real N[L]; // my variable
versus
vector[L] N; // my variable
From what I understand, both declare a variable N as a vector of length L.
Is the only difference between the two that the first way specifies the variable type? Can they be used interchangeably? Should they belong do different parts of the Stan code (e.g., data
vs parameters
or model
)?
Thanks for explaining!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
真实名称[size]
和vector [size]名称
可以互换使用。它们的内部存储方式不同,因此您可以通过一个或另一个获得更好的性能。某些操作也可能仅限于一个和另一个操作(例如向量乘法),而循环循环的最佳顺序会更改。例如,使用矩阵
与一个2-D数组,首先循环首先与列循环更有效,但是如果您有一个更具体的示例,则会出现。读取此内容的方法是:Means
name
是类型Real
的数组,因此一堆reals
被存储在一起。表示名称是大小
size
的向量,它也是一堆存储在一起的REAL。但是vector
Stan中的数据类型基于eigen
c ++库(C ++),这允许其他操作。您还可以创建这样的向量数组:
它将产生
k
sizen
的矢量的数组。底线:您可以通过使用
vector
或real
进行任何模型,但在计算效率中不一定等效。real name[size]
andvector[size] name
can be used pretty interchangeably. They are stored differently internally, so you can get better performance with one or the other. Some operations might also be restricted to one and the other (e.g. vector multiplication) and the optimal order to loop over them changes. E.g. with amatrix
vs. a 2-D array, it is more efficient to loop over rows first vs. columns first, but those will come up if you have a more specific example. The way to read this is:means
name
is an array of typereal
, so a bunch ofreals
that are stored together.means that name is a vector of size
size
, which is also a bunch of reals stored together. But thevector
data type in STAN is based on theeigen
c++ library (c++) and that allows for other operations.You can also create arrays of vectors like this:
which is going to produce an array of
K
vectors of sizeN
.Bottom line: You can get any model running with using
vector
orreal
, but they're not necessarily equivalent in the computational efficiency.