Skip to content

juliangruber/binary-shannon-entropy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

binary-shannon-entropy

Calculate the shannon entropy of a buffer.

build status

Example

var calc = require('binary-shannon-entropy');

calc(Buffer('aaaaa'));  // => 0
calc(Buffer('fffff'));  // => 0
calc(Buffer('aafaa'));  // => 0.7219280948873623
calc(Buffer('abcdef')); // => 2.584962500721156

Installation

$ npm install binary-shannon-entropy

API

calc(buf[, start][, end])

Return a number between 0 and 8, giving the Shannon entropy to the base of 2.

Optionally limit the area in the buffer to inspect by start and end.

Algorithm

H = -Sum(P_i * log2(P_i))

License

MIT