1 year ago

#342715

test-img

spazznolo

Create n length vector with given entropy

I'm looking to create a n length binary sequence with specific entropy. For example, a sequence of 100 with values 0 or 1 with entropy 0.01. Is this possible? Can be done in either R or Python. Here's the function I'm using to calculate entropy.

norm_ent <- function(s){
  
  s1 <- which(s %in% 1)
  
  iet <- c(s1[1], diff(s1), length(s)+1-tail(s1,1))
  
  iet <- iet/(length(s)+1)
  
  h <- 1+((sum(log(iet)*iet))/log(sum(s)+1))
  
  return(h)
  
}

python

r

entropy

0 Answers

Your Answer

Accepted video resources