R/methods.R

globalVariables(c("error", "func", "eq", "id", "label", "y", "derivate", "type"))

#' @export
print.brain <- function(x, ...) {
  #print("brain", ...)
  .prt(x)
}

#' @export
plot.log <- function(x, ...){
  par(mfrow=c(2,1))
  plot(x$iteration, x$error, xlab = "iterations", ylab = "error", type = "l")
  points(x %>% dplyr::filter(error == min(error)), col = "red", pch = 19)
  plot(x$iteration, x$rate, xlab = "iterations", ylab = "learning rate", type = "l")
  par(mfrow=c(1,1))
}

#' @export
print.squash_function <- function(x, ...){
  fun <- gsub("_activation", "", x)
  cat(
    crayon::yellow(cli::symbol$info), fun,": ",
    activations %>% dplyr::filter(func == fun) %>% dplyr::pull(eq),
    "\n"
  )
}

#' @export
print.cost_function <- function(x, ...){
  fun <- gsub("opts\\['cost'\\] = synaptic.trainer.cost.", "", tolower(x))
  cat(
    crayon::yellow(cli::symbol$info), fun,":",
    "\n"
  )
}
brain-r/brain documentation built on May 21, 2019, 4:05 a.m.