constants in Stan code

90 views
Skip to first unread message

Tamas Papp

unread,
May 13, 2016, 5:35:50 AM5/13/16
to Stan users mailing list
There are a few floating point constants needed to formulate the
likelihood in a model I am working on. I am wondering what the
recommended approach is for constants, as I could not find anything in
the manual (sorry if it is there and I missed it).

For the sake of example, let the constant be gamma=0.5 (just for
illustration). I thought of the following options:

1. as a function in the relevant block:

functions {
// gamma constant
real gamma() {
return 0.5;
}
}

Pros: probably folded by the compiler. Cons: using gamma() is cumbersome.

2. as data:

data {
real gamma; // constant, needs to be provided as data
}

Pros: natural to use. Cons: not folded, needs to be provided when
running the Stan program.

3. abusing the transformed parameters block

transformed parameters {
real gamma;
gamma <- 0.5;
}

Pros: natural to use. Cons: not folded.

Did I miss a better way? What do you use?

Best,

Tamas

Krzysztof Sakrejda

unread,
May 13, 2016, 6:15:35 AM5/13/16
to Stan users mailing list
Transformed data?

Michael Betancourt

unread,
May 13, 2016, 6:28:18 AM5/13/16
to stan-...@googlegroups.com
I tend to use transformed data myself.

On May 13, 2016, at 11:15 AM, Krzysztof Sakrejda <krzysztof...@gmail.com> wrote:

> Transformed data?
>
> --
> 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.

Reply all
Reply to author
Forward
0 new messages