Uses pre-trained FORDE model to simulate synthetic data.
Arguments
- params
Circuit parameters learned via
forde
.- n_synth
Number of synthetic samples to generate.
- evidence
Optional set of conditioning events. This can take one of three forms: (1) a partial sample, i.e. a single row of data with some but not all columns; (2) a data frame of conditioning events, which allows for inequalities and intervals; or (3) a posterior distribution over leaves; see Details and Examples.
- evidence_row_mode
Interpretation of rows in multi-row evidence. If
'separate'
, each row inevidence
is a separate conditioning event for whichn_synth
synthetic samples are generated. If'or'
, the rows are combined with a logical or; see Examples.- round
Round continuous variables to their respective maximum precision in the real data set?
- sample_NAs
Sample NAs respecting the probability for missing values in the original data.
- nomatch
What to do if no leaf matches a condition in
evidence
? Options are to force sampling from a random leaf, either with a warning ("force_warning"
) or without a warning ("force"
), or to returnNA
, also with a warning ("na_warning"
) or without a warning ("na"
). The default is"force_warning"
.- stepsize
Stepsize defining number of evidence rows handled in one for each step. Defaults to nrow(evidence)/num_registered_workers for
parallel == TRUE
.- parallel
Compute in parallel? Must register backend beforehand, e.g. via
doParallel
ordoFuture
; see examples.
Details
forge
simulates a synthetic dataset of n_synth
samples. First,
leaves are sampled in proportion to either their coverage (if
evidence = NULL
) or their posterior probability. Then, each feature is
sampled independently within each leaf according to the probability mass or
density function learned by forde
. This will create realistic
data so long as the adversarial RF used in the previous step satisfies the
local independence criterion. See Watson et al. (2023).
There are three methods for (optionally) encoding conditioning events via the
evidence
argument. The first is to provide a partial sample, where
some columns from the training data are missing or set to NA
. The second is to
provide a data frame with condition events. This supports inequalities and intervals.
Alternatively, users may directly input a pre-calculated posterior
distribution over leaves, with columns f_idx
and wt
. This may
be preferable for complex constraints. See Examples.
References
Watson, D., Blesch, K., Kapar, J., & Wright, M. (2023). Adversarial random forests for density estimation and generative modeling. In Proceedings of the 26th International Conference on Artificial Intelligence and Statistics, pp. 5357-5375.
See also
arf
, adversarial_rf
, forde
, expct
, lik
Examples
# Train ARF and estimate leaf parameters
arf <- adversarial_rf(iris)
#> Iteration: 0, Accuracy: 76.61%
#> Iteration: 1, Accuracy: 42.47%
psi <- forde(arf, iris)
# Generate 100 synthetic samples from the iris dataset
x_synth <- forge(psi, n_synth = 100)
# Condition on Species = "setosa"
evi <- data.frame(Species = "setosa")
x_synth <- forge(psi, n_synth = 100, evidence = evi)
# Condition on Species = "setosa" and Sepal.Length > 6
evi <- data.frame(Species = "setosa",
Sepal.Length = "(6, Inf)")
x_synth <- forge(psi, n_synth = 100, evidence = evi)
# Alternative syntax for </> conditions
evi <- data.frame(Sepal.Length = ">6")
x_synth <- forge(psi, n_synth = 100, evidence = evi)
# Negation condition, i.e. all classes except "setosa"
evi <- data.frame(Species = "!setosa")
x_synth <- forge(psi, n_synth = 100, evidence = evi)
# Condition on first two data rows with some missing values
evi <- iris[1:2,]
evi[1, 1] <- NA_real_
evi[1, 5] <- NA_character_
evi[2, 2] <- NA_real_
x_synth <- forge(psi, n_synth = 1, evidence = evi)
# Or just input some distribution on leaves
# (Weights that do not sum to unity are automatically scaled)
n_leaves <- nrow(psi$forest)
evi <- data.frame(f_idx = psi$forest$f_idx, wt = rexp(n_leaves))
x_synth <- forge(psi, n_synth = 100, evidence = evi)
if (FALSE) { # \dontrun{
# Parallelization with doParallel
doParallel::registerDoParallel(cores = 4)
# ... or with doFuture
doFuture::registerDoFuture()
future::plan("multisession", workers = 4)
} # }