Sampling from a density up to normalisation constant

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

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);
}
2 Likes

you mean y there.

1 Like

Fixed. Thanks.

1 Like