testthat::test_that("max_split_depth retains deepest-splittable-node semantics", { set.seed(10) invisible(capture.output( fit <- boostPM::fit_boostpm( matrix(c(0.1, 0.3, 0.7, 0.9), ncol = 1L), add_noise = FALSE, Omega = matrix(c(0, 1), nrow = 1L), max_marginal_trees = 1, max_dependence_trees = 0, c0 = 0.1, gamma = 0, max_split_depth = 0, min_node_observations = 1, prior_split_prob = 1, n_bins = 2 ) )) testthat::expect_identical(fit$tree_diagnostics$node_count, 3L) testthat::expect_identical(fit$tree_diagnostics$max_depth, 1L) }) testthat::test_that("split equality is assigned left during fit and evaluation", { set.seed(11) invisible(capture.output( fit <- boostPM::fit_boostpm( matrix(c(0.25, 0.5, 0.75), ncol = 1L), add_noise = FALSE, Omega = matrix(c(0, 1), nrow = 1L), max_marginal_trees = 1, max_dependence_trees = 0, c0 = 0.9, gamma = 0, max_split_depth = 0, min_node_observations = 1, prior_split_prob = 1, n_bins = 2 ) )) testthat::expect_equal(fit$trees[[1]]$theta[[1]], 0.65, tolerance = 1e-15) expected_importance <- (2 / 3) * log(0.65 / 0.5) + (1 / 3) * log(0.35 / 0.5) testthat::expect_lte( abs(as.numeric(fit$variable_importance) - expected_importance), 1e-15 ) at_boundary <- stats::predict( fit, matrix(0.5, ncol = 1L), type = "details" ) testthat::expect_equal( as.numeric(at_boundary$log_density), log(0.65 / 0.5), tolerance = 1e-15 ) }) testthat::test_that("density outside Omega has log density negative infinity", { fit <- make_one_split_fit(theta = 0.25, location = 0.5) outside <- matrix(c(-0.1, 0.25, 1.1), ncol = 1L) result <- stats::predict(fit, outside, type = "details") testthat::expect_identical( as.numeric(result$log_density), c(-Inf, log(0.5), -Inf) ) testthat::expect_identical(result$mean_log_density_path, -Inf) }) testthat::test_that("a rejected early-stopping tree is not stored or applied", { data <- small_two_dimensional_data() set.seed(12) invisible(capture.output( fit <- boostPM::fit_boostpm( data, add_noise = FALSE, Omega = cbind(c(0, 0), c(1, 1)), max_marginal_trees = 5, max_dependence_trees = 5, c0 = 0.1, gamma = 0, max_split_depth = 1, min_node_observations = 1, early_stop = c(200, 2), prior_split_prob = 0.9, n_bins = 4 ) )) testthat::expect_length(fit$trees, 0L) testthat::expect_equal(nrow(fit$tree_diagnostics), 0L) testthat::expect_length(fit$heldout_diagnostics$mean_log_density_improvement, 3L) testthat::expect_false(any(fit$heldout_diagnostics$accepted)) testthat::expect_equal(fit$residual_coordinates, t(data), tolerance = 1e-15) })