{"id":355705,"date":"2024-05-20T23:14:19","date_gmt":"2024-05-20T23:14:19","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=355705"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2024-05-20T23:14:19","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=355705","title":{"rendered":"<span>1. Information theory + ML. Entropy<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>I&#8217;ve long wanted to create educational materials on the topic of <a href=\"https:\/\/en.wikipedia.org\/wiki\/Mutual_information\" rel=\"noopener noreferrer nofollow\">Information Theory<\/a> + <a href=\"https:\/\/en.wikipedia.org\/wiki\/Machine_learning\" rel=\"noopener noreferrer nofollow\">Machine Learning<\/a>. I found some old drafts and decided to polish them up here, on Habr. <\/p>\n<p>Information Theory and Machine Learning seem to me like an interesting pair of fields, the deep connection between which is often unknown to ML engineers, and whose synergy has not yet been fully revealed.  <\/p>\n<p>When I tell colleagues that <a href=\"https:\/\/en.wikipedia.org\/wiki\/Cross-entropy#Cross-entropy_loss_function_and_logistic_regression\" rel=\"noopener noreferrer nofollow\">LogLoss <\/a>on the test set and <a href=\"https:\/\/en.wikipedia.org\/wiki\/Mutual_information\" rel=\"noopener noreferrer nofollow\">Mutual Information<\/a> between the prediction and the predicted value are directly related, and that you can get one from the other using a simple formula, they often express genuine surprise. There is a link from the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Cross-entropy#Cross-entropy_loss_function_and_logistic_regression\" rel=\"noopener noreferrer nofollow\">LogLoss<\/a> Wikipedia page to <a href=\"https:\/\/en.wikipedia.org\/wiki\/Mutual_information\" rel=\"noopener noreferrer nofollow\">Mutual Information<\/a>, but that&#8217;s about it.<\/p>\n<p>Information Theory can become (or rather, <a href=\"https:\/\/arxiv.org\/pdf\/2004.14941.pdf\" rel=\"noopener noreferrer nofollow\">has become<\/a>) a source of understanding how and why different ML methods work, especially neural networks, and can also provide <a href=\"http:\/\/www.its.caltech.edu\/~daw\/papers\/98-Wage2.pdf\" rel=\"noopener noreferrer nofollow\">ideas for improving gradient-based optimization methods<\/a>.<\/p>\n<p>Let&#8217;s start with basic concepts like Entropy, Information in a message, Mutual Information, and channel capacity. Next, there will be materials on the similarity between tasks of maximizing Mutual Information and minimizing Loss in regression problems. Then there will be a section on Information Geometry: <a href=\"https:\/\/en.wikipedia.org\/wiki\/Fisher_information_metric\" rel=\"noopener noreferrer nofollow\">Fisher metric<\/a>, geodesics, gradient methods, and their connection to Gaussian processes (moving along the gradient using SGD is moving along the geodesic with noise).<\/p>\n<p>It&#8217;s also necessary to touch upon <a href=\"https:\/\/en.wikipedia.org\/wiki\/Akaike_information_criterion\" rel=\"noopener noreferrer nofollow\">AIC<\/a>, <a href=\"https:\/\/en.wikipedia.org\/wiki\/Information_bottleneck_method\" rel=\"noopener noreferrer nofollow\">Information Bottleneck<\/a>, and discuss how information flows in neural networks \u2013 Mutual Information between layers (<a href=\"https:\/\/www.youtube.com\/watch?v=XL07WEc2TRI&amp;ab_channel=StanfordOnline\" rel=\"noopener noreferrer nofollow\">Information Theory of Deep Learning, Naftali Tishby<\/a>), and much more. It&#8217;s not certain that I&#8217;ll be able to cover everything listed, but I&#8217;ll try to get started.<\/p>\n<p><strong>1. Basic Definitions<\/strong>   <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"H({p_1, ..., P_M}) = \\sum^M_{i = 1} p_i\\log(1\/p_i)\\;\\;\\;\\;\\;\\;\\;(1)\" alt=\"H({p_1, ..., P_M}) = \\sum^M_{i = 1} p_i\\log(1\/p_i)\\;\\;\\;\\;\\;\\;\\;(1)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ee3\/a45\/b1d\/ee3a45b1d161a62b5c9ce4f3e0839b17.svg\" width=\"336\" height=\"60\"\/><img class=\"formula\" source=\"\\sum_{i=1}^M p_i =1, \\;\\; p_i > 0.\\;\\;\\;\\;\\;\\;&#187; alt=&#187;\\sum_{i=1}^M p_i =1, \\;\\; p_i > 0.\\;\\;\\;\\;\\;\\;&#187; src=&#187;https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3b0\/b7c\/de0\/3b0b7cde0e031276d3f6ceef94156d05.svg&#187; width=&#187;191&#8243; height=&#187;60&#8243;\/><\/p>\n<p>Let&#8217;s describe them. We&#8217;ll start with basic definitions  <\/p>\n<p><strong>Definition 1.1: Uncertainty<\/strong> is the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Logarithm\" rel=\"noopener noreferrer nofollow\">logarithm<\/a> base 2 of the number of equiprobable possibilities: <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"H = \\log_2{N}\" alt=\"H = \\log_2{N}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/2cd\/f46\/a3e\/2cdf46a3eb57f288711a1f0e5f2b8951.svg\" width=\"97\" height=\"21\"\/>. It is measured in <strong>bits<\/strong>. For example, the uncertainty of an unknown <strong>binary word<\/strong> of length <em>k<\/em> is equal to k.  <\/p>\n<details class=\"spoiler\">\n<summary>Logarithm<\/summary>\n<div class=\"spoiler__content\">\n<p>The <a href=\"https:\/\/en.wikipedia.org\/wiki\/Logarithm\" rel=\"noopener noreferrer nofollow\">logarithm<\/a> base 2 of a number is how many times you need to divide the number by 2 to get a number less than or equal to 1. For example,<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\log_2(1) = 0, ; \\log_2(2) = 1, ; \\log_2(4) = 2,; \\log_2(8) = 3,; \\log_2(1024) = 10.\" alt=\"\\log_2(1) = 0, ; \\log_2(2) = 1, ; \\log_2(4) = 2,; \\log_2(8) = 3,; \\log_2(1024) = 10.\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/21b\/710\/6d4\/21b7106d42f69bf152710eccf9051e73.svg\" width=\"580\" height=\"22\"\/><\/p>\n<p>For non-powers of two, this function smoothly extends. For example,<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\log_2(3) = 1.5849\\ldots, ; \\log_2(10) = 3.3219\\ldots\" alt=\"\\log_2(3) = 1.5849\\ldots, ; \\log_2(10) = 3.3219\\ldots\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/45b\/31e\/81a\/45b31e81ab34cb80a80ffeeb20866e0b.svg\" width=\"356\" height=\"22\"\/><\/p>\n<p>An important property of logarithms:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\log(x) - \\log(y) = \\log(x\/y).\" alt=\"\\log(x) - \\log(y) = \\log(x\/y).\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/4be\/324\/635\/4be32463576026493bf89db759273d52.svg\" width=\"225\" height=\"22\"\/><\/p>\n<p>Try to derive it from the non-strict definition above for the case when <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"x\" alt=\"x\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3d0\/106\/917\/3d01069178ba5c7a9406b4a353b8cc00.svg\" width=\"11\" height=\"12\"\/> and <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"y\" alt=\"y\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/754\/86c\/ffa\/75486cffa912b9301e84c7d188b57f62.svg\" width=\"10\" height=\"15\"\/> are powers of two.<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>Binary words<\/summary>\n<div class=\"spoiler__content\">\n<p>Binary words of length k are sequences of zeros and ones of length k. Each character in a binary words is called a bit. For example, here are binary words of length 5:<\/p>\n<p>00000, 00001, 00010, 00011, 00100, 00101, &#8230; , 11100, 11101, 111110, 11111 <\/p>\n<p>There are 32 of them. <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\log_2(32) = 5\" alt=\"\\log_2(32) = 5\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8f1\/b11\/9b0\/8f1b119b0263093016729dbcbf04b196.svg\" width=\"103\" height=\"22\"\/> , which means the uncertainty of a 5-bit word is 5.<\/p>\n<p>That&#8217;s exactly the number of unknown bits in an unknown 5-bit binary word.<\/p>\n<p>Thus, each symbol in a binary word is called a &#171;bit,&#187; but a &#171;bit&#187; is also a unit of uncertainty measurement. And this example helps to understand why.<\/p>\n<\/div>\n<\/details>\n<p>For brevity,  <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\log_2\" alt=\"\\log_2\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/629\/0b6\/4f9\/6290b64f9e98b9c747db7863426b4b5f.svg\" width=\"33\" height=\"21\"\/> is simply denoted as <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\log\" alt=\"\\log\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/cf7\/132\/0f5\/cf71320f56b85b4cccf1ff453b18a63c.svg\" width=\"25\" height=\"20\"\/> throughout.<\/p>\n<p><strong>Definition 1.2: Information in a message<\/strong> is the difference in uncertainty before receiving the message and after.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"I(message) = H(before) - H(after)\\;\\;\\;\\;\\;\\;\\;\\; (2)\" alt=\"I(message) = H(before) - H(after)\\;\\;\\;\\;\\;\\;\\;\\; (2)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/57f\/fc9\/e7b\/57ffc9e7b47743f93037a9bf338068b8.svg\" width=\"0\" height=\"0\"\/><\/p>\n<p>This is also measured in bits.<\/p>\n<p>For example, Vanya has chosen a number from 1 to 100. We are told that it is less than or equal to 50. The uncertainty before the message is <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\log\u2061100\" alt=\"\\log\u2061100\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5af\/0c8\/c0a\/5af0c8c0ac3eb61ff17a14ef6b82b119.svg\" width=\"57\" height=\"20\"\/>, and after the message, it is <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\log \u206150\" alt=\"\\log \u206150\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7ca\/a9c\/619\/7caa9c6191158d0f9c1c5e5d007f4776.svg\" width=\"48\" height=\"21\"\/>. Therefore, there is 1 bit of information in this message. By skillfully asking binary questions (questions to which the answer is either YES or NO), you can extract exactly 1 bit of information.<\/p>\n<p>Some questions are inefficient. For instance, the question &#171;Is the number less than or equal to 25?&#187; reduces uncertainty by <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\log\u2061100\u2212\\log\u206125=\\log\u2061(100\/25)=2\" alt=\"\\log\u2061100\u2212\\log\u206125=\\log\u2061(100\/25)=2\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/eec\/7f9\/be1\/eec7f9be1e6f74bd51245e522717e642.svg\" width=\"289\" height=\"22\"\/> bits with a probability of 0.25, and with a probability of 0.75, it only reduces it by <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\log\u2061(100)\u2212\\log\u2061(75)=\\log\u2061(100\/75)\" alt=\"\\log\u2061(100)\u2212\\log\u2061(75)=\\log\u2061(100\/75)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b22\/80a\/a82\/b2280aa82243d743e382e3191bf598ed.svg\" width=\"284\" height=\"22\"\/> bits, which on average is <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"0.25\\log\u2061(1\/0.25)+0.75\\log\u2061(1\/0.75)=0.811278\" alt=\"0.25\\log\u2061(1\/0.25)+0.75\\log\u2061(1\/0.75)=0.811278\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/995\/666\/ae3\/995666ae3e4c3d27e650aeb975332ca0.svg\" width=\"390\" height=\"22\"\/> bits. If you divide the set of possibilities in a ratio of <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"x : 1 - x\" alt=\"x : 1 - x\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/da5\/a04\/338\/da5a0433890fc3a2423fb32904e0edd5.svg\" width=\"71\" height=\"17\"\/><\/em>, with your question, then the average amount of information in the answer is <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"x\\log\u2061(1\/x)+(1\u2212x)\\log\u2061(1\/(1\u2212x))\" alt=\"x\\log\u2061(1\/x)+(1\u2212x)\\log\u2061(1\/(1\u2212x))\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/34a\/e8d\/01e\/34ae8d01e851e275adefa4e8dee25c6f.svg\" width=\"295\" height=\"22\"\/>.<\/p>\n<p>We will denote this expression as <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"H({x, 1-x})\" alt=\"H({x, 1-x})\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/dc2\/769\/e2d\/dc2769e2db33eb9c65be3ffdcfcc93ae.svg\" width=\"96\" height=\"22\"\/> or <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"H(x)\" alt=\"H(x)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c8a\/d08\/427\/c8ad084276b867a1aa03b55f616d60db.svg\" width=\"43\" height=\"22\"\/>. Here, as programmers, we <strong>overload the function H<\/strong> to work in two cases &#8212; when a pair of numbers is input, the sum of which is 1, and when one number is from the interval [0, 1].<\/p>\n<p><strong>Definition 1.3:<\/strong>\u00a0<em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"H(\\{x, 1-x\\}) = H(x) =  x \\log (1\/x) + (1 - x ) \\log(1\/(1-x))\" alt=\"H(\\{x, 1-x\\}) = H(x) =  x \\log (1\/x) + (1 - x ) \\log(1\/(1-x))\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9e6\/78f\/84e\/9e678f84e0b9ed878040af22d804ee57.svg\" width=\"504\" height=\"22\"\/><\/em>  <\/p>\n<details class=\"spoiler\">\n<summary>Plot H(x)<\/summary>\n<div class=\"spoiler__content\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/63d\/21e\/1a3\/63d21e1a3db7aee9e27c49e2f068cf22.png\" width=\"1498\" height=\"1466\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/63d\/21e\/1a3\/63d21e1a3db7aee9e27c49e2f068cf22.png\"\/><\/figure>\n<\/p>\n<\/div>\n<\/details>\n<p>It&#8217;s evident that by asking binary questions, you can extract a maximum of 1 bit of information on average (the maximum value of the function <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"H(x))\" alt=\"H(x))\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/cbc\/1c0\/6eb\/cbc1c06ebdcc66b4098a3658283f801f.svg\" width=\"51\" height=\"22\"\/>. Let&#8217;s reiterate: yes, you can directly ask questions like &#171;Is the number equal to 57?&#187; and if you&#8217;re lucky, you can get log(100) bits of information. However, if luck is not on your side, you will only get log(100\/99) bits of information. <strong>The average number of bits of information<\/strong> for such types of questions is<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"(1\/100) \\cdot \\log(100) + (99\/100) \\cdot \\log(100\/99) = 0.08079...\" alt=\"(1\/100) \\cdot \\log(100) + (99\/100) \\cdot \\log(100\/99) = 0.08079...\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3b0\/101\/689\/3b0101689085ad24593d787eb38d3fa2.svg\" width=\"459\" height=\"22\"\/> which is noticeably less than 1.<\/p>\n<p>In this example, there are 100 possibilities, which means the initial uncertainty is<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\log\u2061(100)\" alt=\"\\log\u2061(100)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/80e\/c70\/05d\/80ec7005d83186cae0729851cde0c834.svg\" width=\"72\" height=\"22\"\/>\u2013 this is how many binary questions you, on average, need to ask Vanya to find out the answer. However, the number is not an integer, so you need to round it up.<\/p>\n<p>If we ask not binary questions but questions that imply a natural number from 1 to M as the answer, we can get more than one bit of information in a single response. If we ask a question for which all M answers are equally likely, then on average, we will get <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\log M\" alt=\"\\log M\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9e2\/322\/737\/9e232273733f1ec9e26760d73928f5e5.svg\" width=\"48\" height=\"20\"\/> bits. However, if the probability of answer <em>i<\/em> is <em>p<\/em>(<em>i<\/em>), then the average number of bits in the response will be:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"H(\\{p_1, \\ldots, p_M\\}) = \\sum_{i=1}^M p_i \\log(1 \/ p_i).\\;\\;\\;\\;\\;\\;\\;\\;(1)\" alt=\"H(\\{p_1, \\ldots, p_M\\}) = \\sum_{i=1}^M p_i \\log(1 \/ p_i).\\;\\;\\;\\;\\;\\;\\;\\;(1)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3f8\/7a1\/824\/3f87a1824f9b9b01764642cb9ff2746d.svg\" width=\"371\" height=\"60\"\/><\/p>\n<p><strong>Definition 1.4: The entropy of a discrete distribution<\/strong> \u00a0<em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"P=\\{p_i\\}_{i=1}^M\" alt=\"P=\\{p_i\\}_{i=1}^M\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/dab\/bb1\/0bb\/dabbb10bba7824e62360037d005899af.svg\" width=\"101\" height=\"26\"\/><\/em>   is defined by the formula (1) above.<\/p>\n<p>Here, we have overloaded the function H for the case when a discrete distribution is provided as input.<\/p>\n<p><strong>SO: The first straightforward way to arrive at the formula for entropy <\/strong><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"H(P)\" alt=\"H(P)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9b6\/6f3\/beb\/9b66f3beb2789195757fc57494b4e4d8.svg\" width=\"47\" height=\"22\"\/><strong> is to calculate the average number of bits of information in response to a question with equiprobable answers.<\/strong><\/p>\n<p>Let&#8217;s go further. Suppose Vanya doesn&#8217;t choose a number but samples it from the distribution <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"P=\\{p_i\\}_{i=1}^M\" alt=\"P=\\{p_i\\}_{i=1}^M\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a45\/7d7\/8ed\/a457d78ed8460cca030b060d9c5ab302.svg\" width=\"101\" height=\"26\"\/><\/em>  . How many binary questions do we need to ask Vanya to determine the sampled number? Intuitively, we need to divide the set of possibilities into two subsets, not necessarily of equal size but with approximately equal total probability, and ask Vanya which of the two subsets contains the sampled number. Get the answer and continue in the same manner with the reduced set of possibilities &#8212; again dividing it into two subsets with roughly equal probability, asking Vanya which of the two subsets contains the sampled number, and so on. The idea is good but not quite practical. It turns out it&#8217;s more effective to work backward and start building the partition tree from the bottom. Specifically, find the two least probable outcomes and merge them into a single new outcome, thus reducing the number of possibilities by 1. Then, once again, find the two least probable outcomes and merge them into a new one, and so on, ultimately constructing a binary tree. The numbers are located in the leaves of this tree. The internal nodes are labeled with sets of numbers from the subtree they represent, and the root is labeled with the set of all numbers. This tree provides an algorithm for how to ask Vanya questions. You should start at the root of the tree and ask Vanya which way to go &#8212; left or right (which of the two children subsets contains the sampled number) according to this tree structure. This tree not only provides the recipe for the fastest average method of guessing the number but also serves as the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Huffman_coding\" rel=\"noopener noreferrer nofollow\">Huffman algorithm for data compression<\/a>.<\/p>\n<p><strong>Task 1.1:<\/strong> Study the Huffman code. Prove that a text with an original length of <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"N\" alt=\"N\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/bbd\/04c\/d51\/bbd04cd51583028a89a5f2ccc91312a1.svg\" width=\"17\" height=\"17\"\/> characters, in its compressed form, has a length bounded from below by <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"N \\cdot H(P)\" alt=\"N \\cdot H(P)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/819\/122\/7c7\/8191227c74d4a512bde31e0d54963571.svg\" width=\"78\" height=\"22\"\/> bits, and under favorable circumstances, it achieves this bound.<\/p>\n<p><strong>So, the formula <\/strong><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"H(P)\" alt=\"H(P)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/aef\/ad1\/1b9\/aefad11b9e3d737060cb0bbe0671acd6.svg\" width=\"47\" height=\"22\"\/><strong> arises when solving the problem of finding the minimum average number of binary questions needed to determine the outcome of a random variable with distribution <\/strong><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"P\" alt=\"P\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c23\/96c\/e00\/c2396ce00c4483e84273f44631d7f632.svg\" width=\"14\" height=\"17\"\/><strong>.<\/strong><\/p>\n<p>This is the second way to arrive at formula (1).<\/p>\n<p>For a random variable <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\u03be\" alt=\"\u03be\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/42e\/5a7\/3a8\/42e5a73a8a1c1035f82f942f7c1e5871.svg\" width=\"9\" height=\"20\"\/>, we will use the following notations for the entropy of its distribution <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"P=\\{{p_i}\\}_{i=1}^M\" alt=\"P=\\{{p_i}\\}_{i=1}^M\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3a6\/fac\/50b\/3a6fac50b1783f2017e179196c5548a0.svg\" width=\"100\" height=\"25\"\/> (once again, &#171;overloading&#187; the function <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"H\" alt=\"H\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/acc\/820\/61d\/acc82061d83af9dfbe118c1c728fad79.svg\" width=\"17\" height=\"17\"\/>):<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"H(\\xi)\" alt=\"H(\\xi)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d56\/7e9\/6ac\/d567e96ace0bf272f6ad7cc6df7f107f.svg\" width=\"41\" height=\"22\"\/> or <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"H(P)\" alt=\"H(P)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/24e\/231\/d93\/24e231d9314e66000509e11cfb084c6c.svg\" width=\"47\" height=\"22\"\/> or <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"H({\\{p_i}\\}_{i=1}^M)\" alt=\"H({\\{p_i}\\}_{i=1}^M)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8f0\/264\/e4c\/8f0264e4c47b26d188a53cdaa5cecef8.svg\" width=\"92\" height=\"25\"\/> or <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"H(\\{p_i\\}_i)\" alt=\"H(\\{p_i\\}_i)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/cf6\/504\/93e\/cf650493eda4c519c0cdc5a7c0d98717.svg\" width=\"76\" height=\"22\"\/><\/p>\n<p>There&#8217;s yet another, a third, simple way to arrive at the formula for entropy, but it requires knowledge of <a href=\"https:\/\/en.wikipedia.org\/wiki\/Stirling%27s_approximation\" rel=\"noopener noreferrer nofollow\">the Stirling formula<\/a>.<\/p>\n<p><strong>Task 1.2:<\/strong> You have an unknown binary word of length k (a sequence of ones and zeros, a total of <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"k\" alt=\"k\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/85d\/30a\/674\/85d30a674a5ddfbe584b3c489ebacd6a.svg\" width=\"10\" height=\"17\"\/> characters). You are told that it contains 35% ones. What is the value of <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"I(message) \/ k\" alt=\"I(message) \/ k\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/dd5\/81c\/d82\/dd581cd82334cd2a3f26151860736183.svg\" width=\"117\" height=\"22\"\/> for large <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"k \\; ?\" alt=\"k \\; ?\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3c3\/9cb\/d07\/3c39cbd07b5608fe127720d35a4523ec.svg\" width=\"25\" height=\"17\"\/><\/p>\n<details class=\"spoiler\">\n<summary>Answer<\/summary>\n<div class=\"spoiler__content\">\n<p>Approximately<em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\log 2  - (p \\log(1 \/ p) + (1 - p) \\log(1 \/ (1 - p))) = \\log 2 - H(\\{p, 1-p\\})\" alt=\"\\log 2  - (p \\log(1 \/ p) + (1 - p) \\log(1 \/ (1 - p))) = \\log 2 - H(\\{p, 1-p\\})\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/32d\/8ca\/56f\/32d8ca56f7d6db949ad28d9998627b47.svg\" width=\"565\" height=\"22\"\/><\/em>, where\u00a0<em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"p = 0.35\" alt=\"p = 0.35\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5d2\/82a\/120\/5d282a12078a7dd01fc8aeff240cdcd3.svg\" width=\"71\" height=\"20\"\/><\/em>  <\/p>\n<\/div>\n<\/details>\n<p><strong>Task 1.3:<\/strong> Vanya has an unknown word of length k in an alphabet of size M. He has provided the proportions of all the letters in the word as <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"P = {p_1, ..., p_M}\" alt=\"P = {p_1, ..., p_M}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/340\/0d7\/6d9\/3400d76d9749a8535a45eba31728034c.svg\" width=\"127\" height=\"20\"\/>. <br \/>What is the value of I(message) \/ k for large k? <\/p>\n<details class=\"spoiler\">\n<summary>Answer<\/summary>\n<div class=\"spoiler__content\"><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\approx \\log M - \\sum_{i=1}^M{p_i \\log(1 \/ p_i)} = \\log M - H(P)\" alt=\"\\approx \\log M - \\sum_{i=1}^M{p_i \\log(1 \/ p_i)} = \\log M - H(P)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/6ab\/065\/82c\/6ab06582cabd6173a30d936fa6a983bd.svg\" width=\"366\" height=\"60\"\/><\/p>\n<\/div>\n<\/details>\n<p>So, Task 1.3 is indeed the third way to arrive at formula (1).<\/p>\n<p><strong>Definition 1.5:<\/strong> Information in a message about a certain random variable is the difference in entropies: <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"I(message) = H(P_{apriori}) - H(P_{aposteriori}).\" alt=\"I(message) = H(P_{apriori}) - H(P_{aposteriori}).\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/1f2\/0ef\/1e7\/1f20ef1e778fde506695e545f834eceb.svg\" width=\"354\" height=\"23\"\/><\/p>\n<p>The values of a random discrete variable can be seen as letters, and each successive letter in a word is just another measurement of the random variable. So, the information in a message about a certain random variable is the number of bits of information about measurements of that random variable, normalized by the number of measurements.<\/p>\n<p><strong>Problem 1.4<\/strong>: What is the entropy of the discrete distribution <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"P = {\\{\\lambda ^ i \\cdot (1 - \\lambda)}\\}_{i = 0}^{\\infty}\" alt=\"P = {\\{\\lambda ^ i \\cdot (1 - \\lambda)}\\}_{i = 0}^{\\infty}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5d1\/312\/e40\/5d1312e401551dbdee91f436f71d849b.svg\" width=\"175\" height=\"26\"\/>? How much information is contained in the message <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\xi \\ne 0\" alt=\"\\xi \\ne 0\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/38e\/2c0\/910\/38e2c0910e3ff75d1aee49f0fd5d83ea.svg\" width=\"44\" height=\"21\"\/>, where <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\xi\" alt=\"\\xi\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/528\/7e3\/13d\/5287e313d55d59725ede8dd7ed172e3d.svg\" width=\"9\" height=\"20\"\/> has the distribution <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"P\" alt=\"P\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f12\/8ea\/4ee\/f128ea4eeae47b9744c70160b6df044a.svg\" width=\"14\" height=\"17\"\/>?<\/p>\n<details class=\"spoiler\">\n<summary>Answer<\/summary>\n<div class=\"spoiler__content\"><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"H(P) = H(\\lambda) \/ (1 - \\lambda)\" alt=\"H(P) = H(\\lambda) \/ (1 - \\lambda)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e98\/5c7\/b9f\/e985c7b9f63893722d101af68536d1c5.svg\" width=\"187\" height=\"22\"\/><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"I(``\\xi \\ne 0'') = 0\" alt=\"I(``\\xi \\ne 0'') = 0\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/72d\/f3c\/f94\/72df3cf944c1b24d3df660906c0ba76e.svg\" width=\"126\" height=\"23\"\/><\/p>\n<p>This result requires acceptance. How can this be? \u2013 We were given seemingly non-zero information, eliminated the most probable option from the possibilities. However, the uncertainty about the remaining possibilities remains the same, so the formula <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"H(before) - H(after)\" alt=\"H(before) - H(after)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d46\/6a1\/bbe\/d466a1bbe4c367c7c0204260f2544919.svg\" width=\"188\" height=\"22\"\/> yields an answer of 0.  <\/p>\n<\/div>\n<\/details>\n<p><strong>Task 1.5:<\/strong> Provide an example of a finite distribution and a message that does not reduce but increases uncertainty.<\/p>\n<details class=\"spoiler\">\n<summary>\u041e\u0442\u0432\u0435\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p><em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"P = \\{0.8, 0.1,0.1\\}\" alt=\"P = \\{0.8, 0.1,0.1\\}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7b2\/2cb\/f99\/7b22cbf99382527f051993c363585ecd.svg\" width=\"152\" height=\"22\"\/><\/em>, and message = &#171;this is not the first element&#187;. Then\u00a0<em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"P_{after} = \\{0, 0.5, 0.5\\},\\ H(P) = 0.9219,\\ H(P_{after}) = 1.0\" alt=\"P_{after} = \\{0, 0.5, 0.5\\},\\ H(P) = 0.9219,\\ H(P_{after}) = 1.0\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/228\/59b\/a3b\/22859ba3b657d68a1a54e4c180a30f7e.svg\" width=\"455\" height=\"23\"\/><\/em>  <\/p>\n<\/div>\n<\/details>\n<p>The ancient wisdom &#171;in much wisdom is much grief&#187; in this context gets another interesting interpretation: the modern world, science, and human life are such that new &#171;messages&#187; about history and the structure of the world only increase uncertainty.<\/p>\n<p>Discrete distributions on a countable set of values that decay exponentially (geometric progressions) have the property of unchanged uncertainty when receiving information, meaning that among the first elements, there is no correct answer. Distributions with less than exponential decay (e.g., <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"p_k={C \/ k^2}\" alt=\"p_k={C \/ k^2}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d49\/dc1\/a9b\/d49dc1a9b354c6dfbf817d03cc35a7c4.svg\" width=\"88\" height=\"25\"\/>) only increase uncertainty when discarding the first elements.<\/p>\n<p><strong>Problem 1.6:<\/strong> Write the formula for the entropy of the Poisson distribution<\/p>\n<p><em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"p_k=e^{-\\lambda}{\\lambda^k \\over k!}, k=0,;1,\\ldots,+\\infty\" alt=\"p_k=e^{-\\lambda}{\\lambda^k \\over k!}, k=0,;1,\\ldots,+\\infty\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/76a\/921\/c93\/76a921c9325812efb34c1eb2197bcc88.svg\" width=\"260\" height=\"46\"\/><\/em><\/p>\n<p>Find a simple approximation for large <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\lambda\" alt=\"\\lambda\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/552\/74f\/ad3\/55274fad3200599322283c0b752bfa45.svg\" width=\"11\" height=\"17\"\/>.<\/p>\n<details class=\"spoiler\">\n<summary>Answer<\/summary>\n<div class=\"spoiler__content\"><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"H(\\{p_k\\}_{k=0}^{\\infty})={1\\over  2} \\log (2\\pi e \\lambda) - {1\\over 12 \\lambda}-{1\\over 24 \\lambda^2}+O(1\/\\lambda^3)\" alt=\"H(\\{p_k\\}_{k=0}^{\\infty})={1\\over  2} \\log (2\\pi e \\lambda) - {1\\over 12 \\lambda}-{1\\over 24 \\lambda^2}+O(1\/\\lambda^3)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/49d\/696\/77d\/49d69677dd38befd737581821fb08d8c.svg\" width=\"452\" height=\"44\"\/><\/p>\n<\/div>\n<\/details>\n<p><strong>Task 1.7:<\/strong> Given the distribution <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\rho(x)\" alt=\"\\rho(x)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c7a\/27f\/2a6\/c7a27f2a6d25b11fb586fcb19aa98007.svg\" width=\"36\" height=\"22\"\/> of a real random variable. Let <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"Q(\\rho,\\varepsilon)\" alt=\"Q(\\rho,\\varepsilon)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/425\/c24\/829\/425c24829aa4aafdf1dc734151084664.svg\" width=\"58\" height=\"22\"\/> be the average number of binary questions needed to determine some outcome of the random variable with an accuracy of <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\varepsilon\" alt=\"\\varepsilon\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/872\/cc1\/594\/872cc1594c72256f39d47b9261db4b7b.svg\" width=\"9\" height=\"12\"\/>. Find an approximate expression for <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"Q(\\rho,\\varepsilon)\" alt=\"Q(\\rho,\\varepsilon)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/af3\/f93\/bce\/af3f93bcecc281a5ece7970b9cc7812b.svg\" width=\"58\" height=\"22\"\/> for small values of <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\varepsilon\" alt=\"\\varepsilon\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/0c4\/3fc\/eca\/0c43fceca4b447357db54fdfac01a91d.svg\" width=\"9\" height=\"12\"\/>. <\/p>\n<details class=\"spoiler\">\n<summary>Answer<\/summary>\n<div class=\"spoiler__content\"><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\sum_i \\rho(x_i) \\cdot \\varepsilon \\cdot \\log (1 \/ (\\rho(x_i) \\cdot \\varepsilon) ) \\approx \\log(1\/\\varepsilon) - \\int_{-\\infty}^{+\\infty} \\rho(x)\\log(\\rho(x))dx =\" alt=\"\\sum_i \\rho(x_i) \\cdot \\varepsilon \\cdot \\log (1 \/ (\\rho(x_i) \\cdot \\varepsilon) ) \\approx \\log(1\/\\varepsilon) - \\int_{-\\infty}^{+\\infty} \\rho(x)\\log(\\rho(x))dx =\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b18\/38a\/211\/b1838a2111b525ecbd5fc3a6e21d49ec.svg\" width=\"574\" height=\"55\"\/><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"= \\log(1\/\\varepsilon) + H(\\rho)\" alt=\"= \\log(1\/\\varepsilon) + H(\\rho)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/710\/08a\/d9b\/71008ad9b24940e01685969d92789eda.svg\" width=\"154\" height=\"22\"\/><\/p>\n<p>(see definition of entropy of a continuous distribution below).<\/p>\n<\/div>\n<\/details>\n<p><strong>Definition 1.6:<\/strong> The entropy of a continuous distribution is given by<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"H(\\rho) = -\\int_X \\rho(x) \\log(\\rho(x)) dx\" alt=\"H(\\rho) = -\\int_X \\rho(x) \\log(\\rho(x)) dx\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/db3\/3ad\/c2b\/db33adc2b02b30695a936a3e36149466.svg\" width=\"253\" height=\"47\"\/><\/p>\n<p>Here, we have once again overloaded the symbol H for the case when the argument is a probability density function (PDF).<\/p>\n<p><strong>Task 1.8:<\/strong> Given two distributions <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\rho_1(x)\" alt=\"\\rho_1(x)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/efa\/e68\/30a\/efae6830a10c4921f8b6b7260719dae0.svg\" width=\"45\" height=\"22\"\/><\/em>and\u00a0<em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\rho_2(x)\" alt=\"\\rho_2(x)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3db\/2bb\/e4e\/3db2bbe4e22872e4306c337307fc7d4f.svg\" width=\"45\" height=\"22\"\/><\/em> of two real random variables. What does the difference <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"Q(\\rho_1,  \\varepsilon) -  Q(\\rho_2, \\varepsilon)\" alt=\"Q(\\rho_1,  \\varepsilon) -  Q(\\rho_2, \\varepsilon)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/4ea\/3a3\/fe4\/4ea3a3fe45c701e7dee55c04571735ec.svg\" width=\"159\" height=\"22\"\/><\/em> approach as\u00a0<em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\varepsilon\\to0\" alt=\"\\varepsilon\\to0\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/46c\/5ef\/a63\/46c5efa632a3ec725d0ef43b51d6ed38.svg\" width=\"49\" height=\"17\"\/><\/em>?<\/p>\n<details class=\"spoiler\">\n<summary>Answer<\/summary>\n<div class=\"spoiler__content\"><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"H(\\rho_1) - H(\\rho_2)\" alt=\"H(\\rho_1) - H(\\rho_2)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/858\/ddb\/77f\/858ddb77f8f22532b2f354aa9b6d6740.svg\" width=\"125\" height=\"22\"\/><\/p>\n<\/div>\n<\/details>\n<p><strong>Task 1.9:<\/strong> What is the entropy of a normal distribution <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\mathcal{N}(\\mu, \\sigma)\" alt=\"\\mathcal{N}(\\mu, \\sigma)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/765\/270\/b10\/765270b10f53ad5370f140a350109f82.svg\" width=\"66\" height=\"23\"\/><\/em>? <\/p>\n<details class=\"spoiler\">\n<summary>Answer<\/summary>\n<div class=\"spoiler__content\"><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"1\/2  \\cdot (1 + \\log(2\\pi \\sigma^2))\" alt=\"1\/2  \\cdot (1 + \\log(2\\pi \\sigma^2))\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3a3\/c1d\/935\/3a3c1d935447d5a3b663e2eb61f33333.svg\" width=\"171\" height=\"25\"\/><\/p>\n<\/div>\n<\/details>\n<p><strong>Task 1.10:<\/strong> Write down the formula for the entropy of an exponential distribution <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\rho(x)=e^{-x\/a}\/a\" alt=\"\\rho(x)=e^{-x\/a}\/a\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/127\/300\/0f9\/1273000f9c09f6f16413de821b22baa7.svg\" width=\"126\" height=\"26\"\/><\/em>. <\/p>\n<p><strong>Problem 1.11:<\/strong> A random variable <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\xi\" alt=\"\\xi\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d3b\/7b9\/21d\/d3b7b921d42cbc8557e112b6db50a2c1.svg\" width=\"9\" height=\"21\"\/><\/em> is a mixture of two random variables, meaning its distribution <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\rho(x)\" alt=\"\\rho(x)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/575\/3a5\/136\/5753a5136967c8e70c3c6133abf00830.svg\" width=\"36\" height=\"22\"\/><\/em>is a weighted sum of distributions:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\rho(x) = w_1\\rho_1(x) + w_2\\rho_2(x),\\;\\;\\;\\;w_1 + w_2 = 1\" alt=\"\\rho(x) = w_1\\rho_1(x) + w_2\\rho_2(x),\\;\\;\\;\\;w_1 + w_2 = 1\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/daf\/762\/c58\/daf762c58956dac1bb9672ec3f0acb4c.svg\" width=\"358\" height=\"22\"\/><\/p>\n<p>Let the set of values taken by <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\xi_1\" alt=\"\\xi_1\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/025\/717\/a27\/025717a275c382d442817b6c91f530b5.svg\" width=\"17\" height=\"21\"\/><\/em>not overlap with the set of values taken by <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\xi_2\" alt=\"\\xi_2\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/895\/afe\/229\/895afe22960975d841c2b52af8897192.svg\" width=\"17\" height=\"21\"\/><\/em>, in other words, let the supports of these two random variables not intersect. Find an expression for the entropy\u00a0<em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"H(\\xi)\" alt=\"H(\\xi)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3d7\/698\/23d\/3d769823d78bbf301efd9414e74167ba.svg\" width=\"41\" height=\"22\"\/><\/em>in terms of the entropies <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"H(\\xi_1)\" alt=\"H(\\xi_1)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/fbb\/6f7\/949\/fbb6f794964fa87007304bc9a9a86a3e.svg\" width=\"50\" height=\"22\"\/><\/em>and <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"H(\\xi_2)\" alt=\"H(\\xi_2)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/92e\/539\/040\/92e539040471a5e3130b0a7b4f4ffaa1.svg\" width=\"50\" height=\"22\"\/><\/em>.<\/p>\n<details class=\"spoiler\">\n<summary>Answer<\/summary>\n<div class=\"spoiler__content\"><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"H(\\rho) = -\\int_{X_1+X_2} \\rho(x) \\log(\\rho(x)) dx \\\\=-\\int_{X_1+X_2} (w_1\\rho_1(x)+ w_2\\rho_2(x))\\log(w_1\\rho_1(x) + w_2\\rho_2(x)) dx =\\\\ =-\\int_{X_1} w_1\\rho_1(x) \\log(w_1\\rho_1(x)) dx-\\int_{X_2} w_2\\rho_2(x) \\log(w_2\\rho_2(x)) dx\" alt=\"H(\\rho) = -\\int_{X_1+X_2} \\rho(x) \\log(\\rho(x)) dx \\\\=-\\int_{X_1+X_2} (w_1\\rho_1(x)+ w_2\\rho_2(x))\\log(w_1\\rho_1(x) + w_2\\rho_2(x)) dx =\\\\ =-\\int_{X_1} w_1\\rho_1(x) \\log(w_1\\rho_1(x)) dx-\\int_{X_2} w_2\\rho_2(x) \\log(w_2\\rho_2(x)) dx\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c81\/c51\/308\/c81c5130853bfcac400de90d2b3dd2f0.svg\" width=\"619\" height=\"157\"\/><\/p>\n<p>The last equality here is possible only because the supports of <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"X_1\" alt=\"X_1\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/62e\/97b\/267\/62e97b267b11ce4240baffb42c2f09c6.svg\" width=\"25\" height=\"19\"\/>\u200b and <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"X_2\" alt=\"X_2\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/82b\/35e\/32f\/82b35e32f05471bafb2e2c65743ba7f0.svg\" width=\"25\" height=\"19\"\/>\u200b from the two distributions do not overlap as stated in the problem. Next, we will transform this expression into<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"-w_1\\int_{X_1} \\rho_1(x) \\log(w_1\\rho_1(x))- w_2\\int_{X_2} \\rho_2(x) \\log(w_2\\rho_2(x))dx=\\\\=w_1\\cdot H_1 + w_2\\cdot H_2 -w_1\\log w_1 - w_2\\log w_2\" alt=\"-w_1\\int_{X_1} \\rho_1(x) \\log(w_1\\rho_1(x))- w_2\\int_{X_2} \\rho_2(x) \\log(w_2\\rho_2(x))dx=\\\\=w_1\\cdot H_1 + w_2\\cdot H_2 -w_1\\log w_1 - w_2\\log w_2\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/07c\/2b6\/fb8\/07c2b6fb83648153756090b0514b78c1.svg\" width=\"619\" height=\"75\"\/><\/p>\n<p>In this problem, the goal was to show that even in the simple case of non-overlapping supports, entropies do not simply add up with their respective weights, but there is an additional term <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"-(w_1\\log w_1 + w_2 \\log w_2)\" alt=\"-(w_1\\log w_1 + w_2 \\log w_2)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/038\/5b8\/0c1\/0385b80c18481459f226257a3746f3b2.svg\" width=\"206\" height=\"22\"\/>. When the weights are equal to 1\/2, this additional term is equal to 1.  <\/p>\n<p>The interpretation of the formula is as follows: when an outcome is measured, with a probability of <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"w_1\" alt=\"w_1\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/004\/5cf\/77b\/0045cf77bf7488de96c74fffe6604f3d.svg\" width=\"23\" height=\"14\"\/>, it lies in <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"X_1\" alt=\"X_1\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/42a\/71e\/f78\/42a71ef78d0e7ec6bd5cac541b18b778.svg\" width=\"25\" height=\"19\"\/>, and with a probability of <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"w_2\" alt=\"w_2\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/80d\/a34\/ac0\/80da34ac02e959d3f3575829b54b15eb.svg\" width=\"23\" height=\"14\"\/>, it lies in <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"X_2\" alt=\"X_2\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/2de\/960\/1c8\/2de9601c82350625415ae29854f281d3.svg\" width=\"25\" height=\"19\"\/>. Consequently, we incur an uncertainty of <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"H_1\" alt=\"H_1\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/65a\/f4d\/6e0\/65af4d6e0aebfa506342952f501cd53e.svg\" width=\"25\" height=\"19\"\/> values on the set <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"X_1\" alt=\"X_1\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/301\/d19\/386\/301d19386c12b2ca652071ebecd2a62a.svg\" width=\"25\" height=\"19\"\/>, or an uncertainty of <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"H_2\" alt=\"H_2\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/452\/de4\/6f7\/452de46f78b7a15c4cb4c4302b57ac75.svg\" width=\"25\" height=\"19\"\/> on the set <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"X_2\" alt=\"X_2\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/596\/1f8\/5d7\/5961f85d71b0252efd4be78d25392b22.svg\" width=\"25\" height=\"19\"\/>. However, to determine in which set the measurement lies, on average, we will need to ask <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"-(w_1\\log w_1 + w_2 \\log w_2)\" alt=\"-(w_1\\log w_1 + w_2 \\log w_2)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ce0\/bd4\/01d\/ce0bd401d4ca11102a983d95c6980473.svg\" width=\"206\" height=\"22\"\/> questions.<\/p>\n<p>From this, it follows, in particular, that a mixture with coefficients of 1\/2 of two normal random variables with the same variance, but significantly different means, has an entropy, that is 1 greater than the entropy of a single normal distribution. The supports of normal random variables span the entire real line, which means they overlap, but in the case of significantly different means, this overlap can be neglected.<\/p>\n<\/div>\n<\/details>\n<p><strong>Task 1.12<\/strong>: A random variable <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\xi\" alt=\"\\xi\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/99f\/f18\/c86\/99ff18c86956f0cf223363fff1f57012.svg\" width=\"9\" height=\"21\"\/><\/em>  is equally likely to be 0 or 1. Another random variable <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\nu\" alt=\"\\nu\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d93\/ad0\/aec\/d93ad0aec13d5fe010b97e214cd5ae63.svg\" width=\"10\" height=\"12\"\/><\/em> depends on <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\xi\" alt=\"\\xi\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/99f\/f18\/c86\/99ff18c86956f0cf223363fff1f57012.svg\" width=\"9\" height=\"21\"\/><\/em> : if <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\xi=0\" alt=\"\\xi=0\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/27b\/d58\/89b\/27bd5889be66451a563d8c4d40f6ea7b.svg\" width=\"44\" height=\"21\"\/><\/em> , then <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\nu\" alt=\"\\nu\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b27\/70b\/3e4\/b2770b3e4df599f04038bdf1c15e779b.svg\" width=\"10\" height=\"12\"\/><\/em>   is sampled from <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\mathcal{N}(0, 1)\" alt=\"\\mathcal{N}(0, 1)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c57\/9c2\/575\/c579c257595d74d2b5e4a5d80399f2bf.svg\" width=\"63\" height=\"23\"\/><\/em>, and if <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\xi=1\" alt=\"\\xi=1\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/edb\/57f\/4d1\/edb57f4d17048b20530965e136ea13c3.svg\" width=\"44\" height=\"21\"\/><\/em>, then <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\nu\" alt=\"\\nu\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b27\/70b\/3e4\/b2770b3e4df599f04038bdf1c15e779b.svg\" width=\"10\" height=\"12\"\/><\/em> is sampled from <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\mathcal{N}(\\mu, 1)\" alt=\"\\mathcal{N}(\\mu, 1)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b54\/f77\/192\/b54f77192787f5efbd4daf8c1493feef.svg\" width=\"65\" height=\"23\"\/><\/em>. How many bits of information about the random variable <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\nu\" alt=\"\\nu\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b27\/70b\/3e4\/b2770b3e4df599f04038bdf1c15e779b.svg\" width=\"10\" height=\"12\"\/><\/em> are contained in the message <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"``\\xi=0&quot;\" alt=\"``\\xi=0&quot;\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f33\/c30\/cc1\/f33c30cc172f54540c5b4b362cba2823.svg\" width=\"70\" height=\"21\"\/><\/em>(as a function of <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\mu\" alt=\"\\mu\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/625\/aa6\/3b0\/625aa63b0128fa343595f7737bb953e1.svg\" width=\"12\" height=\"16\"\/><\/em>)?<\/p>\n<details class=\"spoiler\">\n<summary>Answer<\/summary>\n<div class=\"spoiler__content\">\n<p>There is a numerical answer to this:  <\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/77c\/770\/772\/77c770772d1ee165c1fb9653a4b71913.png\" width=\"1200\" height=\"758\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/77c\/770\/772\/77c770772d1ee165c1fb9653a4b71913.png\"\/><\/figure>\n<p>It&#8217;s clear that the graph starts at 0 and approaches 1:<\/p>\n<ul>\n<li>\n<p>When <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\mu=0\" alt=\"\\mu=0\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/24e\/ed2\/f94\/24eed2f94201100b5d812162167a3b89.svg\" width=\"48\" height=\"21\"\/><\/em>, both Gaussians are identical, and the message about which one was chosen provides no information.<\/p>\n<\/li>\n<li>\n<p>When <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\mu=5\" alt=\"\\mu=5\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8bf\/ac2\/342\/8bfac2342693b5fca402cce3c2378009.svg\" width=\"48\" height=\"21\"\/><\/em>, we have a mixture of two Gaussian distributions with widely separated centers. The message about the value of\u00a0<em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\xi\" alt=\"\\xi\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d79\/3bf\/afe\/d793bfafef3638353d006d52e4f990a2.svg\" width=\"9\" height=\"21\"\/><\/em> indicates which of the two &#171;bell curves&#187; the answer is in, reducing the number of possibilities by approximately <strong>half<\/strong>, and uncertainty <strong>decreases by 1<\/strong>. The &#171;approximation&#187; is related to the fact that the &#171;curves&#187; overlap, but the overlap size quickly decreases with increasing <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\mu\" alt=\"\\mu\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/324\/66f\/fc1\/32466ffc10d9f026b8017f4a3b8992f2.svg\" width=\"12\" height=\"16\"\/><\/em>.<\/p>\n<\/li>\n<li>\n<p>In the vicinity of <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\mu=0\" alt=\"\\mu=0\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/24e\/ed2\/f94\/24eed2f94201100b5d812162167a3b89.svg\" width=\"48\" height=\"21\"\/><\/em>, there is a quadratic growth, roughly <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"(\\mu\/2.37)^2\" alt=\"(\\mu\/2.37)^2\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7bf\/0fd\/8ab\/7bf0fd8ab7752a3c922f7c60f0ac0d52.svg\" width=\"80\" height=\"25\"\/><\/em>.<\/p>\n<\/li>\n<li>\n<p>The approach to 1 occurs approximately according to the law <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"1-e^{-(\\mu\/2.74)^2 - 0.21}.\" alt=\"1-e^{-(\\mu\/2.74)^2 - 0.21}.\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/703\/3f4\/b3e\/7033f4b3edb2ccea1bdfd46f6bd65b17.svg\" width=\"153\" height=\"26\"\/><\/em><\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/details>\n<p><strong>Task 1.13:<\/strong> The random variable\u00a0<em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\xi\" alt=\"\\xi\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/99f\/f18\/c86\/99ff18c86956f0cf223363fff1f57012.svg\" width=\"9\" height=\"21\"\/><\/em> is structured as follows: first, a number <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\lambda\" alt=\"\\lambda\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/1c0\/f97\/e0b\/1c0f97e0b3fa892497792a6afc5d439f.svg\" width=\"11\" height=\"17\"\/><\/em> is sampled from an exponential distribution with mean <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\lambda_0=10\" alt=\"\\lambda_0=10\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/fa1\/564\/3fb\/fa15643fb1b8b34058d24f9e73d8f620.svg\" width=\"66\" height=\"20\"\/><\/em>, and then a random number <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"x\" alt=\"x\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/16b\/e9e\/b17\/16be9eb177bb873b691a3aea3594750f.svg\" width=\"11\" height=\"12\"\/><\/em> is sampled from a Poisson distribution with parameter <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\lambda\" alt=\"\\lambda\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c32\/981\/a65\/c32981a65b45d4191ff20b0090131cdc.svg\" width=\"11\" height=\"17\"\/><\/em>. We received a message that one measurement yielded <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"x=10\" alt=\"x=10\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/eb9\/d5c\/2bd\/eb9d5c2bd935ec13f4b0f8510035573a.svg\" width=\"57\" height=\"17\"\/><\/em>. How many bits of information did we gain about the random variable <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\lambda\" alt=\"\\lambda\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3ef\/2ce\/e0a\/3ef2cee0add8149bf970419808cfa156.svg\" width=\"11\" height=\"17\"\/><\/em>? Provide a numerical answer. How many bits of information will the sequence of measurements 10, 9, 11, 8, 10 provide?<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"I(``x=10&quot;) = (4861 - 2520\\cdot \\gamma - 252\\cdot \\log(3628800\/11))\/(252\\cdot \\log(2)) \\approx 1.17.  \\\\ I(``x=10, 9, 11, 8, 10&quot;) = 3.729.\" alt=\"I(``x=10&quot;) = (4861 - 2520\\cdot \\gamma - 252\\cdot \\log(3628800\/11))\/(252\\cdot \\log(2)) \\approx 1.17.  \\\\ I(``x=10, 9, 11, 8, 10&quot;) = 3.729.\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/4f7\/b61\/f15\/4f7b61f158a850ada045651737015a52.svg\" width=\"697\" height=\"50\"\/><\/p>\n<p><strong>Task 1.14:<\/strong> The random variable\u00a0<em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\xi\" alt=\"\\xi\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/99f\/f18\/c86\/99ff18c86956f0cf223363fff1f57012.svg\" width=\"9\" height=\"21\"\/><\/em> is constructed as follows: first, a number <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"p\" alt=\"p\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d3a\/bbc\/846\/d3abbc8461865235a1ad8e4fc73fa983.svg\" width=\"11\" height=\"15\"\/><\/em> is sampled once from a beta distribution with parameters <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\alpha=9, \\beta=1\" alt=\"\\alpha=9, \\beta=1\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/4d5\/d3b\/e18\/4d5d3be186026b9b3c3bc4a1f5f1f187.svg\" width=\"104\" height=\"20\"\/><\/em>, and then a random number is sampled from a binomial distribution with parameters <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"n=100, \\;p\" alt=\"n=100, \\;p\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a5d\/f8c\/62f\/a5df8c62f93e0050369860a066db517e.svg\" width=\"91\" height=\"20\"\/><\/em>. We received a message that one measurement of <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\xi\" alt=\"\\xi\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/17a\/3b4\/2c6\/17a3b42c697efc4a1cfdf08975e12e61.svg\" width=\"9\" height=\"21\"\/><\/em> resulted in 10 (meaning 10 out of 100 coin flips resulted in heads). How many bits of information did we gain about the hidden random variable <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"p\" alt=\"p\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3d7\/68a\/7a3\/3d768a7a3dbd4f73548011d5af32717e.svg\" width=\"11\" height=\"15\"\/><\/em>? Provide a numerical answer. How many bits of information will a sequence of measurements 10, 9, 11, 8, 10 provide?<\/p>\n<p><strong>Task 1.15:<\/strong> Random variables <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"p_1,\\; p_2,\\;\\ldots,p_{10}\" alt=\"p_1,\\; p_2,\\;\\ldots,p_{10}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/dd5\/992\/bb7\/dd5992bb715e87410b3345d0ff888e73.svg\" width=\"127\" height=\"15\"\/><\/em>  are sampled from a beta distribution with parameters <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\alpha=9, \\beta=1\" alt=\"\\alpha=9, \\beta=1\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/4d5\/d3b\/e18\/4d5d3be186026b9b3c3bc4a1f5f1f187.svg\" width=\"104\" height=\"20\"\/><\/em>. The actual values of <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"p_1,\\; p_2,\\;\\ldots,p_{10}\" alt=\"p_1,\\; p_2,\\;\\ldots,p_{10}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/dd5\/992\/bb7\/dd5992bb715e87410b3345d0ff888e73.svg\" width=\"127\" height=\"15\"\/><\/em> are unknown to us, but we have been given 10 measurements <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"x_1,\\;x_2,\\;\\ldots,x_{10}\" alt=\"x_1,\\;x_2,\\;\\ldots,x_{10}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ccc\/437\/993\/ccc437993a1960b41a2d626f59d6c97b.svg\" width=\"130\" height=\"15\"\/><\/em> from 10 binomial distributions with parameters <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"n=100, \\;p_i\" alt=\"n=100, \\;p_i\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d8b\/a82\/1ef\/d8ba821ef15ee0edceb8fbdb0092a2e2.svg\" width=\"98\" height=\"20\"\/><\/em>, and this is our knowledge about <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"p_1,\\; p_2,\\;\\ldots,p_{10}\" alt=\"p_1,\\; p_2,\\;\\ldots,p_{10}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/4b0\/fe8\/46c\/4b0fe846ce78777357e58e28cfe83d5a.svg\" width=\"127\" height=\"15\"\/><\/em>\u200b. How many bits of information will we gain on average about a random binomial variable with parameters <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"n=100, \\;p_i\" alt=\"n=100, \\;p_i\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d8b\/a82\/1ef\/d8ba821ef15ee0edceb8fbdb0092a2e2.svg\" width=\"98\" height=\"20\"\/><\/em>\u200b when we are told the value of <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"i\" alt=\"i\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3a5\/510\/44d\/3a551044d09dcdaa34d15621c0af3f5e.svg\" width=\"7\" height=\"16\"\/><\/em>? What if <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"p_1,\\; p_2,\\;\\ldots,p_{10}\" alt=\"p_1,\\; p_2,\\;\\ldots,p_{10}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/4b0\/fe8\/46c\/4b0fe846ce78777357e58e28cfe83d5a.svg\" width=\"127\" height=\"15\"\/><\/em> are known with absolute certainty (i.e., <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"n=\\infty\" alt=\"n=\\infty\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/dcf\/f47\/739\/dcff47739e9fe0258f3fa91ce28b1c9a.svg\" width=\"57\" height=\"12\"\/><\/em>)? What if 10 is replaced with <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\infty\" alt=\"\\infty\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/4a1\/e7b\/422\/4a1e7b422d32599c269089fb680f5ea1.svg\" width=\"20\" height=\"12\"\/><\/em>?<\/p>\n<p>This problem can be formulated in the language of machine learning as follows: we have a categorical feature <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"i\" alt=\"i\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/764\/a1f\/819\/764a1f819c89132da6b6d24b350b0341.svg\" width=\"7\" height=\"16\"\/><\/em> to predict a binary variable (&#8216;will the user click on the banner or not&#8217;). How good will our prediction be if, in the training data, we only have historical data about the number of clicks and non-clicks for these 10 categories?<\/p>\n<p><strong>Task 1.16:<\/strong> A random variable <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\xi\" alt=\"\\xi\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8f1\/53d\/6fc\/8f153d6fc8ebfc40b0709e651fd95e6a.svg\" width=\"9\" height=\"21\"\/><\/em> follows a normal distribution <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\mathcal{N}(a,\\varepsilon^2)\" alt=\"\\mathcal{N}(a,\\varepsilon^2)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/cfd\/350\/3a2\/cfd3503a2b0b58899678fab8df897e9c.svg\" width=\"72\" height=\"25\"\/><\/em>. The value of <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"a\" alt=\"a\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5e8\/6f9\/cbf\/5e86f9cbf5134043b8b011c971510183.svg\" width=\"10\" height=\"12\"\/><\/em> is unknown to us, but we know that it was sampled from a distribution <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\mathcal{N}(0,\\sigma^2)\" alt=\"\\mathcal{N}(0,\\sigma^2)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8f3\/4b0\/2b3\/8f34b02b354529ef1853a7a116e3110b.svg\" width=\"73\" height=\"25\"\/><\/em>. On average, how much information will we gain about <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"a\" alt=\"a\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/6ab\/3fb\/3cf\/6ab3fb3cfc6a74d8d2fe3c48f3cc329a.svg\" width=\"10\" height=\"12\"\/><\/em> from the first measurement of <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\xi\" alt=\"\\xi\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8f1\/53d\/6fc\/8f153d6fc8ebfc40b0709e651fd95e6a.svg\" width=\"9\" height=\"21\"\/><\/em>? How will the amount of information gained grow with the number of measurements?<\/p>\n<details class=\"spoiler\">\n<summary>Answer<\/summary>\n<div class=\"spoiler__content\">\n<p>The initial variance <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"a\" alt=\"a\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/470\/51c\/66e\/47051c66e44ea00b765086c5767ef0c0.svg\" width=\"10\" height=\"12\"\/><\/em> is equal to <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\sigma^2\" alt=\"\\sigma^2\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/33d\/575\/cf6\/33d575cf6ae3cb8547a6aaa078c29268.svg\" width=\"20\" height=\"21\"\/><\/em>. After <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"m\" alt=\"m\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7b2\/a37\/354\/7b2a37354e731c6d2747a83fc040a630.svg\" width=\"17\" height=\"12\"\/><\/em> measurements, the variance decreases to <\/p>\n<p><em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\sigma_m^2=\\left({1\\over \\sigma^2} + {m \\over \\varepsilon^2}\\right)^{-1}\" alt=\"\\sigma_m^2=\\left({1\\over \\sigma^2} + {m \\over \\varepsilon^2}\\right)^{-1}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/2cc\/a48\/497\/2cca48497affee935feb9853c7d84086.svg\" width=\"175\" height=\"54\"\/><\/em>.<\/p>\n<p>From the initial entropy <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"C + 0.5\\cdot \\log(\\sigma^2)\" alt=\"C + 0.5\\cdot \\log(\\sigma^2)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/194\/b65\/a8d\/194b65a8d18be78f32906497e99aaed4.svg\" width=\"138\" height=\"25\"\/><\/em>, subtract the final entropy <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"C + 0.5\\cdot \\log(\\sigma_m^2)\" alt=\"C + 0.5\\cdot \\log(\\sigma_m^2)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e70\/4de\/ccc\/e704deccc33fed1d55ca28169883883b.svg\" width=\"143\" height=\"23\"\/><\/em>, and we get<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"{1\\over  2} \\cdot \\log\\left(1 + m\\cdot {\\varepsilon^2 \\over \\sigma^2}\\right)\" alt=\"{1\\over  2} \\cdot \\log\\left(1 + m\\cdot {\\varepsilon^2 \\over \\sigma^2}\\right)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/980\/4e4\/c7a\/9804e4c7a718e273af742c2a2bddb2bb.svg\" width=\"174\" height=\"51\"\/><\/p>\n<p>Thus, for large <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"m\" alt=\"m\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/151\/34a\/0ee\/15134a0ee2c391f820a6d9d57969dca3.svg\" width=\"17\" height=\"12\"\/><\/em>, the information grows as <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"c + {1\\over 2}\\log(m)\" alt=\"c + {1\\over 2}\\log(m)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8d9\/303\/6d2\/8d93036d26837b5323cf570a1ab361e5.svg\" width=\"108\" height=\"42\"\/><\/em>, and the error <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\sigma_m\" alt=\"\\sigma_m\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/68a\/4cf\/7be\/68a4cf7be8685ab4be88c1f67a9d41d3.svg\" width=\"25\" height=\"15\"\/><\/em>decreases approximately proportionally to <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"1\/\\sqrt{m}\" alt=\"1\/\\sqrt{m}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ea1\/d82\/95c\/ea1d8295c5594105b6f1140eba80c2f3.svg\" width=\"53\" height=\"24\"\/><\/em>\u200b. <\/p>\n<p>This means that the number of correct digits in the decimal representation of the number <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"a\" alt=\"a\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/562\/7a7\/84d\/5627a784d935406f15ef6122baa6c230.svg\" width=\"10\" height=\"12\"\/><\/em> grows as <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\log(\\sqrt{m}) \/\\log(10)\" alt=\"\\log(\\sqrt{m}) \/\\log(10)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f70\/74e\/929\/f7074e9299bee530052d7aedc3537e2c.svg\" width=\"146\" height=\"24\"\/><\/em>. If you want to get one more correct decimal digit of the number <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"a\" alt=\"a\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/26a\/ed1\/e00\/26aed1e00f225a0d9ccd5a811f16fdef.svg\" width=\"10\" height=\"12\"\/><\/em>, you need to increase the number of measurements <em><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"m\" alt=\"m\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/92a\/a75\/846\/92aa75846340df96ca60f16ff6740eeb.svg\" width=\"17\" height=\"12\"\/><\/em> by a factor of 100.<\/p>\n<\/div>\n<\/details>\n<p>Continuation:<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/habr.com\/en\/articles\/764942\/\" rel=\"noopener noreferrer nofollow\">Part 2 &#8212; Mutual Information:<\/a> In this part, the concept of Mutual Information is explained. It opens doors to error-correcting codes, compression algorithms, and provides a new perspective on Machine Learning problems.<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/habr.com\/en\/articles\/781874\/\" rel=\"noopener noreferrer nofollow\">Part 3 &#8212; ML &amp; Mutual Information:<\/a> Fundamentals of Machine Learning in the context of information theory.<\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/763090\/\"> https:\/\/habr.com\/ru\/articles\/763090\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>I&#8217;ve long wanted to create educational materials on the topic of <a href=\"https:\/\/en.wikipedia.org\/wiki\/Mutual_information\" rel=\"noopener noreferrer nofollow\">Information Theory<\/a> + <a href=\"https:\/\/en.wikipedia.org\/wiki\/Machine_learning\" rel=\"noopener noreferrer nofollow\">Machine Learning<\/a>. I found some old drafts and decided to polish them up here, on Habr. <\/p>\n<p>Information Theory and Machine Learning seem to me like an interesting pair of fields, the deep connection between which is often unknown to ML engineers, and whose synergy has not yet been fully revealed.  <\/p>\n<p>When I tell colleagues that <a href=\"https:\/\/en.wikipedia.org\/wiki\/Cross-entropy#Cross-entropy_loss_function_and_logistic_regression\" rel=\"noopener noreferrer nofollow\">LogLoss <\/a>on the test set and <a href=\"https:\/\/en.wikipedia.org\/wiki\/Mutual_information\" rel=\"noopener noreferrer nofollow\">Mutual Information<\/a> between the prediction and the predicted value are directly related, and that you can get one from the other using a simple formula, they often express genuine surprise. There is a link from the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Cross-entropy#Cross-entropy_loss_function_and_logistic_regression\" rel=\"noopener noreferrer nofollow\">LogLoss<\/a> Wikipedia page to <a href=\"https:\/\/en.wikipedia.org\/wiki\/Mutual_information\" rel=\"noopener noreferrer nofollow\">Mutual Information<\/a>, but that&#8217;s about it.<\/p>\n<p>Information Theory can become (or rather, <a href=\"https:\/\/arxiv.org\/pdf\/2004.14941.pdf\" rel=\"noopener noreferrer nofollow\">has become<\/a>) a source of understanding how and why different ML methods work, especially neural networks, and can also provide <a href=\"http:\/\/www.its.caltech.edu\/~daw\/papers\/98-Wage2.pdf\" rel=\"noopener noreferrer nofollow\">ideas for improving gradient-based optimization methods<\/a>.<\/p>\n<p>Let&#8217;s start with basic concepts like Entropy, Information in a message, Mutual Information, and channel capacity. Next, there will be materials on the similarity between tasks of maximizing Mutual Information and minimizing Loss in regression problems. Then there will be a section on Information Geometry: <a href=\"https:\/\/en.wikipedia.org\/wiki\/Fisher_information_metric\" rel=\"noopener noreferrer nofollow\">Fisher metric<\/a>, geodesics, gradient methods, and their connection to Gaussian processes (moving along the gradient using SGD is moving along the geodesic with noise).<\/p>\n<p>It&#8217;s also necessary to touch upon <a href=\"https:\/\/en.wikipedia.org\/wiki\/Akaike_information_criterion\" rel=\"noopener noreferrer nofollow\">AIC<\/a>, <a href=\"https:\/\/en.wikipedia.org\/wiki\/Information_bottleneck_method\" rel=\"noopener noreferrer nofollow\">Information Bottleneck<\/a>, and discuss how information flows in neural networks \u2013 Mutual Information between layers (<a href=\"https:\/\/www.youtube.com\/watch?v=XL07WEc2TRI&amp;ab_channel=StanfordOnline\" rel=\"noopener noreferrer nofollow\">Information Theory of Deep Learning, Naftali Tishby<\/a>), and much more. It&#8217;s not certain that I&#8217;ll be able to cover everything listed, but I&#8217;ll try to get started.<\/p>\n<p><strong>1. Basic Definitions<\/strong>   <\/p>\n<p> 0.\\;\\;\\;\\;\\;\\;&#187; alt=&#187;\\sum_{i=1}^M p_i =1, \\;\\; p_i > 0.\\;\\;\\;\\;\\;\\;&#187; src=&#187;https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3b0\/b7c\/de0\/3b0b7cde0e031276d3f6ceef94156d05.svg&#187; width=&#187;191&#8243; height=&#187;60&#8243;\/><\/p>\n<p>Let&#8217;s describe them. We&#8217;ll start with basic definitions  <\/p>\n<p><strong>Definition 1.1: Uncertainty<\/strong> is the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Logarithm\" rel=\"noopener noreferrer nofollow\">logarithm<\/a> base 2 of the number of equiprobable possibilities: . It is measured in <strong>bits<\/strong>. For example, the uncertainty of an unknown <strong>binary word<\/strong> of length <em>k<\/em> is equal to k.  <\/p>\n<details class=\"spoiler\">\n<summary>Logarithm<\/summary>\n<div class=\"spoiler__content\">\n<p>The <a href=\"https:\/\/en.wikipedia.org\/wiki\/Logarithm\" rel=\"noopener noreferrer nofollow\">logarithm<\/a> base 2 of a number is how many times you need to divide the number by 2 to get a number less than or equal to 1. For example,<\/p>\n<p>For non-powers of two, this function smoothly extends. For example,<\/p>\n<p>An important property of logarithms:<\/p>\n<p>Try to derive it from the non-strict definition above for the case when  and  are powers of two.<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>Binary words<\/summary>\n<div class=\"spoiler__content\">\n<p>Binary words of length k are sequences of zeros and ones of length k. Each character in a binary words is called a bit. For example, here are binary words of length 5:<\/p>\n<p>00000, 00001, 00010, 00011, 00100, 00101, &#8230; , 11100, 11101, 111110, 11111 <\/p>\n<p>There are 32 of them.  , which means the uncertainty of a 5-bit word is 5.<\/p>\n<p>That&#8217;s exactly the number of unknown bits in an unknown 5-bit binary word.<\/p>\n<p>Thus, each symbol in a binary word is called a &#171;bit,&#187; but a &#171;bit&#187; is also a unit of uncertainty measurement. And this example helps to understand why.<\/p>\n<\/div>\n<\/details>\n<p>For brevity,   is simply denoted as  throughout.<\/p>\n<p><strong>Definition 1.2: Information in a message<\/strong> is the difference in uncertainty before receiving the message and after.<\/p>\n<p>This is also measured in bits.<\/p>\n<p>For example, Vanya has chosen a number from 1 to 100. We are told that it is less than or equal to 50. The uncertainty before the message is , and after the message, it is . Therefore, there is 1 bit of information in this message. By skillfully asking binary questions (questions to which the answer is either YES or NO), you can extract exactly 1 bit of information.<\/p>\n<p>Some questions are inefficient. For instance, the question &#171;Is the number less than or equal to 25?&#187; reduces uncertainty by  bits with a probability of 0.25, and with a probability of 0.75, it only reduces it by  bits, which on average is  bits. If you divide the set of possibilities in a ratio of <em><\/em>, with your question, then the average amount of information in the answer is .<\/p>\n<p>We will denote this expression as  or . Here, as programmers, we <strong>overload the function H<\/strong> to work in two cases &#8212; when a pair of numbers is input, the sum of which is 1, and when one number is from the interval [0, 1].<\/p>\n<p><strong>Definition 1.3:<\/strong>\u00a0<em><\/em>  <\/p>\n<details class=\"spoiler\">\n<summary>Plot H(x)<\/summary>\n<div class=\"spoiler__content\">\n<figure class=\"full-width\"><\/figure>\n<\/p>\n<\/div>\n<\/details>\n<p>It&#8217;s evident that by asking binary questions, you can extract a maximum of 1 bit of information on average (the maximum value of the function . Let&#8217;s reiterate: yes, you can directly ask questions like &#171;Is the number equal to 57?&#187; and if you&#8217;re lucky, you can get log(100) bits of information. However, if luck is not on your side, you will only get log(100\/99) bits of information. <strong>The average number of bits of information<\/strong> for such types of questions is which is noticeably less than 1.<\/p>\n<p>In this example, there are 100 possibilities, which means the initial uncertainty is\u2013 this is how many binary questions you, on average, need to ask Vanya to find out the answer. However, the number is not an integer, so you need to round it up.<\/p>\n<p>If we ask not binary questions but questions that imply a natural number from 1 to M as the answer, we can get more than one bit of information in a single response. If we ask a question for which all M answers are equally likely, then on average, we will get  bits. However, if the probability of answer <em>i<\/em> is <em>p<\/em>(<em>i<\/em>), then the average number of bits in the response will be:<\/p>\n<p><strong>Definition 1.4: The entropy of a discrete distribution<\/strong> \u00a0<em><\/em>   is defined by the formula (1) above.<\/p>\n<p>Here, we have overloaded the function H for the case when a discrete distribution is provided as input.<\/p>\n<p><strong>SO: The first straightforward way to arrive at the formula for entropy <\/strong><strong> is to calculate the average number of bits of information in response to a question with equiprobable answers.<\/strong><\/p>\n<p>Let&#8217;s go further. Suppose Vanya doesn&#8217;t choose a number but samples it from the distribution <em><\/em>  . How many binary questions do we need to ask Vanya to determine the sampled number? Intuitively, we need to divide the set of possibilities into two subsets, not necessarily of equal size but with approximately equal total probability, and ask Vanya which of the two subsets contains the sampled number. Get the answer and continue in the same manner with the reduced set of possibilities &#8212; again dividing it into two subsets with roughly equal probability, asking Vanya which of the two subsets contains the sampled number, and so on. The idea is good but not quite practical. It turns out it&#8217;s more effective to work backward and start building the partition tree from the bottom. Specifically, find the two least probable outcomes and merge them into a single new outcome, thus reducing the number of possibilities by 1. Then, once again, find the two least probable outcomes and merge them into a new one, and so on, ultimately constructing a binary tree. The numbers are located in the leaves of this tree. The internal nodes are labeled with sets of numbers from the subtree they represent, and the root is labeled with the set of all numbers. This tree provides an algorithm for how to ask Vanya questions. You should start at the root of the tree and ask Vanya which way to go &#8212; left or right (which of the two children subsets contains the sampled number) according to this tree structure. This tree not only provides the recipe for the fastest average method of guessing the number but also serves as the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Huffman_coding\" rel=\"noopener noreferrer nofollow\">Huffman algorithm for data compression<\/a>.<\/p>\n<p><strong>Task 1.1:<\/strong> Study the Huffman code. Prove that a text with an original length of  characters, in its compressed form, has a length bounded from below by  bits, and under favorable circumstances, it achieves this bound.<\/p>\n<p><strong>So, the formula <\/strong><strong> arises when solving the problem of finding the minimum average number of binary questions needed to determine the outcome of a random variable with distribution <\/strong><strong>.<\/strong><\/p>\n<p>This is the second way to arrive at formula (1).<\/p>\n<p>For a random variable , we will use the following notations for the entropy of its distribution  (once again, &#171;overloading&#187; the function ):<\/p>\n<p> or  or  or <\/p>\n<p>There&#8217;s yet another, a third, simple way to arrive at the formula for entropy, but it requires knowledge of <a href=\"https:\/\/en.wikipedia.org\/wiki\/Stirling%27s_approximation\" rel=\"noopener noreferrer nofollow\">the Stirling formula<\/a>.<\/p>\n<p><strong>Task 1.2:<\/strong> You have an unknown binary word of length k (a sequence of ones and zeros, a total of  characters). You are told that it contains 35% ones. What is the value of  for large <\/p>\n<details class=\"spoiler\">\n<summary>Answer<\/summary>\n<div class=\"spoiler__content\">\n<p>Approximately<em><\/em>, where\u00a0<em><\/em>  <\/p>\n<\/div>\n<\/details>\n<p><strong>Task 1.3:<\/strong> Vanya has an unknown word of length k in an alphabet of size M. He has provided the proportions of all the letters in the word as . <br \/>What is the value of I(message) \/ k for large k? <\/p>\n<details class=\"spoiler\">\n<summary>Answer<\/summary>\n<div class=\"spoiler__content\">\n<\/div>\n<\/details>\n<p>So, Task 1.3 is indeed the third way to arrive at formula (1).<\/p>\n<p><strong>Definition 1.5:<\/strong> Information in a message about a certain random variable is the difference in entropies: <\/p>\n<p>The values of a random discrete variable can be seen as letters, and each successive letter in a word is just another measurement of the random variable. So, the information in a message about a certain random variable is the number of bits of information about measurements of that random variable, normalized by the number of measurements.<\/p>\n<p><strong>Problem 1.4<\/strong>: What is the entropy of the discrete distribution ? How much information is contained in the message , where  has the distribution ?<\/p>\n<details class=\"spoiler\">\n<summary>Answer<\/summary>\n<div class=\"spoiler__content\">\n<p>This result requires acceptance. How can this be? \u2013 We were given seemingly non-zero information, eliminated the most probable option from the possibilities. However, the uncertainty about the remaining possibilities remains the same, so the formula  yields an answer of 0.  <\/p>\n<\/div>\n<\/details>\n<p><strong>Task 1.5:<\/strong> Provide an example of a finite distribution and a message that does not reduce but increases uncertainty.<\/p>\n<details class=\"spoiler\">\n<summary>\u041e\u0442\u0432\u0435\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p><em><\/em>, and message = &#171;this is not the first element&#187;. Then\u00a0<em><\/em>  <\/p>\n<\/div>\n<\/details>\n<p>The ancient wisdom &#171;in much wisdom is much grief&#187; in this context gets another interesting interpretation: the modern world, science, and human life are such that new &#171;messages&#187; about history and the structure of the world only increase uncertainty.<\/p>\n<p>Discrete distributions on a countable set of values that decay<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-355705","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/355705","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=355705"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/355705\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=355705"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=355705"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=355705"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}