Implements conditional sampling using Knockoffs.
Details
The KnockoffSampler samples Knockoffs based on the task data.
This class allows arbitrary knockoff_fun
, which also means that no input checking
against supported feature types can be done. Use KnockoffGaussianSampler or
KnockoffSequentialSampler for these variants specifically.
References
Watson D, Wright M (2021). “Testing conditional independence in supervised learning algorithms.” Machine Learning, 110(8), 2107-2129. doi:10.1007/s10994-021-06030-6 .
Blesch K, Watson D, Wright M (2023). “Conditional feature importance for mixed data.” AStA Advances in Statistical Analysis, 108(2), 259-278. doi:10.1007/s10182-023-00477-9 .
Super classes
xplainfi::FeatureSampler
-> xplainfi::ConditionalSampler
-> KnockoffSampler
Methods
Method new()
Creates a new instance of the KnockoffSampler class.
Usage
KnockoffSampler$new(
task,
knockoff_fun = function(x) knockoff::create.second_order(as.matrix(x)),
iters = 1
)
Arguments
task
(mlr3::Task) Task to sample from
knockoff_fun
(
function
) Step size for variance adjustment. Default are second-order Gaussian knockoffs.iters
(
integer(1)
: 1) Number of repetitions theknockoff_fun
is applied to create multiplex_tilde
instances per observation.
Method sample()
Sample from stored task using knockoff values. Replaces specified feature(s) with their knockoff counterparts from the pre-generated knockoff matrix.
Arguments
feature
(
character
) Feature(s) to sample.row_ids
(
integer()
|NULL
) Row IDs to use. IfNULL
, uses all rows.
Examples
library(mlr3)
task = tgen("2dnormals")$generate(n = 100)
# Create sampler with default parameters
sampler = KnockoffSampler$new(task)
# Sample using row_ids from stored task
sampled_data = sampler$sample("x1")
if (FALSE) { # \dontrun{
# Example with sequential knockoffs (https://github.com/kormama1/seqknockoff)
task = tgen("simplex")$generate(n = 100)
sampler_seq = KnockoffSampler$new(task, knockoff_fun = seqknockoff::knockoffs_seq)
sampled_seq = sampler_seq$sample("x1")
} # }