R/parse_losses_from_train_v_file.R

Defines functions parse_losses_from_train_v_file

Documented in parse_losses_from_train_v_file

#' Parse the `losses_from_train_v.csv` file
#'
#' Parse the `losses_from_train_v.csv` file
#' @inheritParams default_params_doc
#' @return a tibble with columns:
#'  * `n`: the epoch
#'  * `t`: the time this epoch took, in seconds
#' @author Richèl J.C. Bilderbeek
#' @export
parse_losses_from_train_v_file <- function(losses_from_train_v_filename) {
  testthat::expect_true(file.exists(losses_from_train_v_filename))
  text <- readr::read_lines(file = losses_from_train_v_filename)
  text_matrix <- stringr::str_split(text, pattern = ",", simplify = TRUE)
  testthat::expect_equal(2, nrow(text_matrix))
  t <- tibble::tibble(
    epoch = as.numeric(text_matrix[1, ]),
    losses_from_train_v = as.numeric(text_matrix[2, ])
  )
  t
}
richelbilderbeek/gcaer documentation built on March 25, 2024, 3:08 p.m.