Skip to content

Commit

Permalink
Updated fix for Issue #214
Browse files Browse the repository at this point in the history
test: added test cases for `tune.spls()`. These are just placeholders as more robust testing criteria needs to be established as well as this document will be fully updated as part of PR #206
  • Loading branch information
Max-Bladen committed Dec 13, 2022
1 parent 27e8097 commit 2ec08e7
Showing 1 changed file with 22 additions and 51 deletions.
73 changes: 22 additions & 51 deletions tests/testthat/test-tune.spls.R
Original file line number Diff line number Diff line change
@@ -1,59 +1,30 @@
context("tune.spls")

test_that("tune.spls works with and without parallel", code = {
test_that("tune.spls works ", code = {
data("nutrimouse")
X <- nutrimouse$gene
Y <- nutrimouse$lipid
test.keepX <- c(5,10)
ncomp <- 2
nrepeat <- 3
folds <- 3

RNGversion(.mixo_rng()) ## in case RNG changes!
set.seed(42)
tune.spls.res = tune.spls(X, Y, ncomp = 3,
test.keepX = seq(5, 10, 5),
test.keepY = seq(3, 6, 3), measure = "cor",
folds = 5, nrepeat = 3, progressBar = F)

## ----------- tune.spls works fine -----------
set.seed(12)
tune.spls11 <-
tune.spls(
X = X,
Y = Y,
ncomp = ncomp,
measure = 'cor',
test.keepX = test.keepX,
test.keepY = test.keepX,
folds = folds,
nrepeat = nrepeat
)
expect_is(tune.spls11, "tune.spls")
expect_equal(c(comp1 = 10, comp2 = 5), tune.spls11$choice.keepX)
expect_equal(c(comp1 = 5, comp2 = 5), tune.spls11$choice.keepY)
expect_equal(class(tune.spls.res), c("tune.pls", "tune.spls"))
})

test_that("tune.spls works in parallel", code = {

## ----------- tune(method="spls") same as tune.spls -----------
set.seed(12)
tune.spls12 <-
tune(
method = "spls",
X = X,
Y = Y,
ncomp = ncomp,
measure = 'cor',
test.keepX = test.keepX,
test.keepY = test.keepX,
folds = folds,
nrepeat = nrepeat
)
library(BiocParallel)
data("nutrimouse")
X <- nutrimouse$gene
Y <- nutrimouse$lipid

.almost_identical(tune.spls11, tune.spls12)
set.seed(42)
tune.spls.res = suppressWarnings(tune.spls(X, Y, ncomp = 3,
test.keepX = seq(1, 10, 1),
test.keepY = seq(3, 6, 3), measure = "cor",
folds = 5, nrepeat = 3, progressBar = F,
BPPARAM = SnowParam(workers = 4)))

## ----------- tune.spls parallel works fine -----------
# set.seed(12)
# tune.spls31 <- tune.spls(X, Y, ncomp = ncomp, test.keepX = test.keepX, folds = folds,
# nrepeat = nrepeat, BPPARAM = SnowParam(workers = 2, RNGseed = 12))
# TODO tune.spls runs full model nrepeat times for each keepX and keepY!
# TODO tune.spls fails with SnowParam
# expect_is(tune.spls31, "tune.spls")
# set.seed(12)
# tune.spls13 <- tune(method = "spls", X = X, Y = Y, ncomp = ncomp, test.keepX = test.keepX, folds = folds,
# nrepeat = nrepeat, cpus = 2)
# .almost_identical(tune.spls13, tune.spls31)
})
expect_equal(class(tune.spls.res), c("tune.pls", "tune.spls"))
})

0 comments on commit 2ec08e7

Please sign in to comment.