#' Reset
#'
#' Resets the brain, removing everything, including the architecture.
#'
#' @inheritParams architecture
#'
#' @export
clear <- function(brain){
brain$brain$eval("net.clear()")
return(brain)
}
#' Optimize
#'
#' Deativate self optimization of the network.
#'
#' @inheritParams architecture
#' @param opt Set to \code{FALSE} to deactivate self-optimization.
#'
#' @note Makes the learning slower but consumes less memory.
#'
#' @export
optimize_brain <- function(brain, opt = FALSE){
brain$brain$eval(
paste0("net.setOptimize(", tolower(opt), ")")
)
return(brain)
}
#' Balance
#'
#' Scale data (input and output) between 0 and 1.
#'
#' @param x A vector of class \code{numeric}
#'
#' @examples
#' x <- rnorm(20, 3, 7)
#'
#' range(x)
#'
#' (scaled <- balance(x))
#'
#' range(scaled)
#'
#' @export
balance <- function(x){
if(!inherits(x, "numeric") & !inherits(x, "integer")){
cat(
crayon::yellow(cli::symbol$star), "x is not numeric, not scaling.\n"
)
return(x)
} else {
return((x - min(x)) / (max(x) - min(x)))
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.