Random draws of data vector

I’m working on a model that pre-samples random uniform variables and then transforms them as a function of a parameter of interest. The transformed variables are only used for numerical integration.

We’re running into an issue where we are drawing too many of these random uniform variables (on the order of tens/hundreds of millions) and are running into memory constraints. One idea we had was to instead draw a small but sufficiently large number (perhaps 1,000 or 10,000) of uniform variables, but do the transformation on random but deterministic samples of the uniform variables.

Is there a good way to generate these random permutations with a seed? I’m looking for something like the very made-up sample_values below:

for (i in 1:I) {
    vector[n_draws] random_draws = sample_values(predrawn_variables, n_draws, seed=i);

You can use the categorical_rng to do something like sample() in R, if that is what you are looking for? Or are you trying to do that in the transformed parameters/model block?

1 Like

If the points are just for numerical integration, then you could possibly just use Gauss–Kronrod? Or, if necessary, QMC. More details of the numerical integration problem might help.

1 Like

I can’t do categorical_rng here because the resampling step occurs in a user-defined function (it also seems to lack a seed). Basically we are pre-drawing uniform variables outside the model, passing them in through data, and then we need deterministic subsamples for each individual in our sample.

I’m checking in with my coauthors here – I suspect a quadrature is probably going to be the most effective here.

FYI we ended up just implementing a quadrature. Thanks everyone!