realize draws n samples from a distribution and wraps them in an empirical_dist. This is the universal fallback that lets any dist object be converted to a discrete approximation on which methods like cdf, density, and conditional are always available.

realize(x, n = 10000, ...)

# S3 method for class 'dist'
realize(x, n = 10000, ...)

# S3 method for class 'empirical_dist'
realize(x, ...)

# S3 method for class 'realized_dist'
realize(x, n = 10000, ...)

Arguments

x

A distribution object (inheriting from dist).

n

Number of samples (default: 10000).

...

Additional arguments passed to methods.

Value

An empirical_dist (or realized_dist) object.

Details

For non-empirical distributions, the result is a realized_dist that preserves the source distribution as provenance metadata. This enables re-sampling via realize(x$source, n = ...) and informative printing.

The empirical_dist method is a no-op: the distribution is already materialized.

The realized_dist method re-samples from the original source distribution, allowing cheap regeneration with a different sample size.

Examples

# \donttest{
set.seed(1)
x <- normal(0, 1)
rd <- realize(x, n = 1000)
mean(rd)
#> [1] -0.01164814
# }