From a Bayesian perspective, the usual way of doing something like this is to try to choose `x`

to minimize *the expectation of* `F(Q(x))`

with respect to `alpha`

and `beta`

. In other words, for any `x`

, evaluate `F(Q(x))`

for each posterior draw of `alpha`

and `beta`

and calculate the mean of `F(Q(x))`

over the posterior draws. Then choose a better `x`

until you find a minimum.

I think what you might be saying is that you are treating `Q(x)`

as a random variable, in which case for each posterior draw of `alpha`

and `beta`

, draw from the posterior *predictive* distribution of `Q`

— which can be accomplished in Stan by calling `poisson_log_rng(alpha + beta * x)`

— and calculate the mean of `F(Q(x))`

over the posterior *predictive* draws. For each `x`

, the objective function is not deterministic. There is nothing built into Stan to specifically handle this, but you should be able to do stochastic gradient descent or something. Actually, the ADVI implementation in Stan does something similar, but its optimization routine is not exported in a general way.