<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by thiru veeran on Medium]]></title>
        <description><![CDATA[Stories by thiru veeran on Medium]]></description>
        <link>https://medium.com/@mailtothirugnanam?source=rss-32366e89f3f5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*txnmh6bTD_88uKQ5</url>
            <title>Stories by thiru veeran on Medium</title>
            <link>https://medium.com/@mailtothirugnanam?source=rss-32366e89f3f5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 10:47:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mailtothirugnanam/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Information theory, Information content, Entropy, Cross Entropy.]]></title>
            <link>https://medium.com/@mailtothirugnanam/information-theory-information-content-entropy-cross-entropy-f1ec7f2881a7?source=rss-32366e89f3f5------2</link>
            <guid isPermaLink="false">https://medium.com/p/f1ec7f2881a7</guid>
            <category><![CDATA[information-theory]]></category>
            <dc:creator><![CDATA[thiru veeran]]></dc:creator>
            <pubDate>Sat, 18 Jan 2020 06:02:13 GMT</pubDate>
            <atom:updated>2020-01-18T06:02:13.520Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello to everyone, its always nice to know what is actually happening behind the scenes of an event that we are encountering in our day to day life. Today i am going to explain why cross entropy used as loss function in some ML algorithms and DL.</p><p>Now let us consider a problem. We have to predict which team is going to lift the cup in IPL 2019. So x is the random variable which takes values on three teams for say CHENNAI SUPER KINGS, DELHI CAPITALS, SUN RISERS HYDERABAD. Now let us consider a true probability distribution on x, lets say [0.3,0.6,0.1] its in the order of team that we listed before i.e 0.3 for chennai, 0.6 for delhi, 0.1 for hyderabad. Now we are asking an person to say the probability of winning percentage of each team and he is giving predicted distribution like this[0.2,0.4,0.4].</p><p>As we have said [0.3,0.6,0.1] is the true winning probability distribution now we have to assess how wrong the predicted probability is. Simply we can take sum of squared error loss i.e(( 0.2–0.3)**2+(0.4–0.6)**2+(0.4–0.1)**2) and we can use this as an objective function and give it to the learning algorithm to reduce the error. This may be an way of doing it but we want an better way of doing(considering elements sum to 1)</p><p>Now i am having three pictures with me lets say dog,cat,tiger. While training my model i will give the picture and its correct label to my model. let say i have given tiger as the input picture then the distribution will look like [0,0,1]. And now at test time if i give an picture of an tiger to my model its going to give its prediction in the form of distribution. Consider my model outputs the distribution as [0.25,0.5,0.25]. But how can we make our model as a better predictor. To do so we have to reduce the error it made during prediction i.e getting the value close to 1 or 1(by adjusting the model parameters) to the input image i have given.In our case bringing the third element of the vector close to 1. So now we have two distributions p and q. p is the actual distribution, q is the predicted distribution</p><p>Now lets return back to our cricket example, i am into betting and i have to say which team is going to win. Again x is the random variable which can take values on three teams and there is an probability distribution on those teams and also there is some loss or again which depends on the happening of that event. It looks like</p><h3>X(random variable) [CHENNAI, DELHI, HYDERABAD]</h3><h3>P(X) [0.3,0.5,0.2]</h3><h3>MONEY[10K, 20K, -10K]</h3><p>there is 30 percent chance that i will earn 10k and 50 percent chance that i will earn 20k and 20 percent chance that i will lose 10 k.Expected profit(0.3*10k+0.5*20k+0.2*-10k).</p><p>Now lets get into information content. Its like, information content will be high when some thing enhanced my knowledge. For example if there is more dark clouds and my friend is saying today its going to rain. There is no surprise on it since there is high probability of rain when dark cloud appears. So here information content is low. Information content will be high when someone says today there is going to be heavy rain in march month(chennai). Normally heavy rain in march month has very low probability. What it says is information content will be high when probability is low and it will be low when probability is high.</p><h3>In other words INFORMATION CONTENT IS INVERSELY PROPORTIONAL TO PROBABILITY</h3><p>Now consider we have given with two independent random variable A and B.</p><p>lets say A will take on values whether chennai or delhi is going to win and B take on values whether in the next month there is going to be aheavy rain or not.</p><p>Now if i am saying something about these two events. what will be the information content of the two variables</p><h3>IC(A and B)=IC(A)+IC(B) because they are independent.</h3><p>now there exist an function in which when i plug in the probability to the function it will give me the information content</p><h3>f(p(A.B))=f(p(A)+f(p(B) as we know IC depends on probability</h3><blockquote><strong>now what is actually happening here is i have a function <em>f(p(A,B)) which equals to f(p(A))+f(p(B))</em></strong></blockquote><p>its looks similar to log function right!</p><p>that is why information content is the log of the probability</p><h3>IC(A)=log(p(A))</h3><p>but i wanted it to be inversely proportional</p><h3>IC(A)=log(1/p(A))</h3><p>and that is why</p><h3>IC(A)=- log p(A) negative sign appears in it</h3><p>now lets take random variable x which take on values three teams we discussed and for each team there is aprobability associated with it such that it sums to one.</p><p>now it means since i have probability values for each team i have information content on each team. now consider information content as the value associated with that probability as we have seen 10 k for chennai 20k for delhi like that.</p><p>now if i want to know entropy or expected information content means we will do same as we done in that case.</p><p>so now</p><h3>entropy = — (p (x=chennai) log p(x=chennai)+p (x=delhi) log p(x=delhi)+p (x=hyderabad) log p(x=hyderabad)</h3><p>now whats the entropy if delhi wins</p><p>the second term in the formula will have 1 log 1 and remaining terms will be 0 log some value the resultant will be zero.</p><h3>CROSS ENTROPY</h3><p>Consider we are trying to transmit a message and x is the random variable and it take on values like [proceed,stop,return,stay]. we use encode this message and send and assuming all are equally likely to be transmitted</p><p>00 proceed p=0.25</p><p>01 stop p = 0.25</p><p>10 return p = 0.25</p><p>11 stay p = 0.25</p><p>now the information content is</p><h3>log(1/4)=2 bits</h3><p>now if there is eight messages it will be</p><p>000</p><p>001</p><p>010</p><p>::::</p><p>:::</p><p>110</p><p>111</p><p>it takes eighth values again assuming everything equally likely each will have p=1/8</p><h3>log(1/8)=3 bits</h3><p>now if we have four messages without equally likely</p><p>proceed with p=1/2</p><p>stop with p=1/4</p><p>return with p=1/8</p><p>stay with p=1/8</p><p>each will use different bits to transfer message and message which i will send most frequently that is A will use fewer bits than others since its going to nbe transmitted many times.</p><p>now if i want to know the expectation of bits will be sent of this</p><p>proceed with p=1/2 bits=1</p><p>stop with p=1/4 bits=2</p><p>return with p=1/8 bits=3</p><p>stay with p=1/8 bits=3</p><p>expected bits= 1.75 on average we will use 1.75 bits.if we consider everthing equally likely we will use average of 2 bits. we are saving some bits!</p><p>consider there is a some true distribution from where these messages arrive but we dont know what this true distribution is.</p><p>consider messages are streaming in multiples of 1000 and we dont have access to entire message. we will predict a distribution based on what we have seen so far in the streaming pattern and now we will assign bit range for next message based on the predicted probability.But the problem here is, we assigned some bit range for the next message which we have decided from the distribution of the message streamed.There might be variation in the distribution due to the streaming of unseen messages for which we don’t have access.</p><p>p is true distribution [p1,p2,p3,p4]</p><p>q is the estimated distribution [q1,q2,q3,q4]</p><p>we dont have access to p and we are assigning bits based on q eg. — logq1,- log q2.</p><p>now p=[p1,p2,p3,p4]</p><p>and</p><p>q=[-logq1,-logq2,-logq3,-logq4]</p><p>now expectation will be</p><ul><li>-(p1 logq1+p2logq2+pnlogqn) (p values will be imagined as how we know label for every observation in the train data)</li><li>now if we assign some bit for message ‘proceed’ which might wrong means then p1 will take care on that.</li></ul><p>now our ultimate goal(minimizing the loss function) boils down to</p><h3>minimize -(p1 log q1+p2 logq2+pn log qn) with respect to qi</h3><p>to achieve the above problem we can take partial derivative of every variable i.e q1,q2,q3 and set it to zero.</p><p>but it wont work because here we are dealing with constarined optimization problem where qi sums to 1.</p><p>for this we can use lagrange multiplier</p><p>now objective function looks like</p><h3>-(p1 logq1+pn logqn)+lambda((q1+qn)-1)</h3><p>now the intuition behind this is</p><h3>-(p1 logq1+pn logqn) .this is the quantity that we are trying to minimize and to do that we have added a factor which takes care of our constrain.</h3><p>since (q1+qn) =1 is our constrain.if it gets satisfied means</p><p>(q1+qn)-1) this will go to zero and i will be staying at the minimum value got for this one -(p1 logq1+pn logqn).</p><p>if we violate the constrain, (q1+qn)-1) wont go to zero and it will inflate my minimum value.</p><p>lambda is the adjusting parameter to ensure its non negative.</p><h4>now differentiating this will give us -(p1 logq1+pn logqn)+lambda((q1+qn)-1)</h4><h3>- p1/q1+lambda(1)=0</h3><h3>p1=lambda(q1) lamda becomes 1</h3><h3>p1=q1</h3><ul><li>hence cross entropy says that if the true distribution is equal to the predicted distribution, loss function will be at its minima.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f1ec7f2881a7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Information theory, Information content, Entropy, Cross Entropy.]]></title>
            <link>https://medium.com/@mailtothirugnanam/information-theory-information-content-entropy-cross-entropy-19de96292740?source=rss-32366e89f3f5------2</link>
            <guid isPermaLink="false">https://medium.com/p/19de96292740</guid>
            <category><![CDATA[loss-function]]></category>
            <dc:creator><![CDATA[thiru veeran]]></dc:creator>
            <pubDate>Tue, 11 Dec 2018 19:06:44 GMT</pubDate>
            <atom:updated>2018-12-11T19:06:44.587Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello to everyone, its always nice to know what is actually happening behind the scenes of an event that we are encountering in our day to day life. Today i am going to explain why cross entropy used as loss function in some ML algorithms and DL.</p><p>Now let us consider a problem. We have to predict which team is going to lift the cup in IPL 2019. So x is the random variable which takes values on three teams for say CHENNAI SUPER KINGS, DELHI CAPITALS, SUN RISERS HYDERABAD. Now let us consider a true probability distribution on x, lets say [0.3,0.6,0.1] its in the order of team that we listed before i.e 0.3 for chennai, 0.6 for delhi, 0.1 for hyderabad. Now we are asking an person to say the probability of winning percentage of each team and he is giving predicted distribution like this[0.2,0.4,0.4].</p><p>As we have said [0.3,0.6,0.1] is the true winning probability distribution now we have to assess how wrong the predicted probability is. Simply we can take sum of squared error loss i.e(( 0.2–0.3)**2+(0.4–0.6)**2+(0.4–0.1)**2) and we can use this as an objective function and give it to the learning algorithm to reduce the error. This may be an way of doing it but we want an better way of doing(considering elements sum to 1)</p><p>Now i am having three pictures with me lets say dog,cat,tiger. While training my model i will give the picture and its correct label to my model. let say i have given tiger as the input picture then the distribution will look like [0,0,1]. And now at test time if i give an picture of an tiger to my model its going to give its prediction in the form of distribution. Consider my model outputs the distribution as [0.25,0.5,0.25]. But how can we make our model as a better predictor. To do so we have to reduce the error it made during prediction i.e getting the value close to 1 or 1(by adjusting the model parameters) to the input image i have given.In our case bringing the third element of the vector close to 1. So now we have two distributions p and q. p is the actual distribution, q is the predicted distribution</p><p>Now lets return back to our cricket example, i am into betting and i have to say which team is going to win. Again x is the random variable which can take values on three teams and there is an probability distribution on those teams and also there is some loss or again which depends on the happening of that event. It looks like</p><h3>X(random variable) [CHENNAI, DELHI, HYDERABAD]</h3><h3>P(X) [0.3,0.5,0.2]</h3><h3>MONEY[10K, 20K, -10K]</h3><p>there is 30 percent chance that i will earn 10k and 50 percent chance that i will earn 20k and 20 percent chance that i will lose 10 k.Expected profit(0.3*10k+0.5*20k+0.2*-10k).</p><p>Now lets get into information content. Its like, information content will be high when some thing enhanced my knowledge. For example if there is more dark clouds and my friend is saying today its going to rain. There is no surprise on it since there is high probability of rain when dark cloud appears. So here information content is low. Information content will be high when someone says today there is going to be heavy rain in march month(chennai). Normally heavy rain in march month has very low probability. What it says is information content will be high when probability is low and it will be low when probability is high.</p><h3>In other words INFORMATION CONTENT IS INVERSELY PROPORTIONAL TO PROBABILITY</h3><p>Now consider we have given with two independent random variable A and B.</p><p>lets say A will take on values whether chennai or delhi is going to win and B take on values whether in the next month there is going to be aheavy rain or not.</p><p>Now if i am saying something about these two events. what will be the information content of the two variables</p><h3>IC(A and B)=IC(A)+IC(B) because they are independent.</h3><p>now there exist an function in which when i plug in the probability to the function it will give me the information content</p><h3>f(p(A.B))=f(p(A)+f(p(B) as we know IC depends on probability</h3><blockquote><strong>now what is actually happening here is i have a function <em>f(p(A,B)) which equals to f(p(A))+f(p(B))</em></strong></blockquote><p>its looks similar to log function right!</p><p>that is why information content is the log of the probability</p><h3>IC(A)=log(p(A))</h3><p>but i wanted it to be inversely proportional</p><h3>IC(A)=log(1/p(A))</h3><p>and that is why</p><h3>IC(A)=- log p(A) negative sign appears in it</h3><p>now lets take random variable x which take on values three teams we discussed and for each team there is aprobability associated with it such that it sums to one.</p><p>now it means since i have probability values for each team i have information content on each team. now consider information content as the value associated with that probability as we have seen 10 k for chennai 20k for delhi like that.</p><p>now if i want to know entropy or expected information content means we will do same as we done in that case.</p><p>so now</p><h3>entropy = — (p (x=chennai) log p(x=chennai)+p (x=delhi) log p(x=delhi)+p (x=hyderabad) log p(x=hyderabad)</h3><p>now whats the entropy if delhi wins</p><p>the second term in the formula will have 1 log 1 and remaining terms will be 0 log some value the resultant will be zero.</p><h3>CROSS ENTROPY</h3><p>Consider we are trying to transmit a message and x is the random variable and it take on values like [proceed,stop,return,stay]. we use encode this message and send and assuming all are equally likely to be transmitted</p><p>00 proceed p=0.25</p><p>01 stop p = 0.25</p><p>10 return p = 0.25</p><p>11 stay p = 0.25</p><p>now the information content is</p><h3>log(1/4)=2 bits</h3><p>now if there is eight messages it will be</p><p>000</p><p>001</p><p>010</p><p>::::</p><p>:::</p><p>110</p><p>111</p><p>it takes eighth values again assuming everything equally likely each will have p=1/8</p><h3>log(1/8)=3 bits</h3><p>now if we have four messages without equally likely</p><p>proceed with p=1/2</p><p>stop with p=1/4</p><p>return with p=1/8</p><p>stay with p=1/8</p><p>each will use different bits to transfer message and message which i will send most frequently that is A will use fewer bits than others since its going to nbe transmitted many times.</p><p>now if i want to know the expectation of bits will be sent of this</p><p>proceed with p=1/2 bits=1</p><p>stop with p=1/4 bits=2</p><p>return with p=1/8 bits=3</p><p>stay with p=1/8 bits=3</p><p>expected bits= 1.75 on average we will use 1.75 bits.if we consider everthing equally likely we will use average of 2 bits. we are saving some bits!</p><p>consider there is a some true distribution from where these messages arrive but we dont know what this true distribution is.</p><p>consider messages are streaming in multiples of 1000 and we dont have access to entire message. we will predict a distribution based on what we have seen so far in the streaming pattern and now we will assign bit range for next message based on the predicted probability.But the problem here is, we assigned some bit range for the next message which we have decided from the distribution of the message streamed.There might be variation in the distribution due to the streaming of unseen messages for which we don’t have access.</p><p>p is true distribution [p1,p2,p3,p4]</p><p>q is the estimated distribution [q1,q2,q3,q4]</p><p>we dont have access to p and we are assigning bits based on q eg. - logq1,- log q2.</p><p>now p=[p1,p2,p3,p4]</p><p>and</p><p>q=[-logq1,-logq2,-logq3,-logq4]</p><p>now expectation will be</p><ul><li>-(p1 logq1+p2logq2+pnlogqn) (p values will be imagined as how we know label for every observation in the train data)</li><li>now if we assign some bit for message ‘proceed’ which might wrong means then p1 will take care on that.</li></ul><p>now our ultimate goal(minimizing the loss function) boils down to</p><h3>minimize -(p1 log q1+p2 logq2+pn log qn) with respect to qi</h3><p>to achieve the above problem we can take partial derivative of every variable i.e q1,q2,q3 and set it to zero.</p><p>but it wont work because here we are dealing with constarined optimization problem where qi sums to 1.</p><p>for this we can use lagrange multiplier</p><p>now objective function looks like</p><h3>-(p1 logq1+pn logqn)+lambda((q1+qn)-1)</h3><p>now the intuition behind this is</p><h3>-(p1 logq1+pn logqn) .this is the quantity that we are trying to minimize and to do that we have added a factor which takes care of our constrain.</h3><p>since (q1+qn) =1 is our constrain.if it gets satisfied means</p><p>(q1+qn)-1) this will go to zero and i will be staying at the minimum value got for this one -(p1 logq1+pn logqn).</p><p>if we violate the constrain, (q1+qn)-1) wont go to zero and it will inflate my minimum value.</p><p>lambda is the adjusting parameter to ensure its non negative.</p><h4>now differentiating this will give us -(p1 logq1+pn logqn)+lambda((q1+qn)-1)</h4><h3>- p1/q1+lambda(1)=0</h3><h3>p1=lambda(q1) lamda becomes 1</h3><h3>p1=q1</h3><ul><li>hence cross entropy says that if the true distribution is equal to the predicted distribution, loss function will be at its minima.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=19de96292740" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>