tanszek:oktatas:techcomm:information
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| tanszek:oktatas:techcomm:information [2025/10/06 20:40] – [Entropy] knehez | tanszek:oktatas:techcomm:information [2026/10/06 07:01] (current) – [Example: three coin tosses] knehez | ||
|---|---|---|---|
| Line 11: | Line 11: | ||
| $$ I_E = \log_2 \frac{1}{p_E} = -\log_2( p_E ) [bit] $$ | $$ I_E = \log_2 \frac{1}{p_E} = -\log_2( p_E ) [bit] $$ | ||
| - | Shannon used the logarithm to measure information because only the logarithmic function makes the information of independent events additive. If two independent events | + | Shannon used the logarithm to measure information because only the logarithmic function makes the information of independent events additive. If two independent events |
| We expect that the total information should add up: | We expect that the total information should add up: | ||
| Line 17: | Line 17: | ||
| $$ I(A,B) = I(A) + I(B) $$ | $$ I(A,B) = I(A) + I(B) $$ | ||
| - | Only the logarithm satisfies this property: | + | The logarithm satisfies this property: |
| $$ I(p) = -\log p \quad \Rightarrow \quad I(A,B) = -\log(p(A)p(B)) = I(A) + I(B) $$ | $$ I(p) = -\log p \quad \Rightarrow \quad I(A,B) = -\log(p(A)p(B)) = I(A) + I(B) $$ | ||
| - | If we used \( I(p) = 1/p \), the values would multiply, not add. | + | If we used \( I(p) = 1/p \), the values would multiply |
| - | The properties of a logarithm function play an important role in modeling the quantitative properties of a given information. | + | ==== Example: three coin tosses ==== |
| + | |||
| + | Consider three independent tosses of a fair coin. The probability of heads on each toss is \(1/2\). The probability of getting heads on all three tosses is: | ||
| + | |||
| + | $$ p(H,H,H) = \frac{1}{2} \cdot \frac{1}{2} \cdot \frac{1}{2} = \frac{1}{8} $$ | ||
| + | |||
| + | If we used \(I(p) = 1/p\), learning that one toss resulted in heads would give an information value of: | ||
| + | |||
| + | $$ I(H) = \frac{1}{1/ | ||
| + | |||
| + | Adding the information values of the three individual outcomes would give \(2+2+2=6\). However, applying the same formula to the combined outcome gives: | ||
| + | |||
| + | $$ I(H,H,H) = \frac{1}{1/ | ||
| + | |||
| + | Therefore, this formula does not make information additive: \(8 \neq 2+2+2\). Instead, the values multiply: \(8 = 2 \cdot 2 \cdot 2\). | ||
| + | |||
| + | With the logarithmic formula, learning the result of each coin toss provides **1 bit** of information: | ||
| + | |||
| + | $$ I(H) = -\log_2(1/ | ||
| + | |||
| + | Learning that all three tosses resulted in heads provides: | ||
| + | |||
| + | $$ I(H,H,H) = -\log_2(1/ | ||
| + | |||
| + | This is exactly the sum of the information from the three individual outcomes: **1 + 1 + 1 = 3 bits**. We obtain the same total information whether we learn the results one by one or all at once. | ||
| + | |||
| + | ---- | ||
| + | |||
| + | The properties of the logarithm function play an important role in modeling the quantitative properties of information. | ||
| If an event space consist of two equal-probability event \(p(E_1) = p(E_2) = 0.5 \) then, | If an event space consist of two equal-probability event \(p(E_1) = p(E_2) = 0.5 \) then, | ||
| - | $$ I_{E_1} = I_{E_2} = \log_2 \frac{1}{0.5} = - \log_2 | + | $$ I_{E_1} = I_{E_2} = \log_2 \frac{1}{0.5} = - \log_2 |
| So the unit of the information means the news value which is connected to the simple, less likely, same probability choice. | So the unit of the information means the news value which is connected to the simple, less likely, same probability choice. | ||
| Line 45: | Line 73: | ||
| The average information content of the set of messages is called the //entropy// of the message set. | The average information content of the set of messages is called the //entropy// of the message set. | ||
| - | $$ H_E = \sum_{i=1}^n p_i \cdot I_{E_i} = \sum_{i=1}^n p_i \cdot \log_2 \frac{1}{p_i} = - \sum_{i=1}^n p_i \cdot \log_2 p_i$$ | + | $$ H_E = \sum_{i=1}^n p_i \cdot I_{E_i} = \sum_{i=1}^n p_i \cdot \log_2 \frac{1}{p_i} = - \sum_{i=1}^n p_i \cdot \log_2 p_i [bit]$$ |
| **Example**: | **Example**: | ||
| Line 55: | Line 83: | ||
| {{: | {{: | ||
| - | We can see that entropy is highest when the two events are equally likely. In general, in this model, entropy is low when our event system includes events with low probabilities. | + | For two possible outcomes, |
| - | Entropy | + | Entropy |
| - | Example: | + | Unlikely outcomes do not necessarily mean entropy is low. For example, if there are 256 equally likely outcomes, each has a probability of only 1/256, but the entropy is 8 bits. What matters is the whole probability distribution, |
| - | - If a source always sends the same letter (“AAAAA…”), | + | Example: |
| - | | + | |
| + | * If every letter occurs with equal probability (e.g., random characters), | ||
| - | This concept is crucial in various fields, including //data compression//, | + | This concept is crucial in various fields, including //data compression//, |
| ==== Redundancy ==== | ==== Redundancy ==== | ||
| Line 125: | Line 154: | ||
| #include < | #include < | ||
| #include < | #include < | ||
| + | #include < | ||
| - | float calculateEntropy(unsigned | + | float calculateEntropy(unsigned |
| - | char sample[] = "Some poetry types are unique to particular cultures and genres and respond to yQ%v? | + | int main(void) { |
| + | const char sample[] = | ||
| + | | ||
| + | "and respond to yQ%v? | ||
| + | "poet writes. Readers accustomed to identifying poetry with Dante, | ||
| + | "Goethe, Mickiewicz, or Rumi may think of it as written in lines " | ||
| + | "based on rhyme and regular meter. There are, however, traditions, | ||
| + | "such as Biblical poetry and alliterative verse, that use other " | ||
| + | "means to create rhythm and euphony. Much modern poetry reflects | ||
| + | "a critique of poetic tradition, testing the principle of euphony | ||
| + | "itself or altogether forgoing rhyme or set rhythm."; | ||
| - | int main() | ||
| - | { | ||
| - | unsigned int byteCounter[256]; | ||
| const int windowWidth = 20; | const int windowWidth = 20; | ||
| + | unsigned char counts[256]; | ||
| - | | + | int sampleLength |
| - | { | + | |
| - | memset(byteCounter, | + | |
| - | char *p = & | + | for (int start = 0; start <= sampleLength - windowWidth; start++) { |
| - | char *end = & | + | memset(counts, |
| - | | + | |
| - | | + | for (int j = 0; j < windowWidth; |
| - | | + | |
| + | counts[c]++; | ||
| } | } | ||
| - | | + | |
| - | printf(" | + | |
| + | printf(" | ||
| } | } | ||
| + | return 0; | ||
| } | } | ||
| - | + | float calculateEntropy(unsigned | |
| - | float calculateEntropy(unsigned | + | |
| - | { | + | |
| float entropy = 0.0f; | float entropy = 0.0f; | ||
| - | + | | |
| - | | + | if (counts[i] > 0) { |
| - | | + | float freq = (float)counts[i] / length; |
| - | if (bytes[i] != 0) | + | entropy |
| - | | + | |
| - | float freq = (float) | + | |
| - | entropy | + | |
| } | } | ||
| } | } | ||
| return entropy; | return entropy; | ||
| } | } | ||
| + | |||
| </ | </ | ||
tanszek/oktatas/techcomm/information.1759783229.txt.gz · Last modified: by knehez
