<script data-pm-proxy="intercept"></script><?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:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0"><channel><title><![CDATA[Making Sense of Machine Learning Mathematics]]></title><description><![CDATA[Studying the mathematics that underlies machine learning, one step at a time.]]></description><link>https://petalbyte.substack.com</link><image><url>https://substackcdn.com/image/fetch/$s_!ASAu!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fpetalbyte.substack.com%2Fimg%2Fsubstack.png</url><title>Making Sense of Machine Learning Mathematics</title><link>https://petalbyte.substack.com</link></image><generator>Substack</generator><lastBuildDate>Thu, 03 Sep 2026 08:34:56 GMT</lastBuildDate><atom:link href="/__u/petalbyte.substack.com/feed" rel="self" type="application/rss+xml"/><copyright><![CDATA[Louise B]]></copyright><language><![CDATA[en]]></language><webMaster><![CDATA[petalbyte@substack.com]]></webMaster><itunes:owner><itunes:email><![CDATA[petalbyte@substack.com]]></itunes:email><itunes:name><![CDATA[Louise B]]></itunes:name></itunes:owner><itunes:author><![CDATA[Louise B]]></itunes:author><googleplay:owner><![CDATA[petalbyte@substack.com]]></googleplay:owner><googleplay:email><![CDATA[petalbyte@substack.com]]></googleplay:email><googleplay:author><![CDATA[Louise B]]></googleplay:author><itunes:block><![CDATA[Yes]]></itunes:block><item><title><![CDATA[Why do I need to know about Markov chains?]]></title><description><![CDATA[Building intuition by answering some basic questions first.]]></description><link>https://petalbyte.substack.com/p/why-do-i-need-to-know-about-markov</link><guid isPermaLink="false">https://petalbyte.substack.com/p/why-do-i-need-to-know-about-markov</guid><dc:creator><![CDATA[Louise B]]></dc:creator><pubDate>Thu, 27 Aug 2026 13:50:36 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/df17c580-96fe-4cc6-97f4-35c35b00859f_1200x630.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>For me, abstract ideas are nice but they don&#8217;t stick unless I put them into some very concrete context.</p><p>So, before I review Markov chains and their important properties, I&#8217;m going to sketch out a landscape to fit those abstractions into.</p><p>Specifically: Why are Markov chains and their properties prerequisite topics in machine learning mathematics? What do they help us achieve?</p><p><em>(Note: If you&#8217;ve forgotten lots of previously-studied maths, like I have, check out the exercises at the end of this post. They should help refresh your memory, starting from probability basics.)</em></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://petalbyte.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Making Sense of Machine Learning Mathematics! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h2>1. Orientation</h2><p>We are building a machine learning model. We have a set of training data. We want to build a model that will make good predictions about data points that we haven&#8217;t seen yet.</p><p>We need to know what the model&#8217;s parameters (<strong>&#952;</strong>, or &#8220;theta&#8221;) should be.</p><p>Sometimes we are happy with a single best <strong>&#952;</strong>, i.e. a model that outputs one good answer.</p><p>In these situations, finding <strong>&#952;</strong> is an optimisation problem.</p><p>But, at other times, we prefer a spread of &#8220;good candidates&#8221; for the parameters. We don&#8217;t want to find a single best <strong>&#952;</strong>, because that is just one prediction without any information about how uncertain it is.</p><p>Instead, we want many plausible thetas,  providing a range of predictions for good model parameters, with a sense of how good of a prediction each <strong>&#952;</strong> is.</p><blockquote><p><em>&#8230;having the full posterior can be very useful for a downstream task.</em></p><p>Deisenroth et al, ch. 6.3</p></blockquote><div class="native-video-embed" data-component-name="VideoPlaceholder" data-attrs="{&quot;mediaUploadId&quot;:&quot;ad698f7c-3560-4ebd-8291-dfd77e11d2a5&quot;,&quot;duration&quot;:null}"></div><p style="text-align: center;"><em>Searching for one optimal theta vs a sample of candidate thetas.</em></p><h2>2. A Bayesian approach</h2><p>We want a set of good candidates for <strong>&#952;</strong>. So we can be fancy and take a Bayesian approach, by considering a probability distribution over theta.</p><p>With that, and the training data, we can define the probability P(<strong>&#952;</strong>|data), known as the posterior distribution.</p><p>Some values of <strong>&#952;</strong> are more likely to be good (higher posterior probability), while others are less likely (lower posterior probability).</p><p>And we&#8217;d like to gather a collection of likely-good values by sampling from this posterior distribution, once found.</p><p>Finding this posterior distribution is known as Bayesian inference.</p><div class="native-video-embed" data-component-name="VideoPlaceholder" data-attrs="{&quot;mediaUploadId&quot;:&quot;f7a6afa1-4acb-4c36-ab5a-633f1543e8b2&quot;,&quot;duration&quot;:null}"></div><p style="text-align: center;"><em>We want to sample from the posterior distribution.</em></p><h2>3. Some Bayesian problems</h2><p>So we need to understand the posterior distribution. However, we cannot compute it directly.</p><p>We might have an intractable integral to deal with:</p><blockquote><p><em>More specifically, if we do not choose a conjugate prior on the parameters (Section 6.6.1), the integrals in (8.22) and (8.23) are not analytically tractable, and we cannot compute the posterior, the predictions, or the marginal likelihood in closed form.</em></p><p>Deisenroth et al, ch. 8.4</p></blockquote><p>In other words:</p><blockquote><p><em>But for many other distributions that are of scientific interest, the normalizing constant in the PDF or PMF is unknown, and beyond the reach of the fastest available computers and the fanciest available mathematical techniques.</em></p><p>Blitzstein and Hwang, ch. 12</p></blockquote><p>That is to say, even though the denominator on the right-hand side of this statement of Bayes&#8217; theorem looks very inoffensive to me:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!ZXfd!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a39b089-3d69-496b-8ffb-517acf7077bb.svg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!ZXfd!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a39b089-3d69-496b-8ffb-517acf7077bb.svg 424w, /__u/substackcdn.com/image/fetch/$s_!ZXfd!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a39b089-3d69-496b-8ffb-517acf7077bb.svg 848w, /__u/substackcdn.com/image/fetch/$s_!ZXfd!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a39b089-3d69-496b-8ffb-517acf7077bb.svg 1272w, /__u/substackcdn.com/image/fetch/$s_!ZXfd!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a39b089-3d69-496b-8ffb-517acf7077bb.svg 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!ZXfd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a39b089-3d69-496b-8ffb-517acf7077bb.svg" width="200" height="52.747252747252745" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4a39b089-3d69-496b-8ffb-517acf7077bb.svg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:384,&quot;width&quot;:1456,&quot;resizeWidth&quot;:200,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;{\\displaystyle P(A\\vert B)={\\frac {P(B\\vert A)P(A)}{P(B)}}}&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="{\displaystyle P(A\vert B)={\frac {P(B\vert A)P(A)}{P(B)}}}" title="{\displaystyle P(A\vert B)={\frac {P(B\vert A)P(A)}{P(B)}}}" srcset="/__u/substackcdn.com/image/fetch/$s_!ZXfd!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a39b089-3d69-496b-8ffb-517acf7077bb.svg 424w, /__u/substackcdn.com/image/fetch/$s_!ZXfd!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a39b089-3d69-496b-8ffb-517acf7077bb.svg 848w, /__u/substackcdn.com/image/fetch/$s_!ZXfd!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a39b089-3d69-496b-8ffb-517acf7077bb.svg 1272w, /__u/substackcdn.com/image/fetch/$s_!ZXfd!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a39b089-3d69-496b-8ffb-517acf7077bb.svg 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>&#8230;it actually causes some significant problems here. We cannot find our P(<strong>&#952;</strong>|data)!</p><h2>4. A Markov chain appears</h2><p>It turns out that we can build a Markov chain with a stationary distribution that <em>is</em> the posterior.</p><p>(The chain must have the right properties: irreducibility, and aperiodicity.)</p><p>When we run this chain and collect the states it visits (a process called Markov chain Monte Carlo, or MCMC), we obtain a collection of points.</p><p>These points are samples from the posterior that we care about. They will be mostly good candidates for <strong>&#952;</strong>.</p><blockquote><p><em>Here, we can use stochastic approximations, such as Markov chain Monte Carlo (MCMC) (Gilks et al., 1996)&#8230;</em></p><p>Deisenroth et al, ch. 8.4</p></blockquote><p>And:</p><blockquote><p><em>The basic idea is to</em> <em>build your own Markov chain so that the distribution of interest is the stationary distribution of the chain.</em></p><p>Blitzstein and Hwang, ch. 12</p></blockquote><p>When we eventually use our model to make predictions, the model will use all of the candidate <strong>&#952;</strong> values each time, outputting each prediction as an average over them.</p><p>Good <strong>&#952;</strong> values are more common in the collection of candidates, so they help push that average in the right direction.</p><p>And the spread of the candidate <strong>&#952;</strong> values is our (un)certainty score.</p><blockquote><p><em>[The model&#8217;s prediction is] an average over all plausible parameter values <strong>&#952;</strong>, where the plausibility is encapsulated by the parameter distribution p(<strong>&#952;</strong>).</em></p><p>Deisenroth et al, ch 8.4.2</p></blockquote><div class="native-video-embed" data-component-name="VideoPlaceholder" data-attrs="{&quot;mediaUploadId&quot;:&quot;dd7ccb54-fece-4982-b276-2a8d8ac8bcb6&quot;,&quot;duration&quot;:null}"></div><p style="text-align: center;"><em>Markov chain Monte Carlo allows us to gather a collection of samples from an approximation of the posterior distribution that we care about, </em>P(<strong>&#952;</strong>|data)<em>.</em></p><div><hr></div><p>This leaves me with more questions than answers, but that&#8217;s the goal.</p><p>With this rough sketch of the landscape, it&#8217;s easier to see what I need to look at next.</p><p>(It&#8217;ll be stationary distributions of Markov chains, and the mysterious but important properties a chain must have for MCMC.)</p><p><em>The following exercises should help refresh the memory of anyone who (like me) has forgotten lots of the maths they previously studied.</em></p><div class="callout-block" data-callout="true"><h4>Exercises:</h4><ol><li><p>An inbox contains 1,000 emails: 200 are spam, 800 are not spam.<br>The word &#8220;free&#8221; appears in 160 of the spam emails, but only in 80 of the others.</p><ol><li><p>If you pick an email at random, what is the probability of it being spam?</p></li><li><p>If you pick an email at random, what is the probability of the email containing the word &#8220;free&#8221;?</p></li></ol></li><li><p>In the same email inbox:</p><ol><li><p>Given an email <em>is spam</em>, what is the probability that it contains the word &#8220;free&#8221;?</p></li><li><p>Given an email contains the word &#8220;free&#8221;, what is the probability of it being spam?</p></li></ol></li></ol><p><em>You can access the remaining exercises by subscribing, if you wish:</em></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://petalbyte.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="/__u/petalbyte.substack.com/subscribe"><span>Subscribe now</span></a></p></div><div class="callout-block" data-callout="true"><h4>Solutions:</h4><ol><li><p></p><ol><li><p>200/1,000 = 0.2</p></li><li><p>We have 160 + 80 = 240 emails containing the word "free", so the probability of picking one is 240/1,000 = 0.24</p></li></ol></li><li><p></p><ol><li><p>160/200 = 0.8</p></li><li><p>160/240 &#8776; 0.667</p></li></ol></li></ol><p><em>You can access the remaining solutions by subscribing, if you wish:</em></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://petalbyte.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="/__u/petalbyte.substack.com/subscribe"><span>Subscribe now</span></a></p></div><div class="callout-block" data-callout="true"><h4>References and resources:</h4><ul><li><p>Blitzstein and Hwang, &#8220;Introduction to Probability&#8221;, 2019</p></li><li><p>Deisenroth et al, &#8220;Mathematics for Machine Learning&#8221;, 2020</p></li><li><p>Hastie et al, &#8220;The Elements of Statistical Learning&#8221;, 2009</p></li><li><p><a href="https://en.wikipedia.org/wiki/Bayes%27_theorem">https://en.wikipedia.org/wiki/Bayes%27_theorem</a></p></li><li><p><a href="https://www.youtube.com/watch?v=0zf8IHMcs0A">The difficulty with real life Bayesian inference: high multidimensional integrals (and sums)</a></p></li></ul><ul><li><p><a href="https://ocw.mit.edu/courses/15-097-prediction-machine-learning-and-statistics-spring-2012/553a0822984b08bc611306c93533a0a3_MIT15_097S12_lec15.pdf">https://ocw.mit.edu/courses/15-097-prediction-machine-learning-and-statistics-spring-2012/553a0822984b08bc611306c93533a0a3_MIT15_097S12_lec15.pdf</a></p></li><li><p><a href="https://personal.math.vt.edu/day/IntroChains/IntroChains.pdf">https://personal.math.vt.edu/day/IntroChains/IntroChains.pdf</a></p></li><li><p><a href="https://math.stackexchange.com/questions/1685547/understanding-stationary-distributions-of-markov-chains">https://math.stackexchange.com/questions/1685547/understanding-stationary-distributions-of-markov-chains</a></p></li></ul></div>]]></content:encoded></item><item><title><![CDATA[Study with me: The Minkowski distance family]]></title><description><![CDATA[Let's learn about this machine that outputs distance measures.]]></description><link>https://petalbyte.substack.com/p/study-with-me-the-minkowski-distance</link><guid isPermaLink="false">https://petalbyte.substack.com/p/study-with-me-the-minkowski-distance</guid><dc:creator><![CDATA[Louise B]]></dc:creator><pubDate>Sun, 16 Aug 2026 17:19:13 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/8eadf336-0882-414e-b06f-5220ef2a6feb_1200x630.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Before this weekend, I had not spent much time thinking about the different ways to measure the space between two points on a plane.</p><p>I was aware that straight line distance, and distance along a curve, are two importantly different things.</p><p>After all, if I am at the North Pole, and you are at the South Pole, and I am hosting a garden party, then we must be realistic about your travel time.</p><p>(Or, in machine learning terms, if my data points lie on a <a href="https://en.wikipedia.org/wiki/Manifold_hypothesis">manifold</a>, then I must calculate the distances between them appropriately.)</p><p>But, even if we&#8217;re traversing a completely flat plane, we can still have an argument about how much distance we&#8217;ve covered.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://petalbyte.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Making Sense of Machine Learning Mathematics! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h2>Choosing how we measure distance</h2><p>In statistical modelling, the distance between two points often represents the error between a model&#8217;s prediction and the actual value.</p><p>Our entire goal may be to minimise this distance, as this means minimising the error in the model.</p><p>Since we can&#8217;t minimise a hand wave, we need a precise distance measurement.</p><p>And that means we need to make a choice. For example:</p><ol><li><p>Would we like to consider the length of the straight line between two points?</p></li><li><p>Would we prefer to count the total number of steps in all directions required to get from point A to point B?</p></li><li><p>Would we prefer to think about only the direction that requires the most steps?</p></li></ol><div class="native-video-embed" data-component-name="VideoPlaceholder" data-attrs="{&quot;mediaUploadId&quot;:&quot;8e7cec1c-6349-4242-8147-aa404348c4a1&quot;,&quot;duration&quot;:null}"></div><p>There are some interesting implications from these choices.</p><p>Option 1 involves Pythagoras&#8217; theorem, and thus squaring. If you square 2, it only goes to 4. But if you square 22, it goes all the way to 484. So, with this choice, we must remember that exponentiation gets wild, and this will impact the distance measure.</p><p>So, with Option 1, our model&#8217;s error might seem much worse than if we did a simpler count of steps, e.g. Option 2 or 3.</p><p>Note that these options are more formally known as the <strong>Euclidean norm</strong>, the <strong>Manhattan </strong>(or <strong>taxicab</strong>) <strong>norm</strong>, and the <strong>Chebyshev </strong>(or <strong>chessboard</strong>) <strong>norm</strong>.</p><h2>The two-step process we must follow</h2><p>(Pun intended, apologies.)</p><p>To compute the distance between two points, we:</p><ol><li><p>Find the differences between each component of the two points, and thus obtain the <strong>difference vector</strong>, <em><strong>v</strong></em></p></li><li><p>Choose a norm, such as one of those mentioned in the previous section, that will turn that difference vector into our final distance value</p></li></ol><p>So we see that distances are norms of differences.</p><p>The following table is a bit of a notation-dump, but examples will follow, and I&#8217;ll add exercises (with solutions) at the end for anyone who learns best by doing (like me).</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!7UIr!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F600b1d5a-f520-4aa1-b386-034e4ea723bb_1802x672.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!7UIr!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F600b1d5a-f520-4aa1-b386-034e4ea723bb_1802x672.png 424w, /__u/substackcdn.com/image/fetch/$s_!7UIr!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F600b1d5a-f520-4aa1-b386-034e4ea723bb_1802x672.png 848w, /__u/substackcdn.com/image/fetch/$s_!7UIr!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F600b1d5a-f520-4aa1-b386-034e4ea723bb_1802x672.png 1272w, /__u/substackcdn.com/image/fetch/$s_!7UIr!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F600b1d5a-f520-4aa1-b386-034e4ea723bb_1802x672.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!7UIr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F600b1d5a-f520-4aa1-b386-034e4ea723bb_1802x672.png" width="1456" height="543" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/600b1d5a-f520-4aa1-b386-034e4ea723bb_1802x672.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:543,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:149531,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/211390478?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F600b1d5a-f520-4aa1-b386-034e4ea723bb_1802x672.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!7UIr!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F600b1d5a-f520-4aa1-b386-034e4ea723bb_1802x672.png 424w, /__u/substackcdn.com/image/fetch/$s_!7UIr!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F600b1d5a-f520-4aa1-b386-034e4ea723bb_1802x672.png 848w, /__u/substackcdn.com/image/fetch/$s_!7UIr!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F600b1d5a-f520-4aa1-b386-034e4ea723bb_1802x672.png 1272w, /__u/substackcdn.com/image/fetch/$s_!7UIr!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F600b1d5a-f520-4aa1-b386-034e4ea723bb_1802x672.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Here&#8217;s an example of each of these three choices giving us slightly different results.</p><div class="native-video-embed" data-component-name="VideoPlaceholder" data-attrs="{&quot;mediaUploadId&quot;:&quot;7a5f85a9-2e1e-4ae4-92b3-54ec6a9b83f4&quot;,&quot;duration&quot;:null}"></div><h2>Organising our options into a family</h2><p>This article&#8217;s title is &#8220;<em>Study with me: The Minkowski distance family</em>&#8221; because this was my favourite thing to discover this weekend.</p><p>Minkowski essentially gives us a machine that outputs the norms we&#8217;ve been looking at here by simply adjusting its parameter, <em>p</em>.</p><p>The Minkowski distance family is defined as:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!Ok7C!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F873b4a95-fa78-4d8b-8852-9a068da0cba8_1830x276.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!Ok7C!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F873b4a95-fa78-4d8b-8852-9a068da0cba8_1830x276.png 424w, /__u/substackcdn.com/image/fetch/$s_!Ok7C!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F873b4a95-fa78-4d8b-8852-9a068da0cba8_1830x276.png 848w, /__u/substackcdn.com/image/fetch/$s_!Ok7C!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F873b4a95-fa78-4d8b-8852-9a068da0cba8_1830x276.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Ok7C!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F873b4a95-fa78-4d8b-8852-9a068da0cba8_1830x276.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!Ok7C!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F873b4a95-fa78-4d8b-8852-9a068da0cba8_1830x276.png" width="596" height="90.05494505494505" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/873b4a95-fa78-4d8b-8852-9a068da0cba8_1830x276.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:220,&quot;width&quot;:1456,&quot;resizeWidth&quot;:596,&quot;bytes&quot;:59616,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/211390478?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F873b4a95-fa78-4d8b-8852-9a068da0cba8_1830x276.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!Ok7C!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F873b4a95-fa78-4d8b-8852-9a068da0cba8_1830x276.png 424w, /__u/substackcdn.com/image/fetch/$s_!Ok7C!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F873b4a95-fa78-4d8b-8852-9a068da0cba8_1830x276.png 848w, /__u/substackcdn.com/image/fetch/$s_!Ok7C!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F873b4a95-fa78-4d8b-8852-9a068da0cba8_1830x276.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Ok7C!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F873b4a95-fa78-4d8b-8852-9a068da0cba8_1830x276.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Setting <em>p = 1</em> gives us the Manhattan norm:</p><div class="native-video-embed" data-component-name="VideoPlaceholder" data-attrs="{&quot;mediaUploadId&quot;:&quot;45514f89-f766-4ad7-9389-c328fdd06da9&quot;,&quot;duration&quot;:null}"></div><p>Setting <em>p = 2</em> gives us the Euclidean norm:</p><div class="native-video-embed" data-component-name="VideoPlaceholder" data-attrs="{&quot;mediaUploadId&quot;:&quot;27c36582-174c-486a-9a59-ae989c6c3d9b&quot;,&quot;duration&quot;:null}"></div><p>And <em>p = &#8734;</em> gives us the Chebyshev norm:</p><div class="native-video-embed" data-component-name="VideoPlaceholder" data-attrs="{&quot;mediaUploadId&quot;:&quot;102b67bb-c0fe-4e5d-89af-3ed107510066&quot;,&quot;duration&quot;:null}"></div><p>(Notice that we factor out the largest component of the distance vector to ensure the rest become zero as <em>p</em> approaches infinity.)</p><p>Isn&#8217;t that lovely?</p><div class="callout-block" data-callout="true"><h5>Exercises</h5><ol><li><p>Does the Chebyshev norm still work if all components of the difference vector are of equal size? For example, if <em>A - B = (3,3)</em></p></li><li><p>If I suggest that another distance metric for spaces of n &gt; 1 dimensions is <em>d(a,b) = |a<sub>1</sub> - b<sub>1</sub>|</em>, where we only examine the difference between the first coordinates of a point, is this a valid claim?</p><ol><li><p>If not, which of the rules listed under &#8220;Mathematical formalization&#8221; <a href="https://en.wikipedia.org/wiki/Distance#Mathematical_formalization">here</a> is broken?</p></li></ol></li></ol><p>There are three more exercises available to subscribers.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://petalbyte.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="/__u/petalbyte.substack.com/subscribe"><span>Subscribe now</span></a></p><h5>Solutions</h5><ol><li><p>All is well here!</p></li><li><p>No - consider the distance between (1, 1) and (1, 7) under this metric</p><ol><li><p>The second rule, that &#8220;The distance between distinct objects is always positive&#8221;, is broken</p></li></ol></li></ol><p>The solutions to the subscriber exercises are &#8216;hidden&#8217; here.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://petalbyte.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="/__u/petalbyte.substack.com/subscribe"><span>Subscribe now</span></a></p></div><div class="callout-block" data-callout="true"><h5>References and resources</h5><ul><li><p>Deisenroth et al, &#8220;Mathematics for Machine Learning&#8221;, 2020</p></li><li><p>Hastie et al, &#8220;The Elements of Statistical Learning&#8221;, 2009</p></li><li><p><a href="/__u/patricknicolas.substack.com/p/riemannian-manifolds-1-foundation?open=false#%C2%A7limitation-of-euclidean-geometry">https://patricknicolas.substack.com/p/riemannian-manifolds-1-foundation?open=false#%C2%A7limitation-of-euclidean-geometry</a></p></li><li><p><a href="https://en.wikipedia.org/wiki/Chebyshev_distance">https://en.wikipedia.org/wiki/Chebyshev_distance</a></p></li><li><p><a href="https://en.wikipedia.org/wiki/Minkowski_distance">https://en.wikipedia.org/wiki/Minkowski_distance</a></p></li><li><p><a href="https://en.wikipedia.org/wiki/Distance#Mathematical_formalization">https://en.wikipedia.org/wiki/Distance#Mathematical_formalization</a></p></li><li><p><a href="https://en.wikipedia.org/wiki/Curse_of_dimensionality">https://en.wikipedia.org/wiki/Curse_of_dimensionality</a></p></li></ul></div><p></p>]]></content:encoded></item><item><title><![CDATA[Study with me: Indexed sets]]></title><description><![CDATA[So much more interesting than they sound!]]></description><link>https://petalbyte.substack.com/p/study-with-me-indexed-sets</link><guid isPermaLink="false">https://petalbyte.substack.com/p/study-with-me-indexed-sets</guid><dc:creator><![CDATA[Louise B]]></dc:creator><pubDate>Sun, 09 Aug 2026 20:14:12 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/4d5923c0-8177-4ea9-9f7c-33913e1a4849_1200x630.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>I did not think indexed sets would be interesting to learn about, and I was wrong.</p><p>My beginner&#8217;s introduction last week actually surprised me multiple times.</p><p>I will share exactly why.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://petalbyte.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Making Sense of Machine Learning Mathematics! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h2>1. The practical surprises</h2><p>Indexed sets give us ordering, and permit repeated values.</p><p>Imagine we want to use social media posts&#8217; like counts to represent how engaging each post is.</p><p>Post A has 2 likes, Post B has 1 like, and Post C has 2 likes.</p><p>If we want these like counts to be easy to iterate through, we might collect them into a set. But sets don&#8217;t keep track of duplicates, or ordering.</p><p>We try to store 2, 1, and 2, but end up with {1, 2}.</p><p>The solution to this is intuitive. We need to mark each value in our collection with something that represents its position.</p><p>If I annotate my collection of post like counts to do this, it might look like &#8220;first: 2&#8221;, &#8220;second: 1&#8221;, &#8220;third: 2&#8221;.</p><p>How can we use plain sets to achieve this?</p><p>This is quite a tricky question, IMO, but luckily Kuratowski <a href="https://en.wikipedia.org/wiki/Ordered_pair#Kuratowski's_definition">already figured it out</a>.</p><p>We can use plain sets to make ordered pairs: {{1}, {1, 2}}, {{2}, {2, 1}}, {{3}, {3, 2}}</p><p>(I&#8217;ll include an exercise at the end that involves looking more closely at this.)</p><p>And we can use a neater, and probably very familiar, notation for these ordered pairs: (1, 2), (2, 1), (3, 2)</p><p>Our set of post like counts now looks like this: {(1, 2), (2, 1), (3, 2)}</p><p>These ordered pairs allow us to retain repeated post like counts, because position values will <em>not</em> be repeated.</p><p>And, although the set doesn&#8217;t care much about ordering, the position value in each pair in the set still provides the information we need.</p><p>After all, ordering isn&#8217;t so much about arranging things nicely, but more about understanding where the elements of our set sit relative to one another, and about being able to locate one easily.</p><p>(At least, these things matter to someone working with computers, which a person working on a machine learning model probably is.)</p><p>So now we have an indexed set.</p><p>And to pick apart <em>exactly</em> what we have, it is:</p><ol><li><p>An index set, <em>I</em>, containing the position values that we&#8217;re using (in our case, <em>I </em>= {1, 2, 3})</p></li><li><p>A mapping, <em>x</em>, from each <em>i </em>in the index set <em>I</em> to the values we care about (in our case, <em>i</em> = 1 maps to 2, <em>i</em> = 2 maps to 1, and <em>i</em> = 3 maps to 2)</p></li></ol><p>Those are the tools that allow us to label each element in our set of post like counts with a position value.</p><p>There is some tidy notation, too: <em>X</em> = (<em>x<sub>i</sub></em>)<em><sub>i</sub></em><sub> &#8712; </sub><em><sub>I</sub></em></p><p>And we can also write out <em>X</em> as (<em>x<sub>1</sub></em>,<em> x<sub>2</sub></em>, &#8230;, <em>x<sub>n</sub></em>).</p><p>This probably looks very familiar, as it&#8217;s used for things like listing the components in a vector, or the set of vectors in a spanning set, or an ordered list of objects for programming purposes (e.g. Python&#8217;s <a href="https://docs.python.org/3/library/stdtypes.html#tuples">tuples</a>).</p><p>But as someone who has used this kind of structure countless times, without ever questioning how it was itself constructed, this was all a surprising realisation.</p><p>And it wasn&#8217;t the only one!</p><h2>2. The unintuitive and thought-provoking surprises</h2><p>The next unexpectedly interesting question I ran into was, &#8220;What happens when we try to find unions and intersections of families of indexed sets?&#8221;</p><p>(To be clear, now the sets in the families are indexed, not the values in the sets.)</p><p>For a beginner like me, this means first considering small indexed families, and thinking about what they look like.</p><div class="native-video-embed" data-component-name="VideoPlaceholder" data-attrs="{&quot;mediaUploadId&quot;:&quot;758d1df3-5981-4476-a347-83773fa2f7ab&quot;,&quot;duration&quot;:null}"></div><p>And then asking which elements are in at least one of them, or in all of them:</p><div class="native-video-embed" data-component-name="VideoPlaceholder" data-attrs="{&quot;mediaUploadId&quot;:&quot;3afcfbc6-ed33-4d7c-a751-98c40a215c96&quot;,&quot;duration&quot;:null}"></div><p>If the family gets very large, there&#8217;s a bit more reasoning required in deciding what is in their intersection. </p><p>What do you think the intersection of <em>A<sub>i</sub></em> = {<em>n</em> &#8712; &#8469; : <em>n</em> &#8805; <em>i</em>} will be?</p><div class="native-video-embed" data-component-name="VideoPlaceholder" data-attrs="{&quot;mediaUploadId&quot;:&quot;8bc0eb6f-e8d3-4ac1-a7c1-ac1c715db9ec&quot;,&quot;duration&quot;:null}"></div><p>To increase the challenge a little, we can consider a family where each set is an open interval:</p><div class="native-video-embed" data-component-name="VideoPlaceholder" data-attrs="{&quot;mediaUploadId&quot;:&quot;ab945cc2-db39-4c5e-b639-9b00a9443857&quot;,&quot;duration&quot;:null}"></div><p>Here, it&#8217;s as though we&#8217;re asking, &#8220;What number is smaller than 1/<em>i</em> for all <em>i</em> in &#8477;<sup>+</sup>?&#8221;, which is a question I simply did not expect when I first started looking at indexed sets last week.</p><div><hr></div><p>So there you have it: All the ways I was wrong about indexed sets being dull. I&#8217;m glad to have been so mistaken.</p><p>Some exercises below, for anyone who might find them useful.</p><h3>Exercises</h3><ol><li><p>Which of these two data sets requires order and disambiguation of duplicate values, and why?</p><ol><li><p>A week&#8217;s daily step counts</p></li><li><p>The unique hashtags across a social media user&#8217;s posts</p></li></ol></li><li><p>Take a look at the <a href="https://en.wikipedia.org/wiki/Ordered_pair#Kuratowski's_definition">Kuratowski definition</a> of ordered pairs and write out some examples, to show yourself how (1,2) &#8800; (2,1)</p></li><li><p>Consider the indexed family <em>A<sub>i</sub></em>&#8203; = {<em>i</em>, <em>i </em>+ 2}, <em>i </em>&#8712; {1,2,3,4}. Enumerate the family by writing out <em>A<sub>1</sub>&#8203;</em>, <em>A<sub>2</sub></em>&#8203;, <em>A<sub>3</sub></em>&#8203;, <em>A<sub>4</sub></em>&#8203;.</p></li></ol><p>There are more exercises available for subscribers.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://petalbyte.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="/__u/petalbyte.substack.com/subscribe"><span>Subscribe now</span></a></p><div class="callout-block" data-callout="true"><h4>Resources and references</h4><ul><li><p>Deisenroth et al, &#8220;Mathematics for Machine Learning&#8221;, 2020</p></li><li><p>Casella and Berger, &#8220;Statistical Inference&#8221;, 2nd ed., 2002</p></li><li><p>Halmos, &#8220;Naive Set Theory&#8221;, 1974</p></li><li><p><a href="https://math.stackexchange.com/q/3438884">https://math.stackexchange.com/q/3438884</a></p></li></ul></div>]]></content:encoded></item><item><title><![CDATA[Topics I've repeated recently (and may again)]]></title><description><![CDATA[Embarrassing? Perhaps.]]></description><link>https://petalbyte.substack.com/p/topics-ive-repeated-recently-and</link><guid isPermaLink="false">https://petalbyte.substack.com/p/topics-ive-repeated-recently-and</guid><dc:creator><![CDATA[Louise B]]></dc:creator><pubDate>Sun, 02 Aug 2026 07:08:06 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/81dbc3a4-337e-441c-80f1-751a48133c8c_1200x630.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>My favourite part of studying maths is figuring out why I don&#8217;t understand something.</p><p>To be honest, I generally don&#8217;t understand anything.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://petalbyte.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Making Sense of Machine Learning Mathematics! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p>But I have discovered a workaround.</p><p>If I skip trying to understand, and instead only investigate <em>why</em> I don&#8217;t understand, then&#8230; some understanding occurs as a byproduct.</p><p>(Although it&#8217;s important not to get overexcited and look too closely at it, because it evades inspection and may disappear entirely.)</p><p>Here are a few examples.</p><h2>1. Implicit Differentiation</h2><p>I would apply this technique to problems that I recognised as requiring it, but fail to do so whenever the problem was disguised in some way.</p><p>When this happens, it means I don&#8217;t understand the fundamental usefulness of the technique.</p><p>In this kind of situation, I&#8217;m often rescued by one or more posts on <a href="https://math.stackexchange.com/">math.stackexchange.com</a>, where brave people ask questions and knowledgeable ones kindly reply.</p><p>It&#8217;s a good place to find &#8220;human&#8221; explanations, where informal language and personal choice of emphasis give the information dimensionality and context.</p><p>(Example: In person, I might say, &#8220;<em>This</em> is the part to notice!&#8221; with some gesticulation, while a textbook typically lists facts neutrally as though meant to be ignored.)</p><p><a href="https://math.stackexchange.com/questions/1570222/what-is-the-difference-between-implicit-differentiation-and-differentiation">This thread</a> was helpful, particularly because one comment linked out to <a href="https://www.math.ucdavis.edu/~kouba/CalcOneDIRECTORY/implicitdiffdirectory/ImplicitDiff.html">a resource</a> that human-ly communicates the significance of not being able to fully separate <em>y</em> from <em>x</em> in some equations.</p><p>Notice the capitalisation of <em>EXPLICITLY</em> and <em>IMPLICITLY</em>. Now I understand what is important.</p><p>This resource also reminds me that some graphs look like this:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!f2XK!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf868b30-6150-4d30-b454-328398d2ed3f_1690x1516.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!f2XK!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf868b30-6150-4d30-b454-328398d2ed3f_1690x1516.png 424w, /__u/substackcdn.com/image/fetch/$s_!f2XK!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf868b30-6150-4d30-b454-328398d2ed3f_1690x1516.png 848w, /__u/substackcdn.com/image/fetch/$s_!f2XK!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf868b30-6150-4d30-b454-328398d2ed3f_1690x1516.png 1272w, /__u/substackcdn.com/image/fetch/$s_!f2XK!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf868b30-6150-4d30-b454-328398d2ed3f_1690x1516.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!f2XK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf868b30-6150-4d30-b454-328398d2ed3f_1690x1516.png" width="300" height="269.0934065934066" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/cf868b30-6150-4d30-b454-328398d2ed3f_1690x1516.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1306,&quot;width&quot;:1456,&quot;resizeWidth&quot;:300,&quot;bytes&quot;:212950,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/208533026?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf868b30-6150-4d30-b454-328398d2ed3f_1690x1516.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!f2XK!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf868b30-6150-4d30-b454-328398d2ed3f_1690x1516.png 424w, /__u/substackcdn.com/image/fetch/$s_!f2XK!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf868b30-6150-4d30-b454-328398d2ed3f_1690x1516.png 848w, /__u/substackcdn.com/image/fetch/$s_!f2XK!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf868b30-6150-4d30-b454-328398d2ed3f_1690x1516.png 1272w, /__u/substackcdn.com/image/fetch/$s_!f2XK!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf868b30-6150-4d30-b454-328398d2ed3f_1690x1516.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><em>y = x&#178;y&#179; + x&#179;y&#178;</em></figcaption></figure></div><p>Here, the answer to &#8220;What is <em>y</em> when <em>x</em> is 1?&#8221; is not clear. (See: <a href="https://en.wikipedia.org/wiki/Vertical_line_test">the vertical line test</a>.)</p><p>So: Explicit differentiation finds an expression for the slope of a function for <strong>any</strong> value of <em>x</em>, while implicit differentiation gives us an expression for a <strong>particular</strong> <strong>point</strong>&#8217;s slope.</p><p>(This is why the result may contain both coordinates.)</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!MwWp!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f76ecb0-aa8b-4c32-86ef-cb17a424eb35_1820x360.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!MwWp!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f76ecb0-aa8b-4c32-86ef-cb17a424eb35_1820x360.png 424w, /__u/substackcdn.com/image/fetch/$s_!MwWp!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f76ecb0-aa8b-4c32-86ef-cb17a424eb35_1820x360.png 848w, /__u/substackcdn.com/image/fetch/$s_!MwWp!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f76ecb0-aa8b-4c32-86ef-cb17a424eb35_1820x360.png 1272w, /__u/substackcdn.com/image/fetch/$s_!MwWp!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f76ecb0-aa8b-4c32-86ef-cb17a424eb35_1820x360.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!MwWp!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f76ecb0-aa8b-4c32-86ef-cb17a424eb35_1820x360.png" width="266" height="52.61538461538461" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3f76ecb0-aa8b-4c32-86ef-cb17a424eb35_1820x360.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:288,&quot;width&quot;:1456,&quot;resizeWidth&quot;:266,&quot;bytes&quot;:32807,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/208533026?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f76ecb0-aa8b-4c32-86ef-cb17a424eb35_1820x360.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!MwWp!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f76ecb0-aa8b-4c32-86ef-cb17a424eb35_1820x360.png 424w, /__u/substackcdn.com/image/fetch/$s_!MwWp!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f76ecb0-aa8b-4c32-86ef-cb17a424eb35_1820x360.png 848w, /__u/substackcdn.com/image/fetch/$s_!MwWp!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f76ecb0-aa8b-4c32-86ef-cb17a424eb35_1820x360.png 1272w, /__u/substackcdn.com/image/fetch/$s_!MwWp!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f76ecb0-aa8b-4c32-86ef-cb17a424eb35_1820x360.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>So now I know what to look for in varied problems that require this technique.</p><h2>2. The Rank-Nullity Theorem</h2><p>This theorem is very simple to look at:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!HABc!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2133a684-bead-436c-b1f9-9b05b239a01f_1804x148.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!HABc!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2133a684-bead-436c-b1f9-9b05b239a01f_1804x148.png 424w, /__u/substackcdn.com/image/fetch/$s_!HABc!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2133a684-bead-436c-b1f9-9b05b239a01f_1804x148.png 848w, /__u/substackcdn.com/image/fetch/$s_!HABc!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2133a684-bead-436c-b1f9-9b05b239a01f_1804x148.png 1272w, /__u/substackcdn.com/image/fetch/$s_!HABc!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2133a684-bead-436c-b1f9-9b05b239a01f_1804x148.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!HABc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2133a684-bead-436c-b1f9-9b05b239a01f_1804x148.png" width="446" height="36.45192307692308" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2133a684-bead-436c-b1f9-9b05b239a01f_1804x148.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:119,&quot;width&quot;:1456,&quot;resizeWidth&quot;:446,&quot;bytes&quot;:28376,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/208533026?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2133a684-bead-436c-b1f9-9b05b239a01f_1804x148.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!HABc!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2133a684-bead-436c-b1f9-9b05b239a01f_1804x148.png 424w, /__u/substackcdn.com/image/fetch/$s_!HABc!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2133a684-bead-436c-b1f9-9b05b239a01f_1804x148.png 848w, /__u/substackcdn.com/image/fetch/$s_!HABc!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2133a684-bead-436c-b1f9-9b05b239a01f_1804x148.png 1272w, /__u/substackcdn.com/image/fetch/$s_!HABc!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2133a684-bead-436c-b1f9-9b05b239a01f_1804x148.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>But the implications have not been immediately obvious to me.</p><p>In &#8220;Mathematics for Machine Learning&#8221; (2020), Deisenroth et al mention that this theorem is also referred to as &#8220;the fundamental theorem of linear mappings&#8221;.</p><p>And they list three of its consequences, including that it can tell us when a system of linear equations has infinitely many solutions, or when a mapping is bijective.</p><p>(I recommend reading chapter 2.7.3, as they include helpful informal statements alongside the formal ones, plus a diagram.)</p><p>However, the higher-order consequences of this theorem are beyond my current linear algebra knowledge.</p><p>I can appreciate that, if a mapping is not bijective, then it effectively causes us to lose information. Perhaps this is connected to compression, in some way. Although I know this loss is not always a bad thing, such as when using principal component analysis (PCA) to simplify problems by discarding carefully-chosen, less-important dimensions.</p><p>And it&#8217;s always useful to know when a system of equations has infinitely many solutions.</p><p>It might also be significant that we know exactly which vectors we will &#8220;lose&#8221; through the mapping, as this set is simply the kernel.</p><p>But this is something I am not yet sure about, so I will be reading more.</p><h2>3. Probability Distributions</h2><p>This section&#8217;s title should be even broader. It could even be &#8220;Statistics Fundamentals&#8221;.</p><p>My issue here is knowledge organisation. I&#8217;ve studied these topics without building a mental map of how they connect to each other, or a timeline of when and why they were new and exciting.</p><p>These structures give ideas a landscape to populate. They get homes, with signposts. Their characteristics make sense because of the environment they inhabit.</p><p>But currently, concepts like &#8220;z-score&#8221;, &#8220;Poisson distribution&#8221;, and &#8220;density function&#8221; hover in random places, so I can&#8217;t find them when I need them.</p><p>Fortunately, many great versions of these topic maps and timelines have already been created by others. No need for me to reinvent the wheel. I&#8217;ll search for my favourites, and make flashcards from them, to most efficiently resolve this issue.</p><div><hr></div><p>There are countless more things that I don&#8217;t yet understand well, but I&#8217;ll pause here.</p><p>If you have favourite resources for any of these topics, feel free to recommend them.</p><div class="callout-block" data-callout="true"><h5>References and resources</h5><ul><li><p>Deisenroth et al, &#8220;Mathematics for Machine Learning&#8221;, 2020</p></li><li><p><a href="https://www.math.ucdavis.edu/~kouba/CalcOneDIRECTORY/implicitdiffdirectory/ImplicitDiff.html">Implicit Differentiation Problems - math.ucdavis.edu</a></p></li></ul></div><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://petalbyte.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Making Sense of Machine Learning Mathematics! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Why does a plane equation have so many forms?]]></title><description><![CDATA[Possibly obvious for many, but not for me.]]></description><link>https://petalbyte.substack.com/p/why-does-a-plane-equation-have-so</link><guid isPermaLink="false">https://petalbyte.substack.com/p/why-does-a-plane-equation-have-so</guid><dc:creator><![CDATA[Louise B]]></dc:creator><pubDate>Sun, 19 Jul 2026 18:04:11 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/7270880a-e8d7-4114-8dc0-9e8d8898d372_1200x630.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Why are there so many forms of a plane equation?</p><p>I think this is something that does naturally become clear over time, with further studying. But I find it difficult to retain information when I don&#8217;t have much context for it, and feel a little frustrated about this question at the moment.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://petalbyte.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading (Surprisingly Simple) Machine Learning Mathematics! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p>So it&#8217;s time for some side-tracking into how the plane equation forms I&#8217;m reviewing fit into the bigger picture, where the bigger picture (for me) is machine learning mathematics.</p><p>So my question is actually: Why are there so many forms of a plane equation, <em>and when do we use each form in machine learning</em>?</p><p>I&#8217;ll be looking at these forms:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!mfIj!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F79d638d5-add5-4f2d-a62d-8aadb833f088_1810x578.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!mfIj!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F79d638d5-add5-4f2d-a62d-8aadb833f088_1810x578.png 424w, /__u/substackcdn.com/image/fetch/$s_!mfIj!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F79d638d5-add5-4f2d-a62d-8aadb833f088_1810x578.png 848w, /__u/substackcdn.com/image/fetch/$s_!mfIj!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F79d638d5-add5-4f2d-a62d-8aadb833f088_1810x578.png 1272w, /__u/substackcdn.com/image/fetch/$s_!mfIj!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F79d638d5-add5-4f2d-a62d-8aadb833f088_1810x578.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!mfIj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F79d638d5-add5-4f2d-a62d-8aadb833f088_1810x578.png" width="1456" height="465" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/79d638d5-add5-4f2d-a62d-8aadb833f088_1810x578.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:465,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:61317,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/207566333?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F79d638d5-add5-4f2d-a62d-8aadb833f088_1810x578.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!mfIj!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F79d638d5-add5-4f2d-a62d-8aadb833f088_1810x578.png 424w, /__u/substackcdn.com/image/fetch/$s_!mfIj!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F79d638d5-add5-4f2d-a62d-8aadb833f088_1810x578.png 848w, /__u/substackcdn.com/image/fetch/$s_!mfIj!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F79d638d5-add5-4f2d-a62d-8aadb833f088_1810x578.png 1272w, /__u/substackcdn.com/image/fetch/$s_!mfIj!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F79d638d5-add5-4f2d-a62d-8aadb833f088_1810x578.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>(Note that these forms are listed in two columns, with each column containing two very closely-related forms. The left-hand forms might be generally referred to as &#8220;parametric representations&#8221;, and the right-hand ones as &#8220;implicit representations&#8221;.)</p><p>And I&#8217;ll be drawing inspiration from <a href="https://arxiv.org/pdf/0807.4802">this paper</a>, most of which is far beyond my current level, but which mentions something quite incredibly useful for me in its introduction:</p><blockquote><p><em>To give a simple example, the parametric description [of a rational algebraic curve or surface] is better for drawing a surface, as it allows to rapidly generate points on the surface, which can then be interpolated, whereas an implicit representation is better adapted for testing if a given point lies on the surface, since one only needs to check whether the point verifies the algebraic condition that defines the surface.</em></p></blockquote><p>Now, I don&#8217;t know whether this can <em>exactly</em> be applied to the ways of describing two-dimensional planes that I&#8217;m reviewing currently.</p><p>But Wikipedia <a href="https://en.wikipedia.org/wiki/Plane_(mathematics)">tells me</a> that &#8220;a plane is a surface&#8221;, so the following will be my simple interpretation of the ideas in the quoted text, applied to the planes I&#8217;m reviewing currently, sitting in three-dimensional space.</p><p>I believe this will provide some of the context I am looking for, even if imperfect and needing further iteration in future.</p><h2>Generating Planes</h2><p>Sometimes, we want to generate, or navigate around, a plane. The parametric and vector forms of a plane equation are the most useful for that.</p><p>Recalling the vector form of a line, one point (with position vector) plus one more vector allows us to reach and traverse a line, or one-dimensional space:</p><div class="native-video-embed" data-component-name="VideoPlaceholder" data-attrs="{&quot;mediaUploadId&quot;:&quot;8ab81d89-c81e-4ce4-adb7-46cc3333d9be&quot;,&quot;duration&quot;:null}"></div><p>And the intuition for the vector form of a plane equation follows, where we add one more vector to be able to navigate along an additional dimension, i.e. a plane:</p><div class="native-video-embed" data-component-name="VideoPlaceholder" data-attrs="{&quot;mediaUploadId&quot;:&quot;a0ff8b8b-63e1-4f28-a9b9-79cb11ccb222&quot;,&quot;duration&quot;:null}"></div><p>In machine learning, principal component analysis (PCA) provides an example of where we might imagine ourselves using vectors to discover and navigate a plane.</p><p>In PCA, the goal is to reduce the dimensionality of a data set. We find new directions through the data, ranked by how much variance lies along each, and keep only the most important ones.</p><p>This involves finding the data&#8217;s mean, and centring the data there. And then finding the eigenvectors of that centred data&#8217;s covariance matrix.</p><p>The eigenvectors are the principal components (directions of maximal variance). We&#8217;ll keep the most important ones of those.</p><p>In this example of data in a three-dimensional space, the covariance matrix gives us three eigenvectors. We keep the top two, and they span the two-dimensional plane we&#8217;re navigating.</p><div class="native-video-embed" data-component-name="VideoPlaceholder" data-attrs="{&quot;mediaUploadId&quot;:&quot;3dff6c38-bc74-41c5-9fbb-0bd20923ba1f&quot;,&quot;duration&quot;:null}"></div><p>Not all of the data points sit on the plane, and we see their projections onto the plane appear at the end.</p><p>Those projections represent the reconstruction error, which is the information we lost by discarding that dimension.</p><h2>Separating Planes</h2><p>Sometimes we care more about how a plane divides a space, perhaps acting as a boundary between the points on either side.</p><p>And in these times, we might use the Cartesian or normal forms of a plane equation, perhaps as a function that takes a point, <strong>x</strong>, and returns how far that point sits from the plane, measured along the normal direction.</p><div class="native-video-embed" data-component-name="VideoPlaceholder" data-attrs="{&quot;mediaUploadId&quot;:&quot;6df95091-99d8-439d-9235-d909931454cf&quot;,&quot;duration&quot;:null}"></div><p>This makes it easy to see that the plane or boundary itself is comprised of the points where this function outputs zero.</p><p>It&#8217;s also easy to see when points sit on one side of the plane, or the other, and how far from the plane they are.</p><div class="native-video-embed" data-component-name="VideoPlaceholder" data-attrs="{&quot;mediaUploadId&quot;:&quot;b5fec79c-7340-401c-a5ae-ffc3d338ce3a&quot;,&quot;duration&quot;:null}"></div><p>In machine learning, this is (in my opinion) a useful visualisation for the decision boundary created by a binary classification model.</p><p>During training, the model will have to keep checking whether it&#8217;s figured out the best decision boundary to correctly classify data points, by seeing whether the boundary divides the points in the data space correctly.</p><p>If there&#8217;s too much error (points on the wrong side) when checking against real data with known classes, then the model keeps adjusting the boundary until it divides the data points more correctly.</p><div class="native-video-embed" data-component-name="VideoPlaceholder" data-attrs="{&quot;mediaUploadId&quot;:&quot;44274c2b-436a-4b98-aa64-887526a42720&quot;,&quot;duration&quot;:null}"></div><div><hr></div><p>I&#8217;m still learning <a href="https://github.com/3b1b/manim">Manim</a>, so those animations took far too much time (although they might not look like it!).</p><p>However, I love creating maths visuals, whether they particularly need to exist or not, so I&#8217;ll be back next week with more.</p><div class="callout-block" data-callout="true"><h5>References and resources</h5><ul><li><p>Deisenroth et al, &#8220;Mathematics for Machine Learning&#8221;, 2020</p></li><li><p><a href="https://tutorial.math.lamar.edu/classes/calciii/eqnsofplanes.aspx">https://tutorial.math.lamar.edu/classes/calciii/eqnsofplanes.aspx</a></p></li><li><p><a href="https://arxiv.org/pdf/0807.4802">https://arxiv.org/pdf/0807.4802</a></p></li><li><p><a href="https://www.cs.toronto.edu/~mren/teach/csc411_19s/lec/lec12_matt.pdf">https://www.cs.toronto.edu/~mren/teach/csc411_19s/lec/lec12_matt.pdf</a></p></li><li><p><a href="https://kmoy1.github.io/ML_Book/chapters/Ch2/hyperplanes.html">https://kmoy1.github.io/ML_Book/chapters/Ch2/hyperplanes.html</a></p></li><li><p><a href="https://en.wikipedia.org/wiki/Plane_(mathematics)">https://en.wikipedia.org/wiki/Plane_(mathematics)</a></p></li></ul></div><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://petalbyte.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading (Surprisingly Simple) Machine Learning Mathematics! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Deciphering Notation: Double Summation]]></title><description><![CDATA[With some visual interpretations to help.]]></description><link>https://petalbyte.substack.com/p/deciphering-notation-double-summation</link><guid isPermaLink="false">https://petalbyte.substack.com/p/deciphering-notation-double-summation</guid><dc:creator><![CDATA[Louise B]]></dc:creator><pubDate>Sun, 12 Jul 2026 08:32:40 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/117228eb-5a25-47df-930b-60aefb0c8014_1200x630.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Just as I recover from tensor contraction notation, I run into this:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!QUEH!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8a0b44d8-3e23-4da3-b9db-963eedac878e_1296x142.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!QUEH!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8a0b44d8-3e23-4da3-b9db-963eedac878e_1296x142.png 424w, /__u/substackcdn.com/image/fetch/$s_!QUEH!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8a0b44d8-3e23-4da3-b9db-963eedac878e_1296x142.png 848w, /__u/substackcdn.com/image/fetch/$s_!QUEH!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8a0b44d8-3e23-4da3-b9db-963eedac878e_1296x142.png 1272w, /__u/substackcdn.com/image/fetch/$s_!QUEH!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8a0b44d8-3e23-4da3-b9db-963eedac878e_1296x142.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!QUEH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8a0b44d8-3e23-4da3-b9db-963eedac878e_1296x142.png" width="1296" height="142" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8a0b44d8-3e23-4da3-b9db-963eedac878e_1296x142.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:142,&quot;width&quot;:1296,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:11519,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/206576490?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8a0b44d8-3e23-4da3-b9db-963eedac878e_1296x142.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!QUEH!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8a0b44d8-3e23-4da3-b9db-963eedac878e_1296x142.png 424w, /__u/substackcdn.com/image/fetch/$s_!QUEH!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8a0b44d8-3e23-4da3-b9db-963eedac878e_1296x142.png 848w, /__u/substackcdn.com/image/fetch/$s_!QUEH!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8a0b44d8-3e23-4da3-b9db-963eedac878e_1296x142.png 1272w, /__u/substackcdn.com/image/fetch/$s_!QUEH!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8a0b44d8-3e23-4da3-b9db-963eedac878e_1296x142.png 1456w" sizes="100vw" fetchpriority="high"></picture><div></div></div></a><figcaption class="image-caption"><em>Source: MathAcademy.com</em></figcaption></figure></div><p>More notation that I should be able to parse but have completely forgotten how.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://petalbyte.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading (Surprisingly Simple) Machine Learning Mathematics! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p>The common thread between tensor contraction and double summation notation, and the initial trouble I had with them, might be the multi-dimensionality hiding behind such a small and innocuous-seeming set of symbols.</p><p>So let&#8217;s take a second to look at what this notation is conveying so efficiently.</p><h2>The easiest example</h2><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!uL3I!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe29eff61-59d3-4134-9186-0270ccf2fed2_1200x200.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!uL3I!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe29eff61-59d3-4134-9186-0270ccf2fed2_1200x200.png 424w, /__u/substackcdn.com/image/fetch/$s_!uL3I!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe29eff61-59d3-4134-9186-0270ccf2fed2_1200x200.png 848w, /__u/substackcdn.com/image/fetch/$s_!uL3I!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe29eff61-59d3-4134-9186-0270ccf2fed2_1200x200.png 1272w, /__u/substackcdn.com/image/fetch/$s_!uL3I!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe29eff61-59d3-4134-9186-0270ccf2fed2_1200x200.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!uL3I!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe29eff61-59d3-4134-9186-0270ccf2fed2_1200x200.png" width="728" height="121.33333333333333" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e29eff61-59d3-4134-9186-0270ccf2fed2_1200x200.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:200,&quot;width&quot;:1200,&quot;resizeWidth&quot;:728,&quot;bytes&quot;:10623,&quot;alt&quot;:&quot;A mathematical expression showing a double summation: the sum over i from 1 to 2 of the sum over j from 1 to 2 of a subscript ij.&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/206576490?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe29eff61-59d3-4134-9186-0270ccf2fed2_1200x200.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="A mathematical expression showing a double summation: the sum over i from 1 to 2 of the sum over j from 1 to 2 of a subscript ij." title="A mathematical expression showing a double summation: the sum over i from 1 to 2 of the sum over j from 1 to 2 of a subscript ij." srcset="/__u/substackcdn.com/image/fetch/$s_!uL3I!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe29eff61-59d3-4134-9186-0270ccf2fed2_1200x200.png 424w, /__u/substackcdn.com/image/fetch/$s_!uL3I!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe29eff61-59d3-4134-9186-0270ccf2fed2_1200x200.png 848w, /__u/substackcdn.com/image/fetch/$s_!uL3I!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe29eff61-59d3-4134-9186-0270ccf2fed2_1200x200.png 1272w, /__u/substackcdn.com/image/fetch/$s_!uL3I!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe29eff61-59d3-4134-9186-0270ccf2fed2_1200x200.png 1456w" sizes="100vw"></picture><div></div></div></a></figure></div><p>For anyone familiar with programming fundamentals, double summation can be thought of as a nested loop:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;plaintext&quot;,&quot;nodeId&quot;:&quot;1533bc2e-5372-42d0-8ca7-e245a69b7864&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-plaintext">total = 0
for i in 1..m:              # the outer loop
    for j in 1..n:          # the inner loop
        total += a[i][j]</code></pre></div><p>We can also visualise a nice and tidy grid:</p><div class="native-video-embed" data-component-name="VideoPlaceholder" data-attrs="{&quot;mediaUploadId&quot;:&quot;0ced160f-1d39-42d6-8886-5f6a330427b1&quot;,&quot;duration&quot;:null}"></div><p>The important idea is that we evaluate the inner sum first, initially fixing the outer index at its first value.</p><p>Then we increment the outer index, and evaluate the inner sum again.</p><p>And so on.</p><div class="callout-block" data-callout="true"><h5>Quick Practice (1)</h5><p>Calculate the value of:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!rgU1!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F351cdf1f-a71c-4e08-b336-83c955c03006_1200x200.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!rgU1!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F351cdf1f-a71c-4e08-b336-83c955c03006_1200x200.png 424w, /__u/substackcdn.com/image/fetch/$s_!rgU1!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F351cdf1f-a71c-4e08-b336-83c955c03006_1200x200.png 848w, /__u/substackcdn.com/image/fetch/$s_!rgU1!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F351cdf1f-a71c-4e08-b336-83c955c03006_1200x200.png 1272w, /__u/substackcdn.com/image/fetch/$s_!rgU1!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F351cdf1f-a71c-4e08-b336-83c955c03006_1200x200.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!rgU1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F351cdf1f-a71c-4e08-b336-83c955c03006_1200x200.png" width="1200" height="200" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/351cdf1f-a71c-4e08-b336-83c955c03006_1200x200.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:200,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:11651,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/206576490?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F351cdf1f-a71c-4e08-b336-83c955c03006_1200x200.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!rgU1!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F351cdf1f-a71c-4e08-b336-83c955c03006_1200x200.png 424w, /__u/substackcdn.com/image/fetch/$s_!rgU1!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F351cdf1f-a71c-4e08-b336-83c955c03006_1200x200.png 848w, /__u/substackcdn.com/image/fetch/$s_!rgU1!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F351cdf1f-a71c-4e08-b336-83c955c03006_1200x200.png 1272w, /__u/substackcdn.com/image/fetch/$s_!rgU1!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F351cdf1f-a71c-4e08-b336-83c955c03006_1200x200.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p><em>Solution at end of article.</em></p></div><h2>A slightly less easy example</h2><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!cg48!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69c14fbf-a5cb-4caf-aa3b-8e1ae48ae074_1200x200.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!cg48!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69c14fbf-a5cb-4caf-aa3b-8e1ae48ae074_1200x200.png 424w, /__u/substackcdn.com/image/fetch/$s_!cg48!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69c14fbf-a5cb-4caf-aa3b-8e1ae48ae074_1200x200.png 848w, /__u/substackcdn.com/image/fetch/$s_!cg48!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69c14fbf-a5cb-4caf-aa3b-8e1ae48ae074_1200x200.png 1272w, /__u/substackcdn.com/image/fetch/$s_!cg48!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69c14fbf-a5cb-4caf-aa3b-8e1ae48ae074_1200x200.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!cg48!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69c14fbf-a5cb-4caf-aa3b-8e1ae48ae074_1200x200.png" width="1200" height="200" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/69c14fbf-a5cb-4caf-aa3b-8e1ae48ae074_1200x200.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:200,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:12002,&quot;alt&quot;:&quot;A mathematical expression showing a double summation: the sum over i from 1 to 2 of the sum over j from 1 to 2 of a subscript ij times b subscript i.&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/206576490?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69c14fbf-a5cb-4caf-aa3b-8e1ae48ae074_1200x200.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="A mathematical expression showing a double summation: the sum over i from 1 to 2 of the sum over j from 1 to 2 of a subscript ij times b subscript i." title="A mathematical expression showing a double summation: the sum over i from 1 to 2 of the sum over j from 1 to 2 of a subscript ij times b subscript i." srcset="/__u/substackcdn.com/image/fetch/$s_!cg48!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69c14fbf-a5cb-4caf-aa3b-8e1ae48ae074_1200x200.png 424w, /__u/substackcdn.com/image/fetch/$s_!cg48!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69c14fbf-a5cb-4caf-aa3b-8e1ae48ae074_1200x200.png 848w, /__u/substackcdn.com/image/fetch/$s_!cg48!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69c14fbf-a5cb-4caf-aa3b-8e1ae48ae074_1200x200.png 1272w, /__u/substackcdn.com/image/fetch/$s_!cg48!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69c14fbf-a5cb-4caf-aa3b-8e1ae48ae074_1200x200.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Here we have a product of two terms in the sum, where one term (<em>b<sub>i</sub></em>) only varies across one index, but the other (<em>a<sub>ij</sub></em>) varies across both.</p><p>We can understand this one using the same grid as before, keeping in mind that each <em>a<sub>ij</sub></em> is now multiplied by the relevant <em>b<sub>i</sub></em>.</p><div class="native-video-embed" data-component-name="VideoPlaceholder" data-attrs="{&quot;mediaUploadId&quot;:&quot;625e628b-9f42-48e0-907a-ffae91df2841&quot;,&quot;duration&quot;:null}"></div><div class="callout-block" data-callout="true"><h5>Quick Practice (2)</h5><p>Calculate the value of:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!dNXV!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36e0feca-af19-4d75-a9b6-eaa6b554a477_1200x200.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!dNXV!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36e0feca-af19-4d75-a9b6-eaa6b554a477_1200x200.png 424w, /__u/substackcdn.com/image/fetch/$s_!dNXV!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36e0feca-af19-4d75-a9b6-eaa6b554a477_1200x200.png 848w, /__u/substackcdn.com/image/fetch/$s_!dNXV!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36e0feca-af19-4d75-a9b6-eaa6b554a477_1200x200.png 1272w, /__u/substackcdn.com/image/fetch/$s_!dNXV!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36e0feca-af19-4d75-a9b6-eaa6b554a477_1200x200.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!dNXV!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36e0feca-af19-4d75-a9b6-eaa6b554a477_1200x200.png" width="1200" height="200" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/36e0feca-af19-4d75-a9b6-eaa6b554a477_1200x200.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:200,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:12153,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/206576490?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36e0feca-af19-4d75-a9b6-eaa6b554a477_1200x200.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!dNXV!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36e0feca-af19-4d75-a9b6-eaa6b554a477_1200x200.png 424w, /__u/substackcdn.com/image/fetch/$s_!dNXV!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36e0feca-af19-4d75-a9b6-eaa6b554a477_1200x200.png 848w, /__u/substackcdn.com/image/fetch/$s_!dNXV!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36e0feca-af19-4d75-a9b6-eaa6b554a477_1200x200.png 1272w, /__u/substackcdn.com/image/fetch/$s_!dNXV!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36e0feca-af19-4d75-a9b6-eaa6b554a477_1200x200.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p><em>Solution at end of article.</em></p></div><h2>An interesting example</h2><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!o5Cf!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F30112e47-3aff-4326-87de-baf5095e94c9_1200x200.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!o5Cf!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F30112e47-3aff-4326-87de-baf5095e94c9_1200x200.png 424w, /__u/substackcdn.com/image/fetch/$s_!o5Cf!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F30112e47-3aff-4326-87de-baf5095e94c9_1200x200.png 848w, /__u/substackcdn.com/image/fetch/$s_!o5Cf!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F30112e47-3aff-4326-87de-baf5095e94c9_1200x200.png 1272w, /__u/substackcdn.com/image/fetch/$s_!o5Cf!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F30112e47-3aff-4326-87de-baf5095e94c9_1200x200.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!o5Cf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F30112e47-3aff-4326-87de-baf5095e94c9_1200x200.png" width="1200" height="200" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/30112e47-3aff-4326-87de-baf5095e94c9_1200x200.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:200,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:10541,&quot;alt&quot;:&quot;A mathematical expression showing a double summation with a coupled inner bound: the sum over i from 1 to 3 of the sum over j from 1 to i of a subscript ij.&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/206576490?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F30112e47-3aff-4326-87de-baf5095e94c9_1200x200.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="A mathematical expression showing a double summation with a coupled inner bound: the sum over i from 1 to 3 of the sum over j from 1 to i of a subscript ij." title="A mathematical expression showing a double summation with a coupled inner bound: the sum over i from 1 to 3 of the sum over j from 1 to i of a subscript ij." srcset="/__u/substackcdn.com/image/fetch/$s_!o5Cf!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F30112e47-3aff-4326-87de-baf5095e94c9_1200x200.png 424w, /__u/substackcdn.com/image/fetch/$s_!o5Cf!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F30112e47-3aff-4326-87de-baf5095e94c9_1200x200.png 848w, /__u/substackcdn.com/image/fetch/$s_!o5Cf!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F30112e47-3aff-4326-87de-baf5095e94c9_1200x200.png 1272w, /__u/substackcdn.com/image/fetch/$s_!o5Cf!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F30112e47-3aff-4326-87de-baf5095e94c9_1200x200.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>This is quite a fun one to apply the grid visualisation to, and best (re-)discovered for yourself if it&#8217;s been a while since you last saw a double summation like this.</p><div class="native-video-embed" data-component-name="VideoPlaceholder" data-attrs="{&quot;mediaUploadId&quot;:&quot;7f33aed0-4dc3-4e1d-aefa-b767497c7511&quot;,&quot;duration&quot;:null}"></div><h2>Why are we looking at double summations?</h2><p>A very good question. My understanding at present:</p><ul><li><p>The course I&#8217;m following (see &#8220;References and resources&#8221; below) likely uses double summation as practice for dealing with a more general increase in dimension on sums (and their continuous counterpart, integrals), since machine learning often involves working with very high-dimensional data, and with joint probability distributions</p></li><li><p>Bishop&#8217;s &#8220;Pattern Recognition and Machine Learning&#8221; textbook includes some double (or higher!) summation notation in several chapters: <em>&#8220;8.4. Inference in Graphical Models&#8221;</em>,<em> &#8220;9. Mixture Models and EM&#8221;</em>,<em> </em>and<em> &#8220;13.2. Hidden Markov Models&#8221;</em>, so we clearly must be well-prepared for these encounters</p></li></ul><div><hr></div><p>To be honest, my study goal for this summer is to not be stressed out about studying. So I&#8217;m not sure yet what next week&#8217;s post will be about. But it probably won&#8217;t be long before I&#8217;m tripped up by some spooky notation again, and I&#8217;ll write it all up when it happens.</p><div class="callout-block" data-callout="true"><h4>References and resources</h4><ul><li><p><a href="https://en.wikipedia.org/wiki/Summation">https://en.wikipedia.org/wiki/Summation</a></p></li><li><p><a href="https://mathworld.wolfram.com/DoubleSeries.html">https://mathworld.wolfram.com/DoubleSeries.html</a></p></li><li><p><a href="https://math.stackexchange.com/a/2416860">https://math.stackexchange.com/a/2416860</a></p></li><li><p>Bishop, &#8220;Pattern Recognition and Machine Learning&#8221;, 2006</p></li></ul><p>The course I&#8217;m following: &#8220;<a href="https://www.mathacademy.com/courses/mathematics-for-machine-learning">Mathematics for Machine Learning</a>&#8221; by MathAcademy.</p></div><div class="callout-block" data-callout="true"><h5>Exercise solutions</h5><ol><li><p>12</p></li><li><p>19</p></li></ol></div><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://petalbyte.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading (Surprisingly Simple) Machine Learning Mathematics! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Study with me: Logic fundamentals (part 2)]]></title><description><![CDATA[From truth tables to neural networks, thanks to XOR the troublemaker.]]></description><link>https://petalbyte.substack.com/p/study-with-me-logic-fundamentals-3bf</link><guid isPermaLink="false">https://petalbyte.substack.com/p/study-with-me-logic-fundamentals-3bf</guid><dc:creator><![CDATA[Louise B]]></dc:creator><pubDate>Sun, 05 Jul 2026 17:13:43 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/30da0ac4-82ed-4c7d-af52-6d79afb7688b_1200x630.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Is there anything simpler than a truth table? (Genuine question.)</p><p>I love them.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://petalbyte.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading (Surprisingly Simple) Machine Learning Mathematics! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p>They make it very easy to see and appreciate some of the most well-known Boolean functions, NAND (&#8220;not AND&#8221;), NOR (&#8220;not OR&#8221;), and XOR (&#8220;exclusive OR&#8221;):</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!3PTt!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6340509-ebdb-40e7-8377-6df30b61b4b3_2094x424.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!3PTt!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6340509-ebdb-40e7-8377-6df30b61b4b3_2094x424.png 424w, /__u/substackcdn.com/image/fetch/$s_!3PTt!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6340509-ebdb-40e7-8377-6df30b61b4b3_2094x424.png 848w, /__u/substackcdn.com/image/fetch/$s_!3PTt!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6340509-ebdb-40e7-8377-6df30b61b4b3_2094x424.png 1272w, /__u/substackcdn.com/image/fetch/$s_!3PTt!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6340509-ebdb-40e7-8377-6df30b61b4b3_2094x424.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!3PTt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6340509-ebdb-40e7-8377-6df30b61b4b3_2094x424.png" width="1456" height="295" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d6340509-ebdb-40e7-8377-6df30b61b4b3_2094x424.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:295,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:82949,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/205278383?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6340509-ebdb-40e7-8377-6df30b61b4b3_2094x424.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!3PTt!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6340509-ebdb-40e7-8377-6df30b61b4b3_2094x424.png 424w, /__u/substackcdn.com/image/fetch/$s_!3PTt!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6340509-ebdb-40e7-8377-6df30b61b4b3_2094x424.png 848w, /__u/substackcdn.com/image/fetch/$s_!3PTt!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6340509-ebdb-40e7-8377-6df30b61b4b3_2094x424.png 1272w, /__u/substackcdn.com/image/fetch/$s_!3PTt!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd6340509-ebdb-40e7-8377-6df30b61b4b3_2094x424.png 1456w" sizes="100vw" fetchpriority="high"></picture><div></div></div></a></figure></div><p>If you&#8217;re looking to pick a favourite, you might consider NAND, which offers functional completeness.</p><p>This means that we can construct all other Boolean operations from NAND. For example, &#8220;NOT <em>x</em>&#8221;:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!BmRc!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdb93c8d-b66d-40c4-bfd2-24fe0699253a_2092x246.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!BmRc!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdb93c8d-b66d-40c4-bfd2-24fe0699253a_2092x246.png 424w, /__u/substackcdn.com/image/fetch/$s_!BmRc!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdb93c8d-b66d-40c4-bfd2-24fe0699253a_2092x246.png 848w, /__u/substackcdn.com/image/fetch/$s_!BmRc!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdb93c8d-b66d-40c4-bfd2-24fe0699253a_2092x246.png 1272w, /__u/substackcdn.com/image/fetch/$s_!BmRc!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdb93c8d-b66d-40c4-bfd2-24fe0699253a_2092x246.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!BmRc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdb93c8d-b66d-40c4-bfd2-24fe0699253a_2092x246.png" width="1456" height="171" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/bdb93c8d-b66d-40c4-bfd2-24fe0699253a_2092x246.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:171,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:42316,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/205278383?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdb93c8d-b66d-40c4-bfd2-24fe0699253a_2092x246.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!BmRc!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdb93c8d-b66d-40c4-bfd2-24fe0699253a_2092x246.png 424w, /__u/substackcdn.com/image/fetch/$s_!BmRc!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdb93c8d-b66d-40c4-bfd2-24fe0699253a_2092x246.png 848w, /__u/substackcdn.com/image/fetch/$s_!BmRc!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdb93c8d-b66d-40c4-bfd2-24fe0699253a_2092x246.png 1272w, /__u/substackcdn.com/image/fetch/$s_!BmRc!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdb93c8d-b66d-40c4-bfd2-24fe0699253a_2092x246.png 1456w" sizes="100vw"></picture><div></div></div></a></figure></div><p>Another example, &#8220;AND&#8221;:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!gsde!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f1ca44f-e357-4174-a160-7e3ec1262b68_2094x424.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!gsde!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f1ca44f-e357-4174-a160-7e3ec1262b68_2094x424.png 424w, /__u/substackcdn.com/image/fetch/$s_!gsde!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f1ca44f-e357-4174-a160-7e3ec1262b68_2094x424.png 848w, /__u/substackcdn.com/image/fetch/$s_!gsde!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f1ca44f-e357-4174-a160-7e3ec1262b68_2094x424.png 1272w, /__u/substackcdn.com/image/fetch/$s_!gsde!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f1ca44f-e357-4174-a160-7e3ec1262b68_2094x424.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!gsde!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f1ca44f-e357-4174-a160-7e3ec1262b68_2094x424.png" width="1456" height="295" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8f1ca44f-e357-4174-a160-7e3ec1262b68_2094x424.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:295,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:89102,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/205278383?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f1ca44f-e357-4174-a160-7e3ec1262b68_2094x424.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!gsde!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f1ca44f-e357-4174-a160-7e3ec1262b68_2094x424.png 424w, /__u/substackcdn.com/image/fetch/$s_!gsde!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f1ca44f-e357-4174-a160-7e3ec1262b68_2094x424.png 848w, /__u/substackcdn.com/image/fetch/$s_!gsde!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f1ca44f-e357-4174-a160-7e3ec1262b68_2094x424.png 1272w, /__u/substackcdn.com/image/fetch/$s_!gsde!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f1ca44f-e357-4174-a160-7e3ec1262b68_2094x424.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption"><em>Imagine making &#8220;AND&#8221; out of &#8220;not AND&#8221;! The audacity.</em></figcaption></figure></div><p>But, in my opinion, you should also consider XOR for top spot.</p><p>In computer science, there are &#8220;XOR tricks&#8221; that can be used to solve certain problems.</p><p>For example, when working with binary numbers, XOR can be used to &#8220;flip&#8221; bits from zero to one, or from one to zero:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;plaintext&quot;,&quot;nodeId&quot;:&quot;da81e0be-ecd0-4cab-bcce-20c8255ba888&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-plaintext">x    = 1010   # This binary number represents 10
mask = 0110   # This binary number represents 6, but it will also allow us 
              # to flip bits 1 and 2 of another binary number

x XOR mask = 1100   # This binary number represents 12 but, more importantly,
                    # we see the expected result of XOR's "flip" of bits 1 and 2</code></pre></div><p>Interestingly, XOR can then be used again to obtain the unmodified binary number:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;plaintext&quot;,&quot;nodeId&quot;:&quot;1343d419-db6e-467e-940e-34cbca0d5778&quot;}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-plaintext">(x XOR mask) XOR mask = 1010</code></pre></div><p>That is to say, XOR is its own inverse, and this is handy in certain situations. For example, if we want to toggle certain configuration or permissions flags on or off (and then back again), we can do this efficiently with XOR.</p><p>But in machine learning, XOR managed to <em>create</em> a problem. One that caused a significant slowing in the rate of research into neural networks when it was written about by Minsky and Papert in their 1969 book, &#8220;Perceptrons&#8221;.</p><p>The problem is that XOR is not linearly separable. That is to say, we can&#8217;t draw a single straight line that separates the two output classes.</p><p>And a single-layer perceptron (a type of neural network) can only learn linearly separable functions. So it cannot represent XOR.</p><p>However, in the 80s the pace of research picked up again. Multi-layer networks (with a hidden layer) trained via backpropagation could solve the XOR problem, because their multiple layers allowed them to divide the input space with more than one boundary.</p><p>The following are some animations I made to share my currently-simple understanding of the XOR problem and its solution. (See &#8220;Resources&#8221; at the end of this post for a video lecture I found with much more detail, if you&#8217;re curious.)</p><p>We can graph XOR on a two-dimensional plane, creating a unit square:</p><div class="native-video-embed" data-component-name="VideoPlaceholder" data-attrs="{&quot;mediaUploadId&quot;:&quot;263834c2-8a99-4326-a34b-c9cfe70bf822&quot;,&quot;duration&quot;:null}"></div><p>If we try to separate the points where A XOR B = 1 with a straight line, we simply cannot:</p><div class="native-video-embed" data-component-name="VideoPlaceholder" data-attrs="{&quot;mediaUploadId&quot;:&quot;26d5dddb-2c12-41e9-a71f-0059bc8c8059&quot;,&quot;duration&quot;:null}"></div><p>And this is a problem because, if we are building a binary classification model, we need decision boundaries that divide the space into classification regions.</p><p>(Very simply: If a data point sits in one region, then it&#8217;s in one class. If a data point sits in the other region, it is in the other class. Thus, the data point has been classified.)</p><p>The solution is, essentially, to transform the input space itself. Once a hidden layer has done its work, we can imagine the data points sitting in a warped space that positions the 1s in such a way that they can then be linearly separated from the 0s:</p><div class="native-video-embed" data-component-name="VideoPlaceholder" data-attrs="{&quot;mediaUploadId&quot;:&quot;7cd2ff75-3f24-4c8c-8e51-b9c7b60b6cc7&quot;,&quot;duration&quot;:null}"></div><p>Bishop&#8217;s book (referenced below) has a good short summary of the history here, and you can of course read the original works by Rosenblatt, and Minksy. Let me know if you do!</p><div><hr></div><p>I&#8217;m not sure exactly what I&#8217;ll write about next week.</p><p>The course I&#8217;m following (included in the resource list below) interleaves topics. Whenever something seems far more mysterious than it should, I read more widely and summarise my findings here.</p><p>(One known study activity next week: Some visuals to improve my ability to parse double sum notation! I&#8217;ll probably just post them as a note, so feel free to follow if you&#8217;d like to see them.)</p><div class="callout-block" data-callout="true"><h4>Resources and references:</h4><ul><li><p><a href="https://en.wikipedia.org/wiki/Sheffer_stroke#Functional_completeness">https://en.wikipedia.org/wiki/Sheffer_stroke#Functional_completeness</a></p></li><li><p><a href="https://en.wikipedia.org/wiki/XOR_swap_algorithm">https://en.wikipedia.org/wiki/XOR_swap_algorithm</a></p></li><li><p>Bishop, &#8220;Pattern Recognition and Machine Learning&#8221;, 2006</p></li><li><p><a href="https://dev.to/jbahire/demystifying-the-xor-problem-1blk">https://dev.to/jbahire/demystifying-the-xor-problem-1blk</a></p></li><li><p><a href="https://www.youtube.com/watch?v=tk0XpP_QaBY">ITS 365 - The XOR problem and Neural Networks (part 1)</a></p></li></ul><p>The course I&#8217;m currently following is Math Academy&#8217;s &#8220;<a href="https://mathacademy.com/courses/mathematics-for-machine-learning">Mathematics for Machine Learning</a>&#8221;.</p></div><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://petalbyte.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading (Surprisingly Simple) Machine Learning Mathematics! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Study with me: Logic fundamentals (part 1)]]></title><description><![CDATA[Putting some introductory ideas into a machine learning context, to help with retention and intuition development.]]></description><link>https://petalbyte.substack.com/p/study-with-me-logic-fundamentals</link><guid isPermaLink="false">https://petalbyte.substack.com/p/study-with-me-logic-fundamentals</guid><dc:creator><![CDATA[Louise B]]></dc:creator><pubDate>Sun, 28 Jun 2026 19:35:58 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/56472383-0200-455c-8009-8b658193764d_1200x630.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>I didn&#8217;t study mathematical logic fundamentals until the first year of my undergraduate degree, in an &#8220;Introduction to Proofs&#8221; course that felt challenging to me at the time but was, in retrospect, not very difficult.</p><p>(I started undergrad without the kind of preparation that I would now recommend to anyone else. Hence all this review that I&#8217;m doing.)</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://petalbyte.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading (Surprisingly Simple) Machine Learning Mathematics! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p>And now I&#8217;ve reached logic fundamentals in the online course I&#8217;m following (&#8220;Mathematics for Machine Learning&#8221; on MathAcademy), and would like to avoid one of my prior learning mistakes: Not putting abstract information into concrete context.</p><p>So here I&#8217;ll try a few ways of creating initial connections between some logic basics and some ML concepts, to help with retention and intuition development.</p><h2>Classifier decision regions and predicate sets</h2><p>To get started with logic, we need to learn what statements and predicates are.</p><p>A mathematical statement is an expression that is either true or false:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!8CxZ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b7c694f-ba6a-4762-bc68-b11201a92df8_1948x282.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!8CxZ!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b7c694f-ba6a-4762-bc68-b11201a92df8_1948x282.png 424w, /__u/substackcdn.com/image/fetch/$s_!8CxZ!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b7c694f-ba6a-4762-bc68-b11201a92df8_1948x282.png 848w, /__u/substackcdn.com/image/fetch/$s_!8CxZ!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b7c694f-ba6a-4762-bc68-b11201a92df8_1948x282.png 1272w, /__u/substackcdn.com/image/fetch/$s_!8CxZ!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b7c694f-ba6a-4762-bc68-b11201a92df8_1948x282.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!8CxZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b7c694f-ba6a-4762-bc68-b11201a92df8_1948x282.png" width="1456" height="211" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8b7c694f-ba6a-4762-bc68-b11201a92df8_1948x282.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:211,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:67097,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/203968195?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b7c694f-ba6a-4762-bc68-b11201a92df8_1948x282.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!8CxZ!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b7c694f-ba6a-4762-bc68-b11201a92df8_1948x282.png 424w, /__u/substackcdn.com/image/fetch/$s_!8CxZ!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b7c694f-ba6a-4762-bc68-b11201a92df8_1948x282.png 848w, /__u/substackcdn.com/image/fetch/$s_!8CxZ!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b7c694f-ba6a-4762-bc68-b11201a92df8_1948x282.png 1272w, /__u/substackcdn.com/image/fetch/$s_!8CxZ!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b7c694f-ba6a-4762-bc68-b11201a92df8_1948x282.png 1456w" sizes="100vw" fetchpriority="high"></picture><div></div></div></a></figure></div><p>And a predicate is a statement with a variable, so its truth depends on the value taken by the variable:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!BPuP!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc1356808-a7f8-40b6-a628-63821170487e_1950x282.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!BPuP!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc1356808-a7f8-40b6-a628-63821170487e_1950x282.png 424w, /__u/substackcdn.com/image/fetch/$s_!BPuP!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc1356808-a7f8-40b6-a628-63821170487e_1950x282.png 848w, /__u/substackcdn.com/image/fetch/$s_!BPuP!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc1356808-a7f8-40b6-a628-63821170487e_1950x282.png 1272w, /__u/substackcdn.com/image/fetch/$s_!BPuP!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc1356808-a7f8-40b6-a628-63821170487e_1950x282.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!BPuP!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc1356808-a7f8-40b6-a628-63821170487e_1950x282.png" width="1456" height="211" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c1356808-a7f8-40b6-a628-63821170487e_1950x282.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:211,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:49752,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/203968195?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc1356808-a7f8-40b6-a628-63821170487e_1950x282.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!BPuP!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc1356808-a7f8-40b6-a628-63821170487e_1950x282.png 424w, /__u/substackcdn.com/image/fetch/$s_!BPuP!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc1356808-a7f8-40b6-a628-63821170487e_1950x282.png 848w, /__u/substackcdn.com/image/fetch/$s_!BPuP!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc1356808-a7f8-40b6-a628-63821170487e_1950x282.png 1272w, /__u/substackcdn.com/image/fetch/$s_!BPuP!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc1356808-a7f8-40b6-a628-63821170487e_1950x282.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>We can apply logical connectives, AND, OR and NOT, to statements and predicates in the way we&#8217;d expect, too.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!Tj9Q!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd16da26-ddb1-44bb-8aba-d1e4f2deed5d_1952x290.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!Tj9Q!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd16da26-ddb1-44bb-8aba-d1e4f2deed5d_1952x290.png 424w, /__u/substackcdn.com/image/fetch/$s_!Tj9Q!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd16da26-ddb1-44bb-8aba-d1e4f2deed5d_1952x290.png 848w, /__u/substackcdn.com/image/fetch/$s_!Tj9Q!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd16da26-ddb1-44bb-8aba-d1e4f2deed5d_1952x290.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Tj9Q!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd16da26-ddb1-44bb-8aba-d1e4f2deed5d_1952x290.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!Tj9Q!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd16da26-ddb1-44bb-8aba-d1e4f2deed5d_1952x290.png" width="1456" height="216" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/dd16da26-ddb1-44bb-8aba-d1e4f2deed5d_1952x290.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:216,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:63780,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/203968195?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd16da26-ddb1-44bb-8aba-d1e4f2deed5d_1952x290.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!Tj9Q!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd16da26-ddb1-44bb-8aba-d1e4f2deed5d_1952x290.png 424w, /__u/substackcdn.com/image/fetch/$s_!Tj9Q!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd16da26-ddb1-44bb-8aba-d1e4f2deed5d_1952x290.png 848w, /__u/substackcdn.com/image/fetch/$s_!Tj9Q!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd16da26-ddb1-44bb-8aba-d1e4f2deed5d_1952x290.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Tj9Q!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd16da26-ddb1-44bb-8aba-d1e4f2deed5d_1952x290.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>To put these abstract ideas into a (slightly) practical context, we can consider a classification scenario, where our goal is to label images according to the kinds of animals in the image.</p><p>Our predicates might be <em>P(x): &#8220;x contains a cat&#8221;</em>  and <em>Q(x): &#8220;x contains a dog&#8221;</em>, where the variable references a particular image we are labelling.</p><p>The truth sets <em>{x: P(x)}</em> and <em>{x: Q(x)}</em> then become decision regions of our classifier.</p><p>And we can visualise the logical connectives, such as AND and OR, in the familiar Venn diagram-like way.</p><div class="native-video-embed" data-component-name="VideoPlaceholder" data-attrs="{&quot;mediaUploadId&quot;:&quot;d800a948-6624-4adc-a7b9-cfda21a6c8a7&quot;,&quot;duration&quot;:null}"></div><h2>Decision trees with logical leaves</h2><p>Truth tables are another early logic fundamental. And they are already simple, and visual, which I appreciate.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!keGN!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8a78bed-5950-4301-8624-8b64e3e85458_1664x370.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!keGN!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8a78bed-5950-4301-8624-8b64e3e85458_1664x370.png 424w, /__u/substackcdn.com/image/fetch/$s_!keGN!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8a78bed-5950-4301-8624-8b64e3e85458_1664x370.png 848w, /__u/substackcdn.com/image/fetch/$s_!keGN!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8a78bed-5950-4301-8624-8b64e3e85458_1664x370.png 1272w, /__u/substackcdn.com/image/fetch/$s_!keGN!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8a78bed-5950-4301-8624-8b64e3e85458_1664x370.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!keGN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8a78bed-5950-4301-8624-8b64e3e85458_1664x370.png" width="1456" height="324" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f8a78bed-5950-4301-8624-8b64e3e85458_1664x370.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:324,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:57112,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/203968195?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8a78bed-5950-4301-8624-8b64e3e85458_1664x370.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!keGN!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8a78bed-5950-4301-8624-8b64e3e85458_1664x370.png 424w, /__u/substackcdn.com/image/fetch/$s_!keGN!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8a78bed-5950-4301-8624-8b64e3e85458_1664x370.png 848w, /__u/substackcdn.com/image/fetch/$s_!keGN!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8a78bed-5950-4301-8624-8b64e3e85458_1664x370.png 1272w, /__u/substackcdn.com/image/fetch/$s_!keGN!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8a78bed-5950-4301-8624-8b64e3e85458_1664x370.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Third column: &#8220;A and B&#8221;. Fourth column: &#8220;A or B&#8221;.</figcaption></figure></div><p>In machine learning, decision trees can be used for classification tasks, and a decision tree can be interpreted as a truth table with a conjunction (&#8220;AND&#8221;) column.</p><div class="native-video-embed" data-component-name="VideoPlaceholder" data-attrs="{&quot;mediaUploadId&quot;:&quot;e32f2478-9b3d-4a74-a50f-34b1633df097&quot;,&quot;duration&quot;:null}"></div><p>(Hopefully that isn&#8217;t too inaccurate, biologically-speaking.)</p><p>Decision trees might be built recursively, followed by pruning, where &#8216;less useful&#8217; nodes are removed to obtain a subtree.</p><p>Although the definition of &#8216;less useful&#8217; is rather more complex in practice, I&#8217;ll stick to a very simple example of pruning a tree to remove redundant paths.</p><p>Shown alongside a truth table, this illustrates another fundamental: Logical equivalence.</p><p>Two statements are logically equivalent if they have identical truth values in their respective truth tables (i.e. two matching columns).</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!KlmF!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbae7293-664a-4288-9567-54affcf7559b_1946x432.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!KlmF!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbae7293-664a-4288-9567-54affcf7559b_1946x432.png 424w, /__u/substackcdn.com/image/fetch/$s_!KlmF!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbae7293-664a-4288-9567-54affcf7559b_1946x432.png 848w, /__u/substackcdn.com/image/fetch/$s_!KlmF!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbae7293-664a-4288-9567-54affcf7559b_1946x432.png 1272w, /__u/substackcdn.com/image/fetch/$s_!KlmF!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbae7293-664a-4288-9567-54affcf7559b_1946x432.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!KlmF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbae7293-664a-4288-9567-54affcf7559b_1946x432.png" width="1456" height="323" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/cbae7293-664a-4288-9567-54affcf7559b_1946x432.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:323,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:69987,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/203968195?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbae7293-664a-4288-9567-54affcf7559b_1946x432.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!KlmF!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbae7293-664a-4288-9567-54affcf7559b_1946x432.png 424w, /__u/substackcdn.com/image/fetch/$s_!KlmF!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbae7293-664a-4288-9567-54affcf7559b_1946x432.png 848w, /__u/substackcdn.com/image/fetch/$s_!KlmF!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbae7293-664a-4288-9567-54affcf7559b_1946x432.png 1272w, /__u/substackcdn.com/image/fetch/$s_!KlmF!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbae7293-664a-4288-9567-54affcf7559b_1946x432.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Third column: &#8220;(Not A) or B). Fourth column: &#8220;A implies B&#8221;.</figcaption></figure></div><p>And this is something we can also see visually in a decision tree that contains some redundant paths:</p><div class="native-video-embed" data-component-name="VideoPlaceholder" data-attrs="{&quot;mediaUploadId&quot;:&quot;8b540dbf-821e-41ff-bb7e-de9650998e46&quot;,&quot;duration&quot;:null}"></div><div><hr></div><p>I wanted to also review Boolean functions and logical operations this week, perhaps in connection to perceptrons, but that&#8217;ll have to be next week&#8217;s post.</p><div class="callout-block" data-callout="true"><h4>Resources and references</h4><ul><li><p><a href="https://scikit-learn.org/0.15/modules/multiclass.html">https://scikit-learn.org/0.15/modules/multiclass.html</a></p></li><li><p>James et al, &#8220;An Introduction to Statistical Learning&#8221;, 2023</p></li><li><p><a href="https://icml.cc/virtual/2025/poster/46051">McTavish et al, &#8220;Leveraging Predictive Equivalence in Decision Trees&#8221;, 2025</a></p></li><li><p><a href="https://www.oranlooney.com/post/ml-from-scratch-part-4-decision-tree/">https://www.oranlooney.com/post/ml-from-scratch-part-4-decision-tree/</a></p></li></ul><p>The course I&#8217;m following: &#8220;<a href="https://mathacademy.com/courses/mathematics-for-machine-learning">Mathematics for Machine Learning</a>&#8221;, on MathAcademy.</p></div><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://petalbyte.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading (Surprisingly Simple) Machine Learning Mathematics! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Study with me: Tensor reshaping]]></title><description><![CDATA[With some practical exercises for clarity.]]></description><link>https://petalbyte.substack.com/p/study-with-me-tensor-reshaping</link><guid isPermaLink="false">https://petalbyte.substack.com/p/study-with-me-tensor-reshaping</guid><dc:creator><![CDATA[Louise B]]></dc:creator><pubDate>Sun, 21 Jun 2026 09:48:58 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/a36a64b9-1c1f-4c64-a0e8-12e45690f53e_1200x630.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>I enjoyed learning about tensors and tensor contraction last week, despite initially feeling anxious about the notation. (It&#8217;s simple in that way that sometimes means a bit too much is hidden behind a few innocent-looking symbols.)</p><p>Of course, in a physics or pure mathematics context, tensors are a deeper topic than in ML. This post will treat tensors as multidimensional arrays used in computational work, but I do recommend further study of tensors in other contexts to anyone curious.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://petalbyte.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading (Surprisingly Simple) Machine Learning Mathematics! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p>Back to my tensor contraction notation jumpscare: By resetting my expectations to just figuring out some ML tensor basics last week, and patiently revisiting those ideas a few times, I was able to feel a sense of progression. And since I study because I like to progress my understanding, that was the ideal result.</p><p>In particular, I&#8217;ve had time to just get used to adding an extra axis to a matrix.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!hU5y!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e62e044-9653-428f-90f8-a76c2e06da93_2102x512.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!hU5y!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e62e044-9653-428f-90f8-a76c2e06da93_2102x512.png 424w, /__u/substackcdn.com/image/fetch/$s_!hU5y!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e62e044-9653-428f-90f8-a76c2e06da93_2102x512.png 848w, /__u/substackcdn.com/image/fetch/$s_!hU5y!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e62e044-9653-428f-90f8-a76c2e06da93_2102x512.png 1272w, /__u/substackcdn.com/image/fetch/$s_!hU5y!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e62e044-9653-428f-90f8-a76c2e06da93_2102x512.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!hU5y!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e62e044-9653-428f-90f8-a76c2e06da93_2102x512.png" width="1456" height="355" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6e62e044-9653-428f-90f8-a76c2e06da93_2102x512.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:355,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:122283,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/202822424?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e62e044-9653-428f-90f8-a76c2e06da93_2102x512.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!hU5y!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e62e044-9653-428f-90f8-a76c2e06da93_2102x512.png 424w, /__u/substackcdn.com/image/fetch/$s_!hU5y!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e62e044-9653-428f-90f8-a76c2e06da93_2102x512.png 848w, /__u/substackcdn.com/image/fetch/$s_!hU5y!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e62e044-9653-428f-90f8-a76c2e06da93_2102x512.png 1272w, /__u/substackcdn.com/image/fetch/$s_!hU5y!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e62e044-9653-428f-90f8-a76c2e06da93_2102x512.png 1456w" sizes="100vw" fetchpriority="high"></picture><div></div></div></a><figcaption class="image-caption"><em>My current mental model.</em></figcaption></figure></div><p>(Or many more than one axis, of course, but if you know how to visualise that then do share in the comments.)</p><div class="callout-block" data-callout="true"><h5>Try it yourself:</h5><ol><li><p>For each of the following objects, what is its order (i.e. how many axes does it have)?</p><ol><li><p>The scalar <em>a</em></p></li><li><p>The vector <em>[x, y z]</em></p></li><li><p>The matrix <em>[[a, b, c], [d, e, f], [g, h, i]]</em></p></li></ol></li><li><p>If we represent an order 3 tensor, <em>T<sub>ijk</sub></em>, as follows, and use 1-based indexing, what is <em>T<sub>232</sub>?</em></p></li></ol><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!Ajmv!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F175f3c02-9842-441c-a820-037373f7cd4f_959x215.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!Ajmv!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F175f3c02-9842-441c-a820-037373f7cd4f_959x215.png 424w, /__u/substackcdn.com/image/fetch/$s_!Ajmv!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F175f3c02-9842-441c-a820-037373f7cd4f_959x215.png 848w, /__u/substackcdn.com/image/fetch/$s_!Ajmv!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F175f3c02-9842-441c-a820-037373f7cd4f_959x215.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Ajmv!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F175f3c02-9842-441c-a820-037373f7cd4f_959x215.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!Ajmv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F175f3c02-9842-441c-a820-037373f7cd4f_959x215.png" width="959" height="215" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/175f3c02-9842-441c-a820-037373f7cd4f_959x215.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:215,&quot;width&quot;:959,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:17496,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/202822424?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F175f3c02-9842-441c-a820-037373f7cd4f_959x215.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!Ajmv!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F175f3c02-9842-441c-a820-037373f7cd4f_959x215.png 424w, /__u/substackcdn.com/image/fetch/$s_!Ajmv!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F175f3c02-9842-441c-a820-037373f7cd4f_959x215.png 848w, /__u/substackcdn.com/image/fetch/$s_!Ajmv!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F175f3c02-9842-441c-a820-037373f7cd4f_959x215.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Ajmv!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F175f3c02-9842-441c-a820-037373f7cd4f_959x215.png 1456w" sizes="100vw"></picture><div></div></div></a></figure></div><p><em>Answers at end of article.</em></p></div><h2>Tensor permuting and reshaping</h2><p>In machine learning, we might be working with tensors as multidimensional arrays, and we might sometimes need to mould one into a more convenient shape.</p><blockquote><p>To date, most convolutional neural network architectures output predictions by flattening 3rd-order activation tensors, and applying fully-connected output layers.<em><br>&#8212;<a href="https://ibug.doc.ic.ac.uk/media/uploads/documents/tensor_regression_networks.pdf">Kossaifi et al, &#8220;Tensor Regression Networks&#8221;, July 2017</a></em></p></blockquote><p>Managing computation cost is a likely reason for this:</p><blockquote><p>Although the computational cost (measured in number of scalar&nbsp;multiplications) is the same both ways, it is usually preferable to recast [binary tensor contraction] as multiplication as modern hardware performs vectorized operations much faster than when using the equivalent FOR loop.<br><em>&#8212;<a href="https://www.tensors.net/tutorial-1">https://www.tensors.net/tutorial-1</a></em></p></blockquote><p>This recasting can involve permuting a tensor, as well as reshaping it.</p><p>Permuting a tensor reorders its dimensions by swapping its indices. This doesn&#8217;t change the tensor&#8217;s entries, just the location they can be retrieved from.</p><p>Swapping the indices of an order 2 tensor, visualised as a 3x3 matrix, results in the familiar transpose:</p><div class="native-video-embed" data-component-name="VideoPlaceholder" data-attrs="{&quot;mediaUploadId&quot;:&quot;0043cdc4-b392-4dd2-b983-66aadf409615&quot;,&quot;duration&quot;:null}"></div><p>(As a sidenote here, Deisenroth (2020) specifies: &#8220;When we &#8216;transpose&#8217; a tensor, we mean swapping the first two dimensions&#8221;.)</p><p>If we visualise an order 3 tensor as a stack of matrices, and choose to swap the index that tracks the &#8216;stack layer&#8217;, then it may look like this:</p><div class="native-video-embed" data-component-name="VideoPlaceholder" data-attrs="{&quot;mediaUploadId&quot;:&quot;1f8bc48d-3e53-40e2-a23d-3f5a2a0714e8&quot;,&quot;duration&quot;:null}"></div><p>One <a href="https://apxml.com/courses/getting-started-with-pytorch/chapter-2-advanced-tensor-manipulations/reshaping-rearranging-tensors">PyTorch tutorial</a> gives an example scenario in which someone might permute a tensor:</p><blockquote><p>Imagine you have image data stored as (Channels, Height, Width) but need it in (Height, Width, Channels) format for a specific library or visualization. [PyTorch&#8217;s function] <code>permute()</code> is the tool for this.</p></blockquote><div class="callout-block" data-callout="true"><h5>Try it yourself:</h5><p>Given the same order 3 tensor representation as before, <em>T<sub>ijk</sub></em>:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!Ajmv!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F175f3c02-9842-441c-a820-037373f7cd4f_959x215.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!Ajmv!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F175f3c02-9842-441c-a820-037373f7cd4f_959x215.png 424w, /__u/substackcdn.com/image/fetch/$s_!Ajmv!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F175f3c02-9842-441c-a820-037373f7cd4f_959x215.png 848w, /__u/substackcdn.com/image/fetch/$s_!Ajmv!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F175f3c02-9842-441c-a820-037373f7cd4f_959x215.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Ajmv!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F175f3c02-9842-441c-a820-037373f7cd4f_959x215.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!Ajmv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F175f3c02-9842-441c-a820-037373f7cd4f_959x215.png" width="959" height="215" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/175f3c02-9842-441c-a820-037373f7cd4f_959x215.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:215,&quot;width&quot;:959,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:17496,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/202822424?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F175f3c02-9842-441c-a820-037373f7cd4f_959x215.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="/__u/substackcdn.com/image/fetch/$s_!Ajmv!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F175f3c02-9842-441c-a820-037373f7cd4f_959x215.png 424w, /__u/substackcdn.com/image/fetch/$s_!Ajmv!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F175f3c02-9842-441c-a820-037373f7cd4f_959x215.png 848w, /__u/substackcdn.com/image/fetch/$s_!Ajmv!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F175f3c02-9842-441c-a820-037373f7cd4f_959x215.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Ajmv!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F175f3c02-9842-441c-a820-037373f7cd4f_959x215.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>If we permute <em>T<sub>ijk</sub> </em>by swapping its <em>j</em> and <em>k</em> axes to obtain <em>T&#8242;<sub>ikj</sub></em>, what entry do we find at <em>T&#8242;<sub>212</sub>?</em></p><p><em>Answer at end of article.</em></p></div><p>Now, onto reshaping, where we might combine any number of tensor indices into a single, larger index, or separate a larger index into smaller ones.</p><p>Again, this is easily visualised with matrices:</p><div class="native-video-embed" data-component-name="VideoPlaceholder" data-attrs="{&quot;mediaUploadId&quot;:&quot;26bbbc4d-ce35-43a5-9ef6-f3cc3406ab95&quot;,&quot;duration&quot;:null}"></div><p>But moving up an order isn&#8217;t too bad:</p><div class="native-video-embed" data-component-name="VideoPlaceholder" data-attrs="{&quot;mediaUploadId&quot;:&quot;53652ba7-4109-44f1-8feb-1cc15485dafc&quot;,&quot;duration&quot;:null}"></div><p>The same PyTorch tutorial suggests that &#8220;[tensor reshaping is] highly useful for tasks like flattening a multi-dimensional tensor before passing it to a linear layer&#8221;.</p><p>And Deisenroth briefly describes how we can compute the gradient of a matrix either by finding the partial derivatives and collating them into the order 3 Jacobian tensor, or by flattening the matrix into a vector to compute the Jacobian matrix, and then reshaping the result into the Jacobian tensor.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!tluL!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d58212e-b988-4ea0-af41-90a91c14cc93_970x488.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!tluL!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d58212e-b988-4ea0-af41-90a91c14cc93_970x488.png 424w, /__u/substackcdn.com/image/fetch/$s_!tluL!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d58212e-b988-4ea0-af41-90a91c14cc93_970x488.png 848w, /__u/substackcdn.com/image/fetch/$s_!tluL!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d58212e-b988-4ea0-af41-90a91c14cc93_970x488.png 1272w, /__u/substackcdn.com/image/fetch/$s_!tluL!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d58212e-b988-4ea0-af41-90a91c14cc93_970x488.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!tluL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d58212e-b988-4ea0-af41-90a91c14cc93_970x488.png" width="970" height="488" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6d58212e-b988-4ea0-af41-90a91c14cc93_970x488.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:488,&quot;width&quot;:970,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:62575,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/202822424?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d58212e-b988-4ea0-af41-90a91c14cc93_970x488.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!tluL!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d58212e-b988-4ea0-af41-90a91c14cc93_970x488.png 424w, /__u/substackcdn.com/image/fetch/$s_!tluL!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d58212e-b988-4ea0-af41-90a91c14cc93_970x488.png 848w, /__u/substackcdn.com/image/fetch/$s_!tluL!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d58212e-b988-4ea0-af41-90a91c14cc93_970x488.png 1272w, /__u/substackcdn.com/image/fetch/$s_!tluL!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d58212e-b988-4ea0-af41-90a91c14cc93_970x488.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><em>Deisenroth et al, &#8220;Mathematics for Machine Learning&#8221;, 2020, ch. 5.3</em></figcaption></figure></div><p>(<a href="https://machinelearningmastery.com/a-gentle-introduction-to-the-jacobian/">Here&#8217;s an article</a> with more about the Jacobian and its uses in ML, if useful.)</p><div class="callout-block" data-callout="true"><h5>Try it yourself:</h5><p>Given the same order 3 tensor representation as before, <em>T<sub>ijk</sub></em>:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!Ajmv!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F175f3c02-9842-441c-a820-037373f7cd4f_959x215.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!Ajmv!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F175f3c02-9842-441c-a820-037373f7cd4f_959x215.png 424w, /__u/substackcdn.com/image/fetch/$s_!Ajmv!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F175f3c02-9842-441c-a820-037373f7cd4f_959x215.png 848w, /__u/substackcdn.com/image/fetch/$s_!Ajmv!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F175f3c02-9842-441c-a820-037373f7cd4f_959x215.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Ajmv!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F175f3c02-9842-441c-a820-037373f7cd4f_959x215.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!Ajmv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F175f3c02-9842-441c-a820-037373f7cd4f_959x215.png" width="959" height="215" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/175f3c02-9842-441c-a820-037373f7cd4f_959x215.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:215,&quot;width&quot;:959,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:17496,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:&quot;&quot;,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/202822424?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F175f3c02-9842-441c-a820-037373f7cd4f_959x215.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="/__u/substackcdn.com/image/fetch/$s_!Ajmv!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F175f3c02-9842-441c-a820-037373f7cd4f_959x215.png 424w, /__u/substackcdn.com/image/fetch/$s_!Ajmv!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F175f3c02-9842-441c-a820-037373f7cd4f_959x215.png 848w, /__u/substackcdn.com/image/fetch/$s_!Ajmv!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F175f3c02-9842-441c-a820-037373f7cd4f_959x215.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Ajmv!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F175f3c02-9842-441c-a820-037373f7cd4f_959x215.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>If we reshape <em>T<sub>ijk</sub> </em>by flattening the <em>j</em> and <em>k</em> axes into <em>l</em> to obtain <em>T&#8242;<sub>il</sub></em>, what number is found at <em>T&#8242;<sub>21</sub></em>?</p><p><em>Answer at end of article.</em></p></div><div><hr></div><p>I&#8217;ve barely begun to scratch the surface of tensors and their operations, but the <a href="https://mathacademy.com/courses/mathematics-for-machine-learning">course</a> I&#8217;m following doesn&#8217;t dwell on them much. Over the next few weeks, I&#8217;ll be sticking to its roadmap.</p><p>This will mean returning to reviewing the many topics I&#8217;ve half forgotten across linear algebra, calculus and statistics, which I&#8217;m finding so fun to do without the stress and deadlines of a formal course (for now).</p><div class="callout-block" data-callout="true"><h4>Resources and references:</h4><ul><li><p><a href="https://ibug.doc.ic.ac.uk/media/uploads/documents/tensor_regression_networks.pdf">Kossaifi et al., </a><em><a href="https://ibug.doc.ic.ac.uk/media/uploads/documents/tensor_regression_networks.pdf">Tensor Regression Networks</a></em><a href="https://ibug.doc.ic.ac.uk/media/uploads/documents/tensor_regression_networks.pdf">, July 2017</a></p></li><li><p><a href="https://www.tensors.net/tutorial-1">https://www.tensors.net/tutorial-1</a></p></li><li><p>Deisenroth et al, &#8220;Mathematics for Machine Learning&#8221;, 2020</p></li><li><p><a href="https://en.wikipedia.org/wiki/Tensor_reshaping">https://en.wikipedia.org/wiki/Tensor_reshaping</a></p></li><li><p><a href="https://docs.pytorch.org/docs/2.12/generated/torch.reshape.html">https://docs.pytorch.org/docs/2.12/generated/torch.reshape.html</a></p></li><li><p><a href="https://apxml.com/courses/getting-started-with-pytorch/chapter-2-advanced-tensor-manipulations/reshaping-rearranging-tensors">https://apxml.com/courses/getting-started-with-pytorch/chapter-2-advanced-tensor-manipulations/reshaping-rearranging-tensors</a></p></li></ul></div><div class="callout-block" data-callout="true"><h5>Exercise solutions:</h5><ol><li><p>a) 0, b) 1, c) 2</p></li><li><p>1</p></li><li><p>3</p></li></ol></div><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://petalbyte.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading (Surprisingly Simple) Machine Learning Mathematics! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Study with me: Tensors (part 1)]]></title><description><![CDATA[A cautious peek at multidimensional arrays with a new-to-me operation.]]></description><link>https://petalbyte.substack.com/p/study-with-me-tensors-part-1</link><guid isPermaLink="false">https://petalbyte.substack.com/p/study-with-me-tensors-part-1</guid><dc:creator><![CDATA[Louise B]]></dc:creator><pubDate>Sun, 14 Jun 2026 17:37:07 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/814f1313-cdd9-449b-b36f-53498bc40b32_1200x630.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>I won&#8217;t lie: This notation stressed me out.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!cUBA!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3bad6ac5-9147-4527-b8bf-e74128e02c62_1812x164.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!cUBA!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3bad6ac5-9147-4527-b8bf-e74128e02c62_1812x164.png 424w, /__u/substackcdn.com/image/fetch/$s_!cUBA!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3bad6ac5-9147-4527-b8bf-e74128e02c62_1812x164.png 848w, /__u/substackcdn.com/image/fetch/$s_!cUBA!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3bad6ac5-9147-4527-b8bf-e74128e02c62_1812x164.png 1272w, /__u/substackcdn.com/image/fetch/$s_!cUBA!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3bad6ac5-9147-4527-b8bf-e74128e02c62_1812x164.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!cUBA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3bad6ac5-9147-4527-b8bf-e74128e02c62_1812x164.png" width="1456" height="132" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3bad6ac5-9147-4527-b8bf-e74128e02c62_1812x164.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:132,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:17065,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/201951144?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3bad6ac5-9147-4527-b8bf-e74128e02c62_1812x164.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!cUBA!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3bad6ac5-9147-4527-b8bf-e74128e02c62_1812x164.png 424w, /__u/substackcdn.com/image/fetch/$s_!cUBA!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3bad6ac5-9147-4527-b8bf-e74128e02c62_1812x164.png 848w, /__u/substackcdn.com/image/fetch/$s_!cUBA!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3bad6ac5-9147-4527-b8bf-e74128e02c62_1812x164.png 1272w, /__u/substackcdn.com/image/fetch/$s_!cUBA!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3bad6ac5-9147-4527-b8bf-e74128e02c62_1812x164.png 1456w" sizes="100vw" fetchpriority="high"></picture><div></div></div></a></figure></div><p>It&#8217;s funny because, although I love studying mathematics, and have spent a lot of time unlearning a fear of it, I still sometimes get completely in my own way.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://petalbyte.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading (Surprisingly Simple) Machine Learning Mathematics! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p>And perhaps my brain also sometimes demands reassurance that whatever I&#8217;m looking at has a utility.</p><p>These days, I know the answer (for me) is to pause to figure out a safe entry-point. Ideally the simplest possible one. And then to look for a real-world usage example.</p><p>This post is an example of that, where I reduce my ambition (for now) to just understanding something about what a tensor is, deciphering that spooky notation, and seeing where these ideas might be applied in practice.</p><h2>Tensors</h2><p>In a machine learning context, tensors are multidimensional arrays.</p><p>Deisenroth provides a nice visual:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!nTK2!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc70d601b-5d5b-4bb1-9f9c-685df65b3c87_994x324.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!nTK2!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc70d601b-5d5b-4bb1-9f9c-685df65b3c87_994x324.png 424w, /__u/substackcdn.com/image/fetch/$s_!nTK2!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc70d601b-5d5b-4bb1-9f9c-685df65b3c87_994x324.png 848w, /__u/substackcdn.com/image/fetch/$s_!nTK2!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc70d601b-5d5b-4bb1-9f9c-685df65b3c87_994x324.png 1272w, /__u/substackcdn.com/image/fetch/$s_!nTK2!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc70d601b-5d5b-4bb1-9f9c-685df65b3c87_994x324.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!nTK2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc70d601b-5d5b-4bb1-9f9c-685df65b3c87_994x324.png" width="994" height="324" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c70d601b-5d5b-4bb1-9f9c-685df65b3c87_994x324.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:324,&quot;width&quot;:994,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:48535,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/201951144?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc70d601b-5d5b-4bb1-9f9c-685df65b3c87_994x324.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!nTK2!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc70d601b-5d5b-4bb1-9f9c-685df65b3c87_994x324.png 424w, /__u/substackcdn.com/image/fetch/$s_!nTK2!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc70d601b-5d5b-4bb1-9f9c-685df65b3c87_994x324.png 848w, /__u/substackcdn.com/image/fetch/$s_!nTK2!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc70d601b-5d5b-4bb1-9f9c-685df65b3c87_994x324.png 1272w, /__u/substackcdn.com/image/fetch/$s_!nTK2!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc70d601b-5d5b-4bb1-9f9c-685df65b3c87_994x324.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><em>Deisenroth et al, &#8220;Mathematics for Machine Learning&#8221;, 2020, ch. 5.8</em></figcaption></figure></div><p>So, a tensor extends a matrix along a new axis. And, with every axis, the order of the tensor increments. Starting with a scalar (order 0), up to a matrix (order 2), and so on.</p><p>Since I&#8217;m learning the <a href="https://github.com/3b1b/manim">Manim</a> library at the moment, here&#8217;s an example of an order 3 tensor visualised as four stacked matrices:</p><div class="native-video-embed" data-component-name="VideoPlaceholder" data-attrs="{&quot;mediaUploadId&quot;:&quot;2fdee427-8473-40c0-b644-2c38566e9340&quot;,&quot;duration&quot;:null}"></div><h2>Tensor Contraction</h2><p>Tensor contraction is <a href="https://en.wikipedia.org/wiki/Tensor_contraction">described</a> as a generalisation of the trace of a matrix, and as an extension of matrix multiplication.</p><p>Along with the notation, this left me with more of a puzzled feeling than any initial intuition, which I decided to address with a practical walkthrough.</p><p>Starting with a reminder that the trace of a matrix is the sum of the matrix&#8217;s diagonal entries:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!yiY4!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F27b4fb1d-7690-4178-9de7-2cc3e5b230a6_1828x224.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!yiY4!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F27b4fb1d-7690-4178-9de7-2cc3e5b230a6_1828x224.png 424w, /__u/substackcdn.com/image/fetch/$s_!yiY4!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F27b4fb1d-7690-4178-9de7-2cc3e5b230a6_1828x224.png 848w, /__u/substackcdn.com/image/fetch/$s_!yiY4!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F27b4fb1d-7690-4178-9de7-2cc3e5b230a6_1828x224.png 1272w, /__u/substackcdn.com/image/fetch/$s_!yiY4!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F27b4fb1d-7690-4178-9de7-2cc3e5b230a6_1828x224.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!yiY4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F27b4fb1d-7690-4178-9de7-2cc3e5b230a6_1828x224.png" width="1456" height="178" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/27b4fb1d-7690-4178-9de7-2cc3e5b230a6_1828x224.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:178,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:22603,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/201951144?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F27b4fb1d-7690-4178-9de7-2cc3e5b230a6_1828x224.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!yiY4!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F27b4fb1d-7690-4178-9de7-2cc3e5b230a6_1828x224.png 424w, /__u/substackcdn.com/image/fetch/$s_!yiY4!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F27b4fb1d-7690-4178-9de7-2cc3e5b230a6_1828x224.png 848w, /__u/substackcdn.com/image/fetch/$s_!yiY4!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F27b4fb1d-7690-4178-9de7-2cc3e5b230a6_1828x224.png 1272w, /__u/substackcdn.com/image/fetch/$s_!yiY4!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F27b4fb1d-7690-4178-9de7-2cc3e5b230a6_1828x224.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>When we find the trace of a matrix, we reduce the matrix to a scalar.</p><div class="native-video-embed" data-component-name="VideoPlaceholder" data-attrs="{&quot;mediaUploadId&quot;:&quot;ed6a5fb7-579d-47f0-8f87-511eb02be958&quot;,&quot;duration&quot;:null}"></div><p>This is a reduction from order 2 to order 0, if we consider the matrix a tensor.</p><p>In simple index notation, the trace is:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!BjR7!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F67c0e36d-0937-455e-9e62-bf0d93bdcc46_1828x176.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!BjR7!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F67c0e36d-0937-455e-9e62-bf0d93bdcc46_1828x176.png 424w, /__u/substackcdn.com/image/fetch/$s_!BjR7!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F67c0e36d-0937-455e-9e62-bf0d93bdcc46_1828x176.png 848w, /__u/substackcdn.com/image/fetch/$s_!BjR7!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F67c0e36d-0937-455e-9e62-bf0d93bdcc46_1828x176.png 1272w, /__u/substackcdn.com/image/fetch/$s_!BjR7!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F67c0e36d-0937-455e-9e62-bf0d93bdcc46_1828x176.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!BjR7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F67c0e36d-0937-455e-9e62-bf0d93bdcc46_1828x176.png" width="1456" height="140" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/67c0e36d-0937-455e-9e62-bf0d93bdcc46_1828x176.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:140,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:13024,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/201951144?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F67c0e36d-0937-455e-9e62-bf0d93bdcc46_1828x176.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!BjR7!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F67c0e36d-0937-455e-9e62-bf0d93bdcc46_1828x176.png 424w, /__u/substackcdn.com/image/fetch/$s_!BjR7!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F67c0e36d-0937-455e-9e62-bf0d93bdcc46_1828x176.png 848w, /__u/substackcdn.com/image/fetch/$s_!BjR7!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F67c0e36d-0937-455e-9e62-bf0d93bdcc46_1828x176.png 1272w, /__u/substackcdn.com/image/fetch/$s_!BjR7!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F67c0e36d-0937-455e-9e62-bf0d93bdcc46_1828x176.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Now, to understand the connection between a matrix trace and tensor contraction, which Deisenroth also comments on briefly:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!a40M!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2497dc3f-6755-41c1-bb50-127ed23ffe39_1096x148.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!a40M!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2497dc3f-6755-41c1-bb50-127ed23ffe39_1096x148.png 424w, /__u/substackcdn.com/image/fetch/$s_!a40M!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2497dc3f-6755-41c1-bb50-127ed23ffe39_1096x148.png 848w, /__u/substackcdn.com/image/fetch/$s_!a40M!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2497dc3f-6755-41c1-bb50-127ed23ffe39_1096x148.png 1272w, /__u/substackcdn.com/image/fetch/$s_!a40M!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2497dc3f-6755-41c1-bb50-127ed23ffe39_1096x148.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!a40M!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2497dc3f-6755-41c1-bb50-127ed23ffe39_1096x148.png" width="728" height="98.30656934306569" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2497dc3f-6755-41c1-bb50-127ed23ffe39_1096x148.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:false,&quot;imageSize&quot;:&quot;normal&quot;,&quot;height&quot;:148,&quot;width&quot;:1096,&quot;resizeWidth&quot;:728,&quot;bytes&quot;:46903,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/201951144?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2497dc3f-6755-41c1-bb50-127ed23ffe39_1096x148.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:&quot;center&quot;,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!a40M!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2497dc3f-6755-41c1-bb50-127ed23ffe39_1096x148.png 424w, /__u/substackcdn.com/image/fetch/$s_!a40M!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2497dc3f-6755-41c1-bb50-127ed23ffe39_1096x148.png 848w, /__u/substackcdn.com/image/fetch/$s_!a40M!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2497dc3f-6755-41c1-bb50-127ed23ffe39_1096x148.png 1272w, /__u/substackcdn.com/image/fetch/$s_!a40M!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2497dc3f-6755-41c1-bb50-127ed23ffe39_1096x148.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption"><em>Deisenroth et al, &#8220;Mathematics for Machine Learning&#8221;, 2020, ch. 5.5</em></figcaption></figure></div><p>I appreciated, but did not immediately gain anything from, Deisenroth&#8217;s example, and so worked through my own example of the trace of a third-order tensor yielding a first-order tensor (i.e. a vector):</p><div class="native-video-embed" data-component-name="VideoPlaceholder" data-attrs="{&quot;mediaUploadId&quot;:&quot;6d438a77-09e1-4b46-accb-7acfab83140a&quot;,&quot;duration&quot;:null}"></div><p>In simple index notation, this trace is:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!iXMN!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe4ad7e1-9ee0-47bb-8d17-9e8dd9aae976_1814x160.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!iXMN!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe4ad7e1-9ee0-47bb-8d17-9e8dd9aae976_1814x160.png 424w, /__u/substackcdn.com/image/fetch/$s_!iXMN!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe4ad7e1-9ee0-47bb-8d17-9e8dd9aae976_1814x160.png 848w, /__u/substackcdn.com/image/fetch/$s_!iXMN!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe4ad7e1-9ee0-47bb-8d17-9e8dd9aae976_1814x160.png 1272w, /__u/substackcdn.com/image/fetch/$s_!iXMN!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe4ad7e1-9ee0-47bb-8d17-9e8dd9aae976_1814x160.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!iXMN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe4ad7e1-9ee0-47bb-8d17-9e8dd9aae976_1814x160.png" width="1456" height="128" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/fe4ad7e1-9ee0-47bb-8d17-9e8dd9aae976_1814x160.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:128,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:12827,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/201951144?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe4ad7e1-9ee0-47bb-8d17-9e8dd9aae976_1814x160.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!iXMN!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe4ad7e1-9ee0-47bb-8d17-9e8dd9aae976_1814x160.png 424w, /__u/substackcdn.com/image/fetch/$s_!iXMN!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe4ad7e1-9ee0-47bb-8d17-9e8dd9aae976_1814x160.png 848w, /__u/substackcdn.com/image/fetch/$s_!iXMN!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe4ad7e1-9ee0-47bb-8d17-9e8dd9aae976_1814x160.png 1272w, /__u/substackcdn.com/image/fetch/$s_!iXMN!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe4ad7e1-9ee0-47bb-8d17-9e8dd9aae976_1814x160.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Next, we consider matrix multiplication.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!Krnc!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd536df10-9c51-4dbe-b8f0-6d93e4f35589_474x49.svg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!Krnc!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd536df10-9c51-4dbe-b8f0-6d93e4f35589_474x49.svg 424w, /__u/substackcdn.com/image/fetch/$s_!Krnc!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd536df10-9c51-4dbe-b8f0-6d93e4f35589_474x49.svg 848w, /__u/substackcdn.com/image/fetch/$s_!Krnc!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd536df10-9c51-4dbe-b8f0-6d93e4f35589_474x49.svg 1272w, /__u/substackcdn.com/image/fetch/$s_!Krnc!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd536df10-9c51-4dbe-b8f0-6d93e4f35589_474x49.svg 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!Krnc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd536df10-9c51-4dbe-b8f0-6d93e4f35589_474x49.svg" width="1456" height="151" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d536df10-9c51-4dbe-b8f0-6d93e4f35589_474x49.svg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:151,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;{\\displaystyle {\\begin{bmatrix}1&amp;2\\\\3&amp;4\\end{bmatrix}}{\\begin{bmatrix}5&amp;6\\\\7&amp;8\\end{bmatrix}}={\\begin{bmatrix}1\\cdot 5+2\\cdot 7&amp;1\\cdot 6+2\\cdot 8\\\\3\\cdot 5+4\\cdot 7&amp;3\\cdot 6+4\\cdot 8\\\\\\end{bmatrix}}={\\begin{bmatrix}19&amp;22\\\\43&amp;50\\end{bmatrix}}}&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="{\displaystyle {\begin{bmatrix}1&amp;2\\3&amp;4\end{bmatrix}}{\begin{bmatrix}5&amp;6\\7&amp;8\end{bmatrix}}={\begin{bmatrix}1\cdot 5+2\cdot 7&amp;1\cdot 6+2\cdot 8\\3\cdot 5+4\cdot 7&amp;3\cdot 6+4\cdot 8\\\end{bmatrix}}={\begin{bmatrix}19&amp;22\\43&amp;50\end{bmatrix}}}" title="{\displaystyle {\begin{bmatrix}1&amp;2\\3&amp;4\end{bmatrix}}{\begin{bmatrix}5&amp;6\\7&amp;8\end{bmatrix}}={\begin{bmatrix}1\cdot 5+2\cdot 7&amp;1\cdot 6+2\cdot 8\\3\cdot 5+4\cdot 7&amp;3\cdot 6+4\cdot 8\\\end{bmatrix}}={\begin{bmatrix}19&amp;22\\43&amp;50\end{bmatrix}}}" srcset="/__u/substackcdn.com/image/fetch/$s_!Krnc!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd536df10-9c51-4dbe-b8f0-6d93e4f35589_474x49.svg 424w, /__u/substackcdn.com/image/fetch/$s_!Krnc!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd536df10-9c51-4dbe-b8f0-6d93e4f35589_474x49.svg 848w, /__u/substackcdn.com/image/fetch/$s_!Krnc!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd536df10-9c51-4dbe-b8f0-6d93e4f35589_474x49.svg 1272w, /__u/substackcdn.com/image/fetch/$s_!Krnc!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd536df10-9c51-4dbe-b8f0-6d93e4f35589_474x49.svg 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption"><em>Source: https://en.wikipedia.org/wiki/Tensor_contraction</em></figcaption></figure></div><p>If we write matrix multiplication in simple index notation, we have:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!yTzx!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55c4cb4f-dc4e-4233-99fa-53fb87fd0cc5_1812x228.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!yTzx!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55c4cb4f-dc4e-4233-99fa-53fb87fd0cc5_1812x228.png 424w, /__u/substackcdn.com/image/fetch/$s_!yTzx!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55c4cb4f-dc4e-4233-99fa-53fb87fd0cc5_1812x228.png 848w, /__u/substackcdn.com/image/fetch/$s_!yTzx!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55c4cb4f-dc4e-4233-99fa-53fb87fd0cc5_1812x228.png 1272w, /__u/substackcdn.com/image/fetch/$s_!yTzx!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55c4cb4f-dc4e-4233-99fa-53fb87fd0cc5_1812x228.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!yTzx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55c4cb4f-dc4e-4233-99fa-53fb87fd0cc5_1812x228.png" width="1456" height="183" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/55c4cb4f-dc4e-4233-99fa-53fb87fd0cc5_1812x228.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:183,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:18564,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/201951144?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55c4cb4f-dc4e-4233-99fa-53fb87fd0cc5_1812x228.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!yTzx!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55c4cb4f-dc4e-4233-99fa-53fb87fd0cc5_1812x228.png 424w, /__u/substackcdn.com/image/fetch/$s_!yTzx!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55c4cb4f-dc4e-4233-99fa-53fb87fd0cc5_1812x228.png 848w, /__u/substackcdn.com/image/fetch/$s_!yTzx!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55c4cb4f-dc4e-4233-99fa-53fb87fd0cc5_1812x228.png 1272w, /__u/substackcdn.com/image/fetch/$s_!yTzx!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55c4cb4f-dc4e-4233-99fa-53fb87fd0cc5_1812x228.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>To quote <a href="https://en.wikipedia.org/wiki/Tensor_contraction">Wikipedia</a>: &#8220;Notice how the index <em>j</em>, in between, disappears; this is the essence of tensor contraction.&#8221;</p><p>Here&#8217;s an example of the contraction of two third-order tensors, where we contract two index pairs so that the result is a second-order tensor (a matrix), for easier visualisation:</p><div class="native-video-embed" data-component-name="VideoPlaceholder" data-attrs="{&quot;mediaUploadId&quot;:&quot;e5f8b8d5-5fee-41bd-a1c7-ba1fe1152571&quot;,&quot;duration&quot;:null}"></div><p>In this example, indices <em>j</em> and <em>k</em> vanish.</p><p>So it seems that tensor contraction gives us a way to combine tensors without increasing the order each time (as an outer product would), to avoid rapidly-increasing computation cost.</p><p>Perhaps the discarded dimensions can also be those that don&#8217;t matter so much to the model, when using tensor contraction in a machine learning context.</p><p>Searching around for an example of tensor contraction being applied to a machine learning problem, I found <a href="https://ibug.doc.ic.ac.uk/media/uploads/documents/tensor_regression_networks.pdf">this paper</a>, which mentions &#8220;combin[ing] tensor regression with tensor contraction to further increase efficiency&#8221; of convolutional neural network output.</p><p>And that&#8217;s all for me this week. Daunting notation: clarified!</p><p>Next week, I&#8217;ll take a look at another tensor operation from the <a href="https://www.tensors.net/tutorial-1">tensors.net tutorial</a>, or perhaps at <a href="https://apxml.com/courses/getting-started-with-pytorch/chapter-2-advanced-tensor-manipulations/understanding-broadcasting">tensor broadcasting</a>.</p><div class="callout-block" data-callout="true"><h4>Resources and references:</h4><ul><li><p>Deisenroth et al, &#8220;Mathematics for Machine Learning&#8221;, 2020</p></li><li><p><a href="https://en.wikipedia.org/wiki/Tensor_contraction">https://en.wikipedia.org/wiki/Tensor_contraction</a> </p></li><li><p><a href="https://mathworld.wolfram.com/MatrixTrace.html">https://mathworld.wolfram.com/MatrixTrace.html</a></p></li><li><p><a href="https://www.tensors.net/tutorial-1">https://www.tensors.net/tutorial-1</a></p></li><li><p><a href="https://ibug.doc.ic.ac.uk/media/uploads/documents/tensor_regression_networks.pdf">https://ibug.doc.ic.ac.uk/media/uploads/documents/tensor_regression_networks.pdf</a></p></li></ul><p>I&#8217;m also following the <a href="https://mathacademy.com/courses/mathematics-for-machine-learning">Mathematics for Machine Learning</a> course on Math Academy.</p></div><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://petalbyte.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading (Surprisingly Simple) Machine Learning Mathematics! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Study with me: Set theory ML prerequisites]]></title><description><![CDATA[This week, I reviewed some set theory fundamentals in a machine learning context.]]></description><link>https://petalbyte.substack.com/p/study-with-me-set-theory-ml-prerequisites</link><guid isPermaLink="false">https://petalbyte.substack.com/p/study-with-me-set-theory-ml-prerequisites</guid><dc:creator><![CDATA[Louise B]]></dc:creator><pubDate>Sun, 07 Jun 2026 17:19:21 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/8c43c716-3f43-4ca5-b41b-ab5417674031_1200x630.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>We don&#8217;t need to know <em>too</em> much set theory for machine learning, and it&#8217;s been a busy week, so this topic felt like a good choice for me to review.</p><p>It&#8217;s also a satisfying topic to study, as organising objects into collections that have useful properties makes immediate sense to anyone who&#8217;s ever sorted out a clutter of items at home.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://petalbyte.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading (Surprisingly Simple) Machine Learning Mathematics! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p>Set theory is quite an early topic in mathematics, so I needed to refresh my memory and put the ideas into a machine learning context to suit my current learning path.</p><p>The following are a few examples, in case they can be useful to anyone else studying at a similar level (&#8220;thinking back to undergrad&#8221;).</p><h2>1. Cartesian product of sets</h2><p>If A and B are sets, the Cartesian product <strong>A</strong> &#215; <strong>B</strong> consists of all ordered pairs <em>(a, b)</em> where <em>a</em> is a member of <strong>A</strong> and <em>b</em> is a member of <strong>B</strong>.</p><p>Importantly, the sets <strong>A</strong> and <strong>B</strong> do not need to contain objects of the same type.</p><h3>Machine learning example</h3><p>In the same way that the Cartesian product &#8477; &#215; &#8477; gives us all coordinate points in two dimensional space, the Cartesian product of a dataset&#8217;s features can give the (probably quite high-dimensional) ambient space that the data points will be found in.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!qZUK!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97fcd8b0-8da7-4f9e-98a5-d19e7a8c0b0f_1502x720.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!qZUK!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97fcd8b0-8da7-4f9e-98a5-d19e7a8c0b0f_1502x720.png 424w, /__u/substackcdn.com/image/fetch/$s_!qZUK!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97fcd8b0-8da7-4f9e-98a5-d19e7a8c0b0f_1502x720.png 848w, /__u/substackcdn.com/image/fetch/$s_!qZUK!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97fcd8b0-8da7-4f9e-98a5-d19e7a8c0b0f_1502x720.png 1272w, /__u/substackcdn.com/image/fetch/$s_!qZUK!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97fcd8b0-8da7-4f9e-98a5-d19e7a8c0b0f_1502x720.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!qZUK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97fcd8b0-8da7-4f9e-98a5-d19e7a8c0b0f_1502x720.png" width="1456" height="698" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/97fcd8b0-8da7-4f9e-98a5-d19e7a8c0b0f_1502x720.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:698,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:33944,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/200981459?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97fcd8b0-8da7-4f9e-98a5-d19e7a8c0b0f_1502x720.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!qZUK!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97fcd8b0-8da7-4f9e-98a5-d19e7a8c0b0f_1502x720.png 424w, /__u/substackcdn.com/image/fetch/$s_!qZUK!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97fcd8b0-8da7-4f9e-98a5-d19e7a8c0b0f_1502x720.png 848w, /__u/substackcdn.com/image/fetch/$s_!qZUK!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97fcd8b0-8da7-4f9e-98a5-d19e7a8c0b0f_1502x720.png 1272w, /__u/substackcdn.com/image/fetch/$s_!qZUK!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97fcd8b0-8da7-4f9e-98a5-d19e7a8c0b0f_1502x720.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>We can then think geometrically about the distances between data points, and how densely they are clustered, as an indication of similarity.</p><p>For example, in the K-Nearest Neighbours algorithm, the distance metric might simply be the straight-line/Euclidean distance between two points.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!OlnE!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2650618d-80b0-48cc-8ec4-3d2fdc0a497c_1496x718.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!OlnE!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2650618d-80b0-48cc-8ec4-3d2fdc0a497c_1496x718.png 424w, /__u/substackcdn.com/image/fetch/$s_!OlnE!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2650618d-80b0-48cc-8ec4-3d2fdc0a497c_1496x718.png 848w, /__u/substackcdn.com/image/fetch/$s_!OlnE!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2650618d-80b0-48cc-8ec4-3d2fdc0a497c_1496x718.png 1272w, /__u/substackcdn.com/image/fetch/$s_!OlnE!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2650618d-80b0-48cc-8ec4-3d2fdc0a497c_1496x718.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!OlnE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2650618d-80b0-48cc-8ec4-3d2fdc0a497c_1496x718.png" width="1456" height="699" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2650618d-80b0-48cc-8ec4-3d2fdc0a497c_1496x718.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:699,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:37187,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/200981459?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2650618d-80b0-48cc-8ec4-3d2fdc0a497c_1496x718.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!OlnE!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2650618d-80b0-48cc-8ec4-3d2fdc0a497c_1496x718.png 424w, /__u/substackcdn.com/image/fetch/$s_!OlnE!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2650618d-80b0-48cc-8ec4-3d2fdc0a497c_1496x718.png 848w, /__u/substackcdn.com/image/fetch/$s_!OlnE!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2650618d-80b0-48cc-8ec4-3d2fdc0a497c_1496x718.png 1272w, /__u/substackcdn.com/image/fetch/$s_!OlnE!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2650618d-80b0-48cc-8ec4-3d2fdc0a497c_1496x718.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>And, if our dataset&#8217;s features are quite different (e.g. &#8220;age&#8221; might be any real number in the interval <em>[0,123]</em>, while &#8220;is subscribed&#8221; might be one element from the set <em>{0,1}</em>), then we&#8217;d have no trouble defining the feature space using the Cartesian product, as it is quite agnostic about the sets it operates on.</p><h2>2. Describing planar regions with set-builder notation</h2><p>Set-builder notation allows us to define a set by applying a rule or some conditions to a base set.</p><p>If our base set is all points in &#8477;&#178;, then our condition could restrict our set to only the points on one side of a line (or inside a circle).</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!tj0n!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e0b50c4-b8aa-4099-98e2-52d5faeaf789_1764x732.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!tj0n!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e0b50c4-b8aa-4099-98e2-52d5faeaf789_1764x732.png 424w, /__u/substackcdn.com/image/fetch/$s_!tj0n!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e0b50c4-b8aa-4099-98e2-52d5faeaf789_1764x732.png 848w, /__u/substackcdn.com/image/fetch/$s_!tj0n!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e0b50c4-b8aa-4099-98e2-52d5faeaf789_1764x732.png 1272w, /__u/substackcdn.com/image/fetch/$s_!tj0n!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e0b50c4-b8aa-4099-98e2-52d5faeaf789_1764x732.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!tj0n!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e0b50c4-b8aa-4099-98e2-52d5faeaf789_1764x732.png" width="1456" height="604" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7e0b50c4-b8aa-4099-98e2-52d5faeaf789_1764x732.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:604,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:75970,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/200981459?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e0b50c4-b8aa-4099-98e2-52d5faeaf789_1764x732.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!tj0n!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e0b50c4-b8aa-4099-98e2-52d5faeaf789_1764x732.png 424w, /__u/substackcdn.com/image/fetch/$s_!tj0n!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e0b50c4-b8aa-4099-98e2-52d5faeaf789_1764x732.png 848w, /__u/substackcdn.com/image/fetch/$s_!tj0n!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e0b50c4-b8aa-4099-98e2-52d5faeaf789_1764x732.png 1272w, /__u/substackcdn.com/image/fetch/$s_!tj0n!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e0b50c4-b8aa-4099-98e2-52d5faeaf789_1764x732.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h3>Machine learning example</h3><p>When classifying data with support vector machines, we&#8217;re looking for a linear separator between two classes.</p><p>As we&#8217;ll be working in a feature space with any number of dimensions, the boundary between the two classes will be a hyperplane.</p><p>We can define that hyperplane using set-builder notation as follows:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!5fBv!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d2b9a73-d63a-4212-b741-1980585d25b6_1852x292.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!5fBv!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d2b9a73-d63a-4212-b741-1980585d25b6_1852x292.png 424w, /__u/substackcdn.com/image/fetch/$s_!5fBv!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d2b9a73-d63a-4212-b741-1980585d25b6_1852x292.png 848w, /__u/substackcdn.com/image/fetch/$s_!5fBv!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d2b9a73-d63a-4212-b741-1980585d25b6_1852x292.png 1272w, /__u/substackcdn.com/image/fetch/$s_!5fBv!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d2b9a73-d63a-4212-b741-1980585d25b6_1852x292.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!5fBv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d2b9a73-d63a-4212-b741-1980585d25b6_1852x292.png" width="1456" height="230" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6d2b9a73-d63a-4212-b741-1980585d25b6_1852x292.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:230,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:113664,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/200981459?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d2b9a73-d63a-4212-b741-1980585d25b6_1852x292.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!5fBv!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d2b9a73-d63a-4212-b741-1980585d25b6_1852x292.png 424w, /__u/substackcdn.com/image/fetch/$s_!5fBv!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d2b9a73-d63a-4212-b741-1980585d25b6_1852x292.png 848w, /__u/substackcdn.com/image/fetch/$s_!5fBv!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d2b9a73-d63a-4212-b741-1980585d25b6_1852x292.png 1272w, /__u/substackcdn.com/image/fetch/$s_!5fBv!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d2b9a73-d63a-4212-b741-1980585d25b6_1852x292.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption"><em>Deisenroth et al, &#8220;Mathematics for Machine Learning&#8221;, 2020, ch. 12.1</em></figcaption></figure></div><p>&#8230;where<em> f(<strong>x</strong>) = &#10216;<strong>w</strong>, <strong>x</strong>&#10217; + b</em>.</p><h2>3. Indicator functions</h2><p>An indicator function maps values from a set to either 1 or 0, to &#8220;indicate&#8221; whether an element is a member of a subset.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!JNGD!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff05285c7-1c5a-4b02-9953-0c696c06b9db_1860x172.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!JNGD!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff05285c7-1c5a-4b02-9953-0c696c06b9db_1860x172.png 424w, /__u/substackcdn.com/image/fetch/$s_!JNGD!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff05285c7-1c5a-4b02-9953-0c696c06b9db_1860x172.png 848w, /__u/substackcdn.com/image/fetch/$s_!JNGD!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff05285c7-1c5a-4b02-9953-0c696c06b9db_1860x172.png 1272w, /__u/substackcdn.com/image/fetch/$s_!JNGD!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff05285c7-1c5a-4b02-9953-0c696c06b9db_1860x172.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!JNGD!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff05285c7-1c5a-4b02-9953-0c696c06b9db_1860x172.png" width="1456" height="135" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f05285c7-1c5a-4b02-9953-0c696c06b9db_1860x172.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:135,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:32949,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/200981459?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff05285c7-1c5a-4b02-9953-0c696c06b9db_1860x172.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!JNGD!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff05285c7-1c5a-4b02-9953-0c696c06b9db_1860x172.png 424w, /__u/substackcdn.com/image/fetch/$s_!JNGD!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff05285c7-1c5a-4b02-9953-0c696c06b9db_1860x172.png 848w, /__u/substackcdn.com/image/fetch/$s_!JNGD!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff05285c7-1c5a-4b02-9953-0c696c06b9db_1860x172.png 1272w, /__u/substackcdn.com/image/fetch/$s_!JNGD!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff05285c7-1c5a-4b02-9953-0c696c06b9db_1860x172.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><h3>Machine learning example</h3><p>This example comes from the foundational principles of machine learning in the first chapter of Vapnik&#8217;s book, &#8220;<em>The Nature of Statistical Learning</em>&#8221;.</p><p>Here, he presents the problem of risk minimisation, where we want to minimise the &#8220;risk functional&#8221;, i.e. the expected loss, to find the best approximation of an unknown probability distribution.</p><p>Vapnik lists three main approaches to defining the loss function, with one being pattern recognition, where he defines a loss function that is an indicator function:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!s2m6!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd74c823-782f-4c18-9c06-a250a4712f42_1852x268.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!s2m6!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd74c823-782f-4c18-9c06-a250a4712f42_1852x268.png 424w, /__u/substackcdn.com/image/fetch/$s_!s2m6!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd74c823-782f-4c18-9c06-a250a4712f42_1852x268.png 848w, /__u/substackcdn.com/image/fetch/$s_!s2m6!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd74c823-782f-4c18-9c06-a250a4712f42_1852x268.png 1272w, /__u/substackcdn.com/image/fetch/$s_!s2m6!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd74c823-782f-4c18-9c06-a250a4712f42_1852x268.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!s2m6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd74c823-782f-4c18-9c06-a250a4712f42_1852x268.png" width="1456" height="211" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/dd74c823-782f-4c18-9c06-a250a4712f42_1852x268.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:211,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:132544,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/200981459?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd74c823-782f-4c18-9c06-a250a4712f42_1852x268.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!s2m6!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd74c823-782f-4c18-9c06-a250a4712f42_1852x268.png 424w, /__u/substackcdn.com/image/fetch/$s_!s2m6!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd74c823-782f-4c18-9c06-a250a4712f42_1852x268.png 848w, /__u/substackcdn.com/image/fetch/$s_!s2m6!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd74c823-782f-4c18-9c06-a250a4712f42_1852x268.png 1272w, /__u/substackcdn.com/image/fetch/$s_!s2m6!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd74c823-782f-4c18-9c06-a250a4712f42_1852x268.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption"><em>Vapnik, &#8220;The Nature of Statistical Learning Theory&#8221;, 1995, ch. 1.3.1</em></figcaption></figure></div><p>In fact, here we have an indicator function being scored by another indicator function, just in case we thought such a simple idea might not be important.</p><div><hr></div><p>Although I didn&#8217;t get much time to study last week, putting some set theory fundamentals into a machine learning context was an enjoyable use of that time. 10/10, would recommend.</p><p>If you have a favourite idea in set theory, please do comment to share it.</p><div class="callout-block" data-callout="true"><h4>References and resources</h4><ul><li><p>Bishop, &#8220;Pattern Recognition and Machine Learning&#8221;, 2006</p></li><li><p>Deisenroth et al, &#8220;Mathematics for Machine Learning&#8221;, 2020</p></li><li><p>Vapnik, &#8220;The Nature of Statistical Learning Theory&#8221;, 1995</p></li></ul><p>I&#8217;m also following the <a href="https://mathacademy.com/courses/mathematics-for-machine-learning">Mathematics for Machine Learning</a> course on Math Academy.</p></div><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://petalbyte.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading (Surprisingly Simple) Machine Learning Mathematics! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Study with me: The L-BFGS optimisation algorithm]]></title><description><![CDATA[Faster and smarter gradient descent.]]></description><link>https://petalbyte.substack.com/p/study-with-me-the-l-bfgs-optimisation</link><guid isPermaLink="false">https://petalbyte.substack.com/p/study-with-me-the-l-bfgs-optimisation</guid><dc:creator><![CDATA[Louise B]]></dc:creator><pubDate>Sun, 31 May 2026 10:42:29 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/bd80a2b3-b678-4245-8e71-489c4c045cd7_1200x630.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>While I find structured learning to be far more efficient than a self-directed path that is essentially a <a href="https://en.wikipedia.org/wiki/Random_walk">random walk</a>, I do find that mathematics courses can expect you to wait a long time before you get to see <em>why</em> you had to learn something.</p><p>So, while I&#8217;m studying independently before resuming formal studies (currently following Math Academy&#8217;s <a href="https://mathacademy.com/courses/mathematics-for-machine-learning">Mathematics for Machine Learning</a> course, and planning to do an MSc. course in future), I&#8217;ve been taking some time each week to look at an ML technique that involves the maths I&#8217;m reviewing.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://petalbyte.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading (Surprisingly Simple) Machine Learning Mathematics! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p>For this reason, as I review certain probability distributions on Math Academy, I&#8217;ve <a href="/__u/petalbyte.substack.com/p/study-with-me-classifying-penguins">started to look at</a> binary logistic regression algorithms, where a model will generate classification label predictions that are samples from a Bernoulli distribution.</p><p>Here&#8217;s a simple flow diagram I made to see the steps in a logistic regression algorithm applied to an email spam classification scenario:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!1Nk1!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7a64811-f251-4a8f-a629-3ddb83bddc1f_1948x652.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!1Nk1!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7a64811-f251-4a8f-a629-3ddb83bddc1f_1948x652.png 424w, /__u/substackcdn.com/image/fetch/$s_!1Nk1!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7a64811-f251-4a8f-a629-3ddb83bddc1f_1948x652.png 848w, /__u/substackcdn.com/image/fetch/$s_!1Nk1!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7a64811-f251-4a8f-a629-3ddb83bddc1f_1948x652.png 1272w, /__u/substackcdn.com/image/fetch/$s_!1Nk1!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7a64811-f251-4a8f-a629-3ddb83bddc1f_1948x652.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!1Nk1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7a64811-f251-4a8f-a629-3ddb83bddc1f_1948x652.png" width="1456" height="487" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f7a64811-f251-4a8f-a629-3ddb83bddc1f_1948x652.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:487,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:157435,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/199960985?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7a64811-f251-4a8f-a629-3ddb83bddc1f_1948x652.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!1Nk1!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7a64811-f251-4a8f-a629-3ddb83bddc1f_1948x652.png 424w, /__u/substackcdn.com/image/fetch/$s_!1Nk1!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7a64811-f251-4a8f-a629-3ddb83bddc1f_1948x652.png 848w, /__u/substackcdn.com/image/fetch/$s_!1Nk1!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7a64811-f251-4a8f-a629-3ddb83bddc1f_1948x652.png 1272w, /__u/substackcdn.com/image/fetch/$s_!1Nk1!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7a64811-f251-4a8f-a629-3ddb83bddc1f_1948x652.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Along the way, I discovered that the &#8216;classic&#8217; gradient descent formula I&#8217;d seen in many places (<a href="https://www.khanacademy.org/math/multivariable-calculus/applications-of-multivariable-derivatives/optimizing-multivariable-functions/a/what-is-gradient-descent">example</a>) is not the default optimiser in scikit-learn&#8217;s <a href="https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html">LogisticRegression class</a>. (The optimiser is specified by the `solver` parameter.)</p><p>In fact, the default solver used by that class is an algorithm called L-BFGS.</p><p>Once I&#8217;d recovered from my surprise that we wouldn&#8217;t simply calculate <em>x_{n+1} = x_n - &#945;&#8711;f(x_n)</em> until we&#8217;d arrived at the minimum point of the loss function, I wondered what else could happen, and what kind of mathematics would be involved.</p><p>A quick aside: The L-BFGS algorithm is a clever application of many good ideas, so I recommend the resources listed at the end of this post for anyone who&#8217;d like to dig into the details.</p><p>As someone who&#8217;s still working on their statistics and ML fundamentals, my only goal here is to begin to appreciate why L-BFGS is a commonly-used optimisation algorithm.</p><p>One thing to clarify early on: The &#8220;L&#8221; part of L-BFGS refers to it being a <a href="https://en.wikipedia.org/wiki/Limited-memory_BFGS)">&#8220;limited-memory&#8221; approximation of the BFGS algorithm</a>.</p><p>However, both algorithms &#8220;use an estimate of the inverse Hessian matrix to steer [their] search through variable space&#8221; towards the minimum point of the loss function, and I&#8217;ll be looking at this shared behaviour here.</p><p>To understand what the Hessian matrix is, and why its inverse can make gradient descent more efficient, we can recall some mathematics learned at school.</p><p>Specifically, we might remember that the Taylor expansion of a function can include a term containing the second derivative:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!hvKm!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feda28bc9-24a0-4621-821b-76705d5a4121_1946x156.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!hvKm!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feda28bc9-24a0-4621-821b-76705d5a4121_1946x156.png 424w, /__u/substackcdn.com/image/fetch/$s_!hvKm!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feda28bc9-24a0-4621-821b-76705d5a4121_1946x156.png 848w, /__u/substackcdn.com/image/fetch/$s_!hvKm!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feda28bc9-24a0-4621-821b-76705d5a4121_1946x156.png 1272w, /__u/substackcdn.com/image/fetch/$s_!hvKm!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feda28bc9-24a0-4621-821b-76705d5a4121_1946x156.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!hvKm!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feda28bc9-24a0-4621-821b-76705d5a4121_1946x156.png" width="1456" height="117" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/eda28bc9-24a0-4621-821b-76705d5a4121_1946x156.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:117,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:52845,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/199960985?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feda28bc9-24a0-4621-821b-76705d5a4121_1946x156.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!hvKm!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feda28bc9-24a0-4621-821b-76705d5a4121_1946x156.png 424w, /__u/substackcdn.com/image/fetch/$s_!hvKm!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feda28bc9-24a0-4621-821b-76705d5a4121_1946x156.png 848w, /__u/substackcdn.com/image/fetch/$s_!hvKm!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feda28bc9-24a0-4621-821b-76705d5a4121_1946x156.png 1272w, /__u/substackcdn.com/image/fetch/$s_!hvKm!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feda28bc9-24a0-4621-821b-76705d5a4121_1946x156.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>When we include this term, we discover a quadratic curve that fits the function at that point:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!5-k6!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3beff532-66c5-467a-ba16-1b6c775f14cb_1948x1016.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!5-k6!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3beff532-66c5-467a-ba16-1b6c775f14cb_1948x1016.png 424w, /__u/substackcdn.com/image/fetch/$s_!5-k6!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3beff532-66c5-467a-ba16-1b6c775f14cb_1948x1016.png 848w, /__u/substackcdn.com/image/fetch/$s_!5-k6!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3beff532-66c5-467a-ba16-1b6c775f14cb_1948x1016.png 1272w, /__u/substackcdn.com/image/fetch/$s_!5-k6!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3beff532-66c5-467a-ba16-1b6c775f14cb_1948x1016.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!5-k6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3beff532-66c5-467a-ba16-1b6c775f14cb_1948x1016.png" width="1456" height="759" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3beff532-66c5-467a-ba16-1b6c775f14cb_1948x1016.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:759,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:232383,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/199960985?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3beff532-66c5-467a-ba16-1b6c775f14cb_1948x1016.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!5-k6!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3beff532-66c5-467a-ba16-1b6c775f14cb_1948x1016.png 424w, /__u/substackcdn.com/image/fetch/$s_!5-k6!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3beff532-66c5-467a-ba16-1b6c775f14cb_1948x1016.png 848w, /__u/substackcdn.com/image/fetch/$s_!5-k6!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3beff532-66c5-467a-ba16-1b6c775f14cb_1948x1016.png 1272w, /__u/substackcdn.com/image/fetch/$s_!5-k6!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3beff532-66c5-467a-ba16-1b6c775f14cb_1948x1016.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>And a good step to take towards the minimum of the function that we&#8217;re approximating is the step that takes us to the minimum of that quadratic:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!Xvmh!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e684851-3b7d-4870-b994-e5f84ffa162e_1948x1018.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!Xvmh!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e684851-3b7d-4870-b994-e5f84ffa162e_1948x1018.png 424w, /__u/substackcdn.com/image/fetch/$s_!Xvmh!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e684851-3b7d-4870-b994-e5f84ffa162e_1948x1018.png 848w, /__u/substackcdn.com/image/fetch/$s_!Xvmh!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e684851-3b7d-4870-b994-e5f84ffa162e_1948x1018.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Xvmh!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e684851-3b7d-4870-b994-e5f84ffa162e_1948x1018.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!Xvmh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e684851-3b7d-4870-b994-e5f84ffa162e_1948x1018.png" width="1456" height="761" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2e684851-3b7d-4870-b994-e5f84ffa162e_1948x1018.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:761,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:236722,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/199960985?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e684851-3b7d-4870-b994-e5f84ffa162e_1948x1018.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!Xvmh!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e684851-3b7d-4870-b994-e5f84ffa162e_1948x1018.png 424w, /__u/substackcdn.com/image/fetch/$s_!Xvmh!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e684851-3b7d-4870-b994-e5f84ffa162e_1948x1018.png 848w, /__u/substackcdn.com/image/fetch/$s_!Xvmh!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e684851-3b7d-4870-b994-e5f84ffa162e_1948x1018.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Xvmh!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e684851-3b7d-4870-b994-e5f84ffa162e_1948x1018.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>If we were working with one-dimensional data, we could find the minimum of that quadratic from the function&#8217;s second derivative.</p><p><a href="https://en.wikipedia.org/wiki/Newton%27s_method_in_optimization">Newton&#8217;s method for optimisation</a> does this, first by reworking the Taylor series slightly to more easily use it iteratively:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!-AVJ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3aade37-972b-4731-a94c-8b7e64c7164e_1948x260.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!-AVJ!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3aade37-972b-4731-a94c-8b7e64c7164e_1948x260.png 424w, /__u/substackcdn.com/image/fetch/$s_!-AVJ!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3aade37-972b-4731-a94c-8b7e64c7164e_1948x260.png 848w, /__u/substackcdn.com/image/fetch/$s_!-AVJ!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3aade37-972b-4731-a94c-8b7e64c7164e_1948x260.png 1272w, /__u/substackcdn.com/image/fetch/$s_!-AVJ!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3aade37-972b-4731-a94c-8b7e64c7164e_1948x260.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!-AVJ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3aade37-972b-4731-a94c-8b7e64c7164e_1948x260.png" width="1456" height="194" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f3aade37-972b-4731-a94c-8b7e64c7164e_1948x260.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:194,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:58598,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/199960985?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3aade37-972b-4731-a94c-8b7e64c7164e_1948x260.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!-AVJ!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3aade37-972b-4731-a94c-8b7e64c7164e_1948x260.png 424w, /__u/substackcdn.com/image/fetch/$s_!-AVJ!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3aade37-972b-4731-a94c-8b7e64c7164e_1948x260.png 848w, /__u/substackcdn.com/image/fetch/$s_!-AVJ!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3aade37-972b-4731-a94c-8b7e64c7164e_1948x260.png 1272w, /__u/substackcdn.com/image/fetch/$s_!-AVJ!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3aade37-972b-4731-a94c-8b7e64c7164e_1948x260.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>And then by setting that quadratic approximation equal to zero, to obtain its minimum:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!3hGl!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b738b49-9abf-4032-b413-795239d17e92_1946x518.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!3hGl!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b738b49-9abf-4032-b413-795239d17e92_1946x518.png 424w, /__u/substackcdn.com/image/fetch/$s_!3hGl!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b738b49-9abf-4032-b413-795239d17e92_1946x518.png 848w, /__u/substackcdn.com/image/fetch/$s_!3hGl!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b738b49-9abf-4032-b413-795239d17e92_1946x518.png 1272w, /__u/substackcdn.com/image/fetch/$s_!3hGl!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b738b49-9abf-4032-b413-795239d17e92_1946x518.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!3hGl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b738b49-9abf-4032-b413-795239d17e92_1946x518.png" width="1456" height="388" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5b738b49-9abf-4032-b413-795239d17e92_1946x518.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:388,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:91391,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/199960985?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b738b49-9abf-4032-b413-795239d17e92_1946x518.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!3hGl!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b738b49-9abf-4032-b413-795239d17e92_1946x518.png 424w, /__u/substackcdn.com/image/fetch/$s_!3hGl!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b738b49-9abf-4032-b413-795239d17e92_1946x518.png 848w, /__u/substackcdn.com/image/fetch/$s_!3hGl!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b738b49-9abf-4032-b413-795239d17e92_1946x518.png 1272w, /__u/substackcdn.com/image/fetch/$s_!3hGl!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b738b49-9abf-4032-b413-795239d17e92_1946x518.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>This gives us additional information to use when choosing step sizes during our gradient descent process, essentially suggesting that we step towards the minimum point of the quadratic that we were looking at in the graphs above.</p><p>This is more sophisticated than &#8216;classic&#8217; gradient descent, and can help make it more efficient.</p><p>Of course, in higher dimensions, things are a little less simple, as we need second-order partial derivatives to obtain this kind of information about the optimal descent direction.</p><p>And this is where we look to the Hessian matrix: <a href="https://en.wikipedia.org/wiki/Hessian_matrix">a square matrix of second-order partial derivatives of a scalar-valued function</a>.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!4q9z!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f83bd7a-ff04-4980-abe2-1857817820d0_1946x588.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!4q9z!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f83bd7a-ff04-4980-abe2-1857817820d0_1946x588.png 424w, /__u/substackcdn.com/image/fetch/$s_!4q9z!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f83bd7a-ff04-4980-abe2-1857817820d0_1946x588.png 848w, /__u/substackcdn.com/image/fetch/$s_!4q9z!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f83bd7a-ff04-4980-abe2-1857817820d0_1946x588.png 1272w, /__u/substackcdn.com/image/fetch/$s_!4q9z!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f83bd7a-ff04-4980-abe2-1857817820d0_1946x588.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!4q9z!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f83bd7a-ff04-4980-abe2-1857817820d0_1946x588.png" width="1456" height="440" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4f83bd7a-ff04-4980-abe2-1857817820d0_1946x588.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:440,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:99854,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/199960985?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f83bd7a-ff04-4980-abe2-1857817820d0_1946x588.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!4q9z!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f83bd7a-ff04-4980-abe2-1857817820d0_1946x588.png 424w, /__u/substackcdn.com/image/fetch/$s_!4q9z!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f83bd7a-ff04-4980-abe2-1857817820d0_1946x588.png 848w, /__u/substackcdn.com/image/fetch/$s_!4q9z!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f83bd7a-ff04-4980-abe2-1857817820d0_1946x588.png 1272w, /__u/substackcdn.com/image/fetch/$s_!4q9z!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f83bd7a-ff04-4980-abe2-1857817820d0_1946x588.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><em>From: <a href="https://en.wikipedia.org/wiki/Hessian_matrix#Use_in_optimization">https://en.wikipedia.org/wiki/Hessian_matrix#Use_in_optimization</a></em></figcaption></figure></div><p>In fact, to step to the minimum of the quadratic, we take a step that is proportional to the inverse Hessian times the gradient:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!wL8w!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0536023-f04e-4b54-ae6e-545d881ebc3f_1664x446.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!wL8w!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0536023-f04e-4b54-ae6e-545d881ebc3f_1664x446.png 424w, /__u/substackcdn.com/image/fetch/$s_!wL8w!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0536023-f04e-4b54-ae6e-545d881ebc3f_1664x446.png 848w, /__u/substackcdn.com/image/fetch/$s_!wL8w!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0536023-f04e-4b54-ae6e-545d881ebc3f_1664x446.png 1272w, /__u/substackcdn.com/image/fetch/$s_!wL8w!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0536023-f04e-4b54-ae6e-545d881ebc3f_1664x446.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!wL8w!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0536023-f04e-4b54-ae6e-545d881ebc3f_1664x446.png" width="1456" height="390" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b0536023-f04e-4b54-ae6e-545d881ebc3f_1664x446.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:390,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:82226,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/199960985?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0536023-f04e-4b54-ae6e-545d881ebc3f_1664x446.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!wL8w!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0536023-f04e-4b54-ae6e-545d881ebc3f_1664x446.png 424w, /__u/substackcdn.com/image/fetch/$s_!wL8w!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0536023-f04e-4b54-ae6e-545d881ebc3f_1664x446.png 848w, /__u/substackcdn.com/image/fetch/$s_!wL8w!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0536023-f04e-4b54-ae6e-545d881ebc3f_1664x446.png 1272w, /__u/substackcdn.com/image/fetch/$s_!wL8w!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0536023-f04e-4b54-ae6e-545d881ebc3f_1664x446.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><em>From: <a href="https://optimlib.readthedocs.io/en/latest/api/bfgs.html">https://optimlib.readthedocs.io/en/latest/api/bfgs.html</a></em></figcaption></figure></div><p>As indicated in the above screenshot, the BFGS algorithm <a href="https://en.wikipedia.org/wiki/Hessian_matrix#Use_in_optimization">actually approximates the Hessian</a>, because it can be expensive to compute and store the full Hessian matrix.</p><p>And, for even more efficiency, the L-BFGS algorithm <a href="https://en.wikipedia.org/wiki/Limited-memory_BFGS">stores some information about its previous Hessian approximations</a>, to remove the need for recalculation of the inverse Hessian at each step.</p><p>Note that L-BFGS has limitations, too. I found that scikit-learn&#8217;s <a href="https://scikit-learn.org/stable/modules/linear_model.html#differences-between-solvers">logistic regression guide</a> helpfully summarises some practical details. For example, the type(s) of regularisation that each solver supports, and the datasets that a solver might be more or less compatible with.</p><p>But for now, this quick look at some of the foundational mathematics underlying the BFGS algorithm achieves my goal for this week, so I&#8217;ll wrap up here.</p><p>I&#8217;ll be reviewing second-degree Taylor polynomials of multivariable functions in the Math Academy course soon, and I won&#8217;t need to wonder why we&#8217;re looking at matrices of second-order partial derivatives!</p><div class="callout-block" data-callout="true"><h4>Resources used for this post:</h4><ul><li><p><a href="https://scikit-learn.org/stable/modules/linear_model.html#differences-between-solvers">scikit-learn&#8217;s User Guide page</a> about the differences between solvers, specifically the &#8220;Solver&#8217;s details&#8221; dropdown</p></li><li><p><a href="https://en.wikipedia.org/wiki/Newton%27s_method_in_optimization">https://en.wikipedia.org/wiki/Newton%27s_method_in_optimization</a> </p></li><li><p><a href="https://en.wikipedia.org/wiki/Hessian_matrix#Use_in_optimization">https://en.wikipedia.org/wiki/Hessian_matrix#Use_in_optimization</a></p></li><li><p><a href="https://en.wikipedia.org/wiki/Broyden%E2%80%93Fletcher%E2%80%93Goldfarb%E2%80%93Shanno_algorithm">https://en.wikipedia.org/wiki/Broyden%E2%80%93Fletcher%E2%80%93Goldfarb%E2%80%93Shanno_algorithm</a></p></li><li><p><a href="https://en.wikipedia.org/wiki/Limited-memory_BFGS">https://en.wikipedia.org/wiki/Limited-memory_BFGS</a></p></li><li><p><a href="https://optimlib.readthedocs.io/en/latest/api/bfgs.html">https://optimlib.readthedocs.io/en/latest/api/bfgs.html</a></p></li><li><p>MIT Open CourseWare <a href="https://ocw.mit.edu/courses/18-335j-introduction-to-numerical-methods-spring-2019/pages/week-11/">Numerical Methods</a> lecture notes</p></li><li><p>Purdue <a href="https://www.cs.purdue.edu/homes/jhonorio/16spring-cs52000-quasinewton.pdf">lecture notes</a>, particularly the pseudocode algorithm on the last slide</p></li></ul></div><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://petalbyte.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading (Surprisingly Simple) Machine Learning Mathematics! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Three things I want to understand better in machine learning]]></title><description><![CDATA[And how I plan to learn more about them.]]></description><link>https://petalbyte.substack.com/p/three-things-i-want-to-understand</link><guid isPermaLink="false">https://petalbyte.substack.com/p/three-things-i-want-to-understand</guid><dc:creator><![CDATA[Louise B]]></dc:creator><pubDate>Sat, 23 May 2026 10:57:52 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/a8518636-1543-4129-8b30-679ca3c045d8_1200x630.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>After last week&#8217;s post on <a href="/__u/petalbyte.substack.com/p/study-with-me-classifying-penguins">logistic regression with the maximum likelihood estimator</a>, I ran into several things that I want to dedicate more time to.</p><p>Specifically: the L-BFGS optimisation algorithm, regularisation, and how to tell whether a model is overfitting or generalising well.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://petalbyte.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading (Surprisingly Simple) Machine Learning Mathematics! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p>Given my learning style, I will need to find the simplest possible explanations and connect them to the level of mathematics that I&#8217;m comfortable with.</p><p>So I&#8217;ll be reading up on these topics (and writing some simplified explanations to share) over the next few weeks. And here&#8217;s my plan.</p><h2>The L-BFGS Optimisation Algorithm</h2><p>In scikit-learn&#8217;s LogisticRegression class <a href="https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html">documentation</a>, I saw the <em>solver</em> option for choosing the algorithm used in the optimisation problem.</p><p>The default solver option is L-BFGS, because &#8220;it works reasonably well for a wide class of problems&#8221;.</p><p>I assume this refers to a balance between efficiency and accuracy. But I&#8217;d like to look at some of the details here and, if possible, find a bit of mathematics I can understand at my level.</p><p><strong>Planned starting point:</strong></p><p><a href="https://scikit-learn.org/stable/modules/linear_model.html#differences-between-solvers">scikit-learn&#8217;s User Guide page</a> about the differences between solvers, specifically the &#8220;Solver&#8217;s details&#8221; dropdown, which looks full of interesting details.</p><p>I also see some MIT Open CourseWare <a href="https://ocw.mit.edu/courses/18-335j-introduction-to-numerical-methods-spring-2019/pages/week-11/">Numerical Methods</a> lecture notes that cover the BFGS algorithm, and some Purdue <a href="https://www.cs.purdue.edu/homes/jhonorio/16spring-cs52000-quasinewton.pdf">lecture notes</a> that look quite friendly.</p><h2>Regularisation</h2><p>While reading the scikit-learn documentation pages referenced above, I also ran into the term &#8220;regularisation&#8221; many times.</p><p>I only understand this as some way of avoiding overfitting, at present.</p><p>Although regularisation is critical in machine learning, it&#8217;s a more broadly-applicable idea across statistics, finance and computer science.</p><p>So I&#8217;ll try to find simple examples from these other fields, to avoid overfitting my own understanding.</p><p><strong>Planned starting point:</strong></p><p>A closer look at the <a href="https://en.wikipedia.org/wiki/Regularization_(mathematics)">overview on Wikipedia</a>, and at the visualisation in scikit-learn&#8217;s <a href="https://scikit-learn.org/stable/auto_examples/linear_model/plot_logistic_path.html#sphx-glr-auto-examples-linear-model-plot-logistic-path-py">Regularization path of L1- Logistic Regression</a>.</p><p>Also, the textbook that I&#8217;m probably a little too attached to at this point, Deisenroth&#8217;s &#8220;Mathematics for Machine Learning&#8221;, has section 8.2.3, &#8220;<em>Regularization to Reduce Overfitting</em>&#8221;. </p><h2>Detecting and preventing overfitting</h2><p>The previous topic leads me here, to spend some time understanding where regularisation fits into the bigger picture.</p><p>What are other ways to avoid overfitting (people seem keen on cross-validation)? What formulas and notation are used to describe problems and solutions here? What happens with more complicated models, like artificial neural networks?</p><p><strong>Planned starting point:</strong></p><p>As well as Deisenroth&#8217;s textbook, Google&#8217;s Machine Learning Crash Course has <a href="https://developers.google.com/machine-learning/crash-course/overfitting/generalization">an overview</a> that looks straightforward.</p><p>I also have the &#8220;Introduction to Statistical Learning&#8221; textbook (James et al) that discusses overfitting throughout, and in particular in section 2.2 (&#8220;<em>Assessing Model Accuracy</em>&#8221;).</p><p>And Bishop&#8217;s &#8220;Pattern Recognition and Machine Learning&#8221; has section 5.5, &#8220;<em>Regularization in Neural Networks</em>&#8221;, where I&#8217;ll probably just see if the introduction has any simple-ish takeaways.</p><div><hr></div><p>Well, it looks like I&#8217;ve planned out the next 6-8 weeks of my available study time, if not more! But it&#8217;s such a luxury, in my opinion, to study by following your curiosity.</p><p>(Although I always follow a structured course at the same time, because guidance is important, too. Currently: The &#8220;Mathematics for Machine Learning&#8221; course on Math Academy.)</p><p>If you have any beloved resources that you&#8217;d recommend for any of the topics listed above, please feel free to comment to share them.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://petalbyte.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading (Surprisingly Simple) Machine Learning Mathematics! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Study with me: Classifying penguins with the maximum likelihood estimator]]></title><description><![CDATA[After learning about the MLE last week, I want to understand what happens when it's used in practice.]]></description><link>https://petalbyte.substack.com/p/study-with-me-classifying-penguins</link><guid isPermaLink="false">https://petalbyte.substack.com/p/study-with-me-classifying-penguins</guid><dc:creator><![CDATA[Louise B]]></dc:creator><pubDate>Sat, 16 May 2026 19:08:08 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/a2e8a6cf-c7c4-4834-9aff-5d060e26fdc1_1200x630.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Since spending time deciphering the maximum likelihood estimator (MLE) notation <a href="/__u/petalbyte.substack.com/p/deciphering-notation-the-maximum">last week</a>, I&#8217;ve been curious to see how it might be used in a machine learning context.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!gohn!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F002f5929-cba3-4d3a-a66d-11b71e0abfb8_1820x208.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!gohn!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F002f5929-cba3-4d3a-a66d-11b71e0abfb8_1820x208.png 424w, /__u/substackcdn.com/image/fetch/$s_!gohn!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F002f5929-cba3-4d3a-a66d-11b71e0abfb8_1820x208.png 848w, /__u/substackcdn.com/image/fetch/$s_!gohn!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F002f5929-cba3-4d3a-a66d-11b71e0abfb8_1820x208.png 1272w, /__u/substackcdn.com/image/fetch/$s_!gohn!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F002f5929-cba3-4d3a-a66d-11b71e0abfb8_1820x208.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!gohn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F002f5929-cba3-4d3a-a66d-11b71e0abfb8_1820x208.png" width="1456" height="166" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/002f5929-cba3-4d3a-a66d-11b71e0abfb8_1820x208.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:166,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:25428,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/197978691?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F002f5929-cba3-4d3a-a66d-11b71e0abfb8_1820x208.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!gohn!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F002f5929-cba3-4d3a-a66d-11b71e0abfb8_1820x208.png 424w, /__u/substackcdn.com/image/fetch/$s_!gohn!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F002f5929-cba3-4d3a-a66d-11b71e0abfb8_1820x208.png 848w, /__u/substackcdn.com/image/fetch/$s_!gohn!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F002f5929-cba3-4d3a-a66d-11b71e0abfb8_1820x208.png 1272w, /__u/substackcdn.com/image/fetch/$s_!gohn!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F002f5929-cba3-4d3a-a66d-11b71e0abfb8_1820x208.png 1456w" sizes="100vw" fetchpriority="high"></picture><div></div></div></a><figcaption class="image-caption"><em>The MLE was very rewarding to pick apart</em></figcaption></figure></div><p>This isn&#8217;t entirely straightforward because, of course, machine learning models aren&#8217;t built by simply choosing the equations you feel like using (unless you&#8217;re at a level of expertise that makes model development feel this way, perhaps).</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://petalbyte.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading (Surprisingly Simple) Machine Learning Mathematics! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p>And I feared that LLM sycophancy would cause wasted time, as I find them to be a little &#8220;garbage in, [beautiful] garbage out&#8221; when given an unwise prompt.</p><p>So I started with a naive web search for human-written ideas, and was lucky to find something relevant immediately.</p><p>In <a href="https://stats.stackexchange.com/questions/267393/do-we-ever-use-maximum-likelihood-estimation/267463#267463">this thread</a> on stats.stackexchange.com, someone asks, &#8220;<em>Do we ever use maximum likelihood estimation?&#8221;</em>. And I sympathise with them, honestly. Sometimes we are taught things in such isolation that we learn without understanding.</p><p>The responses in that thread quite kindly and patiently explain that, yes, the MLE is used frequently.</p><p>I found <a href="https://stats.stackexchange.com/a/267458">this response</a> to be a particularly useful signpost:</p><blockquote><p><em>A very typical case is in logistic regression. Logistic regression is a technique used often in machine learning to classify data points. For example, logistic regression can be used to classify whether an email is spam or is not spam or classify whether a person has or does not have a disease.</em></p></blockquote><p>(I&#8217;d also call out <a href="https://stats.stackexchange.com/a/267463">this response</a> for including many helpful links, plus a mention of regularisation, which is something we&#8217;ll stumble into again later.)</p><p>As much as I enjoy taking advice from random discussion threads, I should mention that I also had Bishop&#8217;s &#8220;Pattern Recognition and Machine Learning&#8221; textbook open to section 4.3.2, where we see:</p><blockquote><p><em>We now use maximum likelihood to determine the parameters of the logistic regression model.</em></p></blockquote><p>So, feeling confident that this wasn&#8217;t an entirely nonsense mission, I chose logistic regression to pair with MLE and began my journey of discovering what this might actually look like.</p><p>(Note that this topic only occupies 1.5 pages in Bishop&#8217;s book, vs. several hours of my lifetime, but that is typical.)</p><h2>Finding a data set</h2><p>There&#8217;s a repository called <a href="https://github.com/awesomedata/awesome-public-datasets">awesome-data-sets</a>, which I found overwhelming (although a wonderful resource), so I also prompted Claude for a recommendation.</p><p>We settled on the <a href="https://allisonhorst.github.io/palmerpenguins/">palmerpenguins</a> dataset or, specifically, the <code>penguins</code> dataset provided by this package, which is a simplified version of the raw dataset that it also contains.</p><p>Taking a quick look at the penguin data:</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;python&quot;,&quot;nodeId&quot;:null}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-python"># First five rows:
  species     island  bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g     sex  year
0  Adelie  Torgersen            39.1           18.7              181.0       3750.0    male  2007
1  Adelie  Torgersen            39.5           17.4              186.0       3800.0  female  2007
2  Adelie  Torgersen            40.3           18.0              195.0       3250.0  female  2007
3  Adelie  Torgersen             NaN            NaN                NaN          NaN     NaN  2007
4  Adelie  Torgersen            36.7           19.3              193.0       3450.0  female  2007

# Dataset shape:
(344, 8)

# Columns:
['species', 'island', 'bill_length_mm', 'bill_depth_mm', 'flipper_length_mm', 'body_mass_g', 'sex', 'year']</code></pre></div><p>To make it easier to visualise/plot later, I chose to create a model that will classify penguins into one of two species (Adelie or Gentoo), using just one feature: bill length.</p><p>Since I chose logistic regression as my model class, the probability of a penguin being an Adelie is represented as:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!U9uO!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9075b25d-6d8f-458b-af9f-147d1f6ea9b6_1820x340.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!U9uO!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9075b25d-6d8f-458b-af9f-147d1f6ea9b6_1820x340.png 424w, /__u/substackcdn.com/image/fetch/$s_!U9uO!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9075b25d-6d8f-458b-af9f-147d1f6ea9b6_1820x340.png 848w, /__u/substackcdn.com/image/fetch/$s_!U9uO!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9075b25d-6d8f-458b-af9f-147d1f6ea9b6_1820x340.png 1272w, /__u/substackcdn.com/image/fetch/$s_!U9uO!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9075b25d-6d8f-458b-af9f-147d1f6ea9b6_1820x340.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!U9uO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9075b25d-6d8f-458b-af9f-147d1f6ea9b6_1820x340.png" width="1456" height="272" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9075b25d-6d8f-458b-af9f-147d1f6ea9b6_1820x340.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:272,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:36818,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/197978691?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9075b25d-6d8f-458b-af9f-147d1f6ea9b6_1820x340.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!U9uO!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9075b25d-6d8f-458b-af9f-147d1f6ea9b6_1820x340.png 424w, /__u/substackcdn.com/image/fetch/$s_!U9uO!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9075b25d-6d8f-458b-af9f-147d1f6ea9b6_1820x340.png 848w, /__u/substackcdn.com/image/fetch/$s_!U9uO!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9075b25d-6d8f-458b-af9f-147d1f6ea9b6_1820x340.png 1272w, /__u/substackcdn.com/image/fetch/$s_!U9uO!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9075b25d-6d8f-458b-af9f-147d1f6ea9b6_1820x340.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Here, <em>w</em> and <em>b<strong> </strong></em>represent the unknown parameters the model needs to pick the best values for. And <em>&#963;</em>, the sigmoid function, makes sure we have values between 0 and 1 for our probabilities.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!Bdpf!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65f27123-e320-4900-a7f7-5966de07a014_250x167.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!Bdpf!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65f27123-e320-4900-a7f7-5966de07a014_250x167.png 424w, /__u/substackcdn.com/image/fetch/$s_!Bdpf!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65f27123-e320-4900-a7f7-5966de07a014_250x167.png 848w, /__u/substackcdn.com/image/fetch/$s_!Bdpf!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65f27123-e320-4900-a7f7-5966de07a014_250x167.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Bdpf!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65f27123-e320-4900-a7f7-5966de07a014_250x167.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!Bdpf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65f27123-e320-4900-a7f7-5966de07a014_250x167.png" width="250" height="167" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/65f27123-e320-4900-a7f7-5966de07a014_250x167.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:167,&quot;width&quot;:250,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!Bdpf!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65f27123-e320-4900-a7f7-5966de07a014_250x167.png 424w, /__u/substackcdn.com/image/fetch/$s_!Bdpf!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65f27123-e320-4900-a7f7-5966de07a014_250x167.png 848w, /__u/substackcdn.com/image/fetch/$s_!Bdpf!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65f27123-e320-4900-a7f7-5966de07a014_250x167.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Bdpf!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65f27123-e320-4900-a7f7-5966de07a014_250x167.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption"><em>A sigmoid function (the logistic function, in particular). Source: Wikipedia.org</em></figcaption></figure></div><p>Since I&#8217;m modelling a binary event (essentially &#8220;Adelie or not&#8221;), there&#8217;s a Bernoulli distribution, so the probability of either outcome can be written in one expression:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!TohG!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc1617ead-6691-4d04-a815-97c1b6c7b297_1820x248.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!TohG!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc1617ead-6691-4d04-a815-97c1b6c7b297_1820x248.png 424w, /__u/substackcdn.com/image/fetch/$s_!TohG!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc1617ead-6691-4d04-a815-97c1b6c7b297_1820x248.png 848w, /__u/substackcdn.com/image/fetch/$s_!TohG!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc1617ead-6691-4d04-a815-97c1b6c7b297_1820x248.png 1272w, /__u/substackcdn.com/image/fetch/$s_!TohG!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc1617ead-6691-4d04-a815-97c1b6c7b297_1820x248.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!TohG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc1617ead-6691-4d04-a815-97c1b6c7b297_1820x248.png" width="1456" height="198" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c1617ead-6691-4d04-a815-97c1b6c7b297_1820x248.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:198,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:34162,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/197978691?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc1617ead-6691-4d04-a815-97c1b6c7b297_1820x248.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!TohG!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc1617ead-6691-4d04-a815-97c1b6c7b297_1820x248.png 424w, /__u/substackcdn.com/image/fetch/$s_!TohG!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc1617ead-6691-4d04-a815-97c1b6c7b297_1820x248.png 848w, /__u/substackcdn.com/image/fetch/$s_!TohG!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc1617ead-6691-4d04-a815-97c1b6c7b297_1820x248.png 1272w, /__u/substackcdn.com/image/fetch/$s_!TohG!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc1617ead-6691-4d04-a815-97c1b6c7b297_1820x248.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>(If this looks strange, see <a href="https://www.acsu.buffalo.edu/~adamcunn/probability/bernoulli.html">here</a> for an interactive refresher on Bernoulli distributions.)</p><h2>Putting the MLE to work</h2><p>Now to finally see the MLE in action, picking values for the parameters <em>w</em> and <em>b</em> that maximise the probability of the observed training data under the model.</p><p>I saw in my <a href="/__u/petalbyte.substack.com/p/deciphering-notation-the-maximum">previous post</a> that the MLE turns probability products into a sum of log-probabilities (a log-likelihood). Those sums are much easier to work with.</p><p>So my two-in-one probability becomes:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!vNca!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72a1106d-50d5-4255-8fae-311cd7f8c5d2_1820x240.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!vNca!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72a1106d-50d5-4255-8fae-311cd7f8c5d2_1820x240.png 424w, /__u/substackcdn.com/image/fetch/$s_!vNca!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72a1106d-50d5-4255-8fae-311cd7f8c5d2_1820x240.png 848w, /__u/substackcdn.com/image/fetch/$s_!vNca!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72a1106d-50d5-4255-8fae-311cd7f8c5d2_1820x240.png 1272w, /__u/substackcdn.com/image/fetch/$s_!vNca!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72a1106d-50d5-4255-8fae-311cd7f8c5d2_1820x240.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!vNca!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72a1106d-50d5-4255-8fae-311cd7f8c5d2_1820x240.png" width="1456" height="192" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/72a1106d-50d5-4255-8fae-311cd7f8c5d2_1820x240.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:192,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:42352,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/197978691?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72a1106d-50d5-4255-8fae-311cd7f8c5d2_1820x240.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!vNca!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72a1106d-50d5-4255-8fae-311cd7f8c5d2_1820x240.png 424w, /__u/substackcdn.com/image/fetch/$s_!vNca!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72a1106d-50d5-4255-8fae-311cd7f8c5d2_1820x240.png 848w, /__u/substackcdn.com/image/fetch/$s_!vNca!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72a1106d-50d5-4255-8fae-311cd7f8c5d2_1820x240.png 1272w, /__u/substackcdn.com/image/fetch/$s_!vNca!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72a1106d-50d5-4255-8fae-311cd7f8c5d2_1820x240.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>I&#8217;ll briefly mention that the negative of <em>L(w, b)</em> is the expression for <a href="https://docs.pytorch.org/docs/2.12/generated/torch.nn.BCELoss.html#bceloss">binary cross-entropy loss</a>, so when we hear about &#8220;minimising cross-entropy&#8221; in machine learning, we can recall the MLE and understand what&#8217;s happening there.</p><p>Now, since the goal is to maximise <em>L(w, b)</em>, and we know from calculus that the maximum of a function occurs at points where the gradient is zero, we might take the partial derivatives of <em>L</em> with respect to <em>w</em> and <em>b</em>, and set both to zero.</p><p>(For a well-explained working of this, see the &#8220;<em>Derivatives Without Tears</em>&#8221; section of <a href="https://chrispiech.github.io/probabilityForComputerScientists/en/part5/log_regression/">this Stanford CS109 Course Reader</a>.)</p><p>If we find a <em>(w, b)</em> where both partials equal zero, we have found a candidate for the maximum likelihood estimation. But, unfortunately, we can&#8217;t isolate <em>w</em> and <em>b</em> algebraically because they sit within the sigmoid on the right-hand side of each equation.</p><p>So we turn to numerical optimisation, where an algorithm like gradient descent could help us by iteratively searching for the values of <em>w</em> and <em>b</em> that yield the zero-gradient point.</p><p>In fact, I used scikit-learn here, so the algorithm was L-BFGS (which is a candidate for an upcoming post, to understand why it&#8217;s described as &#8220;<a href="https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html">a good default solver</a>&#8221;).</p><div class="highlighted_code_block" data-attrs="{&quot;language&quot;:&quot;python&quot;,&quot;nodeId&quot;:null}" data-component-name="HighlightedCodeBlockToDOM"><pre class="shiki"><code class="language-python">from palmerpenguins import load_penguins
from sklearn.linear_model import LogisticRegression

# We load the dataset
penguins = load_penguins()

# We create a smaller data frame containing only Adelie and Gentoo penguins,
# and the drop any rows where the bill_length_mm value is missing/NaN
dataframe = penguins[penguins['species'].isin(['Adelie', 'Gentoo'])].dropna(subset=['bill_length_mm'])

# Next, we split the data into model inputs, X, and target labels, y
X = dataframe[['bill_length_mm']].values #=&gt; (number_of_rows, 1)
y = (dataframe['species'] == 'Adelie').astype(int).values  #=&gt; [1] or [0]

# The decision boundary is where the sigmoid outputs 0.5, i.e. where
# the model can't decided between the two classes
decision_boundary = -b / w

# scikit-learn's LogisticRegression classifier applies regularisation
# by default, but we can essentially turn that off (in order to see the
# MLE at work most clearly) by passing a big number, like 1e10, as the
# C parameter
# See: https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html
model = LogisticRegression(C=1e10).fit(X, y)

# We can take a look at the values for w and b that the model found:
print(f"w = {model.coef_[0][0]:.3f}")    #=&gt; -1.214
print(f"b = {model.intercept_[0]:.3f}")  #=&gt; 52.412
print(f"decision boundary = {decision_boundary:.3f} mm") #=&gt; 43.165 mm
</code></pre></div><p>(This is where I ran into regularisation again, which I will also investigate in another post. But back to the MLE for now.)</p><p>The MLE has given a value for <em>w</em> and a value for <em>b</em>. If I plug those values into <em>L(w, b)</em> then I get <em>L &#8776; -38.256</em>.</p><p>Or, by comparison, I can make a no-information guess of (<em>w, b) = (0, 0),</em> and see <em>L &#8776; -189.922</em>.</p><p>So the MLE gives a higher log-probability of seeing the training data than a wild guess, which seems a good thing. Of course, this isn&#8217;t a production model and there are no profound insights here. But it&#8217;s nice to see some outputs from real data.</p><p>My goal was to get a sense of the MLE&#8217;s role in machine learning, so that I&#8217;m not one day asking, <em>&#8220;Is the MLE used anywhere?&#8221;</em>, and I&#8217;d say that&#8217;s been achieved.</p><p>To close, a graph showing where a few bill lengths from the dataset lie in relation to the sigmoid generated by the parameters <em>w = -1.214</em> and <em>b =</em> <em>52.412</em>:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!ODXb!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd7d91897-7436-44d5-b8e7-835d97ec547f_2356x1178.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!ODXb!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd7d91897-7436-44d5-b8e7-835d97ec547f_2356x1178.png 424w, /__u/substackcdn.com/image/fetch/$s_!ODXb!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd7d91897-7436-44d5-b8e7-835d97ec547f_2356x1178.png 848w, /__u/substackcdn.com/image/fetch/$s_!ODXb!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd7d91897-7436-44d5-b8e7-835d97ec547f_2356x1178.png 1272w, /__u/substackcdn.com/image/fetch/$s_!ODXb!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd7d91897-7436-44d5-b8e7-835d97ec547f_2356x1178.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!ODXb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd7d91897-7436-44d5-b8e7-835d97ec547f_2356x1178.png" width="1456" height="728" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d7d91897-7436-44d5-b8e7-835d97ec547f_2356x1178.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:728,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:264234,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/197978691?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd7d91897-7436-44d5-b8e7-835d97ec547f_2356x1178.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!ODXb!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd7d91897-7436-44d5-b8e7-835d97ec547f_2356x1178.png 424w, /__u/substackcdn.com/image/fetch/$s_!ODXb!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd7d91897-7436-44d5-b8e7-835d97ec547f_2356x1178.png 848w, /__u/substackcdn.com/image/fetch/$s_!ODXb!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd7d91897-7436-44d5-b8e7-835d97ec547f_2356x1178.png 1272w, /__u/substackcdn.com/image/fetch/$s_!ODXb!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd7d91897-7436-44d5-b8e7-835d97ec547f_2356x1178.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Since a shorter bill length correlates with Adelie penguins (a class label of 1), the sigmoid curve approaches 1 as bill length decreases. As bill length increases, it approaches 0, for the Gentoo class label of 0. And we see the decision boundary sitting at <em>x = 43.165.</em></p><p>Very simple, but I liked this as a visual of the sigmoid&#8217;s role in logistic regression.</p><div class="callout-block" data-callout="true"><p><em><strong>Some fairly easy things to try, if you like:</strong></em></p><ol><li><p>Refit the model using flipper length or body mass instead of bill length, to see which feature gives the nicest separation</p></li><li><p>Compute the log-likelihood at a few <em>(w, b)</em> values around the MLE to confirm that the MLE really is the maximum</p></li><li><p>Reduce the dataset to just 10 points, with no overlap in bill length between Adelie and Gentoo penguins; how different are the fitted <em>w</em> and <em>b</em>, and why? <em>(See Bishop&#8217;s Exercise 4.14 for the explanation)</em></p></li></ol></div><h5>References and resources:</h5><ul><li><p>CM Bishop, &#8220;Pattern Recognition and Machine Learning&#8221;, 2006</p></li><li><p><a href="https://stats.stackexchange.com/questions/267393/do-we-ever-use-maximum-likelihood-estimation/">https://stats.stackexchange.com/questions/267393/do-we-ever-use-maximum-likelihood-estimation/</a> </p></li><li><p><a href="https://github.com/allisonhorst/palmerpenguins">https://github.com/allisonhorst/palmerpenguins</a></p></li><li><p><a href="https://en.wikipedia.org/wiki/Regularization_(mathematics)">https://en.wikipedia.org/wiki/Regularization_(mathematics)</a></p></li><li><p><a href="https://www.acsu.buffalo.edu/~adamcunn/probability/bernoulli.html">https://www.acsu.buffalo.edu/~adamcunn/probability/bernoulli.html</a></p></li><li><p><a href="https://docs.pytorch.org/docs/2.12/generated/torch.nn.BCELoss.html#bceloss">https://docs.pytorch.org/docs/2.12/generated/torch.nn.BCELoss.html#bceloss</a></p></li><li><p><a href="https://chrispiech.github.io/probabilityForComputerScientists/en/part5/log_regression/">https://chrispiech.github.io/probabilityForComputerScientists/en/part5/log_regression/</a></p></li><li><p><a href="https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html">https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html</a></p></li><li><p><a href="https://en.wikipedia.org/wiki/Regularization_(mathematics)">https://en.wikipedia.org/wiki/Regularization_(mathematics)</a></p></li></ul><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://petalbyte.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading (Surprisingly Simple) Machine Learning Mathematics! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Deciphering Notation: The Maximum Likelihood Estimator]]></title><description><![CDATA[We can unpick many interesting ideas from this equation, used in many areas of supervised learning.]]></description><link>https://petalbyte.substack.com/p/deciphering-notation-the-maximum</link><guid isPermaLink="false">https://petalbyte.substack.com/p/deciphering-notation-the-maximum</guid><dc:creator><![CDATA[Louise B]]></dc:creator><pubDate>Sat, 09 May 2026 17:10:18 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/486e8ac8-801a-41cd-86fd-6cc92f1681e6_1200x630.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>First, the equation:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!1UQv!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe093f0f6-3ce8-4881-9bc0-e89d8e79999b_1836x188.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!1UQv!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe093f0f6-3ce8-4881-9bc0-e89d8e79999b_1836x188.png 424w, /__u/substackcdn.com/image/fetch/$s_!1UQv!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe093f0f6-3ce8-4881-9bc0-e89d8e79999b_1836x188.png 848w, /__u/substackcdn.com/image/fetch/$s_!1UQv!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe093f0f6-3ce8-4881-9bc0-e89d8e79999b_1836x188.png 1272w, /__u/substackcdn.com/image/fetch/$s_!1UQv!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe093f0f6-3ce8-4881-9bc0-e89d8e79999b_1836x188.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!1UQv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe093f0f6-3ce8-4881-9bc0-e89d8e79999b_1836x188.png" width="1456" height="149" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e093f0f6-3ce8-4881-9bc0-e89d8e79999b_1836x188.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:149,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:32499,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/196985127?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe093f0f6-3ce8-4881-9bc0-e89d8e79999b_1836x188.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!1UQv!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe093f0f6-3ce8-4881-9bc0-e89d8e79999b_1836x188.png 424w, /__u/substackcdn.com/image/fetch/$s_!1UQv!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe093f0f6-3ce8-4881-9bc0-e89d8e79999b_1836x188.png 848w, /__u/substackcdn.com/image/fetch/$s_!1UQv!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe093f0f6-3ce8-4881-9bc0-e89d8e79999b_1836x188.png 1272w, /__u/substackcdn.com/image/fetch/$s_!1UQv!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe093f0f6-3ce8-4881-9bc0-e89d8e79999b_1836x188.png 1456w" sizes="100vw" fetchpriority="high"></picture><div></div></div></a></figure></div><p>Next, let&#8217;s set up a simple example for connecting abstractions to the real world:</p><div class="callout-block" data-callout="true"><p><em>We&#8217;re building a model that will tell us how likely it is to rain on a future day.</em></p><p><em>We pretend that previous weather has no impact on later weather, so our training data points are independent.</em></p><p><em>Our training data might look like this:</em></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!AGI3!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fa9de74-dd38-42bd-9fd7-83761aab5581_1112x482.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!AGI3!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fa9de74-dd38-42bd-9fd7-83761aab5581_1112x482.png 424w, /__u/substackcdn.com/image/fetch/$s_!AGI3!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fa9de74-dd38-42bd-9fd7-83761aab5581_1112x482.png 848w, /__u/substackcdn.com/image/fetch/$s_!AGI3!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fa9de74-dd38-42bd-9fd7-83761aab5581_1112x482.png 1272w, /__u/substackcdn.com/image/fetch/$s_!AGI3!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fa9de74-dd38-42bd-9fd7-83761aab5581_1112x482.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!AGI3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fa9de74-dd38-42bd-9fd7-83761aab5581_1112x482.png" width="1112" height="482" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0fa9de74-dd38-42bd-9fd7-83761aab5581_1112x482.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:482,&quot;width&quot;:1112,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:43550,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/196985127?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fa9de74-dd38-42bd-9fd7-83761aab5581_1112x482.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!AGI3!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fa9de74-dd38-42bd-9fd7-83761aab5581_1112x482.png 424w, /__u/substackcdn.com/image/fetch/$s_!AGI3!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fa9de74-dd38-42bd-9fd7-83761aab5581_1112x482.png 848w, /__u/substackcdn.com/image/fetch/$s_!AGI3!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fa9de74-dd38-42bd-9fd7-83761aab5581_1112x482.png 1272w, /__u/substackcdn.com/image/fetch/$s_!AGI3!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fa9de74-dd38-42bd-9fd7-83761aab5581_1112x482.png 1456w" sizes="100vw"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>In other words, we have the training set: </em></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!0uSi!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7944fe71-e1d0-4aa0-abd1-87d98d50425a_1836x152.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!0uSi!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7944fe71-e1d0-4aa0-abd1-87d98d50425a_1836x152.png 424w, /__u/substackcdn.com/image/fetch/$s_!0uSi!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7944fe71-e1d0-4aa0-abd1-87d98d50425a_1836x152.png 848w, /__u/substackcdn.com/image/fetch/$s_!0uSi!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7944fe71-e1d0-4aa0-abd1-87d98d50425a_1836x152.png 1272w, /__u/substackcdn.com/image/fetch/$s_!0uSi!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7944fe71-e1d0-4aa0-abd1-87d98d50425a_1836x152.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!0uSi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7944fe71-e1d0-4aa0-abd1-87d98d50425a_1836x152.png" width="1456" height="121" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7944fe71-e1d0-4aa0-abd1-87d98d50425a_1836x152.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:121,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:27851,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/196985127?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7944fe71-e1d0-4aa0-abd1-87d98d50425a_1836x152.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!0uSi!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7944fe71-e1d0-4aa0-abd1-87d98d50425a_1836x152.png 424w, /__u/substackcdn.com/image/fetch/$s_!0uSi!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7944fe71-e1d0-4aa0-abd1-87d98d50425a_1836x152.png 848w, /__u/substackcdn.com/image/fetch/$s_!0uSi!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7944fe71-e1d0-4aa0-abd1-87d98d50425a_1836x152.png 1272w, /__u/substackcdn.com/image/fetch/$s_!0uSi!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7944fe71-e1d0-4aa0-abd1-87d98d50425a_1836x152.png 1456w" sizes="100vw"></picture><div></div></div></a></figure></div></div><p>Now we can work through the notation piece-by-piece, using the example to illustrate what each part is doing.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://petalbyte.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading (Surprisingly Simple) Machine Learning Mathematics! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h2>The simplest possible model</h2><p>The simplest possible model has one parameter, <em>&#952;</em>, which represents the possibility of rain on any given day:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!CKAp!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03d91f19-7ff1-4882-96c8-abc90d616f38_1836x264.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!CKAp!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03d91f19-7ff1-4882-96c8-abc90d616f38_1836x264.png 424w, /__u/substackcdn.com/image/fetch/$s_!CKAp!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03d91f19-7ff1-4882-96c8-abc90d616f38_1836x264.png 848w, /__u/substackcdn.com/image/fetch/$s_!CKAp!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03d91f19-7ff1-4882-96c8-abc90d616f38_1836x264.png 1272w, /__u/substackcdn.com/image/fetch/$s_!CKAp!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03d91f19-7ff1-4882-96c8-abc90d616f38_1836x264.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!CKAp!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03d91f19-7ff1-4882-96c8-abc90d616f38_1836x264.png" width="1456" height="209" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/03d91f19-7ff1-4882-96c8-abc90d616f38_1836x264.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:209,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:32431,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/196985127?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03d91f19-7ff1-4882-96c8-abc90d616f38_1836x264.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!CKAp!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03d91f19-7ff1-4882-96c8-abc90d616f38_1836x264.png 424w, /__u/substackcdn.com/image/fetch/$s_!CKAp!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03d91f19-7ff1-4882-96c8-abc90d616f38_1836x264.png 848w, /__u/substackcdn.com/image/fetch/$s_!CKAp!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03d91f19-7ff1-4882-96c8-abc90d616f38_1836x264.png 1272w, /__u/substackcdn.com/image/fetch/$s_!CKAp!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03d91f19-7ff1-4882-96c8-abc90d616f38_1836x264.png 1456w" sizes="100vw"></picture><div></div></div></a></figure></div><p>The semicolon in <em>p_model(x; &#952;)</em> is just a notation meaning: &#8220;This is a function of <em>x</em>, and it&#8217;s parameterised by <em>&#952;</em>&#8221; so that different choices of <em>&#952;</em> give different models.</p><p><em>&#952; = 0.5</em> means equal chance of rain or no rain. <em>&#952; = 0.9</em> means it&#8217;s very likely to rain.</p><p>Our task is to pick the best <em>&#952;</em>, where &#8220;best&#8221; means the value of <em>&#952;</em> that makes our actual training data look as likely as possible.</p><div class="callout-block" data-callout="true"><p><em>Recall that our simple example training set is:</em></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!GMq4!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0d9255e-728a-4172-a944-21181a017605_1112x482.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!GMq4!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0d9255e-728a-4172-a944-21181a017605_1112x482.png 424w, /__u/substackcdn.com/image/fetch/$s_!GMq4!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0d9255e-728a-4172-a944-21181a017605_1112x482.png 848w, /__u/substackcdn.com/image/fetch/$s_!GMq4!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0d9255e-728a-4172-a944-21181a017605_1112x482.png 1272w, /__u/substackcdn.com/image/fetch/$s_!GMq4!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0d9255e-728a-4172-a944-21181a017605_1112x482.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!GMq4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0d9255e-728a-4172-a944-21181a017605_1112x482.png" width="1112" height="482" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e0d9255e-728a-4172-a944-21181a017605_1112x482.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:482,&quot;width&quot;:1112,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:43550,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/196985127?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0d9255e-728a-4172-a944-21181a017605_1112x482.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!GMq4!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0d9255e-728a-4172-a944-21181a017605_1112x482.png 424w, /__u/substackcdn.com/image/fetch/$s_!GMq4!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0d9255e-728a-4172-a944-21181a017605_1112x482.png 848w, /__u/substackcdn.com/image/fetch/$s_!GMq4!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0d9255e-728a-4172-a944-21181a017605_1112x482.png 1272w, /__u/substackcdn.com/image/fetch/$s_!GMq4!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0d9255e-728a-4172-a944-21181a017605_1112x482.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>If we pick &#952; = 0.6, then our model tells us the probability of seeing the exact sequence {1,0,1,1,0} is:</em></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!2tlZ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb3a5127-88a4-4327-94fa-08608fe6555a_1836x238.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!2tlZ!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb3a5127-88a4-4327-94fa-08608fe6555a_1836x238.png 424w, /__u/substackcdn.com/image/fetch/$s_!2tlZ!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb3a5127-88a4-4327-94fa-08608fe6555a_1836x238.png 848w, /__u/substackcdn.com/image/fetch/$s_!2tlZ!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb3a5127-88a4-4327-94fa-08608fe6555a_1836x238.png 1272w, /__u/substackcdn.com/image/fetch/$s_!2tlZ!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb3a5127-88a4-4327-94fa-08608fe6555a_1836x238.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!2tlZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb3a5127-88a4-4327-94fa-08608fe6555a_1836x238.png" width="1456" height="189" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/cb3a5127-88a4-4327-94fa-08608fe6555a_1836x238.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:189,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:50464,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/196985127?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb3a5127-88a4-4327-94fa-08608fe6555a_1836x238.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!2tlZ!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb3a5127-88a4-4327-94fa-08608fe6555a_1836x238.png 424w, /__u/substackcdn.com/image/fetch/$s_!2tlZ!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb3a5127-88a4-4327-94fa-08608fe6555a_1836x238.png 848w, /__u/substackcdn.com/image/fetch/$s_!2tlZ!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb3a5127-88a4-4327-94fa-08608fe6555a_1836x238.png 1272w, /__u/substackcdn.com/image/fetch/$s_!2tlZ!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb3a5127-88a4-4327-94fa-08608fe6555a_1836x238.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!FGmv!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5166846-5a37-402c-8515-b28b0b93991b_1836x112.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!FGmv!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5166846-5a37-402c-8515-b28b0b93991b_1836x112.png 424w, /__u/substackcdn.com/image/fetch/$s_!FGmv!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5166846-5a37-402c-8515-b28b0b93991b_1836x112.png 848w, /__u/substackcdn.com/image/fetch/$s_!FGmv!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5166846-5a37-402c-8515-b28b0b93991b_1836x112.png 1272w, /__u/substackcdn.com/image/fetch/$s_!FGmv!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5166846-5a37-402c-8515-b28b0b93991b_1836x112.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!FGmv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5166846-5a37-402c-8515-b28b0b93991b_1836x112.png" width="1456" height="89" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e5166846-5a37-402c-8515-b28b0b93991b_1836x112.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:89,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:23282,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/196985127?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5166846-5a37-402c-8515-b28b0b93991b_1836x112.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!FGmv!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5166846-5a37-402c-8515-b28b0b93991b_1836x112.png 424w, /__u/substackcdn.com/image/fetch/$s_!FGmv!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5166846-5a37-402c-8515-b28b0b93991b_1836x112.png 848w, /__u/substackcdn.com/image/fetch/$s_!FGmv!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5166846-5a37-402c-8515-b28b0b93991b_1836x112.png 1272w, /__u/substackcdn.com/image/fetch/$s_!FGmv!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5166846-5a37-402c-8515-b28b0b93991b_1836x112.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p><em>But if we picked &#952; = 0.3, we&#8217;d find ourselves with:</em></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!7nmT!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4cdc73e8-8008-424e-93b4-9afb12a4d452_1836x104.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!7nmT!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4cdc73e8-8008-424e-93b4-9afb12a4d452_1836x104.png 424w, /__u/substackcdn.com/image/fetch/$s_!7nmT!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4cdc73e8-8008-424e-93b4-9afb12a4d452_1836x104.png 848w, /__u/substackcdn.com/image/fetch/$s_!7nmT!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4cdc73e8-8008-424e-93b4-9afb12a4d452_1836x104.png 1272w, /__u/substackcdn.com/image/fetch/$s_!7nmT!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4cdc73e8-8008-424e-93b4-9afb12a4d452_1836x104.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!7nmT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4cdc73e8-8008-424e-93b4-9afb12a4d452_1836x104.png" width="1456" height="82" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4cdc73e8-8008-424e-93b4-9afb12a4d452_1836x104.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:82,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:22070,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/196985127?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4cdc73e8-8008-424e-93b4-9afb12a4d452_1836x104.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!7nmT!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4cdc73e8-8008-424e-93b4-9afb12a4d452_1836x104.png 424w, /__u/substackcdn.com/image/fetch/$s_!7nmT!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4cdc73e8-8008-424e-93b4-9afb12a4d452_1836x104.png 848w, /__u/substackcdn.com/image/fetch/$s_!7nmT!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4cdc73e8-8008-424e-93b4-9afb12a4d452_1836x104.png 1272w, /__u/substackcdn.com/image/fetch/$s_!7nmT!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4cdc73e8-8008-424e-93b4-9afb12a4d452_1836x104.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p><em>So &#952; = 0.6 makes our data more likely than &#952; = 0.3 does.</em></p></div><p>So we&#8217;re looking for the value of <em>&#952;</em> that maximises this probability which, currently, we&#8217;re calculating as a product.</p><p>At this point, our &#8220;work-in-progress&#8221; maximum likelihood estimator looks like this:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!GYOm!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0907dee3-a57e-458c-83af-3c25f21a5b69_1836x260.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!GYOm!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0907dee3-a57e-458c-83af-3c25f21a5b69_1836x260.png 424w, /__u/substackcdn.com/image/fetch/$s_!GYOm!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0907dee3-a57e-458c-83af-3c25f21a5b69_1836x260.png 848w, /__u/substackcdn.com/image/fetch/$s_!GYOm!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0907dee3-a57e-458c-83af-3c25f21a5b69_1836x260.png 1272w, /__u/substackcdn.com/image/fetch/$s_!GYOm!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0907dee3-a57e-458c-83af-3c25f21a5b69_1836x260.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!GYOm!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0907dee3-a57e-458c-83af-3c25f21a5b69_1836x260.png" width="1456" height="206" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0907dee3-a57e-458c-83af-3c25f21a5b69_1836x260.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:206,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:33684,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/196985127?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0907dee3-a57e-458c-83af-3c25f21a5b69_1836x260.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!GYOm!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0907dee3-a57e-458c-83af-3c25f21a5b69_1836x260.png 424w, /__u/substackcdn.com/image/fetch/$s_!GYOm!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0907dee3-a57e-458c-83af-3c25f21a5b69_1836x260.png 848w, /__u/substackcdn.com/image/fetch/$s_!GYOm!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0907dee3-a57e-458c-83af-3c25f21a5b69_1836x260.png 1272w, /__u/substackcdn.com/image/fetch/$s_!GYOm!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0907dee3-a57e-458c-83af-3c25f21a5b69_1836x260.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><h3>Problems with products, solved by logarithms</h3><p>We notice that, if we had a real-world training set containing a million data points, this product would become <em>extremely</em> small.</p><p>It is called &#8220;numerical underflow&#8221; when numbers become so small they are essentially lost from floating point arithmetic, as they are rounded to zero during computation.</p><p>And we also know that we&#8217;re using the <code>argmax</code> function, which finds the input that yields the largest output for a given function.</p><p>So we think about taking the logarithm of our probability product, because:</p><ol><li><p>The logarithm function turns products into sums, so we won&#8217;t multiply tiny numbers until they disappear completely</p></li><li><p>For numbers between 0 and 1, the closer the number is to zero, the further from zero (in the negative direction) the logarithm will be</p><ol><li><p>More generally, logarithms preserve the order of numbers: If <em>a</em> is greater than <em>b</em>, then <em>log(a)</em> is greater than <em>log(b)</em></p></li></ol></li></ol><div class="callout-block" data-callout="true"><p><em>(We&#8217;ll use the natural logarithm here.)</em></p><p><em>For &#952; = 0.6, the logarithm of our probability product is:</em></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!LDUX!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe08e3023-1c8d-40a1-a7ac-7cfdcbae9f5d_1836x704.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!LDUX!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe08e3023-1c8d-40a1-a7ac-7cfdcbae9f5d_1836x704.png 424w, /__u/substackcdn.com/image/fetch/$s_!LDUX!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe08e3023-1c8d-40a1-a7ac-7cfdcbae9f5d_1836x704.png 848w, /__u/substackcdn.com/image/fetch/$s_!LDUX!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe08e3023-1c8d-40a1-a7ac-7cfdcbae9f5d_1836x704.png 1272w, /__u/substackcdn.com/image/fetch/$s_!LDUX!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe08e3023-1c8d-40a1-a7ac-7cfdcbae9f5d_1836x704.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!LDUX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe08e3023-1c8d-40a1-a7ac-7cfdcbae9f5d_1836x704.png" width="1456" height="558" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e08e3023-1c8d-40a1-a7ac-7cfdcbae9f5d_1836x704.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:558,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:73204,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/196985127?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe08e3023-1c8d-40a1-a7ac-7cfdcbae9f5d_1836x704.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!LDUX!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe08e3023-1c8d-40a1-a7ac-7cfdcbae9f5d_1836x704.png 424w, /__u/substackcdn.com/image/fetch/$s_!LDUX!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe08e3023-1c8d-40a1-a7ac-7cfdcbae9f5d_1836x704.png 848w, /__u/substackcdn.com/image/fetch/$s_!LDUX!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe08e3023-1c8d-40a1-a7ac-7cfdcbae9f5d_1836x704.png 1272w, /__u/substackcdn.com/image/fetch/$s_!LDUX!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe08e3023-1c8d-40a1-a7ac-7cfdcbae9f5d_1836x704.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>And if we set &#952; = 0.3:</em></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!fEnZ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fb87e19-c61b-4c4d-bb9f-7a40931a36c6_1836x484.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!fEnZ!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fb87e19-c61b-4c4d-bb9f-7a40931a36c6_1836x484.png 424w, /__u/substackcdn.com/image/fetch/$s_!fEnZ!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fb87e19-c61b-4c4d-bb9f-7a40931a36c6_1836x484.png 848w, /__u/substackcdn.com/image/fetch/$s_!fEnZ!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fb87e19-c61b-4c4d-bb9f-7a40931a36c6_1836x484.png 1272w, /__u/substackcdn.com/image/fetch/$s_!fEnZ!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fb87e19-c61b-4c4d-bb9f-7a40931a36c6_1836x484.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!fEnZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fb87e19-c61b-4c4d-bb9f-7a40931a36c6_1836x484.png" width="1456" height="384" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9fb87e19-c61b-4c4d-bb9f-7a40931a36c6_1836x484.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:384,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:49934,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/196985127?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fb87e19-c61b-4c4d-bb9f-7a40931a36c6_1836x484.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!fEnZ!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fb87e19-c61b-4c4d-bb9f-7a40931a36c6_1836x484.png 424w, /__u/substackcdn.com/image/fetch/$s_!fEnZ!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fb87e19-c61b-4c4d-bb9f-7a40931a36c6_1836x484.png 848w, /__u/substackcdn.com/image/fetch/$s_!fEnZ!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fb87e19-c61b-4c4d-bb9f-7a40931a36c6_1836x484.png 1272w, /__u/substackcdn.com/image/fetch/$s_!fEnZ!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fb87e19-c61b-4c4d-bb9f-7a40931a36c6_1836x484.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>Of course, the sum allows us to avoid the multiplication of increasingly tiny numbers.</em></p><p><em>Our log-probabilities are negative, but higher probabilities become negative numbers that are closer to zero, so </em><code>argmax</code><em> can still identify the &#8220;best&#8221; value for &#952; without any trouble.</em></p></div><p>So we&#8217;re very happy with this logarithm decision.</p><p>And we can update our &#8220;work-in-progress&#8221; maximum likelihood estimator to:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!DAzv!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fded39294-dbbd-45b6-af24-87c385fc97d3_1836x296.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!DAzv!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fded39294-dbbd-45b6-af24-87c385fc97d3_1836x296.png 424w, /__u/substackcdn.com/image/fetch/$s_!DAzv!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fded39294-dbbd-45b6-af24-87c385fc97d3_1836x296.png 848w, /__u/substackcdn.com/image/fetch/$s_!DAzv!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fded39294-dbbd-45b6-af24-87c385fc97d3_1836x296.png 1272w, /__u/substackcdn.com/image/fetch/$s_!DAzv!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fded39294-dbbd-45b6-af24-87c385fc97d3_1836x296.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!DAzv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fded39294-dbbd-45b6-af24-87c385fc97d3_1836x296.png" width="1456" height="235" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ded39294-dbbd-45b6-af24-87c385fc97d3_1836x296.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:235,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:36182,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/196985127?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fded39294-dbbd-45b6-af24-87c385fc97d3_1836x296.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!DAzv!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fded39294-dbbd-45b6-af24-87c385fc97d3_1836x296.png 424w, /__u/substackcdn.com/image/fetch/$s_!DAzv!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fded39294-dbbd-45b6-af24-87c385fc97d3_1836x296.png 848w, /__u/substackcdn.com/image/fetch/$s_!DAzv!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fded39294-dbbd-45b6-af24-87c385fc97d3_1836x296.png 1272w, /__u/substackcdn.com/image/fetch/$s_!DAzv!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fded39294-dbbd-45b6-af24-87c385fc97d3_1836x296.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><h2>Why not take the average?</h2><p>At this point, we spot a new opportunity.</p><p>If we take the average of the log-probabilities for each value of <em>&#952;</em> by dividing their sum by <em>m</em>, this won&#8217;t change the order of the values, either.</p><p>So we can update our &#8220;work-in-progress&#8221; equation to:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!BOWs!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe6fb3359-0b92-4075-9952-1bd3c69f382a_1836x250.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!BOWs!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe6fb3359-0b92-4075-9952-1bd3c69f382a_1836x250.png 424w, /__u/substackcdn.com/image/fetch/$s_!BOWs!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe6fb3359-0b92-4075-9952-1bd3c69f382a_1836x250.png 848w, /__u/substackcdn.com/image/fetch/$s_!BOWs!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe6fb3359-0b92-4075-9952-1bd3c69f382a_1836x250.png 1272w, /__u/substackcdn.com/image/fetch/$s_!BOWs!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe6fb3359-0b92-4075-9952-1bd3c69f382a_1836x250.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!BOWs!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe6fb3359-0b92-4075-9952-1bd3c69f382a_1836x250.png" width="1456" height="198" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e6fb3359-0b92-4075-9952-1bd3c69f382a_1836x250.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:198,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:36422,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/196985127?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe6fb3359-0b92-4075-9952-1bd3c69f382a_1836x250.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!BOWs!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe6fb3359-0b92-4075-9952-1bd3c69f382a_1836x250.png 424w, /__u/substackcdn.com/image/fetch/$s_!BOWs!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe6fb3359-0b92-4075-9952-1bd3c69f382a_1836x250.png 848w, /__u/substackcdn.com/image/fetch/$s_!BOWs!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe6fb3359-0b92-4075-9952-1bd3c69f382a_1836x250.png 1272w, /__u/substackcdn.com/image/fetch/$s_!BOWs!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe6fb3359-0b92-4075-9952-1bd3c69f382a_1836x250.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>(This is just the first half of the opportunity, so continue on to see the whole thing.)</p><p>Next, we consider what would happen if we randomly sampled a data point from our training set to compute the log-probability for, with an equal probability of selecting any one of them.</p><p>In other words, we introduce a random variable, X, with probability distribution, <em>p&#770;_data</em>, to represent a sampled data point and the likelihood of it taking a particular value.</p><div class="callout-block" data-callout="true"><p><em>Recalling our simple example training data:</em></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!cfTP!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc4ff6d0d-0b28-4eff-a9a0-823f1c6ff8f1_1112x482.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!cfTP!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc4ff6d0d-0b28-4eff-a9a0-823f1c6ff8f1_1112x482.png 424w, /__u/substackcdn.com/image/fetch/$s_!cfTP!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc4ff6d0d-0b28-4eff-a9a0-823f1c6ff8f1_1112x482.png 848w, /__u/substackcdn.com/image/fetch/$s_!cfTP!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc4ff6d0d-0b28-4eff-a9a0-823f1c6ff8f1_1112x482.png 1272w, /__u/substackcdn.com/image/fetch/$s_!cfTP!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc4ff6d0d-0b28-4eff-a9a0-823f1c6ff8f1_1112x482.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!cfTP!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc4ff6d0d-0b28-4eff-a9a0-823f1c6ff8f1_1112x482.png" width="1112" height="482" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c4ff6d0d-0b28-4eff-a9a0-823f1c6ff8f1_1112x482.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:482,&quot;width&quot;:1112,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:43550,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/196985127?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc4ff6d0d-0b28-4eff-a9a0-823f1c6ff8f1_1112x482.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!cfTP!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc4ff6d0d-0b28-4eff-a9a0-823f1c6ff8f1_1112x482.png 424w, /__u/substackcdn.com/image/fetch/$s_!cfTP!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc4ff6d0d-0b28-4eff-a9a0-823f1c6ff8f1_1112x482.png 848w, /__u/substackcdn.com/image/fetch/$s_!cfTP!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc4ff6d0d-0b28-4eff-a9a0-823f1c6ff8f1_1112x482.png 1272w, /__u/substackcdn.com/image/fetch/$s_!cfTP!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc4ff6d0d-0b28-4eff-a9a0-823f1c6ff8f1_1112x482.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>If we pick one of the days at random, with equal probability of picking any day, then the likelihood of picking either a 1 or a 0 is:</em></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!2U6B!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb36aeafd-9c6b-4b98-a256-269175d753de_1836x552.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!2U6B!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb36aeafd-9c6b-4b98-a256-269175d753de_1836x552.png 424w, /__u/substackcdn.com/image/fetch/$s_!2U6B!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb36aeafd-9c6b-4b98-a256-269175d753de_1836x552.png 848w, /__u/substackcdn.com/image/fetch/$s_!2U6B!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb36aeafd-9c6b-4b98-a256-269175d753de_1836x552.png 1272w, /__u/substackcdn.com/image/fetch/$s_!2U6B!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb36aeafd-9c6b-4b98-a256-269175d753de_1836x552.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!2U6B!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb36aeafd-9c6b-4b98-a256-269175d753de_1836x552.png" width="1456" height="438" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b36aeafd-9c6b-4b98-a256-269175d753de_1836x552.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:438,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:41324,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/196985127?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb36aeafd-9c6b-4b98-a256-269175d753de_1836x552.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!2U6B!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb36aeafd-9c6b-4b98-a256-269175d753de_1836x552.png 424w, /__u/substackcdn.com/image/fetch/$s_!2U6B!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb36aeafd-9c6b-4b98-a256-269175d753de_1836x552.png 848w, /__u/substackcdn.com/image/fetch/$s_!2U6B!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb36aeafd-9c6b-4b98-a256-269175d753de_1836x552.png 1272w, /__u/substackcdn.com/image/fetch/$s_!2U6B!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb36aeafd-9c6b-4b98-a256-269175d753de_1836x552.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div></div><p>We can then ask what the expected value of the log-probability would be for this sampled data point.</p><p>Since expected value is a weighted average of all values a random variable can take, we see that the expected value of the log-probability of a randomly sampled data point would be the average of all of the log-probabilities.</p><div class="callout-block" data-callout="true"><p><em>Returning to our example, and choosing &#952; = 0.6 to see the result for this expected value calculation, we can take a direct look at the log-probabilities first: </em></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!D00q!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1eea5432-c2a5-4026-bba4-730d598de5ca_1252x460.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!D00q!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1eea5432-c2a5-4026-bba4-730d598de5ca_1252x460.png 424w, /__u/substackcdn.com/image/fetch/$s_!D00q!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1eea5432-c2a5-4026-bba4-730d598de5ca_1252x460.png 848w, /__u/substackcdn.com/image/fetch/$s_!D00q!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1eea5432-c2a5-4026-bba4-730d598de5ca_1252x460.png 1272w, /__u/substackcdn.com/image/fetch/$s_!D00q!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1eea5432-c2a5-4026-bba4-730d598de5ca_1252x460.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!D00q!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1eea5432-c2a5-4026-bba4-730d598de5ca_1252x460.png" width="1252" height="460" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1eea5432-c2a5-4026-bba4-730d598de5ca_1252x460.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:460,&quot;width&quot;:1252,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:76252,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/196985127?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1eea5432-c2a5-4026-bba4-730d598de5ca_1252x460.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!D00q!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1eea5432-c2a5-4026-bba4-730d598de5ca_1252x460.png 424w, /__u/substackcdn.com/image/fetch/$s_!D00q!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1eea5432-c2a5-4026-bba4-730d598de5ca_1252x460.png 848w, /__u/substackcdn.com/image/fetch/$s_!D00q!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1eea5432-c2a5-4026-bba4-730d598de5ca_1252x460.png 1272w, /__u/substackcdn.com/image/fetch/$s_!D00q!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1eea5432-c2a5-4026-bba4-730d598de5ca_1252x460.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>We can sum these log-probabilities and divide by 5, if we want, to obtain approximately -0.673.</em></p><p><em>And, recalling the likelihoods we saw in the previous example section, we can compare this to the expected value weighted average calculation:</em></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!pppK!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F682a3bd1-c0e8-4ba8-90b1-cd9b738c2644_1836x1230.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!pppK!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F682a3bd1-c0e8-4ba8-90b1-cd9b738c2644_1836x1230.png 424w, /__u/substackcdn.com/image/fetch/$s_!pppK!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F682a3bd1-c0e8-4ba8-90b1-cd9b738c2644_1836x1230.png 848w, /__u/substackcdn.com/image/fetch/$s_!pppK!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F682a3bd1-c0e8-4ba8-90b1-cd9b738c2644_1836x1230.png 1272w, /__u/substackcdn.com/image/fetch/$s_!pppK!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F682a3bd1-c0e8-4ba8-90b1-cd9b738c2644_1836x1230.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!pppK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F682a3bd1-c0e8-4ba8-90b1-cd9b738c2644_1836x1230.png" width="1456" height="975" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/682a3bd1-c0e8-4ba8-90b1-cd9b738c2644_1836x1230.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:975,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:118409,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/196985127?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F682a3bd1-c0e8-4ba8-90b1-cd9b738c2644_1836x1230.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!pppK!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F682a3bd1-c0e8-4ba8-90b1-cd9b738c2644_1836x1230.png 424w, /__u/substackcdn.com/image/fetch/$s_!pppK!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F682a3bd1-c0e8-4ba8-90b1-cd9b738c2644_1836x1230.png 848w, /__u/substackcdn.com/image/fetch/$s_!pppK!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F682a3bd1-c0e8-4ba8-90b1-cd9b738c2644_1836x1230.png 1272w, /__u/substackcdn.com/image/fetch/$s_!pppK!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F682a3bd1-c0e8-4ba8-90b1-cd9b738c2644_1836x1230.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div></div><p>That is to say:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!_EVH!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3b77602-6cc4-44e2-8d3a-818eb09d7d9c_1836x512.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!_EVH!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3b77602-6cc4-44e2-8d3a-818eb09d7d9c_1836x512.png 424w, /__u/substackcdn.com/image/fetch/$s_!_EVH!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3b77602-6cc4-44e2-8d3a-818eb09d7d9c_1836x512.png 848w, /__u/substackcdn.com/image/fetch/$s_!_EVH!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3b77602-6cc4-44e2-8d3a-818eb09d7d9c_1836x512.png 1272w, /__u/substackcdn.com/image/fetch/$s_!_EVH!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3b77602-6cc4-44e2-8d3a-818eb09d7d9c_1836x512.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!_EVH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3b77602-6cc4-44e2-8d3a-818eb09d7d9c_1836x512.png" width="1456" height="406" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f3b77602-6cc4-44e2-8d3a-818eb09d7d9c_1836x512.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:406,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:53655,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/196985127?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3b77602-6cc4-44e2-8d3a-818eb09d7d9c_1836x512.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!_EVH!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3b77602-6cc4-44e2-8d3a-818eb09d7d9c_1836x512.png 424w, /__u/substackcdn.com/image/fetch/$s_!_EVH!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3b77602-6cc4-44e2-8d3a-818eb09d7d9c_1836x512.png 848w, /__u/substackcdn.com/image/fetch/$s_!_EVH!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3b77602-6cc4-44e2-8d3a-818eb09d7d9c_1836x512.png 1272w, /__u/substackcdn.com/image/fetch/$s_!_EVH!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff3b77602-6cc4-44e2-8d3a-818eb09d7d9c_1836x512.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>So the expected value of the log-probability for a randomly sampled data point equals the average of the log-probabilities. Interesting!</p><p>And not only interesting but significant, because <em>p&#770;_data</em> is an empirical distribution that becomes a better approximation of the true distribution, <em>p_data</em>,<em> </em>as the training data set grows. This is the <a href="https://en.wikipedia.org/wiki/Law_of_large_numbers">law of large numbers</a>.</p><p>And <em>p_data</em> is what we really want to model (although we can never do so perfectly).</p><p>So we swap this expected value into our &#8220;work-in-progress&#8221; equation:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!4BzA!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8acd5794-228d-4f4b-8c9e-17a123ffc8eb_1836x188.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!4BzA!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8acd5794-228d-4f4b-8c9e-17a123ffc8eb_1836x188.png 424w, /__u/substackcdn.com/image/fetch/$s_!4BzA!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8acd5794-228d-4f4b-8c9e-17a123ffc8eb_1836x188.png 848w, /__u/substackcdn.com/image/fetch/$s_!4BzA!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8acd5794-228d-4f4b-8c9e-17a123ffc8eb_1836x188.png 1272w, /__u/substackcdn.com/image/fetch/$s_!4BzA!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8acd5794-228d-4f4b-8c9e-17a123ffc8eb_1836x188.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!4BzA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8acd5794-228d-4f4b-8c9e-17a123ffc8eb_1836x188.png" width="1456" height="149" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8acd5794-228d-4f4b-8c9e-17a123ffc8eb_1836x188.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:149,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:32499,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/196985127?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8acd5794-228d-4f4b-8c9e-17a123ffc8eb_1836x188.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!4BzA!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8acd5794-228d-4f4b-8c9e-17a123ffc8eb_1836x188.png 424w, /__u/substackcdn.com/image/fetch/$s_!4BzA!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8acd5794-228d-4f4b-8c9e-17a123ffc8eb_1836x188.png 848w, /__u/substackcdn.com/image/fetch/$s_!4BzA!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8acd5794-228d-4f4b-8c9e-17a123ffc8eb_1836x188.png 1272w, /__u/substackcdn.com/image/fetch/$s_!4BzA!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8acd5794-228d-4f4b-8c9e-17a123ffc8eb_1836x188.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>But we have, in fact, arrived at the &#8220;real&#8221; equation. So we can remove the &#8220;work-in-progress&#8221; label, and pause to appreciate our progress (and the equation itself).</p><p>Time for a cup of tea &#9749;&#65039;</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://petalbyte.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading (Surprisingly Simple) Machine Learning Mathematics! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p></p>]]></content:encoded></item><item><title><![CDATA[Study with me: Thinking more carefully about random variables]]></title><description><![CDATA[To understand machine learning, we need to be comfortable working with random variables. Here's how I improved my understanding, with concrete examples and a few exercises.]]></description><link>https://petalbyte.substack.com/p/study-with-me-thinking-about-random</link><guid isPermaLink="false">https://petalbyte.substack.com/p/study-with-me-thinking-about-random</guid><dc:creator><![CDATA[Louise B]]></dc:creator><pubDate>Sat, 02 May 2026 18:35:11 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/5d4c295c-ac76-4bec-ad6e-f4967c4ee3a1_1200x630.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Every time I arrive at a new, more challenging topic in mathematics, I have to revisit some of the relevant fundamentals.</p><p>For example, when I started learning about stochastic gradient descent two weeks ago, I suddenly realised that my understanding of random variables wasn&#8217;t good enough.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://petalbyte.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading (Surprisingly Simple) Machine Learning Mathematics! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p>I knew the formal definition, but that was not making it any easier to parse the new textbook sections I was reading.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!zFJD!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3692392f-8b38-4a34-8f52-31f585cf4079_1154x217.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!zFJD!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3692392f-8b38-4a34-8f52-31f585cf4079_1154x217.png 424w, /__u/substackcdn.com/image/fetch/$s_!zFJD!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3692392f-8b38-4a34-8f52-31f585cf4079_1154x217.png 848w, /__u/substackcdn.com/image/fetch/$s_!zFJD!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3692392f-8b38-4a34-8f52-31f585cf4079_1154x217.png 1272w, /__u/substackcdn.com/image/fetch/$s_!zFJD!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3692392f-8b38-4a34-8f52-31f585cf4079_1154x217.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!zFJD!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3692392f-8b38-4a34-8f52-31f585cf4079_1154x217.png" width="1154" height="217" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3692392f-8b38-4a34-8f52-31f585cf4079_1154x217.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:217,&quot;width&quot;:1154,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:57862,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/196239112?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3692392f-8b38-4a34-8f52-31f585cf4079_1154x217.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!zFJD!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3692392f-8b38-4a34-8f52-31f585cf4079_1154x217.png 424w, /__u/substackcdn.com/image/fetch/$s_!zFJD!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3692392f-8b38-4a34-8f52-31f585cf4079_1154x217.png 848w, /__u/substackcdn.com/image/fetch/$s_!zFJD!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3692392f-8b38-4a34-8f52-31f585cf4079_1154x217.png 1272w, /__u/substackcdn.com/image/fetch/$s_!zFJD!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3692392f-8b38-4a34-8f52-31f585cf4079_1154x217.png 1456w" sizes="100vw" fetchpriority="high"></picture><div></div></div></a><figcaption class="image-caption"><em>Deisenroth et al, &#8220;Mathematics for Machine Learning&#8221;, 2020</em></figcaption></figure></div><p>Something can be <em>turned into</em> a random variable? That wasn&#8217;t mentioned in the formal definition! How and why would we do it?</p><p>I realised I needed to do some wider reading, revisiting the fundamentals armed with some new questions.</p><p>And here&#8217;s what I learned, when I thought I already knew enough.</p><h2>Not random, not a variable</h2><p>First, I reviewed definitions across a few textbooks and websites.</p><p>Deisenroth points out that the words &#8220;random&#8221; and &#8220;variable&#8221; must not be taken literally:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!ebOf!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F827cfc85-0580-4747-85c1-6e0003f45a3b_234x252.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!ebOf!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F827cfc85-0580-4747-85c1-6e0003f45a3b_234x252.png 424w, /__u/substackcdn.com/image/fetch/$s_!ebOf!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F827cfc85-0580-4747-85c1-6e0003f45a3b_234x252.png 848w, /__u/substackcdn.com/image/fetch/$s_!ebOf!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F827cfc85-0580-4747-85c1-6e0003f45a3b_234x252.png 1272w, /__u/substackcdn.com/image/fetch/$s_!ebOf!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F827cfc85-0580-4747-85c1-6e0003f45a3b_234x252.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!ebOf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F827cfc85-0580-4747-85c1-6e0003f45a3b_234x252.png" width="234" height="252" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/827cfc85-0580-4747-85c1-6e0003f45a3b_234x252.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:252,&quot;width&quot;:234,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:20541,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/196239112?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F827cfc85-0580-4747-85c1-6e0003f45a3b_234x252.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!ebOf!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F827cfc85-0580-4747-85c1-6e0003f45a3b_234x252.png 424w, /__u/substackcdn.com/image/fetch/$s_!ebOf!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F827cfc85-0580-4747-85c1-6e0003f45a3b_234x252.png 848w, /__u/substackcdn.com/image/fetch/$s_!ebOf!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F827cfc85-0580-4747-85c1-6e0003f45a3b_234x252.png 1272w, /__u/substackcdn.com/image/fetch/$s_!ebOf!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F827cfc85-0580-4747-85c1-6e0003f45a3b_234x252.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><em>Deisenroth et al, &#8220;Mathematics for Machine Learning&#8221;, 2020</em></figcaption></figure></div><p>And while Goodfellow gives us a definition that does use these words, he follows it with a descriptor that sounds very function-like to me.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!LDFh!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7321a78d-4baf-4099-9423-9d5fae4646df_890x50.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!LDFh!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7321a78d-4baf-4099-9423-9d5fae4646df_890x50.png 424w, /__u/substackcdn.com/image/fetch/$s_!LDFh!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7321a78d-4baf-4099-9423-9d5fae4646df_890x50.png 848w, /__u/substackcdn.com/image/fetch/$s_!LDFh!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7321a78d-4baf-4099-9423-9d5fae4646df_890x50.png 1272w, /__u/substackcdn.com/image/fetch/$s_!LDFh!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7321a78d-4baf-4099-9423-9d5fae4646df_890x50.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!LDFh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7321a78d-4baf-4099-9423-9d5fae4646df_890x50.png" width="890" height="50" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7321a78d-4baf-4099-9423-9d5fae4646df_890x50.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:50,&quot;width&quot;:890,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:15446,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/196239112?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7321a78d-4baf-4099-9423-9d5fae4646df_890x50.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!LDFh!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7321a78d-4baf-4099-9423-9d5fae4646df_890x50.png 424w, /__u/substackcdn.com/image/fetch/$s_!LDFh!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7321a78d-4baf-4099-9423-9d5fae4646df_890x50.png 848w, /__u/substackcdn.com/image/fetch/$s_!LDFh!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7321a78d-4baf-4099-9423-9d5fae4646df_890x50.png 1272w, /__u/substackcdn.com/image/fetch/$s_!LDFh!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7321a78d-4baf-4099-9423-9d5fae4646df_890x50.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption"><em>Goodfellow et al, &#8220;Deep Learning&#8221;, 2016</em></figcaption></figure></div><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!FoZq!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe1da6464-2be0-4663-b778-a36ca6442215_2010x280.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!FoZq!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe1da6464-2be0-4663-b778-a36ca6442215_2010x280.png 424w, /__u/substackcdn.com/image/fetch/$s_!FoZq!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe1da6464-2be0-4663-b778-a36ca6442215_2010x280.png 848w, /__u/substackcdn.com/image/fetch/$s_!FoZq!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe1da6464-2be0-4663-b778-a36ca6442215_2010x280.png 1272w, /__u/substackcdn.com/image/fetch/$s_!FoZq!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe1da6464-2be0-4663-b778-a36ca6442215_2010x280.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!FoZq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe1da6464-2be0-4663-b778-a36ca6442215_2010x280.png" width="728" height="101.5" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e1da6464-2be0-4663-b778-a36ca6442215_2010x280.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:false,&quot;imageSize&quot;:&quot;normal&quot;,&quot;height&quot;:203,&quot;width&quot;:1456,&quot;resizeWidth&quot;:728,&quot;bytes&quot;:188417,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/196239112?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe1da6464-2be0-4663-b778-a36ca6442215_2010x280.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:&quot;center&quot;,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!FoZq!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe1da6464-2be0-4663-b778-a36ca6442215_2010x280.png 424w, /__u/substackcdn.com/image/fetch/$s_!FoZq!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe1da6464-2be0-4663-b778-a36ca6442215_2010x280.png 848w, /__u/substackcdn.com/image/fetch/$s_!FoZq!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe1da6464-2be0-4663-b778-a36ca6442215_2010x280.png 1272w, /__u/substackcdn.com/image/fetch/$s_!FoZq!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe1da6464-2be0-4663-b778-a36ca6442215_2010x280.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption"><em>Goodfellow et al, &#8220;Deep Learning&#8221;, 2016</em></figcaption></figure></div><p>This is a good moment to return to the formal definition, and this diagram I found that pairs well with it (annotations mine):</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!P6SP!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1783070d-8076-4354-b0e9-3176ddddc7a9_1356x358.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!P6SP!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1783070d-8076-4354-b0e9-3176ddddc7a9_1356x358.png 424w, /__u/substackcdn.com/image/fetch/$s_!P6SP!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1783070d-8076-4354-b0e9-3176ddddc7a9_1356x358.png 848w, /__u/substackcdn.com/image/fetch/$s_!P6SP!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1783070d-8076-4354-b0e9-3176ddddc7a9_1356x358.png 1272w, /__u/substackcdn.com/image/fetch/$s_!P6SP!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1783070d-8076-4354-b0e9-3176ddddc7a9_1356x358.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!P6SP!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1783070d-8076-4354-b0e9-3176ddddc7a9_1356x358.png" width="1356" height="358" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1783070d-8076-4354-b0e9-3176ddddc7a9_1356x358.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:358,&quot;width&quot;:1356,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:101189,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/196239112?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1783070d-8076-4354-b0e9-3176ddddc7a9_1356x358.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!P6SP!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1783070d-8076-4354-b0e9-3176ddddc7a9_1356x358.png 424w, /__u/substackcdn.com/image/fetch/$s_!P6SP!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1783070d-8076-4354-b0e9-3176ddddc7a9_1356x358.png 848w, /__u/substackcdn.com/image/fetch/$s_!P6SP!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1783070d-8076-4354-b0e9-3176ddddc7a9_1356x358.png 1272w, /__u/substackcdn.com/image/fetch/$s_!P6SP!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1783070d-8076-4354-b0e9-3176ddddc7a9_1356x358.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><em><a href="https://mathworld.wolfram.com/RandomVariable.html">Source</a></em></figcaption></figure></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!txnR!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9e93e336-b305-426a-a86f-f3842ed472c6_1151x739.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!txnR!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9e93e336-b305-426a-a86f-f3842ed472c6_1151x739.png 424w, /__u/substackcdn.com/image/fetch/$s_!txnR!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9e93e336-b305-426a-a86f-f3842ed472c6_1151x739.png 848w, /__u/substackcdn.com/image/fetch/$s_!txnR!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9e93e336-b305-426a-a86f-f3842ed472c6_1151x739.png 1272w, /__u/substackcdn.com/image/fetch/$s_!txnR!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9e93e336-b305-426a-a86f-f3842ed472c6_1151x739.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!txnR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9e93e336-b305-426a-a86f-f3842ed472c6_1151x739.png" width="1151" height="739" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9e93e336-b305-426a-a86f-f3842ed472c6_1151x739.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:739,&quot;width&quot;:1151,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:116392,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/196239112?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9e93e336-b305-426a-a86f-f3842ed472c6_1151x739.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!txnR!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9e93e336-b305-426a-a86f-f3842ed472c6_1151x739.png 424w, /__u/substackcdn.com/image/fetch/$s_!txnR!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9e93e336-b305-426a-a86f-f3842ed472c6_1151x739.png 848w, /__u/substackcdn.com/image/fetch/$s_!txnR!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9e93e336-b305-426a-a86f-f3842ed472c6_1151x739.png 1272w, /__u/substackcdn.com/image/fetch/$s_!txnR!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9e93e336-b305-426a-a86f-f3842ed472c6_1151x739.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><em><a href="https://nrich.maths.org/articles/what-random-variable-really">Source</a></em></figcaption></figure></div><p>Here, the random variable, X, is shown visually as a function mapping one space to another.</p><p>So we see how X is doing the job of telling us what states, or outputs, are possible, as Goodfellow describes.</p><p>In other words:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!lwlq!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febb257a8-8c98-4bb7-a48c-3688e5419518_1216x116.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!lwlq!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febb257a8-8c98-4bb7-a48c-3688e5419518_1216x116.png 424w, /__u/substackcdn.com/image/fetch/$s_!lwlq!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febb257a8-8c98-4bb7-a48c-3688e5419518_1216x116.png 848w, /__u/substackcdn.com/image/fetch/$s_!lwlq!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febb257a8-8c98-4bb7-a48c-3688e5419518_1216x116.png 1272w, /__u/substackcdn.com/image/fetch/$s_!lwlq!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febb257a8-8c98-4bb7-a48c-3688e5419518_1216x116.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!lwlq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febb257a8-8c98-4bb7-a48c-3688e5419518_1216x116.png" width="1216" height="116" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ebb257a8-8c98-4bb7-a48c-3688e5419518_1216x116.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:116,&quot;width&quot;:1216,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:28712,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/196239112?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febb257a8-8c98-4bb7-a48c-3688e5419518_1216x116.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!lwlq!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febb257a8-8c98-4bb7-a48c-3688e5419518_1216x116.png 424w, /__u/substackcdn.com/image/fetch/$s_!lwlq!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febb257a8-8c98-4bb7-a48c-3688e5419518_1216x116.png 848w, /__u/substackcdn.com/image/fetch/$s_!lwlq!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febb257a8-8c98-4bb7-a48c-3688e5419518_1216x116.png 1272w, /__u/substackcdn.com/image/fetch/$s_!lwlq!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febb257a8-8c98-4bb7-a48c-3688e5419518_1216x116.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption"><em><a href="https://quickmathintuitions.org/random-variables-why-are-they-needed/">Source</a></em></figcaption></figure></div><p>For anyone else who finds that concrete examples are the best scaffolding for intuition, let&#8217;s imagine a simple 6-point dataset:</p><div id="datawrapper-iframe" class="datawrapper-wrap outer" data-attrs="{&quot;url&quot;:&quot;https://datawrapper.dwcdn.net/sE3qb/1/&quot;,&quot;thumbnail_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3ed28392-3f35-4aa8-8e9c-4d604ec4f6ad_1220x250.png&quot;,&quot;thumbnail_url_full&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9ff7c77a-2cdf-4660-82a3-734118771a2f_1220x250.png&quot;,&quot;height&quot;:116,&quot;title&quot;:&quot;Created with Datawrapper&quot;,&quot;description&quot;:&quot;&quot;,&quot;belowTheFold&quot;:true}" data-component-name="DatawrapperToDOM"><iframe id="iframe-datawrapper" class="datawrapper-iframe" src="https://datawrapper.dwcdn.net/sE3qb/1/" width="730" height="116" frameborder="0" scrolling="no" loading="lazy"></iframe><script type="text/javascript">!function(){"use strict";window.addEventListener("message",(function(e){if(void 0!==e.data["datawrapper-height"]){var t=document.querySelectorAll("iframe");for(var a in e.data["datawrapper-height"])for(var r=0;r<t.length;r++){if(t[r].contentWindow===e.source)t[r].style.height=e.data["datawrapper-height"][a]+"px"}}}))}();</script></div><p><em>(You might recognise these numbers from my <a href="/__u/petalbyte.substack.com/p/study-with-me-random-variables-and">previous post on stochastic gradient descent</a>. They are just being used as example values here, but it&#8217;s a fun callback (for me, at least).)</em></p><p>Let X represent the random index drawn when we sample one data point from it.</p><p>Then X is the function that maps a number between 1 and 6 to a data point value.</p><p>If we draw a sample and observe that n = 3, then the data point value is -15.</p><p>The question X represents is, &#8220;What is the value of a data point sampled from this dataset?&#8221;</p><div class="callout-block" data-callout="true"><h5>Exercises</h5><p>Following the diagram shown above, draw a function diagram for each of the following random variables:</p><ol><li><p>X = the number rolled on a fair 6-sided die</p></li><li><p>Y = the number of heads in two coin tosses</p></li><li><p>Z = 1 if a rolled die shows an even number, 0 otherwise</p></li></ol><p>For each of the three diagrams, what question does this random variable encode numerically?</p></div><h2>What random variables are for</h2><p>While I found it interesting to carefully review the definition of a random variable, I always need to put abstract ideas into context to actually deepen my understanding.</p><p>Specifically, I always have the common student question: Why is this important?</p><p>In this case: Why do we want these functions? What do they allow us to do?</p><p>As a software developer, I found the following suggestion interesting:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!Ihjh!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5828fdb-62ce-4200-a9a4-c07d0a67c2ec_1025x100.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!Ihjh!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5828fdb-62ce-4200-a9a4-c07d0a67c2ec_1025x100.png 424w, /__u/substackcdn.com/image/fetch/$s_!Ihjh!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5828fdb-62ce-4200-a9a4-c07d0a67c2ec_1025x100.png 848w, /__u/substackcdn.com/image/fetch/$s_!Ihjh!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5828fdb-62ce-4200-a9a4-c07d0a67c2ec_1025x100.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Ihjh!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5828fdb-62ce-4200-a9a4-c07d0a67c2ec_1025x100.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!Ihjh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5828fdb-62ce-4200-a9a4-c07d0a67c2ec_1025x100.png" width="1025" height="100" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a5828fdb-62ce-4200-a9a4-c07d0a67c2ec_1025x100.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:100,&quot;width&quot;:1025,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:29763,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/196239112?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5828fdb-62ce-4200-a9a4-c07d0a67c2ec_1025x100.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!Ihjh!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5828fdb-62ce-4200-a9a4-c07d0a67c2ec_1025x100.png 424w, /__u/substackcdn.com/image/fetch/$s_!Ihjh!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5828fdb-62ce-4200-a9a4-c07d0a67c2ec_1025x100.png 848w, /__u/substackcdn.com/image/fetch/$s_!Ihjh!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5828fdb-62ce-4200-a9a4-c07d0a67c2ec_1025x100.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Ihjh!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5828fdb-62ce-4200-a9a4-c07d0a67c2ec_1025x100.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption"><em><a href="https://medium.com/@johnswyou/random-variable-or-observation-5aaddb7bc4a5">Source</a></em></figcaption></figure></div><p>In programming, it&#8217;s common to have an entity that will output something when instructed to but, in itself, just represents the ability to obtain an output.</p><p>But this idea became more useful when I was reminded of something it doesn&#8217;t explicitly mention: We do actually know quite a lot about the values that a random variable might take.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!AZMN!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb410c751-70b5-4d7b-b6da-6f176d28411b_930x199.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!AZMN!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb410c751-70b5-4d7b-b6da-6f176d28411b_930x199.png 424w, /__u/substackcdn.com/image/fetch/$s_!AZMN!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb410c751-70b5-4d7b-b6da-6f176d28411b_930x199.png 848w, /__u/substackcdn.com/image/fetch/$s_!AZMN!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb410c751-70b5-4d7b-b6da-6f176d28411b_930x199.png 1272w, /__u/substackcdn.com/image/fetch/$s_!AZMN!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb410c751-70b5-4d7b-b6da-6f176d28411b_930x199.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!AZMN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb410c751-70b5-4d7b-b6da-6f176d28411b_930x199.png" width="930" height="199" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b410c751-70b5-4d7b-b6da-6f176d28411b_930x199.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:199,&quot;width&quot;:930,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:82341,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/196239112?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb410c751-70b5-4d7b-b6da-6f176d28411b_930x199.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!AZMN!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb410c751-70b5-4d7b-b6da-6f176d28411b_930x199.png 424w, /__u/substackcdn.com/image/fetch/$s_!AZMN!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb410c751-70b5-4d7b-b6da-6f176d28411b_930x199.png 848w, /__u/substackcdn.com/image/fetch/$s_!AZMN!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb410c751-70b5-4d7b-b6da-6f176d28411b_930x199.png 1272w, /__u/substackcdn.com/image/fetch/$s_!AZMN!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb410c751-70b5-4d7b-b6da-6f176d28411b_930x199.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption"><em><a href="https://recompilermag.com/issues/issue-2/why-random-variables-are-neither-random-nor-variable/">Source</a></em></figcaption></figure></div><p>In other words, random variables, as functions, are meant to make it possible to work in a normal mathematical way with values that we don&#8217;t exactly know (yet), but which we do know certain things about.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!JLe0!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2eaddb91-c8af-49dc-aad6-7d8a97c30058_1146x121.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!JLe0!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2eaddb91-c8af-49dc-aad6-7d8a97c30058_1146x121.png 424w, /__u/substackcdn.com/image/fetch/$s_!JLe0!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2eaddb91-c8af-49dc-aad6-7d8a97c30058_1146x121.png 848w, /__u/substackcdn.com/image/fetch/$s_!JLe0!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2eaddb91-c8af-49dc-aad6-7d8a97c30058_1146x121.png 1272w, /__u/substackcdn.com/image/fetch/$s_!JLe0!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2eaddb91-c8af-49dc-aad6-7d8a97c30058_1146x121.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!JLe0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2eaddb91-c8af-49dc-aad6-7d8a97c30058_1146x121.png" width="1146" height="121" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2eaddb91-c8af-49dc-aad6-7d8a97c30058_1146x121.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:121,&quot;width&quot;:1146,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:64394,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/196239112?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2eaddb91-c8af-49dc-aad6-7d8a97c30058_1146x121.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!JLe0!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2eaddb91-c8af-49dc-aad6-7d8a97c30058_1146x121.png 424w, /__u/substackcdn.com/image/fetch/$s_!JLe0!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2eaddb91-c8af-49dc-aad6-7d8a97c30058_1146x121.png 848w, /__u/substackcdn.com/image/fetch/$s_!JLe0!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2eaddb91-c8af-49dc-aad6-7d8a97c30058_1146x121.png 1272w, /__u/substackcdn.com/image/fetch/$s_!JLe0!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2eaddb91-c8af-49dc-aad6-7d8a97c30058_1146x121.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption"><em><a href="http://dsw.users.sonic.net/entropy.html">Source</a></em></figcaption></figure></div><p>Returning to our 6-point dataset: We know X will only ever return one of six indices, and therefore one of six data point values. And we know each is equally likely.</p><p>So while we don&#8217;t know what value we&#8217;ll get until we sample, we do know what we <em>might</em> get (and what we definitely would not).</p><div class="callout-block" data-callout="true"><h5>Exercises</h5><p>Look back at the first exercise in the previous section, where you defined X as the number rolled on a fair 6-sided die.</p><p>The mapping diagram is very simple! But there are some interesting questions to ask:</p><p>1. What values can X take, and with what probability?</p><p>2. What is the expected value of X? <em>(The expected value is a weighted average of the possible values, where the weights are the probabilities; for a fair 6-sided die, each of the six values has the probability 1/6)</em></p></div><h2>One practical tip</h2><p>One of the best things I came across in my reading on this topic was this advice:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!oSy7!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76a673ad-63ce-4a6d-97b6-5b75f27e6d6c_1146x317.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!oSy7!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76a673ad-63ce-4a6d-97b6-5b75f27e6d6c_1146x317.png 424w, /__u/substackcdn.com/image/fetch/$s_!oSy7!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76a673ad-63ce-4a6d-97b6-5b75f27e6d6c_1146x317.png 848w, /__u/substackcdn.com/image/fetch/$s_!oSy7!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76a673ad-63ce-4a6d-97b6-5b75f27e6d6c_1146x317.png 1272w, /__u/substackcdn.com/image/fetch/$s_!oSy7!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76a673ad-63ce-4a6d-97b6-5b75f27e6d6c_1146x317.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!oSy7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76a673ad-63ce-4a6d-97b6-5b75f27e6d6c_1146x317.png" width="1146" height="317" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/76a673ad-63ce-4a6d-97b6-5b75f27e6d6c_1146x317.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:317,&quot;width&quot;:1146,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:61895,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/196239112?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76a673ad-63ce-4a6d-97b6-5b75f27e6d6c_1146x317.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!oSy7!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76a673ad-63ce-4a6d-97b6-5b75f27e6d6c_1146x317.png 424w, /__u/substackcdn.com/image/fetch/$s_!oSy7!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76a673ad-63ce-4a6d-97b6-5b75f27e6d6c_1146x317.png 848w, /__u/substackcdn.com/image/fetch/$s_!oSy7!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76a673ad-63ce-4a6d-97b6-5b75f27e6d6c_1146x317.png 1272w, /__u/substackcdn.com/image/fetch/$s_!oSy7!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76a673ad-63ce-4a6d-97b6-5b75f27e6d6c_1146x317.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><em><a href="https://medium.com/@johnswyou/random-variable-or-observation-5aaddb7bc4a5">Source</a></em></figcaption></figure></div><p>It didn&#8217;t fit into either of the previous sections about the definition and purpose of random variables but, IMO, deserves its own space here. Any time another student can share a hard-won insight from their time studying a topic, I&#8217;m listening!</p><p>Referring briefly back to our concrete example: We know X is the random variable, and -15 is a possible realisation.</p><p>And if, after this whole journey, we look again at the snippet from Deisenroth&#8217;s book, the implications of a parameter vector being turned into a random variable are easier to appreciate.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!zFJD!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3692392f-8b38-4a34-8f52-31f585cf4079_1154x217.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!zFJD!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3692392f-8b38-4a34-8f52-31f585cf4079_1154x217.png 424w, /__u/substackcdn.com/image/fetch/$s_!zFJD!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3692392f-8b38-4a34-8f52-31f585cf4079_1154x217.png 848w, /__u/substackcdn.com/image/fetch/$s_!zFJD!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3692392f-8b38-4a34-8f52-31f585cf4079_1154x217.png 1272w, /__u/substackcdn.com/image/fetch/$s_!zFJD!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_webp, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3692392f-8b38-4a34-8f52-31f585cf4079_1154x217.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!zFJD!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3692392f-8b38-4a34-8f52-31f585cf4079_1154x217.png" width="1154" height="217" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3692392f-8b38-4a34-8f52-31f585cf4079_1154x217.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:217,&quot;width&quot;:1154,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:57862,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://petalbyte.substack.com/i/196239112?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3692392f-8b38-4a34-8f52-31f585cf4079_1154x217.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="/__u/substackcdn.com/image/fetch/$s_!zFJD!, /__u/petalbyte.substack.com/w_424, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3692392f-8b38-4a34-8f52-31f585cf4079_1154x217.png 424w, /__u/substackcdn.com/image/fetch/$s_!zFJD!, /__u/petalbyte.substack.com/w_848, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3692392f-8b38-4a34-8f52-31f585cf4079_1154x217.png 848w, /__u/substackcdn.com/image/fetch/$s_!zFJD!, /__u/petalbyte.substack.com/w_1272, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3692392f-8b38-4a34-8f52-31f585cf4079_1154x217.png 1272w, /__u/substackcdn.com/image/fetch/$s_!zFJD!, /__u/petalbyte.substack.com/w_1456, /__u/petalbyte.substack.com/c_limit, /__u/petalbyte.substack.com/f_auto, /__u/petalbyte.substack.com/q_auto:good, /__u/petalbyte.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3692392f-8b38-4a34-8f52-31f585cf4079_1154x217.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption"><em>Deisenroth et al, &#8220;Mathematics for Machine Learning&#8221;, 2020</em></figcaption></figure></div><p>&#952; was an unknown but fixed quantity that we wanted to estimate, but now we know it is a function associated with a range of values and their probabilities.</p><p>And this paves the way for a (slightly!) easier time studying Bayesian linear regression.</p><div class="callout-block" data-callout="true"><h5>Exercise</h5><p>Recall the random variable X from the previous exercise. Imagine you roll the die and get a 4.</p><p>Which of the following statements are about X (the random variable) and which are about the realisation (the 4)?</p><p>&#9;1. &#8220;Its value is 4&#8221;</p><p>&#9;2. &#8220;Its expected value is 3.5&#8221;</p><p>&#9;3. &#8220;It can take any integer value from 1 to 6&#8221;</p><p>&#9;4. &#8220;It is greater than 3&#8221;</p></div><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://petalbyte.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading (Surprisingly Simple) Machine Learning Mathematics! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p></p>]]></content:encoded></item><item><title><![CDATA[Study with me: Random variables and stochastic gradient descent]]></title><description><![CDATA[A simple but surprisingly useful fact is that, if you roll two dice and average the results, the expected value is exactly the same as if you just rolled one.]]></description><link>https://petalbyte.substack.com/p/study-with-me-random-variables-and</link><guid isPermaLink="false">https://petalbyte.substack.com/p/study-with-me-random-variables-and</guid><dc:creator><![CDATA[Louise B]]></dc:creator><pubDate>Sat, 25 Apr 2026 08:19:55 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/f6c29587-2987-428c-a5c3-af6ae65064a2_1200x630.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Random variables are a special kind of function, representing a value that we don&#8217;t yet know exactly.</p><p>(But, importantly, we do know the range of values it might return, and the likelihood of it returning any particular one of them.)</p><p>A random variable has an <strong>expected value</strong>, which is simply a weighted average of all the possible values that the random variable might return.</p><p>For example, if a random variable represents a roll of a fair 6-sided die, the expected value is:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\frac{1+2+3+4+5+6}{6}=3.5&quot;,&quot;id&quot;:&quot;MNRTUWPMUI&quot;}" data-component-name="LatexBlockToDOM"></div><p>The expected value operator, &#120124;[.], has the property of linearity. For any random variables X and Y:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\mathbb{E}[X + Y] = \\mathbb{E}[X]+\\mathbb{E}[Y] &quot;,&quot;id&quot;:&quot;OBUBQMJMKF&quot;}" data-component-name="LatexBlockToDOM"></div><p>&#8230;which is nice and simple to consider! But what can it help us understand in machine learning?</p><p><em>(Sidenote: While trying to answer this question, I realised I didn&#8217;t have a particularly nuanced understanding of random variables, so I did a bunch of extra reading about that first. It was a worthwhile diversion! I&#8217;ll write up my findings to post here next week, and <a href="https://www.instagram.com/p/DXY3IjBjDmy/">here&#8217;s</a> a shorter post on Instagram in the meantime.)</em></p><p>Back to the present topic: The linearity of expectation, and how surprisingly easily we can see its importance in a machine learning technique called <strong>stochastic gradient descent</strong>.</p><h2>The problem: Training a regression model can get expensive</h2><p>I think the easiest way to understand this is to look at a concrete example, even if the example is greatly simplified.</p><p>So let&#8217;s imagine we are fitting a line, <em>&#375; = wx</em>, to a data set of just six points:</p><div id="datawrapper-iframe" class="datawrapper-wrap outer" data-attrs="{&quot;url&quot;:&quot;https://datawrapper.dwcdn.net/Uy7ce/3/&quot;,&quot;thumbnail_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f1af835b-73c2-4fd3-b88e-c94d264d0077_1220x620.png&quot;,&quot;thumbnail_url_full&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d074a0ae-9e9f-4f9c-ac4c-c31a649ca3ab_1220x620.png&quot;,&quot;height&quot;:303,&quot;title&quot;:&quot;Created with Datawrapper&quot;,&quot;description&quot;:&quot;&quot;,&quot;belowTheFold&quot;:true}" data-component-name="DatawrapperToDOM"><iframe id="iframe-datawrapper" class="datawrapper-iframe" src="https://datawrapper.dwcdn.net/Uy7ce/3/" width="730" height="303" frameborder="0" scrolling="no" loading="lazy"></iframe><script type="text/javascript">!function(){"use strict";window.addEventListener("message",(function(e){if(void 0!==e.data["datawrapper-height"]){var t=document.querySelectorAll("iframe");for(var a in e.data["datawrapper-height"])for(var r=0;r<t.length;r++){if(t[r].contentWindow===e.source)t[r].style.height=e.data["datawrapper-height"][a]+"px"}}}))}();</script></div><p>We can see from the table that <em>w</em> should be around 2, but we&#8217;ll imagine that it&#8217;s not so obvious.</p><p>Our first guess will be that <em>w = 1.5</em>. And we&#8217;d like to improve it by taking a gradient descent step. That is, we&#8217;d like to see whether our next guess should be higher or lower.</p><p>To keep things simple, we will choose a classic squared error to represent the loss (&#8220;wrongness&#8221;) of our current guess for <em>w</em> per data point:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;L_n = (wx_n - y_n)^2&quot;,&quot;id&quot;:&quot;ANUJQKTFOS&quot;}" data-component-name="LatexBlockToDOM"></div><p>Our objective function will be the sum of all of these losses:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;L(w) = \\sum{L_n(w)}&quot;,&quot;id&quot;:&quot;VNNXGGGVGI&quot;}" data-component-name="LatexBlockToDOM"></div><p>(The objective function provides an overall score for the model&#8217;s predictions.)</p><p>As our goal is to reduce loss using gradient descent, we will compute the gradient of the loss for each data point.</p><p>The gradient is a derivative, because it&#8217;s the slope of the function at that point that will tell us whether we&#8217;re moving in the right direction:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\nabla{L_n(w)} = \\frac{\\mathrm{d}L_n}{\\mathrm{d}w} = 2x_n(wx_n - y_n)&quot;,&quot;id&quot;:&quot;NJBSGEIOWD&quot;}" data-component-name="LatexBlockToDOM"></div><p>Let&#8217;s make this all concrete with an updated table, to see what we get from our first gradient descent iteration.</p><div id="datawrapper-iframe" class="datawrapper-wrap outer" data-attrs="{&quot;url&quot;:&quot;https://datawrapper.dwcdn.net/dxk7u/1/&quot;,&quot;thumbnail_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/329b2b2e-9074-47b9-afe1-46b83f3a84c4_1220x628.png&quot;,&quot;thumbnail_url_full&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/864822f7-8831-442c-a8df-d91478568713_1220x628.png&quot;,&quot;height&quot;:306,&quot;title&quot;:&quot;Created with Datawrapper&quot;,&quot;description&quot;:&quot;&quot;,&quot;belowTheFold&quot;:true}" data-component-name="DatawrapperToDOM"><iframe id="iframe-datawrapper" class="datawrapper-iframe" src="https://datawrapper.dwcdn.net/dxk7u/1/" width="730" height="306" frameborder="0" scrolling="no" loading="lazy"></iframe><script type="text/javascript">!function(){"use strict";window.addEventListener("message",(function(e){if(void 0!==e.data["datawrapper-height"]){var t=document.querySelectorAll("iframe");for(var a in e.data["datawrapper-height"])for(var r=0;r<t.length;r++){if(t[r].contentWindow===e.source)t[r].style.height=e.data["datawrapper-height"][a]+"px"}}}))}();</script></div><p>We see each data point&#8217;s gradient is negative, which makes sense because our current guess, <em>w = 1.5</em>, is too small.</p><p>(Reminder that gradient descent involves stepping in the opposite direction of the calculated gradient, so a negative gradient means we should go in the positive direction for our next parameter value.)</p><p>Since our objective function is the sum of all of these losses, we have that our &#8220;full-batch gradient&#8221; is <em>&#9661;L(w) = -131</em>.</p><p>And that means our average gradient per data point is approximately -21.83, which we&#8217;ll come back to in the next section.</p><p>But to conclude this section first: If we needed to repeat a set of calculations like this for a real-world data set that contained millions of points, even one step of gradient descent would be compute-intensive, and we might need thousands of steps.</p><h2>A solution: Random sampling</h2><p>Let&#8217;s remember that the average gradient per data point in our example data set is approximately -21.83. We found this by calculating the full sum of gradients across all of the data points. But we&#8217;d like to cut down the computational work.</p><p>Can we estimate that average using a &#8220;mini-batch&#8221; of data points, to save us having to do so much work? Let&#8217;s see.</p><p>We&#8217;ll say we can only afford to find the sum of gradients for two data points, so our mini-batch size is 2.</p><p>We can randomly pick two indices from the first column of our table. We draw {2, 5}.</p><div id="datawrapper-iframe" class="datawrapper-wrap outer" data-attrs="{&quot;url&quot;:&quot;https://datawrapper.dwcdn.net/dxk7u/2/&quot;,&quot;thumbnail_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7e664693-777d-4f58-9eb4-1ca0305d9a1c_1220x628.png&quot;,&quot;thumbnail_url_full&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b5a68bae-481a-4dbf-9556-639b753ecf1f_1220x628.png&quot;,&quot;height&quot;:310,&quot;title&quot;:&quot;Created with Datawrapper&quot;,&quot;description&quot;:&quot;&quot;,&quot;belowTheFold&quot;:true}" data-component-name="DatawrapperToDOM"><iframe id="iframe-datawrapper" class="datawrapper-iframe" src="https://datawrapper.dwcdn.net/dxk7u/2/" width="730" height="310" frameborder="0" scrolling="no" loading="lazy"></iframe><script type="text/javascript">!function(){"use strict";window.addEventListener("message",(function(e){if(void 0!==e.data["datawrapper-height"]){var t=document.querySelectorAll("iframe");for(var a in e.data["datawrapper-height"])for(var r=0;r<t.length;r++){if(t[r].contentWindow===e.source)t[r].style.height=e.data["datawrapper-height"][a]+"px"}}}))}();</script></div><p>So the average gradient is:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot; \\frac{-8+(-35)}{2} = -21.5&quot;,&quot;id&quot;:&quot;XFMQEYFVLL&quot;}" data-component-name="LatexBlockToDOM"></div><p>&#8230;which is close to the full-batch gradient average.</p><p>But if we had drawn {1, 3}, we&#8217;d have an average mini-batch gradient of:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot; \\frac{-1+(-15)}{2} = -8&quot;,&quot;id&quot;:&quot;KXMCYKYSKI&quot;}" data-component-name="LatexBlockToDOM"></div><p>&#8230;which is not close to the full-batch gradient average. So we see that individual mini-batches can be noisy.</p><p>However, since we&#8217;re now randomly sampling from the data points, each drawn gradient <em>&#9661;L_{n_i}</em> is a random variable. It&#8217;s equally likely to be any of the six values in the fifth column of our table above.</p><p>And most importantly, <em><strong>its expected value is just the average of all of these possible values</strong></em>.</p><p>That is to say:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\mathbb{E}[&#8711;L_{n_i}] = \\frac{&#8722;1 + (&#8722;8) + (&#8722;15) + (&#8722;24) + (&#8722;35) + (&#8722;48)}{6} = &#8722;\\frac{131}{6} \\approx &#8722;21.83&quot;,&quot;id&quot;:&quot;PQDSBYEMIZ&quot;}" data-component-name="LatexBlockToDOM"></div><p>We were calculating the average of a mini-batch gradient as:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot; \\frac{\\nabla L_{n_1} + \\nabla L_{n_2}}{2}&quot;,&quot;id&quot;:&quot;NIUQWCKZZV&quot;}" data-component-name="LatexBlockToDOM"></div><p>&#8230;where n_1 and n_2 are the indices of our two sampled data points.</p><p>So the expected value of that average is:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\frac{\\mathbb{E}[\\nabla L_{n_1} + \\nabla L_{n_2}]}{2}\n&quot;,&quot;id&quot;:&quot;SGKEDLBNXG&quot;}" data-component-name="LatexBlockToDOM"></div><p>And, by the linearity of expected value, we have that this equals:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\frac{\\mathbb{E}[&#8711;L_{n_1}] + \\mathbb{E}[&#8711;L_{n_2}]}{2} = \\frac{&#8722;21.83 + (&#8722;21.83)}{2} = &#8722;21.83.&quot;,&quot;id&quot;:&quot;XRSWUETJPO&quot;}" data-component-name="LatexBlockToDOM"></div><p>So we see that the expected value of the mini-batch average gradient is equal to the full-batch average gradient.</p><p>And this all means that the noise we see in the random sampling approach will, over many gradient descent steps, average out so that we still head in the right direction. But using far fewer computations than a full-batch method.</p><p>It&#8217;s interesting how some quite simple ideas work together here for such a useful result!</p><h3>Next Steps</h3><ul><li><p>You can test out the ideas here yourself by calculating the expected value of the average mini-batch gradient for our example data set, using a batch size of 3 to see how the expected value </p></li><li><p>If needed, you can strengthen your statistics and probability fundamentals using free resources like <a href="https://www.khanacademy.org/math/statistics-probability">KhanAcademy.org</a>,  <a href="https://pll.harvard.edu/catalog?topics%5B708%5D=708&amp;price%5B1%5D=1&amp;max_price=&amp;start_date=&amp;difficulty%5Bintroductory%5D=introductory&amp;keywords=&amp;available_anytime=0&amp;url=">Harvard&#8217;s free courses</a>, and <a href="https://ocw.mit.edu/search/?d=Mathematics&amp;l=Undergraduate&amp;q=statistics">MIT OpenCourseWare</a></p></li><li><p>Learn more about gradient descent using resources like <a href="https://www.khanacademy.org/math/multivariable-calculus/applications-of-multivariable-derivatives/optimizing-multivariable-functions/a/what-is-gradient-descent">KhanAcademy (free)</a>, <a href="https://www.coursera.org/learn/machine-learning">Coursera (some free)</a>, and <a href="https://developers.google.com/machine-learning/crash-course/linear-regression">Google&#8217;s Crash Course</a> (free)</p></li><li><p>Start implementing your own stochastic gradient descent learning routine in a linear regression model by following <a href="https://scikit-learn.org/stable/modules/sgd.html#regression">a tutorial on scikit-learn.org</a>, which will handle the calculations for you (but you&#8217;ll know how and why they work!)</p></li></ul><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://petalbyte.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading (Surprisingly Simple) Machine Learning Mathematics! Subscribe for free to receive new posts when published.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h3>References:</h3><ul><li><p><a href="https://en.wikipedia.org/wiki/Expected_value">https://en.wikipedia.org/wiki/Expected_value</a></p></li><li><p>Deisenroth et al, &#8220;Mathematics for Machine Learning&#8221;, 2020</p></li><li><p>Goodfellow et al, &#8220;Deep Learning&#8221;, 2016</p></li><li><p>James et al, &#8220;An Introduction to Statistical Learning&#8221;, 2023</p></li><li><p>The &#8220;Mathematics for Machine Learning&#8221; course by MathAcademy</p></li></ul>]]></content:encoded></item></channel></rss>