Sample from posterior distribution using trained neural estimator
Source:R/abi_sample_posterior.R
abi_sample_posterior.RdA wrapper around NeuralEstimators::sampleposterior() that automatically
extracts the trained estimator from a trained estimator object created by
abi_train and returns posterior samples in a 3D array format.
Arguments
- trained_estimator
A trained estimator object returned by
abi_train. Must be of classeam_abi_trained_estimatorand contain atrained_estimatorelement.- Z
Data in a format amenable to the neural-network architecture of estimator. Can be a single data set or a list of data sets. If NULL (default), uses
Z_testfrom the ABI input object.- N
Integer; number of approximate posterior samples to draw (default: 1000).
- ...
Additional keyword arguments passed to the Julia version of
sampleposterior(), applicable when estimator is a likelihood-to-evidence-ratio estimator.
Value
A tibble of class eam_abi_posterior_samples containing
posterior samples. Each row represents one posterior sample for one dataset.
Columns include dataset_id (integer dataset identifier) and one
column for each parameter.
Details
This function extracts the trained neural posterior estimator from the
trained estimator object and uses it to sample from the approximate posterior
distribution given data Z. The samples are stacked using Julia's
stack() function, then converted to a tibble in R for easy
manipulation and summarization.
Examples
if (FALSE) { # \dontrun{
# Train an estimator first
trained_estimator <- abi_train(
estimator = estimator,
abi_input = abi_input,
epochs = 100
)
# Sample from posterior using test data (default)
posterior_samples <- abi_sample_posterior(
trained_estimator = trained_estimator,
N = 1000
)
# Sample from posterior for specific data
posterior_samples <- abi_sample_posterior(
trained_estimator = trained_estimator,
Z = abi_input$Z_test,
N = 2000
)
} # }