≡ Menu

Calculating Conditional Entropy in R

 

conditionalEntropy <- function( graph ) {
   # graph is a 2 or 3 column dataframe
   if (ncol(graph) == 2 ) {
      names(graph) <- c("from","to")
      graph$weight <- 1
   } else if (ncol(graph) == 3)
      names(graph) <- c("from","to","weight")
   max <- length(rle(paste(graph$from, graph$to))$values)
   total <- sum(graph$weight)
   entropy <- data.frame(H = 0, Hmax = 0);
   entropy$H <- sum(graph$weight/total * log(graph$weight/total) / log(2)) * -1
   entropy$Hmax <- log(max * (max-1))/log(2)
   return(entropy)
}

 

Related Posts

  • Measuring Load in the Cloud: Correcting for SeasonalityMeasuring Load in the Cloud: Correcting for Seasonality
  • Load Volatility and Resource Planning for your CloudLoad Volatility and Resource Planning for your Cloud
  • Determining Application Performance Profiles in the CloudDetermining Application Performance Profiles in the Cloud
  • The Lambert Effect – Subtleties in Cloud ModelingThe Lambert Effect – Subtleties in Cloud Modeling
  • Analyzing Cloud Performance with CloudForms and RAnalyzing Cloud Performance with CloudForms and R
  • Graphing Wall Street with LittleSis.orgGraphing Wall Street with LittleSis.org
{ 0 comments… add one }