-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from inesortega/v1.1.1
V1.1.0 - Updates after CRAN submission
- Loading branch information
Showing
15 changed files
with
520 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,5 @@ sudo: false | |
cache: packages | ||
after_success: | ||
- Rscript -e 'covr::codecov()' | ||
ignore: | ||
- "R/install.R" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
library(testthat) | ||
library(reticulate) | ||
|
||
skip_if_no_keras <- function() { | ||
|
||
if (!tryCatch( | ||
reticulate::py_module_available("keras"), | ||
error = function(e) return(FALSE) | ||
) | ||
) skip("keras not available for testing...") | ||
} | ||
|
||
# Test case 1: function throws error for missing num_units | ||
test_that("build_feature_NN throws an error for missing num_units", { | ||
skip_if_no_keras() | ||
|
||
# Missing num_units | ||
expect_error(neuralGAM:::build_feature_NN()) | ||
}) | ||
|
||
# num_units is not numeric or vector of integers | ||
test_that("Invalid num_units argument", { | ||
skip_if_no_keras() | ||
expect_error(neuralGAM:::build_feature_NN(num_units = "string")) | ||
}) | ||
|
||
# num_units is not numeric or vector of integers | ||
test_that("Invalid num_units argument", { | ||
skip_if_no_keras() | ||
expect_error(neuralGAM:::build_feature_NN(num_units = c("string", "string2"))) | ||
}) | ||
|
||
# learning_rate is not numeric | ||
test_that("Invalid learning_rate argument", { | ||
skip_if_no_keras() | ||
expect_error(neuralGAM:::build_feature_NN(num_units = 10, learning_rate = "string")) | ||
}) | ||
|
||
# name is not NULL or character string | ||
test_that("Invalid name argument", { | ||
skip_if_no_keras() | ||
expect_error(neuralGAM:::build_feature_NN(num_units = 10, name = 123)) | ||
}) | ||
|
||
# Valid function call | ||
test_that("Valid function call", { | ||
skip_if_no_keras() | ||
testthat::expect_no_error(neuralGAM:::build_feature_NN(num_units = 10, learning_rate = 0.001, name = "test")) | ||
}) | ||
|
||
# Valid function call | ||
test_that("Valid function call with deep layer", { | ||
skip_if_no_keras() | ||
testthat::expect_no_error(neuralGAM:::build_feature_NN(num_units = c(10,20), learning_rate = 0.001, name = "test")) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
library(testthat) | ||
library(reticulate) | ||
|
||
skip_if_no_keras <- function() { | ||
|
||
if (!tryCatch( | ||
reticulate::py_module_available("keras"), | ||
error = function(e) return(FALSE) | ||
) | ||
) skip("keras not available for testing...") | ||
} | ||
|
||
# Test case 1: Check the neuralGAM:::deviance for gaussian family | ||
test_that("neuralGAM:::deviance for gaussian family should be correctly calculated", { | ||
skip_if_no_keras() | ||
|
||
family <- "gaussian" | ||
muhat <- c(0.1, 0.5, 0.9) | ||
y <- c(0.2, 0.6, 0.8) | ||
expected_output <- mean((y - muhat)^2) | ||
actual_output <- neuralGAM:::dev(muhat, y, family) | ||
expect_equal(actual_output, expected_output) | ||
}) | ||
|
||
# Test case 2: Check the neuralGAM:::deviance for binomial family | ||
test_that("neuralGAM:::deviance for binomial family should be correctly calculated", { | ||
skip_if_no_keras() | ||
|
||
family <- "binomial" | ||
muhat <- c(0.2, 0.7, 0.99) | ||
y <- c(0, 1, 1) | ||
|
||
muhat[muhat < 0.0001] <- 0.0001 | ||
muhat[muhat > 0.9999] <- 0.9999 | ||
|
||
entrop <- rep(0, length(y)) | ||
ii <- (1 - y) * y > 0 | ||
if (sum(ii, na.rm = TRUE) > 0) { | ||
entrop[ii] <- 2 * (y[ii] * log(y[ii])) + | ||
((1 - y[ii]) * log(1 - y[ii])) | ||
} else { | ||
entrop <- 0 | ||
} | ||
entadd <- 2 * (y * log(muhat)) + ((1 - y) * log(1 - muhat)) | ||
expected_output <- sum(entrop - entadd, na.rm = TRUE) | ||
|
||
actual_output <- neuralGAM:::dev(muhat, y, family) | ||
expect_equal(actual_output, expected_output) | ||
}) | ||
|
||
# Test case 3: Check for missing 'muhat' argument | ||
test_that("Function should throw an error for missing 'muhat' argument", { | ||
skip_if_no_keras() | ||
|
||
family <- "gaussian" | ||
y <- c(0.2, 0.6, 0.8) | ||
expect_error(neuralGAM:::dev(y = y, family = family)) | ||
}) | ||
|
||
# Test case 4: Check for missing 'y' argument | ||
test_that("Function should throw an error for missing 'y' argument", { | ||
skip_if_no_keras() | ||
|
||
family <- "gaussian" | ||
muhat <- c(0.1, 0.5, 0.9) | ||
expect_error(neuralGAM:::dev(muhat = muhat, family = family)) | ||
}) | ||
|
||
# Test case 5: Check for missing 'family' argument | ||
test_that("Function should throw an error for missing 'family' argument", { | ||
skip_if_no_keras() | ||
|
||
muhat <- c(0.1, 0.5, 0.9) | ||
y <- c(0.2, 0.6, 0.8) | ||
expect_error(neuralGAM:::dev(muhat = muhat, y = y)) | ||
}) | ||
|
||
# Test case 6: Check for unsupported family | ||
test_that("Function should throw an error for unsupported 'family'", { | ||
skip_if_no_keras() | ||
|
||
family <- "poisson" | ||
muhat <- c(0.1, 0.5, 0.9) | ||
y <- c(0.2, 0.6, 0.8) | ||
expect_error(neuralGAM:::dev(muhat, y, family)) | ||
}) |
Oops, something went wrong.