R/bd_decode.R

Defines functions bd_decode

#' Convert strings into matrices
#'
#' This function restores matrices from string objects.
#' It is implemented in several functions, such as \code{get_causal_effect} and \code{get_edge_probs}, when output of \code{learn_DAG} was obtained with \code{save.memory = TRUE}
#'
#' @param string a string to convert into matrix
#' @param separator symbol used to separate elements in the input string
#'
#' @return The (q,q) original matrix from which the string vector was created using the internal function \code{bd_encode}
#'
#' @noRd
#' @keywords internal

bd_decode <- function(string, separator = ";") {
  vec4mat <- as.numeric(strsplit(string, separator)[[1]])
  q <- length(vec4mat)
  matrix(vec4mat, ncol = sqrt(q))
}

Try the BCDAG package in your browser

Any scripts or data that you put into this service are public.

BCDAG documentation built on April 4, 2025, 1:41 a.m.