R6
class that generates Latin hypercube samples (using
randomLHS
) for parameters drawn from configured
distributions: uniform
, Poisson
,
normal
, lognormal
,
beta
, truncated normal
or
triangular
.
It generates a data frame of sample values.
poems::GenericClass
-> LatinHypercubeSampler
attached
A list of dynamically attached attributes (name-value pairs).
parameter_names
A vector of sample parameter names.
parameter_distributions
A list of sample distribution values (nested list with appropriate parameters).
Inherited methods
new()
Initialization method sets parameter names when provided.
LatinHypercubeSampler$new(parameter_names = NULL, ...)
parameter_names
Optional vector of sample parameter names.
...
Additional parameters passed individually.
set_class_parameter()
Sets a parameter to sampled from a vector of classes.
LatinHypercubeSampler$set_class_parameter(parameter_name, classes)
parameter_name
Character string name of sample parameter.
classes
Vector of class values.
set_uniform_parameter()
Sets a parameter to be sampled from a uniform
distribution with lower and upper bounds, optionally rounded to a specified number of decimal places.
LatinHypercubeSampler$set_uniform_parameter(
parameter_name,
lower = 0,
upper = 1,
decimals = NULL
)
parameter_name
Character string name of sample parameter.
lower
Lower bound of the uniform distribution (default = 0).
upper
Upper bound of the uniform distribution (default = 1).
decimals
Optional number of decimals applied to generated samples.
set_normal_parameter()
Sets a parameter to be sampled from a normal
distribution with mean and standard deviation, optionally rounded to a specified number of decimal places.
LatinHypercubeSampler$set_normal_parameter(
parameter_name,
mean = 0,
sd = 1,
decimals = NULL
)
parameter_name
Character string name of sample parameter.
mean
Mean parameter for the normal distribution (default = 0).
sd
Standard deviation parameter for the normal distribution (default = 1).
decimals
Optional number of decimals applied to generated samples.
set_poisson_parameter()
Sets a parameter to be sampled from a Poisson
distribution with lambda parameter. Produces integers.
LatinHypercubeSampler$set_poisson_parameter(parameter_name, lambda = 1)
parameter_name
Character string name of sample parameter.
lambda
Lambda parameter for the Poisson distribution. Must be positive (default = 1).
set_lognormal_parameter()
Sets a parameter to be sampled from a lognormal
distribution with log mean and log standard deviation, optionally expressed as regular mean and SD (overriding log mean/sd), and optionally rounded to a specified number of decimal places.
LatinHypercubeSampler$set_lognormal_parameter(
parameter_name,
meanlog = 0,
sdlog = 1,
mean = NULL,
sd = NULL,
decimals = NULL
)
parameter_name
Character string name of sample parameter.
meanlog
Log mean parameter for the lognormal distribution (default = 0).
sdlog
Log standard deviation parameter for the lognormal distribution (default = 1).
mean
Optional (overriding) regular mean parameter for the lognormal distribution (default = NULL).
sd
Optional (overriding) standard deviation parameter for the lognormal distribution (default = NULL).
decimals
Optional number of decimals applied to generated samples.
set_beta_parameter()
Sets a parameter to be sampled from a beta
distribution configured with alpha and beta parameters, or optionally with mean and standard deviation (overriding alpha and beta), and optionally rounded to a specified number of decimal places.
LatinHypercubeSampler$set_beta_parameter(
parameter_name,
alpha = 1,
beta = 1,
mean = NULL,
sd = NULL,
decimals = NULL
)
parameter_name
Character string name of sample parameter.
alpha
Shaping (towards 1) parameter (> 0) for the beta distribution (default = 1).
beta
Shaping (towards 0) parameter (> 0) for the beta distribution (default = 1).
mean
Optional (overriding) mean parameter for the beta distribution (default = NULL).
sd
Optional (overriding) standard deviation parameter for the beta distribution (default = NULL).
decimals
Optional number of decimals applied to generated samples.
set_truncnorm_parameter()
Sets a parameter to be sampled from a truncated normal
distribution with mean, standard deviation, and lower and upper bounds, optionally rounded to a specified number of decimal places.
LatinHypercubeSampler$set_truncnorm_parameter(
parameter_name,
mean = 0,
sd = 1,
lower = -Inf,
upper = Inf,
decimals = NULL
)
parameter_name
Character string name of sample parameter.
mean
Mean parameter of the truncated normal distribution (default = 0).
sd
Standard deviation of the truncated normal distribution (default = 1).
lower
Lower bound of the truncated normal distribution (default = -Inf, meaning no lower bound).
upper
Upper bound of the truncated normal distribution (default = Inf, meaning no upper bound).
decimals
Optional number of decimals that generated samples are rounded to.
set_triangular_parameter()
Sets a parameter to be sampled from a triangular
distribution with lower and upper bounds and mode (peak), optionally rounded to a specified number of decimal places.
LatinHypercubeSampler$set_triangular_parameter(
parameter_name,
lower = 0,
upper = 1,
mode = (lower + upper)/2,
decimals = NULL
)
parameter_name
Character string name of sample parameter.
lower
Lower bound of the triangular distribution (default = 0).
upper
Upper bound of the triangular distribution (default = 1).
mode
Mode (or peak) of the triangular distribution (default = (lower + upper)/2).
decimals
Optional number of decimals applied to generated samples.
generate_samples()
Generates Latin hypercube sample data (via randomLHS
) for the set parameters using corresponding distributions.
LatinHypercubeSampler$generate_samples(number = 10, random_seed = NULL)
number
Number of samples to generate (default = 10).
random_seed
Optional seed for the random generation of samples.
A data frame of generated sample values.
clone()
The objects of this class are cloneable with this method.
LatinHypercubeSampler$clone(deep = FALSE)
deep
Whether to make a deep clone.
lhs_gen <- LatinHypercubeSampler$new(parameter_names = c("size", "age", "km", "price"))
lhs_gen$set_class_parameter("size", c("small", "medium", "large"))
lhs_gen$set_uniform_parameter("age", lower = 18, upper = 70, decimals = 0)
lhs_gen$set_poisson_parameter("offspring", lambda = 2)
lhs_gen$set_normal_parameter("km", mean = 50000, sd = 20000, decimals = 0)
lhs_gen$set_truncnorm_parameter("kg", mean = 75, sd = 20, lower = 0, upper = Inf, decimals = 2)
lhs_gen$set_lognormal_parameter("price", mean = 30000, sd = 10000, decimals = 0)
lhs_gen$set_beta_parameter("tread", mean = 0.7, sd = 0.1, decimals = 2)
lhs_gen$set_triangular_parameter("rating",
lower = 0, upper = 10, mode = 5,
decimals = 1
)
lhs_gen$generate_samples(number = 10, random_seed = 123)
Run the code above in your browser using DataLab