Skip to content

Commit

Permalink
Protection against rare events of null dimension products
Browse files Browse the repository at this point in the history
  • Loading branch information
jenzopr committed Mar 7, 2017
1 parent 6614cc7 commit ec8a32d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion R/pid.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,10 @@ specific_information <- function(probabilities, source="x1", target="z") {
term1 <- sweep(apply(probabilities, c(source, target), sum), 2, apply(probabilities, target, sum), "/")
term2 <- log2(apply(probabilities, c(source,target), sum) / outer_prod)

colSums(apply(term1 * term2, 2, function(x) {x[is.nan(x)] <- 0; x}))
prod <- apply(term1 * term2, 2, function(x) {x[is.nan(x)] <- 0; x})
if(is.null(dim(prod))) {
return(prod)
} else {
return(colSums(prod))
}
}

0 comments on commit ec8a32d

Please sign in to comment.