question about the transformed parameter block

2,691 views
Skip to first unread message

David Blei

unread,
Mar 5, 2013, 11:04:26 AM3/5/13
to stan-...@googlegroups.com
fellow stan users,

i am a stan rookie and a stan fan.

my question is about what to put in the "model" block and what to put
in the "transformed parameters" block. specifically, why and when do
transformed parameters speed up sampling? my tenuous understanding is
that the parameters are transformed just as often as the model block
is computed about. is that incorrect?

FYI, i am using stan to implement variants of matt taddy's inverse
regression for text. the original model can be found here:

http://arxiv.org/abs/1012.2098

it's a multinomial regression with a high-dimensional (6000) & sparse
response and few covariates (1-3).

best
dave

Matt Hoffman

unread,
Mar 5, 2013, 11:16:32 AM3/5/13
to stan-...@googlegroups.com
Hi Dave,

There's no computational difference (that I know of) between doing the
transformations in the model or transformed parameter block. The main
difference is that if something's in transformed parameters then it'll
get saved—it's just a convenience thing.

Best,
Matt
> --
> 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.
>
>

Ben Goodrich

unread,
Mar 5, 2013, 11:29:07 AM3/5/13
to stan-...@googlegroups.com, mdho...@cs.princeton.edu
On Tuesday, March 5, 2013 11:16:32 AM UTC-5, Matt Hoffman wrote:
There's no computational difference (that I know of) between doing the
transformations in the model or transformed parameter block. The main
difference is that if something's in transformed parameters then it'll
get saved—it's just a convenience thing.

Minor addition: In the transformed parameters block, any stated restrictions on the support of the transformed parameter are checked every time the log-posterior is evaluated, but there are no such checks in the model block (and I think trying to restrict the support of a local variable in the model block will result in a compiler error). So

parameters {
  real
<lower=0> sd;
}
transformed parameters
{
  real
<lower=0> variance;
  variance
= sd * sd; // Stan will verify that variance is non-negative with some minor cost
}
model
{
  real precision
;
  precision
= 1 / variance; // Stan does not verify that precision is non-negative
}

This really only makes a difference if the checking is non-trivial, such as with large covariance matrices and whatnot.

Ben


Ben

Daniel Lee

unread,
Mar 5, 2013, 11:33:40 AM3/5/13
to stan-...@googlegroups.com
Hi Dave,

The additional benefit of using the transformed parameter block is the ability to use constraints on the variables. The constraints are checked once per leapfrog step, which adds a little computational overhead, but can help trap modeling errors early.

If you want a more detailed explanation, there is a chapter in the manual on Program Blocks. The overview subsection discusses how frequently each of the blocks are executed.


Daniel


David Blei

unread,
Mar 5, 2013, 3:23:06 PM3/5/13
to stan-...@googlegroups.com
stan team,

thanks for your clear and helpful answers.

best
dave
Reply all
Reply to author
Forward
0 new messages