Sampling from a density up to normalisation constant


#1

Hi, I was wondering if it’s possible to use Stan to simply sample from a density that I know the formula of up to proportionality?

Usually if I just want to sample from a density, then I might just write something like:

parameters {
y;
}
model {
y ~ some_pdf
}

But if I want to sample from a density proportional to e^(-x^4/8), how do I do this now?

Thanks in advance,
Ryan


#2

The Stan Modeling Language defines log densities for the parameters (optionally conditioned on variables defined in the data or transformed data blocks) up to a normalization constant and the algorithms handle the rest. So just write your unnormalized log density.

parameters {
  y;
}

model {
  target += - 0.125 * pow(y, 4);
}

#3

you mean y there.


#4

Fixed. Thanks.