Constructs a result object from a Bayesian model fitting operation.
Arguments
- success
Logical scalar indicating if the fit succeeded
- fit
The backend fit object (may be NULL if removed by retention policy)
- draws
Matrix of posterior draws (S x P), with column names for parameters
- diagnostics
Named list of diagnostic values (scalars or named numeric vectors)
- timing
List containing total, warmup, and sample timing in seconds
- warnings
Character vector of warning messages captured during fitting
- error
A condition object if the fit failed, NULL otherwise
- data_bundle
Optional list containing the training/test data used for fitting
Details
The bayesim_fit_result class encapsulates all outputs from a Bayesian model fitting operation, including the posterior draws, diagnostics, timing information, and any warnings or errors encountered.
Validation rules:
If
successis FALSE,errormust be non-NULLIf
successis TRUE,errormust be NULLtiming$totalmust be non-negativeIf
drawsis not NULL, it must be a matrix with column names
Examples
# Successful fit
draws <- matrix(rnorm(1000), ncol = 2, nrow = 500)
colnames(draws) <- c("alpha", "beta")
result <- new_fit_result(
success = TRUE,
draws = draws,
diagnostics = list(rhat = c(alpha = 1.01, beta = 1.00)),
timing = list(total = 10.5, warmup = 5.0, sample = 5.5)
)
# Failed fit
result <- new_fit_result(
success = FALSE,
error = simpleError("Convergence failed"),
diagnostics = list(),
timing = list(total = 2.0, warmup = 2.0, sample = 0)
)