Created
February 27, 2018 12:18
-
-
Save n8thangreen/63b68041ce85d1bd38fe275a1b451072 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Branch Joint Probability | |
#' | |
#' @param probs Branch conditional probabilities (array) | |
#' | |
#' @return | |
#' @export | |
#' | |
#' @examples | |
#' branch_joint_probs(probs) * cost | |
#' | |
branch_joint_probs <- function(probs) { | |
struct <- apply(probs, 2, function(x) !is.na(x)) | |
num_from_nodes <- nrow(struct) | |
num_to_nodes <- ncol(struct) | |
for (i in 1:num_from_nodes) { | |
for (j in 1:num_from_nodes) { | |
if (!is.na(probs[i, j])) { | |
probs[j, ] <- probs[j, ] * as.numeric(probs[i, j]) | |
} | |
} | |
} | |
return(probs) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment