-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
richelbilderbeek
committed
Jun 14, 2022
1 parent
3c032f0
commit 677b9d1
Showing
14 changed files
with
268 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#' Create a GCAE model to be used in testing | ||
#' | ||
#' Create a GCAE model to be used in testing | ||
#' @inheritParams default_params_doc | ||
#' @return a GCAE model | ||
#' @examples | ||
#' create_test_model() | ||
#' check_model(create_test_model()) | ||
#' @author Richèl J.C. Bilderbeek | ||
#' @export | ||
create_test_model <- function( | ||
model_filename = gcaer::get_gcaer_filename("M0.json") | ||
) { | ||
gcaer::read_model_file(model_filename) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#' Get the number of neurons in the layent layer from a `model` | ||
#' | ||
#' Get the number of neurons in the layent layer from a `model` | ||
#' @inheritParams default_params_doc | ||
#' @return the number of neurons in the latent layer | ||
#' @seealso use \link{get_n_neurons_in_latent_layer} | ||
#' to get the number of neurons in the latent layer | ||
#' for different input arguments | ||
#' @examples | ||
#' if (is_gcae_repo_cloned()) { | ||
#' # A real GCAE file | ||
#' model_filename <- get_gcae_model_filename("M1") | ||
#' } else { | ||
#' # An example file | ||
#' model_filename <- get_gcaer_filename("M0.json") | ||
#' } | ||
#' model <- read_model_file(model_filename) | ||
#' get_n_neurons_in_latent_layer_from_model(model) | ||
#' @author Richèl J.C. Bilderbeek | ||
#' @export | ||
get_n_neurons_in_latent_layer_from_model <- function(model) { | ||
gcaer::check_model(model) | ||
if (length(model$layers) == 1) { | ||
return(model$layers[[1]]$args$units) | ||
} | ||
|
||
is_dense <- purrr::map_lgl(model$layers, function(e) e$class == "Dense") | ||
has_name <- purrr::map_lgl( | ||
model$layers, | ||
function(e) "name" %in% names(e$args) | ||
) | ||
layer_index <- which(is_dense & has_name) | ||
testthat::expect_equal(1, length(layer_index)) | ||
model$layers[[layer_index]]$args$units[[1]] | ||
} |
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,27 @@ | ||
#' Determine if the `model` is indeed a `model` | ||
#' @inheritParams default_params_doc | ||
#' @return \link{TRUE} if the `model` is indeed a `model` | ||
#' @examples | ||
#' # TRUE | ||
#' is_model(model = create_test_model()) | ||
#' | ||
#' # FALSE | ||
#' is_model(model = "nonsense") | ||
#' is_model(model = "nonsense", verbose = TRUE) | ||
#' @author Richèl J.C. Bilderbeek | ||
#' @export | ||
is_model <- function( | ||
model, | ||
verbose = FALSE | ||
) { | ||
plinkr::check_verbose(verbose) | ||
result <- FALSE | ||
tryCatch({ | ||
gcaer::check_model(model = model) | ||
result <- TRUE | ||
}, error = function(e) { | ||
if (verbose) message(e$message) | ||
} | ||
) | ||
result | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
test_that("use", { | ||
check_model(create_test_model()) | ||
}) |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
test_that("use", { | ||
expect_equal(1 + 1, 2) # Prevents testthat warning for empty test | ||
# See test-gcae_workflow for the use of gcae_project | ||
# See test-do_gcae_experiment for the use of gcae_project | ||
}) |
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 |
---|---|---|
@@ -1,46 +1,14 @@ | ||
test_that("M0, example file", { | ||
test_that("M0, from model", { | ||
model_filename <- get_gcaer_filename("M0.json") | ||
model <- read_model_file(model_filename) | ||
n_neurons <- get_n_neurons_in_latent_layer(model) | ||
expect_equal(2, n_neurons) | ||
}) | ||
|
||
test_that("M0, GCAE file", { | ||
if (!is_gcae_script_fixed()) return() | ||
model_filename <- get_gcae_model_filename("M0") | ||
model <- read_model_file(model_filename) | ||
n_neurons <- get_n_neurons_in_latent_layer(model) | ||
expect_equal(2, n_neurons) | ||
}) | ||
|
||
test_that("M1", { | ||
if (!is_gcae_script_fixed()) return() | ||
model_filename <- get_gcae_model_filename("M1") | ||
model <- read_model_file(model_filename) | ||
n_neurons <- get_n_neurons_in_latent_layer(model) | ||
expect_equal(2, n_neurons) | ||
}) | ||
|
||
test_that("M3d", { | ||
if (!is_gcae_script_fixed()) return() | ||
model_filename <- get_gcae_model_filename("M3d") | ||
model <- read_model_file(model_filename) | ||
n_neurons <- get_n_neurons_in_latent_layer(model) | ||
expect_equal(2, n_neurons) | ||
}) | ||
|
||
test_that("M3e", { | ||
if (!is_gcae_script_fixed()) return() | ||
model_filename <- get_gcae_model_filename("M3e") | ||
model <- read_model_file(model_filename) | ||
n_neurons <- get_n_neurons_in_latent_layer(model) | ||
expect_equal(2, n_neurons) | ||
}) | ||
|
||
test_that("M3f", { | ||
if (!is_gcae_script_fixed()) return() | ||
model_filename <- get_gcae_model_filename("M3f") | ||
model <- read_model_file(model_filename) | ||
n_neurons <- get_n_neurons_in_latent_layer(model) | ||
test_that("M0, from gcae_experiment_params", { | ||
skip("nsphs_ml_qt #55") | ||
gcae_experiment_params <- create_test_gcae_experiment_params() | ||
expect_equal("M0", gcae_experiment_params$gcae_setup$model_id) | ||
n_neurons <- get_n_neurons_in_latent_layer(gcae_experiment_params) | ||
expect_equal(2, n_neurons) | ||
}) |
Oops, something went wrong.