tests/testthat/test-suffix_tree_pruning_vlmc.R

test_that("the C++ context algorithm selects the same PST as the R implementation", {
  withr::local_seed(10)
  for (k in 1:9) {
    x <- sample(0:k, 10000, replace = TRUE)
    model <- vlmc(x)
    x_rev <- rev(x)
    tree <- build_suffix_tree(x_rev[-1], k + 1)
    tree$compute_counts(x_rev[1], FALSE)
    tree$prune_context(2, length(x) / 10, model$cutoff)
    ctx_cpp <- tree$contexts(1, -1)
    ctx_r <- unclass(contexts(model, sequence = TRUE, reverse = TRUE)[["context"]])
    expect_equal(length(ctx_cpp), length(ctx_r))
    expect_true(compare_ctx(ctx_r, ctx_cpp))
  }
})

Try the mixvlmc package in your browser

Any scripts or data that you put into this service are public.

mixvlmc documentation built on June 8, 2025, 12:35 p.m.