Skip to content

Instantly share code, notes, and snippets.

@audy
Created August 31, 2010 19:34
Show Gist options
  • Select an option

  • Save audy/559593 to your computer and use it in GitHub Desktop.

Select an option

Save audy/559593 to your computer and use it in GitHub Desktop.
# SHANNON ENTROPY FUNCTION
def entropy(string)
entropy = 0
prob = []
string.split(//).uniq.each do |c|
prob << string.count(c).to_f / string.length
end
prob.each do |p|
entropy += p*Math.log(p)/Math.log(2.0)
end
-entropy
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment