What is Entropy of each character in a txt file or in a string and how to do it in java?

Viewed 130

I have already seen some questions and answers related to this topic. But they are actually for mathematics and python related. I want to learn what does it mean by entropy of a character in a txt file or in a string and what are the possible ways to find it using Java language.

Thank you.

1 Answers

A single character, in isolation, does not possess entropy (well, I suppose we could say we have a one-in-N chance of guessing it, for an alphabet of N possible characters). 'Entropy' is the absence of order. Thus, the more 'random' a character is in context, the higher its entropy.

Consider the five-character sequence 'banan'. If the next character is 'a', it carries very low entropy - it is highly likely that the sequence as a whole is the word 'banana'.

In order to determine entropy by program, you need knowledge of probabilities. If the domain is 'words', then you need at least to know the likelihood of one letter following from a particular short sequence. Alternatively, given a reasonably complete dictionary, you could compute that likelihood.

There are more technical descriptions, such as the minimum number of bits needed to encode a string. Is that what you had in mind? See this Wikipedia page for example.

Related