Skip to content

Commit

Permalink
more changes for consistency with Python tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jameslamb committed Jun 15, 2021
1 parent 96e7c78 commit 4950ed3
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions R-package/tests/testthat/test_basic.R
Original file line number Diff line number Diff line change
Expand Up @@ -2129,11 +2129,17 @@ context("monotone constraints")
return(any(diff(y) < 0.0) & any(diff(y) > 0.0))
}

# R equivalent of numpy.linspace()
.linspace <- function(start_val, stop_val, num) {
weights <- (seq_len(num) - 1L) / (num - 1L)
return(start_val + weights * (stop_val - start_val))
}

.is_correctly_constrained <- function(learner, x3_to_categorical) {
iterations <- 10L
n <- 1000L
variable_x <- seq_len(n) / n
fixed_xs_values <- seq_len(n) / n
variable_x <- .linspace(0L, 1L, n)
fixed_xs_values <- .linspace(0L, 1L, n)
for (i in seq_len(iterations)) {
fixed_x <- fixed_xs_values[i] * rep(1.0, n)
monotonically_increasing_x <- matrix(
Expand Down Expand Up @@ -2207,7 +2213,7 @@ for (x3_to_categorical in c(TRUE, FALSE)) {
params = params
, data = dtrain
, obj = "regression_l2"
, nrounds = 10L
, nrounds = 100L
)
expect_true({
.is_correctly_constrained(
Expand Down

0 comments on commit 4950ed3

Please sign in to comment.