Skip to contents

Compute the expectation of some query variable(s), optionally conditioned on some event(s).

Usage

expct(
  params,
  query = NULL,
  evidence = NULL,
  evidence_row_mode = c("separate", "or"),
  stepsize = 0,
  parallel = TRUE
)

Arguments

params

Circuit parameters learned via forde.

query

Optional character vector of variable names. Estimates will be computed for each. If NULL, all variables other than those in evidence will be estimated. If evidence contains NAs, those variables will be estimated and a full dataset is returned.

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 in evidence is a separate conditioning event for which n_synth synthetic samples are generated. If 'or', the rows are combined with a logical or; see Examples.

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.

Value

A one row data frame with values for all query variables.

Details

This function computes expected values for any subset of features, optionally conditioned on some event(s).

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.

Examples

# Train ARF and estimate leaf parameters
arf <- adversarial_rf(iris)
#> Iteration: 0, Accuracy: 86.2%
#> Iteration: 1, Accuracy: 44.63%
psi <- forde(arf, iris)

# What is the expected value of Sepal.Length?
expct(psi, query = "Sepal.Length")
#>   Sepal.Length
#> 1          5.8

# What if we condition on Species = "setosa"?
evi <- data.frame(Species = "setosa")
expct(psi, query = "Sepal.Length", evidence = evi)
#>   Sepal.Length
#> 1            5

# Compute expectations for all features other than Species
expct(psi, evidence = evi)
#>   Sepal.Length Sepal.Width Petal.Length Petal.Width
#> 1            5         3.4          1.5         0.3

# 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 <- expct(psi, evidence = evi)