R/helper_bnlearn.R

Defines functions bnfit_to_cpts

Documented in bnfit_to_cpts

#' bnfit to cpts
#'
#' Convert a \code{bn.fit} object (a list of cpts from the bnlearn package)
#' into a list of ordinary array-like cpts
#'
#' @param x A \code{bn.fit} object
#' @export
bnfit_to_cpts <- function(x) {
  cpts <- lapply(x, function(e) {
    ep <- e$prob
    if (length(dim(ep)) == 1L) {
      en <- structure(list(dimnames(ep)[[1]]), names = e$node)
      dimnames(ep) <- en
    }
    ep
  })
}

Try the jti package in your browser

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

jti documentation built on April 12, 2022, 9:05 a.m.