Draws n parameter vectors from the prior and pushes them through the
simulator. The simulator is called on chunks of rows rather than on the
whole matrix at once, which is what lets the run report progress and, under
a future plan, spread the chunks across workers. See nsbi_parallel and
nsbi_progress.
Arguments
- simulator
A function mapping an
n x dimmatrix of parameters to ann x dmatrix of simulated data. Ignored ifthetaandxare given. Column names on its output (e.g. viacolnames(out) <- c("cases_wk1", ...)) become the outcome names used in plots.- prior
An
nsbi_prior(seeprior_uniform(),prior_normal()).- n
Number of simulations.
- seed
Optional integer seed for reproducibility.
- verbose
Print training progress.
- chunk_size
Rows of
thetaper simulator call.NULL(default) splits the run into about 64 chunks. Chunks are the unit of work sent tofutureworkers and the unit of progress reporting; see nsbi_parallel.
Examples
prior <- prior_uniform(c(-1, -1), c(1, 1))
sims <- simulate_for_sbi(function(theta) theta^2, prior, n = 100)
str(sims)
#> List of 2
#> $ theta: num [1:100, 1:2] -0.0435 0.4745 -0.8025 -0.3234 0.3867 ...
#> $ x : num [1:100, 1:2] 0.00189 0.22512 0.64396 0.10456 0.14956 ...
