<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Susie S.Y. Li on Medium]]></title>
        <description><![CDATA[Stories by Susie S.Y. Li on Medium]]></description>
        <link>https://medium.com/@susiesyli?source=rss-2b9882509386------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*X9YUKnYdoT8ZimT0BncZHg.png</url>
            <title>Stories by Susie S.Y. Li on Medium</title>
            <link>https://medium.com/@susiesyli?source=rss-2b9882509386------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 05:39:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@susiesyli/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Monte Carlo Approximation Methods: Which one should you choose and when?]]></title>
            <link>https://medium.com/data-science/monte-carlo-approximation-methods-which-one-should-you-choose-and-when-886a379fb6b?source=rss-2b9882509386------2</link>
            <guid isPermaLink="false">https://medium.com/p/886a379fb6b</guid>
            <category><![CDATA[statistical-learning]]></category>
            <category><![CDATA[deep-dives]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[markov-chains]]></category>
            <category><![CDATA[monte-carlo]]></category>
            <dc:creator><![CDATA[Susie S.Y. Li]]></dc:creator>
            <pubDate>Fri, 25 Aug 2023 21:43:11 GMT</pubDate>
            <atom:updated>2024-04-30T03:22:43.405Z</atom:updated>
            <content:encoded><![CDATA[<h4>Is it Inverse Transformation, Random Walk Metropolis-Hastings, or Gibbs? An analysis focusing on the mathematical foundation, Python implementation from scratch, and pros/cons of each method</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*i62VIe6gL38Dfl0u" /><figcaption>Photo by <a href="https://unsplash.com/@jhonkasalo?utm_source=medium&amp;utm_medium=referral">Joakim Honkasalo</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Introduction to Approximation Sampling</h3><blockquote>For most probabilistic models of practical interest, exact inference is intractable, and so we have to resort to some form of approximation.</blockquote><blockquote>— Pattern Recognition and Machine Learning¹</blockquote><p>Since deterministic inference is often intractable with probabilistic models as we saw just now, we now turn to approximation methods based on numerical sampling, which are known as <strong>Monte Carlo</strong> techniques. The key question we will look at with these methods is computing the expectation of a target function <em>f(z) </em>given a probability distribution <em>p(z)</em>. Recall that the simple definition of expectation is given as an integral:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sjsYsQA4LZcwcv6oixr7Jg.png" /><figcaption>Source: PRML¹ Eq. 11.1</figcaption></figure><p>As we will see, these integrals are too<strong> computationally complex</strong>, so we will turn to <strong>sampling methods </strong>in this article.</p><p>In this article, we will look at 3 core sampling methods: <strong>inverse transformation</strong>, Markov chain Monte Carlo (MCMC), and <strong>Gibbs</strong> Sampling. By understanding the underlying statistical properties and computational requirements of these methods, we will learn that:</p><ul><li><strong>Inverse transformation sampling</strong> is best for simulating data with high accuracy from known and simple distributions, particularly in low dimensions.</li><li><strong>Random Walk Metropolis-Hastings </strong>is best for complex, multi-modal, or unknown distributions, where global exploration and/or convergence is a priority; specifically, the <strong>Metropolis</strong> algorithm — a specific instance of Metropolis-Hastings — can be used for symmetric distributions.</li><li><strong>Gibbs Sampling</strong> is best for high-dimensional problems where conditional distributions are easy to sample from, and efficiency is a priority.</li></ul><h3>Table of Contents</h3><ol><li><a href="#e96f">Inverse Transform Sampling</a><br>• <a href="#93fc">How does the algorithm work?</a><br>• <a href="#d1ff">Python Implementation</a><br>• <a href="#c20f">Prerequisites</a><br>• <a href="#9cdd">Pros &amp; cons</a></li><li><a href="#d20d">Markov Chain Monte Carlo</a><br>• <a href="#2847">Metropolis-Hastings Algorithm</a><br>• <a href="#bfed">Special Instance: Metropolis Algorithm for Symmetrical Distribution</a><br>• <a href="#76a3">Pros/Cons</a></li><li><a href="#c3b6">Gibbs</a><br>• <a href="#42ee">Algorithm</a><br>• <a href="#cf29">Conditions</a><br>• <a href="#0cf9">Gibbs’ relationship with Metropolis-Hastings</a></li><li><a href="#e6ac">Comparison: Pros/Cons of Transformation vs. Met-Hastings vs. Gibbs</a></li></ol><h3>1. Transformation Method: Inverse CDF</h3><p>Inverse Transform Sampling, as its name suggests, uses the inverse cumulative distribution function (CDF) of a target distribution to generate random numbers that follow a desired distribution. The basic idea is:</p><ol><li><strong>Generate a Uniform Random Number</strong>: We draw a number <em>U</em> from a uniform distribution between 0 and 1.</li><li><strong>Apply the Inverse CDF</strong>: Using the inverse of the target distribution’s CDF, transform <em>U</em> into a sample that follows the target distribution.</li></ol><p>Here’s a quick illustration of how the samples (blue) are drawn from the distribution (red):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*bhTgvbQ4HM-M6iD2jX7nfQ.gif" /></figure><p>Inverse CDF is a <strong>computationally</strong> <strong>simple and generalizable </strong>method to sample from distributions for which <strong>we know the CDF</strong>, such as the normal, exponential, gamma or beta distribution.</p><h4>PDF, CDF, and Inverse CDF</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ipAtzhmoS2jKBdnbNAt8NA.png" /><figcaption>(From left to right): PDF, CDF, and Inverse CDF of the standard normal distribution</figcaption></figure><p>In intuitive terms, the CDF is the cumulative value of the PDF, which is equal to the integral of the PDF; then we take the inverse of the CDF function to get the final inverse CDF used for this method.</p><p>Formally, if <em>a </em>is a random variable, then the CDF of <em>a </em>is given by:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2ko14u02SwQI8w74zInoMg.png" /><figcaption>PRML, Eq. 11.5–11.6</figcaption></figure><p>A CDF <em>F </em>has the following key properties:</p><ul><li><em>F</em> is continuous</li><li><em>F</em> is non-decreasing</li><li><em>F</em> has range 0 ≤ cdf(<em>a</em>) ≤ 1 for all <em>a</em> ∈ R</li></ul><h4>How does the inverse CDF algorithm work?</h4><p>The algorithm consists of the following ingredients:</p><p><strong>Input:</strong></p><ul><li>U: <em>U</em> is a uniform random variable drawn between 0 and 1.</li><li>This serves as the input probability for the inverse CDF and is what will be transformed into a sample from the desired distribution.</li></ul><p><strong>Parameter</strong>:</p><ul><li><em>F: </em>the CDF of the target distribution.</li><li>With <em>F, </em>we can simply compute its inverse, <em>F</em>^-1, and use it to map an input value to the desired domain</li></ul><p><strong>Output</strong>:</p><ul><li>x: a random sample drawn from the target distribution.</li><li>This is generated by applying the inverse CDF to the random number from the uniform distribution (input).</li></ul><h4>Python Implementation</h4><p>Now, let’s implement this method from scratch. We will use the exponential function since it will be easy to visualize our samples drawn by inverse CDF and compare them to the exact distribution:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SUuRj5DmENpgveuV0I4eMA.jpeg" /><figcaption>PDF of the exponential function (target distribution)</figcaption></figure><p>By standard calculus integration techniques, we find that the target CDF <em>F(x) </em>is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rXYVKDt44SHa2aGM4Eu2cw.jpeg" /><figcaption>CDF of the exponential function</figcaption></figure><p>The inverse of this CDF is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xLdcxMV_X9HUA3vKLftiTA.jpeg" /><figcaption>Inverse CDF of the exponential function</figcaption></figure><p>We will generate 5000 samples using the Inverse CDF method:</p><pre>import numpy as np<br>import matplotlib.pyplot as plt<br><br># Inverse CDF for the exponential distribution with lambda = 1<br>def inverse_cdf(p):<br>    return -np.log(1 - p)<br><br># Generate 1000 sample values using inverse CDF<br>uniform_samples = np.random.uniform(0, 1, 1000)<br>transformed_samples = inverse_cdf(uniform_samples)<br><br># Generate x values and true PDF<br>x_values = np.linspace(0, np.max(transformed_samples), 1000)<br>pdf_values = np.exp(-x_values)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*bhTgvbQ4HM-M6iD2jX7nfQ.gif" /></figure><h4>Requirements for the inverse CDF algorithm to work</h4><p>The inverse CDF method makes a key assumption:</p><ul><li><strong>CDF <em>F</em> is invertible</strong>: The CDF <em>F </em>must be <strong>invertible</strong>, meaning that each input to <em>F </em>must have a unique output</li></ul><p>This constraint rules out a number of functions. For example, below are a few function types that are common but <strong>non-invertible </strong>(and thus would <strong>not work with inverse CDF)</strong>:</p><ol><li><strong>Constant functions</strong>: Any constant function in the form of <em>f(x) = c</em> where <em>c</em> is a constant is not invertible since every input maps to the same output and thus the function is <strong>not one-to-one</strong>.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*Ve3EFnuTH8H1dW1a7r932Q.jpeg" /><figcaption>The red dots show two of the many x values that map to the same y value in f(x) = 5, making it non-invertible</figcaption></figure><p>2.<strong> Certain quadratic functions</strong>: For example <em>f(x) = x^2</em> is non-invertible since it’s many-to-one (consider <em>f(x) = 1</em>, <em>x</em> could be <em>1</em> or <em>-1</em>).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*tj-XvqD3MdjLOoMgFFKTgw.jpeg" /><figcaption>The red dots show one of the many pairs of x values that map to the same y value in f(x) = x²</figcaption></figure><p>3. <strong>Certain trigonometric functions</strong>: For example <em>f(x) = sin(x)</em> is not invertible over their entire domain since they are periodic, although with <strong>restricted domains</strong> they may be made invertible.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*sTV_EZwkPBdmYTkMdrNX3Q.jpeg" /><figcaption>The red dots show one of the many sets of x values that map to the same y value in f(x) = sin(x) due to its periodicity over the given domain</figcaption></figure><h4>Why does inverse CDF work?</h4><p>The key idea is that a <strong>random variable uniformly distributed between 0 and 1</strong> can be transformed into a <strong>random variable with a certain distribution </strong>by applying the inverse of the target distribution’s CDF, which is assumed to be known and tractable.</p><h4>Advantages</h4><ol><li><strong>Algorithmic simplicity</strong>: it’s very easy to implement with lower-dimensional data, thus having a wide application area across different fields and tasks.</li><li><strong>Sample accuracy: </strong>assuming the CDF and its inversion represents the exact target distribution, the method yields a relatively high exactness compared to other methods such as MCMC which we will see soon.</li></ol><h4>Disadvantages</h4><ol><li><strong>Computational complexity</strong>: For some distributions, the inverse CDF may not have a closed-form expression, making computation challenging or expensive.</li><li><strong>Difficulty with high dimensionality</strong>: It can be difficult to apply in high-dimensional spaces, especially with dependencies between variables.</li><li><strong>Invertibility constraint</strong>: Anytime a CDF is non-invertible, this method becomes invalid. This excludes a number of functions as we saw above.</li><li><strong>Limited to known distributions</strong>: Inverse CDF requires the exact form of the CDF, limiting its application to known distributions only.</li></ol><p>Taking all these limitations into account, there are only a few categories of distributions that we can apply inverse CDF to. In reality, with Big Data and unknown distributions, this method can quickly become unavailable.</p><p>With these advantages and disadvantages in mind, let’s now look at another random sampling framework that tackles these limitations: <strong>Markov Chain Monte Carlo (MCMC).</strong></p><h3>2. Markov Chain Monte Carlo (MCMC)</h3><p>As we saw just now, the inverse CDF transformation method is <strong>highly limited</strong>, especially with<strong> high dimensional </strong>sample spaces. Markov Chain Monte Carlo (MCMC), on the other hand, scales well with dimensionality, enabling us to sample from a much larger family of distributions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*td2dvVfbsAq4P4XZWkV5mg.gif" /><figcaption>An example of Metropolis-Hastings exploring a mixed Gaussian (left), generating samples (right)</figcaption></figure><h4>How does the Metropolis-Hastings algorithm work?</h4><p>In intuitive terms, the algorithm works in the following steps: Similar to inverse CDF, we have a <strong>target distribution</strong> that we’re sampling from. However, we need an additional ingredient: the current state z*, and <em>q(z|z*) </em>depends on z*, creating a Markov chain with samples z¹, z², z³,. Each sample is accepted into the chain only if it satisfies a certain criterion, which we will define below since this criterion differs across variations of the algorithm.</p><p>Let’s formalize it into a more algorithmic structure.</p><p>The algorithm runs in cycles, and each cycle follows these steps:</p><ol><li>Generate a sample <em>z* </em>from the proposal distribution.</li><li>Accept the sample with probability Then we will accept this value with an <strong>acceptance probability, </strong>which in Metropolis-Hastings is defined as:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qm0lXHhfuuUQ_Qy6yOFNqQ.png" /><figcaption>PRML¹ Eq 11.44</figcaption></figure><h4>where</h4><ul><li><em>z*</em> is the current state.</li><li><em>z^T</em> is the proposed new state.</li><li><em>p(z*)</em> is the probability of state z* according to the desired distribution.</li><li><em>p(z^T)</em> is the probability of state <em>z^T</em> according to the desired distribution.</li></ul><p>The logic behind this acceptance threshold is that it ensures that the <strong>more probable states</strong> (according to the desired distribution) are <strong>visited more often</strong>.</p><p>Now, this is the most generalized version of the algorithm; if the proposal distribution is known to be symmetric, meaning that the probability of proposing a move from state <em>x</em> to <em>x</em>′ is the same as proposing a move from <em>x</em>′ to <em>x, </em>i.e. <em>q</em>(<em>x′</em>|<em>x</em>) = <em>q</em>(<em>x|x′</em>), then we can use a special case of Metropolis-Hastings that requires a simpler acceptance threshold.</p><h4>Metropolis algorithm for Symmetric Distributions</h4><p>This is a specific MCMC algorithm that we choose to use <strong>if the proposal distribution is symmetric</strong>, i.e. q(z⁰ | z¹) = q(z¹ | z⁰) for all values of 1 and 0, interpreted as “the probability of transitioning from any state A to state B is equal to the probability of transitioning from B to A”. So, each step of the algorithm becomes:</p><ol><li>Generate a sample z* from the proposal distribution.</li><li>Accept the sample with probability:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P66TxuReLTEhy3jJYkOr0w.png" /><figcaption>Metropolis algorithm acceptance threshold. Src: PRML¹ Eq. 11.33</figcaption></figure><h4>Metropolis-Hastings and Metropolis Algorithms</h4><p>Let’s look at the algorithms side by side. As we saw before, the only difference is the acceptance threshold; all other steps of the algorithms run identically:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lBBhXEql04K0NiOiFFjQkg.jpeg" /><figcaption>Metropolis vs Metropolis-Hastings Algorithm</figcaption></figure><h4>Advantages</h4><ol><li><strong>Convergence to Equilibrium Distribution</strong>: In certain cases, the random walk can converge to a desired equilibrium distribution although it likely takes a long time in high-dimensional spaces.</li><li><strong>Low Computational Cost</strong>: Random walk often requires fewer computational resources compared to other complex sampling methods, making it suitable for problems where computational efficiency is a priority.</li><li><strong>Versatility of application</strong>: Due to its high similarity to naturally occurring patterns, Random Walk has applications in a wide variety of fields:<br>• Physics: Brownian motion of molecules in liquids and gases.<br>• Network Analysis<br>• Financial Markets: to model stock price movements<br>• Population Genetics</li></ol><h4><strong>Disadvantages</strong>:</h4><ol><li><strong>Sensitive to initialization</strong>: The algorithm’s performance can be sensitive to the choice of the starting values, especially if the initialized values are far from the high-density areas.</li><li><strong>Locality traps</strong>: Depending on the complexity of the proposal distribution, the algorithm could get stuck in local optima and have difficulty traversing to other areas along the distribution.</li></ol><p>Now, keeping the Metropolis-Hastings algorithm in mind, let’s look at another special instance of it: Gibbs Sampling.</p><h3>3. Gibbs Sampling</h3><p>Gibbs Sampling is a special instance of Metropolis-Hastings where <strong>each step is always accepted</strong>. Let’s first look at the Gibbs sampling algorithm itself.</p><h4><strong>How does the Gibbs algorithm work?</strong></h4><p>The idea is relatively simple and is best illustrated by first zooming in on a micro example involving sampling from a distribution <em>p(z1, z2, z3) </em>over 3 variables. The algorithm would run in the following steps:</p><ol><li>At timestep <em>T, </em>initialize the starting values to:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*76usazouVsJiH14zWjmkYw.png" /><figcaption>PRML¹</figcaption></figure><p>2. Draw the new value for <em>z1:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zxJ71lFS9IEQxR5uzTS1YA.png" /><figcaption>PRML¹ Eq 11.46</figcaption></figure><p>3. Draw a new value for the second position, <em>z2 </em>from the conditional:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FF5xolokf7r6kjntihVkBw.jpeg" /><figcaption>PRML¹ Eq 11.47</figcaption></figure><p>4. Finally draw a new value for the last position, <em>z3</em>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CFHspZtNulmc3MvwUoypog.png" /><figcaption>PRML¹ Eq 11.48</figcaption></figure><p>5. Repeat this process, cycling through the three variables <em>z1…z3 </em>until it reaches a certain satisfactory threshold.</p><h4>Generalized algorithm</h4><p>Formally, the algorithm is represented by first initializing the starting positions, and then taking <em>T</em> consecutive steps</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jvdmsR4Se8EiLM2u0WfeTQ.png" /><figcaption>Image source: PRML¹ Ch11.3 Gibbs Sampling</figcaption></figure><h4>Conditions for Gibbs to sample from a target distribution correctly</h4><ol><li><strong>Invariance</strong>. The target distribution <em>p(z) </em>is invariant of each Gibbs step, and therefore <em>p(z) </em>is invariant of the entire Markov chain.</li><li><strong>Ergodicity</strong>. If the conditional distributions are all non-zero, then ergodicity is implied since any point in <em>z </em>space is reachable in a finite number of steps.</li><li><strong>Sufficient burn-in</strong>. As we saw with any method that requires random initialization, the first few samples are dependent on the initialization, and the dependence weakens after many iterations.</li></ol><h4>How does this relate to Metropolis-Hastings?</h4><p>In Metropolis-Hastings, we defined the acceptance threshold to be:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cb5xxatxDCcpM32gqdR7nQ.png" /></figure><p>Thus, the Metropolis-Hastings proposal steps are always accepted, as we saw in the Gibbs algorithm.</p><h4>Variations</h4><p>Since the Gibbs method updates one variable at a time, there are strong dependencies between consecutive samples. To overcome this, we could use an intermediate strategy to sample from <strong>groups of variables </strong>instead of <strong>individual variables, </strong>known as <a href="https://www.sciencedirect.com/science/article/pii/S0002929707623398">blocking Gibbs</a>.</p><p>Similarly, by the nature of Markov chains, the examples drawn successively will be correlated. To generate independent samples, we could use sub-sampling within the sequence.</p><h3>4. Pros/Cons: Inverse CDF vs Metropolis-Hastings vs Gibbs</h3><p>Now that we’ve walked through how each algorithm works and its application areas, let’s summarize the defining characteristic of each method.</p><h4>1. Inverse Transformation Sampling</h4><ul><li><strong>Data Size</strong>: Best for moderate-sized datasets.</li><li><strong>Time</strong>: Generally efficient for univariate distributions.</li><li><strong>Data Complexity</strong>: Use for simple distributions where the cumulative distribution function (CDF) and its inverse are known and easy to compute.</li><li><strong>Consider avoiding if:</strong> Sampling high-dimensional variables/distributions.</li><li><strong>Biggest Advantage</strong>: High accuracy if the CDF accurately reflects the target distribution.</li><li><strong>Requirement:</strong> The CDF must be known and invertible.</li></ul><h4>2. Metropolis-Hastings (MCMC)</h4><ul><li><strong>Data Size</strong>: Scalable and suitable for large datasets.</li><li><strong>Time</strong>: Can be computationally intensive, depending on the complexity of the target distribution.</li><li><strong>Data Complexity</strong>: Ideal for complex or multi-modal distributions.</li><li><strong>Biggest Advantages</strong>: <br>- Can sample from a distribution without knowing its normalization constant (the full form)<br>- Great for exploring the global structure of a distribution and guarantees convergence</li><li><strong>Disadvantage: </strong>May suffer from very slow convergence with <br>- complex or multimodal target distribution, since the algorithm may be stuck in local modes and have difficulty transitioning between them;<br>- the variables are highly correlated;<br>- high dimensional spaces; <br>- poor initial values or step size choices</li></ul><h4>3. Gibbs Sampling</h4><ul><li><strong>Data Size</strong>: Suitable for both small and large datasets.</li><li><strong>Time</strong>: Often more efficient than Random Walk Metropolis-Hastings since it doesn’t require acceptance/rejection steps.</li><li><strong>Data Complexity</strong>: Best used when dealing with high-dimensional distributions where you can sample from the conditional distribution of each variable.</li><li><strong>Biggest Advantages</strong>: <br>- Can easily compute conditional distributions;<br>- Less prone to local minima traps compared to Random Walk.</li><li><strong>Requirements</strong>: <br>- Markov chain ergodicity <br>- The full conditional distributions must be known and tractable</li></ul><h4>In summary:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6_vaJcKBGKrJzmmvjg3zvQ.jpeg" /><figcaption>Summary table of pros and cons of inverse CDF, Metropolis-Hastings, and Gibbs</figcaption></figure><h3>Conclusion</h3><p>Thanks for sticking with me this far! In this article, we looked at 3 key approximation sampling methods: Inverse CDF, Metropolis Hastings MCMC, and Gibbs Sampling MCMC. We explored how each algorithm functions, their respective advantages and disadvantages, and typical use-cases.</p><p><strong>Inverse CDF </strong>provides a straightforward method to sample from a known distribution when its CDF is invertible. It’s computationally efficient but is less suitable for high-dimensional or complex distributions.<br><strong>Metropolis Hastings MCMC</strong> offers a more general approach that allows for sampling from distributions that are difficult to tackle otherwise. However, it does require more computational resources and may be sensitive to tuning parameters like the proposal distribution.<br><strong>Gibbs Sampling MCMC</strong> is specifically efficient when the joint distribution is complex but can be broken down into simpler conditional distributions. It’s widely used in machine learning, although it can be slow to converge and memory-intensive for high-dimensional problems.</p><p>[1] Bishop, C. M. (2016). <em>Pattern Recognition and Machine Learning</em> (Softcover reprint of the original 1st edition 2006 (corrected at 8th printing 2009)). Springer New York.</p><p><em>*Images by author unless otherwise stated,</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=886a379fb6b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/monte-carlo-approximation-methods-which-one-should-you-choose-and-when-886a379fb6b">Monte Carlo Approximation Methods: Which one should you choose and when?</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Machine Unlearning in 2023: Where We Are and Where It’s Headed]]></title>
            <link>https://pub.towardsai.net/machine-unlearning-in-2023-where-we-are-and-where-its-headed-2ef19ad0394?source=rss-2b9882509386------2</link>
            <guid isPermaLink="false">https://medium.com/p/2ef19ad0394</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[machine-unlearning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[ai-ethics]]></category>
            <category><![CDATA[ai-safety]]></category>
            <dc:creator><![CDATA[Susie S.Y. Li]]></dc:creator>
            <pubDate>Mon, 24 Jul 2023 15:56:58 GMT</pubDate>
            <atom:updated>2024-11-17T04:20:51.530Z</atom:updated>
            <content:encoded><![CDATA[<h4>A summary of machine unlearning paradigms and methods, the motivation for machine unlearning, current challenges, and future outlook.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WvSOHoP-qNdEM15LLLfn-w.jpeg" /><figcaption>Photo by Unsplash</figcaption></figure><p>Have you ever lied awake at night, kept up by your brain replaying a clip of that one horribly embarrassing memory you wish you could just forget? Keeping certain memories in our minds can be unpleasant, counterproductive, or even harmful. <em>If only our human brain has the ability to forget anything, we wanted to.</em></p><p>Well, it turns out machines and ML models face the same challenge: forgetting counterproductive or harmful memories isn’t always as smooth and easy as a simple click on “delete”.</p><h4>So, what is this field that helps machines forget?</h4><h3>Table of Contents</h3><ol><li><a href="#7890">Introduction to Machine Unlearning</a></li><li><a href="#9346">Applications and Motivations</a></li><li><a href="#033c">Algorithms and Evaluation</a></li><li><a href="#12cf">Current Challenges</a></li></ol><h3>Introduction to Machine Unlearning</h3><p><em>What is machine unlearning and how does it differ from machine learning? Why do we need machine unlearning and what value can it unlock? What is the intuition underlying existing methods and paradigms for machine unlearning?</em></p><p>Machine unlearning is a relatively new field that essentially teaches a trained model to “forget” a certain subset of the input dataset that it was trained on, without significantly affecting performance. There’s a variety of motivations: some personal information is no longer available per updates in data privacy policies; some data is proven to be outdated or inaccurate and is counterproductive for the model; or a model is inadvertently trained on data that perpetuates biases and we want to <strong>remove the specific bias-inducing subset</strong>.</p><p>You may be wondering: this sounds like a simple task of dropping the problematic data subset and retraining a model using the updated dataset. <strong>Why complicate it?</strong></p><p>As it turns out, many models, such as <a href="https://www.griproom.com/fun/how-chatgpt-is-trained-and-how-long-it-took">Large Language Models like ChatGPT</a>, often require vast computational resources to train in the first place. The forget set often constitutes only a small fraction of the total training set; thus the “retrain from scratch” approach becomes an excessively expensive and repetitive solution, necessitating a better algorithm that removes the forget set while preserving the performance of the original model.</p><h3>Applications and Motivations</h3><p><em>What are some use cases motivating the development of machine unlearning? How does machine unlearning uniquely contribute to these fields and tasks? What potential future applications are being explored, and what can we expect?</em></p><p>We’ve mentioned the idea that due to scaling computational resources, the advantage that machine unlearning holds over a full retrain-from-scratch is much more significant on <strong>larger datasets,</strong> often in real-life applications.</p><p>Let’s look at a few of the top application areas necessitating machine unlearning:</p><ul><li><strong>Fair and ethical models (bias removal)</strong>: When trained on massive real-world data, sometimes models pick up on the biases inherent to the dataset. As the model scales, the algorithm can sometimes amplify the bias. In some cases the consequence of model bias can be especially harmful, such as in models used for <a href="https://www.technologyreview.com/2020/07/17/1005396/predictive-policing-algorithms-racist-dismantled-machine-learning-bias-criminal-justice/">predictive policing in preventing crimes</a> or <a href="https://www.wired.com/story/ai-hiring-bias-doj-eecc-guidance/">hiring from a candidate pool</a>. When these biases are identified, they should be immediately removed, and machine unlearning offers a potential way to do this and mitigate harm.</li><li><strong>Data updates (lifelong learning):</strong> Data for a model can become outdated after corrections or updates are made to the dataset for a variety of reasons. Through unlearning and forgetting these counterproductive data points, models can adapt to these changes and produce more accurate predictions. This is especially useful in dynamic learning models such as <a href="https://towardsdatascience.com/deep-lifelong-learning-drawing-inspiration-from-the-human-brain-c4518a2f4fb9">lifelong learning</a>; offloading outdated or incorrect data improves both the accuracy and efficiency of computation.</li><li><strong>Data privacy (the right to be forgotten)</strong>: This is perhaps what machine unlearning has been most commonly associated with. In a rapidly changing digital world, the laws and regulations governing digital practices are constantly updated. Forgetting certain attributes of personal data helps models stay compliant with regulations such as GDPR³ by safeguarding against data leaks or anonymization concerns.</li></ul><h3>Algorithms and Evaluation Metrics</h3><p><em>What are the main algorithmic paradigms in machine unlearning and how are they implemented? What are the strengths and weaknesses of each? What metrics have been proposed to assess machine unlearning performance?</em></p><h4>Methods</h4><p>Essentially the logic behind removing data without completely retraining is to decrease the correlation between certain features and the output. Let’s look at a main technique, known as “d<strong>ata poisoning”</strong>:</p><ul><li>This is where we intentionally add inaccurate data to “confuse” the model about a certain feature or attribute. <br><em>Here’s an example</em>: a model trained on a dataset of crime reports observes a trend where people between 50–60 years old are highly likely to commit crimes. As a result, it unfairly targets the 50–60 age group in future predictive crime detection. To mitigate this bias, we may generate a synthetic dataset of crime statistics among other age groups, matching that of the 50–60 age group <strong>without interfering with other features. </strong>This weakens the strength of the correlation between conviction and the 50–60 age group.</li></ul><h4>Evaluation metrics</h4><p>Since this is a relatively new field, many evaluation standards are still being proposed every day to better assess machine unlearning performance. Below, we highlight a few of the proposed evaluation metrics to measure the quality and effectiveness of machine unlearning methods:</p><ul><li><a href="https://arxiv.org/pdf/2003.10933.pdf"><strong>Forgetting rate</strong></a>: measures the proportion of data samples that originally belonged to a dataset but are no longer recognized after the unlearning process.</li><li><a href="https://openaccess.thecvf.com/content/CVPR2021/papers/Golatkar_Mixed-Privacy_Forgetting_in_Deep_Networks_CVPR_2021_paper.pdf"><strong>Membership Inference Attack</strong></a>: measures the degree to which an adversary can correctly infer whether a data sample is part of the training set for the model. This metric is especially relevant in security contexts.</li></ul><h3>Current Challenges</h3><p><em>What are the major challenges facing the Machine Unlearning field as a whole? What are the challenges that emerge in specific contexts or applications?</em></p><p>Machine unlearning can be quite an intricate task for a number of reasons. In fact, <a href="https://ai.googleblog.com/2023/06/announcing-first-machine-unlearning.html">in July 2023 Google launches a public competition</a> with the aim of unifying and advancing effective machine unlearning methods.</p><ul><li><strong>Lack of standardized evaluation. </strong>Although a number of publications have addressed the notion of a unified assessment metric by using well-known datasets such as <a href="https://www.cs.toronto.edu/~kriz/cifar.html">CIFAR10 and CIFAR100</a> as benchmarks, there lacks a universal evaluation standard that can unify the results produced by different researchers in the field. <br>In fact, this is one of the aims of Google’s recent machine unlearning challenge — to provide a platform to compare different methods “apple-to-apple”².</li><li><strong>Susceptibility to adversarial attacks.</strong> <a href="https://openreview.net/pdf?id=zml9gDnulI9#:~:text=We%20introduce%20camouflaged%20data%20poisoning,the%20model%27s%20predictions%20is%20minimal.">Research</a> has found that models that have been taught to <em>unlearn</em> some data subsets can fall prey to <a href="https://openreview.net/pdf?id=zml9gDnulI9#:~:text=We%20introduce%20camouflaged%20data%20poisoning,the%20model%27s%20predictions%20is%20minimal.">camouflaged attacks</a> because of the poisoning mechanism involved in unlearning.</li></ul><h3>Future directions</h3><p>These current obstacles provide potential directions for interesting future research questions:</p><ul><li>How do we train models to defend against <a href="https://openreview.net/pdf?id=zml9gDnulI9#:~:text=We%20introduce%20camouflaged%20data%20poisoning,the%20model%27s%20predictions%20is%20minimal."><em>camouflaged poisoning attacks</em></a><em>?</em></li><li>How can we leverage computational resources to optimize unlearning efficiency?</li><li>How can we effectively clean and generate data to overcome the lack of training data?</li><li>How can we unify a set of standards to assess unlearning algorithms to ensure consistent evaluation?</li></ul><h3>Conclusion</h3><p>Thanks for sticking with me this far! In this article, we walked through the field of machine unlearning, including its main motivations and application areas, existing methods and paradigms, and current challenges.</p><p>Later in this series, we will take a deeper dive into the technical aspects of existing unlearning algorithms and Python implementations with real statistical and image datasets. Happy coding✌🏼!</p><h3>Bibliography</h3><p>[1] Shaik, T., Tao, X., Xie, H., Li, L., Zhu, X., &amp; Li, Q. (2023). <em>Exploring the Landscape of Machine Unlearning: A Comprehensive Survey and Taxonomy</em>. <a href="https://doi.org/10.48550/ARXIV.2305.06360">https://doi.org/10.48550/ARXIV.2305.06360</a></p><p>[2] <em>Announcing the first Machine Unlearning Challenge</em>. (2023, June 29). Ai.googleblog.com. <a href="https://ai.googleblog.com/2023/06/announcing-first-machine-unlearning.html">https://ai.googleblog.com/2023/06/announcing-first-machine-unlearning.html</a></p><p>[3] European Union Agency for Fundamental Rights. (2019). <em>The General Data Protection Regulation: One year on civil society: awareness, opportunities, and challenges.</em> Publications Office. <a href="https://data.europa.eu/doi/10.2811/538633">https://data.europa.eu/doi/10.2811/538633</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2ef19ad0394" width="1" height="1" alt=""><hr><p><a href="https://pub.towardsai.net/machine-unlearning-in-2023-where-we-are-and-where-its-headed-2ef19ad0394">Machine Unlearning in 2023: Where We Are and Where It’s Headed</a> was originally published in <a href="https://pub.towardsai.net/">Towards AI</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Top Machine Unlearning Reads]]></title>
            <link>https://susiesyli.medium.com/machine-unlearning-must-reads-f939cf31894?source=rss-2b9882509386------2</link>
            <guid isPermaLink="false">https://medium.com/p/f939cf31894</guid>
            <category><![CDATA[machine-unlearning]]></category>
            <category><![CDATA[ai-safety]]></category>
            <category><![CDATA[algorithms]]></category>
            <dc:creator><![CDATA[Susie S.Y. Li]]></dc:creator>
            <pubDate>Thu, 20 Jul 2023 04:51:31 GMT</pubDate>
            <atom:updated>2023-07-22T22:15:15.612Z</atom:updated>
            <content:encoded><![CDATA[<h4>A sorted, constantly updated collection of literature on machine unlearning, from blogs to conference papers, from survey papers to applications to theoretical algorithms and evaluations</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xVlKf309-Dzq2-qD" /><figcaption>Photo by <a href="https://unsplash.com/@jhonkasalo?utm_source=medium&amp;utm_medium=referral">Joakim Honkasalo</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Machine Unlearning is a relatively new field that essentially teaches a trained model to “forget” a certain subset of the input dataset, commonly due to updated data privacy policies but can be useful in a variety of contexts. The most straightforward approach is to drop the forgotten subset from the original dataset and retrain the model from scratch. In reality, this is often far too computationally expensive, thus there is a growing demand for more efficient unlearning algorithms as well as unified evaluation standards.</p><p>This curated reading list caters to diverse audiences: whether you have just stumbled upon the concept of machine unlearning, or you have already designed your own machine unlearning algorithms and are in search of further inspiration, the <a href="#d56b">table of contents</a> has a section that aligns with your interests!</p><p>The list is organized as follows:</p><ul><li><strong>First, by</strong> <strong>topic</strong>: 1) Introduction, 2) Current challenges, 3) Existing algorithmic paradigms, their advantages and drawbacks, and evaluation standards, and 4) Applications</li><li>Then, <strong>each section</strong> is sorted by:<br>- reverse chronological order specific to the publication <em>year</em> <br>- academic and non-academic publication types: <strong>titles with asterisks <em>(*)</em> are articles/blogs, and ones without are papers.</strong></li></ul><h3>Table of Contents</h3><ol><li><a href="#65ac">Introductions to Machine Unlearning</a></li><li><a href="#65d6">Current Challenges</a></li><li><a href="#d097">Algorithms and Evaluation</a></li><li><a href="#cb8d">Applications</a></li></ol><h3>Introduction to Machine Unlearning</h3><p><em>What is machine unlearning and how does it differ from machine learning? Why do we need machine unlearning and what value can it unlock? What is the intuition underlying existing methods and paradigms for machine unlearning?</em></p><ul><li><a href="https://arxiv.org/pdf/2305.06360.pdf">Exploring the Landscape of Machine Unlearning: A Comprehensive Survey and Taxonomy (2023)</a></li><li><a href="https://www.jumpstartmag.com/what-is-machine-unlearning-and-why-it-is-an-important-skill-for-ai/">*What Is Machine “Unlearning” and Why It Is an Important Skill for AI (2023)</a></li><li><a href="https://arxiv.org/pdf/2209.00939.pdf">An Introduction to Machine Unlearning (2022)</a></li><li><a href="https://arxiv.org/pdf/2209.02299.pdf">A Survey of Machine Unlearning (2022)</a></li><li><a href="https://arxiv.org/pdf/2108.11577.pdf">Machine Unlearning of Features and Labels (2022)</a></li><li><a href="https://www.wired.com/story/machines-can-learn-can-they-unlearn/">* Now That Machines Can Learn, Can They Unlearn? (2021)</a></li></ul><h3>Current Challenges</h3><p><em>What are the major challenges facing the Machine Unlearning field as a whole? What are the challenges that emerge in specific contexts or applications?</em></p><ul><li><a href="https://arxiv.org/pdf/2304.03545.pdf">AI Model Disgorgement: Methods and Choices (2023)</a></li><li><a href="https://arxiv.org/pdf/2109.08266.pdf">Hard to Forget: Poisoning Attacks on Certified Machine Unlearning (2022)</a></li><li><a href="https://arxiv.org/pdf/2207.03227.pdf">Challenges and Pitfalls of Bayesian Unlearning (2022)</a></li><li><a href="https://dl.acm.org/doi/pdf/10.1145/3460120.3484756">When Machine Unlearning Jeopardizes Privacy (2021)</a></li></ul><h3>Algorithms and Evaluation</h3><p><em>What are the main algorithmic paradigms in machine unlearning and how are they implemented? What are the strengths and weaknesses of each? What metrics have been proposed to assess machine unlearning performance?</em></p><h4>Algorithms</h4><ul><li><a href="https://arxiv.org/pdf/2111.08947.pdf">Fast Yet Effective Machine Unlearning (2023)</a></li><li><a href="https://arxiv.org/pdf/2304.02350.pdf">Unfolded Self-Reconstruction LSH: Towards Machine Unlearning in Approximate Nearest Neighbour Search (2023)</a></li><li><a href="https://arxiv.org/pdf/2202.13585.pdf">Markov Chain Monte Carlo-Based Machine Unlearning: Unlearning What Needs to be Forgotten (2022)</a></li><li><a href="https://arxiv.org/pdf/2201.05629.pdf">Zero-Shot Machine Unlearning (2022)</a></li><li><a href="https://link.springer.com/content/pdf/10.1007/s10994-022-06178-9.pdf">Machine Unlearning: Linear Filtration for Logit-based Classifiers (2022)</a></li><li><a href="http://Learning by Active Forgetting for Neural Networks">Active Forgetting via Influence Estimation for Neural Networks (2021)</a></li><li><a href="https://arxiv.org/pdf/2106.04378.pdf">Adaptive Machine Unlearning (2021)</a></li><li><a href="https://arxiv.org/pdf/2102.13179.pdf">Machine Unlearning via Algorithmic Stability (2021)</a></li><li><a href="https://arxiv.org/pdf/2003.04247.pdf">Towards Probabilistic Verification of Machine Unlearning (2020)</a></li><li><a href="https://openreview.net/pdf?id=pvCLqcsLJ1N">Remember What You Want to Forget: Algorithms for Machine Unlearning (2020)</a></li></ul><h4>Metrics</h4><ul><li><strong>Layer-wise Distance</strong> — <a href="https://arxiv.org/pdf/2111.08947.pdf">Fast Yet Effective Machine Unlearning (2023)</a></li><li><strong>Reconstruction Error </strong>— <a href="https://arxiv.org/pdf/2304.02350.pdf">Unfolded Self-Reconstruction LSH: Towards Machine Unlearning in Approximate Nearest Neighbour Search (2023)</a></li><li><strong>Unlearning Error</strong> — <a href="https://arxiv.org/pdf/2109.13398.pdf">Unrolling SGD: Understanding Factors Influencing Machine Unlearning (2022)</a></li><li><strong>Forgetting Rate — </strong><a href="https://arxiv.org/pdf/2003.10933.pdf">Learn to Forget: Machine Unlearning Via Neuron Masking (2021)</a></li><li><strong>Accuracy</strong>, <strong>Activation Distance </strong>— <a href="https://arxiv.org/pdf/1911.04933.pdf">Eternal Sunshine of the Spotless Net: Selective Forgetting in Deep Networks (2020)</a></li><li><strong>Anamnesis Index </strong>— <a href="https://pdf.sciencedirectassets.com/271125/1-s2.0-S0893608019X00039/1-s2.0-S0893608019300231/main.pdf?X-Amz-Security-Token=IQoJb3JpZ2luX2VjEOX%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaCXVzLWVhc3QtMSJHMEUCIGBFSQ9zsQKglbBhV8AMSZa0lipwa8s%2FY%2FX3q534t8PsAiEAsdXZgOwsTr%2BkPquJ40vvmfIzv7bnc9bwcVLnWwjQwsMqsgUIbRAFGgwwNTkwMDM1NDY4NjUiDPyzJJE39TwGEE1CMCqPBfn0FR31S1bkvmf9TQ8sZX9aANXo1tZmmwhnHtAOP4TdDEk9X1L5Xao%2BeV%2B%2FgMBv0FRKj9O%2Fd5fG%2Fzvh9gKRubQin4uKQTceBfwx6YTgnxK0%2B5OuMkoJsr2kp1EccJt5nax0ly%2F59FHh8kZ7XyQDpBrF2p2FGcwBGC4DXRYo1h4u8vtBhhRB7moxHUtf70Jr6vMiSAUiabroLBQ2gVCDTpi6GiQHoa9mEiB2UJoMtf%2FbAT8itLqnPTFEOi6xNj0EZDIYJY6jZ2vhkw128Hbm3l8w1jxU2EFg6pKZ13enIHBerSON2kdlZzwZBfhaQ5QLuVIIpYbfQSjo5eMFaTQUnd%2FP6aaaaVZlpuBk3j5KmsiD99%2BMWRM7GzKzTixsunahapTEoYqflWZtboCSWvMGFA5Z8GxrTKEV7L8lbDIhsfK3wGRxyBu1anhIKadWfnb%2B9dxhhQlejDNpGy6LyrAiHAozQkZ6l8jWj11iSXm8NedPb7YbXnSTHR4WS64c%2B%2FaLEInxsN6%2B1zTH9%2BpT8PxilsZ8bdzrzARMzWGvkdQFBKZ%2BuaaYP2i6LcAH2i8NBFlIaNFw2nRna2HyUqy5zi6v8Kn9wM%2B%2FPY64N0cw%2B4zKJT4TWHG%2BV5fwG1Q612J6y8ytzCs9XvwDCOn79LZCKC%2FMzqEcPwKUD1IWZWIEYyYbRTWXcNcSi0sEYh9LHLXtxHYpboMKQhGtL1FqtknZ096n1egLIdRADk4tfeXIl12XGhV0NesoG4R0zUkytALhRMzzu4BWp%2Fi%2BnmR1zSiZyuUzJ%2FhUP0DNgHzGe6a9nb1Zx5fIB8WnGwvOn%2BRpdgSXzWa7q3Pj4PpwoQGSyQ5%2BwgLdznpd7RMkeP1lzFv%2FKMHwv7ow1KDYpQY6sQEahdjXNgsOlVA0S%2FNybeSqYXSwBTGJa1TrR5ZWuqBmtw9IBzHduXdb6rvumiaNlOOrSmDaN0ja011xup5o7oNu4ckwc7v8i1Izy9p6xLnOxOso4C1IILzXzUoHcLZNT9CoMZFJLaZItnrf701eI655ebHdsAbnMiWkvlAcW8JXeUgx1AmpNbtPGK9nrYQW1cqNArBpJjn9OxY2mvgNsDNqkT8A%2F9fgDdKmLeeFhYWF2Ro%3D&amp;X-Amz-Algorithm=AWS4-HMAC-SHA256&amp;X-Amz-Date=20230718T052630Z&amp;X-Amz-SignedHeaders=host&amp;X-Amz-Expires=300&amp;X-Amz-Credential=ASIAQ3PHCVTY6XCCF4HP%2F20230718%2Fus-east-1%2Fs3%2Faws4_request&amp;X-Amz-Signature=a63852c1b374f2643ea853743073db651b213d49567283cdd07396094c10788e&amp;hash=e23b6fe7aa53f424075bee354671939d69eef53de84687a3c34c4a6120351849&amp;host=68042c943591013ac2b2430a89b270f6af2c76d8dfd086a07176afe7c76c2c61&amp;pii=S0893608019300231&amp;tid=spdf-8cca83aa-86f5-4268-a42a-836be322c22b&amp;sid=9fd6600320c6404cdf6a4a12c0237e598409gxrqa&amp;type=client&amp;tsoh=d3d3LnNjaWVuY2VkaXJlY3QuY29t&amp;ua=0a1f55045b5c510551&amp;rr=7e884f654a60fb80&amp;cc=nz">Continual lifelong learning with neural networks: A review (2019)</a></li></ul><h3>Applications</h3><p><em>What are the fields and tasks that machine unlearning is successfully or commonly used for? How does machine unlearning uniquely contribute to these applications? What potential future applications are being explored, and what can we expect?</em></p><p>Here are just a few examples of where machine unlearning has crucial applications:</p><ul><li><strong>Data privacy (the right to be forgotten)</strong>: in a rapidly changing digital world, the laws and regulations governing digital practices are also constantly updating. Machine unlearning certain data helps models stay compliant with regulations such as GDPR¹.</li><li><strong>Data updates (lifelong learning):</strong> data for a model can become outdated after corrections or updates are made for a variety of reasons. Through unlearning and forgetting these counterproductive datapoints, models can adapt to these changes more easily. This is especially useful in dynamic learning models such as <a href="https://towardsdatascience.com/deep-lifelong-learning-drawing-inspiration-from-the-human-brain-c4518a2f4fb9">lifelong learning</a>.</li><li><strong>Bias removal</strong>: when models are trained on real-world data, they will reflect and possibly perpetuate any bias in the dataset, such as in hiring or patient data analysis. When these biases are identified, machine unlearning helps mitigate these impacts by removing features contributing to algorithmic biases.</li><li><a href="https://arxiv.org/pdf/2302.09880.pdf">Towards Unbounded Machine Unlearning (2023)</a></li><li><a href="https://dl.acm.org/doi/pdf/10.1145/3485447.3511997">Recommendation Unlearning (2022)</a></li></ul><h4><strong>Conclusion</strong></h4><p>This article is created with a conscious attempt to select valuable and accessible resources structured around the fundamental topics of machine unlearning, including introductory materials, challenges, algorithms and evaluation techniques, and practical implications but also prevent information overload. Thus, it does not include every single contribution in this vast and rapidly evolving field. <em>If any pivotal studies or methodologies are </em><strong><em>not</em></strong><em> explicitly addressed, it is </em><strong><em>not</em></strong><em> an indication of their lack of importance or value to the field.</em></p><p>[1] European Union Agency for Fundamental Rights. (2019). <em>The General Data Protection Regulation: One year on : civil society: awareness, opportunities and challenges.</em> Publications Office. <a href="https://data.europa.eu/doi/10.2811/538633">https://data.europa.eu/doi/10.2811/538633</a></p><p>[2] Shaik, T., Tao, X., Xie, H., Li, L., Zhu, X., &amp; Li, Q. (2023). <em>Exploring the Landscape of Machine Unlearning: A Comprehensive Survey and Taxonomy</em>. <a href="https://doi.org/10.48550/ARXIV.2305.06360">https://doi.org/10.48550/ARXIV.2305.06360</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f939cf31894" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From Bits to Biology #1: Using LCS Algorithm for Global Sequence Alignment in Computational Biology]]></title>
            <link>https://pub.towardsai.net/from-bits-to-biology-1-using-lcs-algorithm-for-global-sequence-alignment-in-computational-biology-3499c24d2ac8?source=rss-2b9882509386------2</link>
            <guid isPermaLink="false">https://medium.com/p/3499c24d2ac8</guid>
            <category><![CDATA[bioinformatics]]></category>
            <category><![CDATA[computational-biology]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[dynamic-programming]]></category>
            <dc:creator><![CDATA[Susie S.Y. Li]]></dc:creator>
            <pubDate>Wed, 19 Jul 2023 18:01:47 GMT</pubDate>
            <atom:updated>2023-07-27T14:47:50.129Z</atom:updated>
            <content:encoded><![CDATA[<h4>A step-by-step analysis of the Longest Common Subsequence problem and the Sequence Alignment problem with an explanation of their solutions highlighting their similarities and differences</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*iP8T-YhwkTAMVdFb" /><figcaption>Photo by <a href="https://unsplash.com/@sangharsh_l?utm_source=medium&amp;utm_medium=referral">Sangharsh Lohakare</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3><strong>Introduction</strong></h3><p>Welcome! You’ve found the first entry in my From Bits to Biology series, where I explore the connections between general algorithms you may find in a computer science class and computational biology/bioinformatics to make them more intuitive and accessible to those without formal biology training. It took me some time to be convinced you don’t necessarily need a formal biology background to make meaningful contributions in computational biology — an incredibly fascinating field — and I hope I’ll convince you to give it a try if you are in a similar boat :)</p><p>In this article, we are looking at <em>Sequence Alignment</em>, one of the most fundamental problems in computational biology. Alignment of DNA, RNA, and protein sequences has a variety of profound implications, including understanding evolutionary relationships, progressing functional annotation, identifying mutations, and advancing drug design and precision medicine.</p><h3>Table of contents</h3><ol><li><a href="#6b47">Longest Common Subsequence (LCS)</a><br>- <a href="#6b47">LCS Overview</a> <br>- <a href="#be40">LCS Dynamic programming solution</a><br>- <a href="#131b">LCS Python implementation</a></li><li><a href="#0f4d">Global Sequence Alignment (GSA)</a><br>- <a href="#0f4d">GSA Overview</a><br>- <a href="#0d50">Scoring Sytems </a><br>- <a href="#bd28">GSA Dynamic programming solution</a><br>- <a href="#8327">GSA Python implementation</a></li><li><a href="#1cd0">LCS vs. Global Sequence Alignment: Similarities and Differences</a><br>- <a href="#e40a">Summary table</a></li></ol><h3>Longest Common Subsequence (LCS) Problem</h3><p><a href="https://en.wikipedia.org/wiki/Longest_common_subsequence#:~:text=A%20longest%20common%20subsequence%20(LCS,(often%20just%20two%20sequences).">Longest Common Subsequence</a> (LCS) is a classic computer science problem that identifies the longest subsequence among all the valid subsequences shared between 2 or more input sequences.</p><p>Let’s clarify the LCS problem statement by first noting an important distinction between a <em>subsequence </em>and a <em>substring. </em>Take the sequence &quot;ABCDE&quot;:</p><ul><li>A <strong>substring</strong> consists of <em>contiguous</em> characters in their <em>original order</em>. For example, valid substrings include &quot;ABC&quot;, “CD”, etc, but <em>not</em> “ABDE” or “CBA”.</li><li>A <strong>subsequence</strong>, on the other hand, does <em>not</em> have to be contiguous but must also be in the original order. For example, valid subsequences include “AC” and “BFG”.</li></ul><p>The LCS, then, is the longest among all the possible subsequences between 2 or more sequences. Here’s a quick example:</p><figure><img alt="Visual illustration of the shared subsequence between the strings “labrador” and “exploration”" src="https://cdn-images-1.medium.com/max/940/1*NGk1xrcQhQDOaOXVhQpu-A.gif" /><figcaption>The LCS of sequences “labrador” and “exploration” is “<strong>lrao</strong>”. (Image by author)</figcaption></figure><p>In practice, LCS has many applications involving much larger textual data, such as plagiarism detection¹ or Unix’s diff command, necessitating an efficient and <strong>reliable, scalable algorithmic solution</strong>.</p><h4>Formalizing the LCS solution</h4><p>Here’s a refresher on the 3-step dynamic programming solution to LCS:</p><ol><li>Initialization (create an <em>m</em> × <em>n</em> matrix, where <em>m</em> and <em>n </em>are the lengths of sequence 1 and sequences 2).</li><li>Fill out the matrix according to the recurrence formula given below.</li><li>Traceback to find the LCS as well as its length.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XEZ0gFtmeokJfZK2c6Jr-w.png" /><figcaption>Image source: CLRS Introduction to Algorithms² (3rd Edition), Eq 15.9.</figcaption></figure><p>Consider the inputs “LONGEST” and “STONE”. Based on the recurrence relation given above, we fill out the DP matrix and then traceback as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/1*9239OVLBs8xbsgl8AV05qQ.gif" /><figcaption>Illustration of LCS algorithm (Image by author)</figcaption></figure><p>This is the full DP table:</p><figure><img alt="Dynamic programming table showing the scores assigned to each possible pair" src="https://cdn-images-1.medium.com/max/1024/1*GUk50dhKLt4kk93m6lPDfQ.png" /><figcaption>(Image by author)</figcaption></figure><p>This translates into the Python implementation below:</p><pre># Longest Common Subsequence<br>def lcs(seq1, seq2):<br>    m = len(seq1) <br>    n = len(seq2)<br><br>    # Construct dp table <br>    table = [[0 for x in range(n+1)] for x in range(m+1)]<br>    # Fill table based on recursive formula (15.9) from CLRS<br>    for i in range(m+1):<br>        for j in range(n+1):<br>            if i == 0 or j == 0: # case 1 <br>                table[i][j] = 0<br>            elif seq1[i-1] == seq2[j-1]: # case 2 <br>                table[i][j] = table[i-1][j-1] + 1<br>            else: # case 3 <br>                table[i][j] = max(table[i-1][j], table[i][j-1])<br><br>    # Begin traceback from the bottom-rightmost cell <br>    index = table[m][n]<br>    lcs = [&quot;&quot;] * (index+1)<br>    lcs[index] = &quot;&quot;<br><br>    i = m<br>    j = n<br>    while i &gt; 0 and j &gt; 0:<br>        if seq1[i-1] == seq2[j-1]: # add matching characters to LCS<br>            lcs[index-1] = seq1[i-1]<br>            i -= 1<br>            j -= 1<br>            index -= 1<br>        elif table[i-1][j] &gt; table[i][j-1]: <br>            i -= 1<br>        else:<br>            j -= 1<br>            <br>    # Printing the longest common subsequence and its length <br>    print(&quot;Sequence 1: &quot; + seq1 + &quot;\nSequence 2: &quot; + seq2)<br>    print(&quot;LCS: &quot; + lcs + &quot;, length: &quot; + str(len(lcs)))</pre><p>Example usage:</p><pre>seq1 = &#39;STONE&#39;<br>seq2 = &#39;LONGEST&#39;<br>lcs(seq1, seq2)</pre><p>Output:</p><pre>Sequence 1: STONE<br>Sequence 2: LONGEST<br>LCS: ONE, length: 3</pre><p>Now, let’s take a look at how this algorithm is used in the… <a href="#0f4d">↓</a></p><h3>(Global) Sequence Alignment Problem</h3><h4>Why do we want to align DNA/RNA/protein sequences?</h4><p>In intuitive terms, aligning two sequences is a task of locating identical segments between the two sequences, serving the ultimate goal of assessing the level of <em>similarity</em> between them. Relatively straightforward in concept, this task has always been quite intricate in practice because of the uncountable changes that could happen to DNA and protein sequences through evolution. Specifically, common examples of these changes include:</p><ul><li>Point mutation, through insertion, deletion, or substitution:<br>- Insertion example: AAA → A<strong><em>C</em></strong>AA<br>- Deletion example: AAA → AA<br>- Substitution example: AAA → A<strong><em>G</em></strong>A</li><li>Fusion of sequences or segments from different genes</li></ul><p>These unintended changes can introduce ambiguities and differences that mask our understanding of a given sequence. This is where we use alignment techniques to assess the similarity between sequences and <em>infer</em> characteristics such as homology.</p><h4>How do we align sequences?</h4><p>Because of these evolutionary changes, and because of the nature of biological sequence comparisons, unlike in LCS where we simply discard the “unmatchable” elements and only keep the common segment, in global sequence alignment, we must align all characters, which means alignments often involve 3 components:</p><ul><li><strong>Matches</strong>,<strong> </strong>denoted by | between the matching bases</li><li><strong>Mismatches</strong>,<strong> </strong>denoted by blank spaces between the mismatched bases</li><li><strong>Gap insertions</strong>, denoted by dashes —</li></ul><p>Here’s an example. Suppose we have two DNA sequences “ACCCTG” and “ACCTGC”. There are a number of ways to match them base-to-base, taking into consideration the 3 operations we talked about earlier:</p><p>We could align them without any gap insertions:</p><pre>ACCCTGT<br>|||   |<br>ACCTGCT</pre><p>This alignment has 0 gap insertions, 3 matches, followed by 3 mismatches, and then 1 match at the end.</p><p>Or we could allow gap insertions in exchange for more matches:</p><pre>ACCCTG-T<br>||| || |<br>ACC-TGCT</pre><p>This alignment has 6 total matches, 2 gaps, and 0 mismatches (we don’t count a base-gap pair as a mismatch, since a gap penalty already comes with the gap insertion).</p><p>Or, if we really wished, we could also align them this way, which yields only 1 total match:</p><pre>-ACC-CT-GT<br>  |    <br>ACCTG-CT--</pre><p>Between any pair of sequences, there are almost always infinite ways to generate <em>technically</em> correct alignments as we saw just now. Some of them will be quite obviously worse than others, but there will be a few “approximately equally good” ones, such as options 1 and 2 above.</p><p>So, how do we evaluate the quality of each alignment, choose the optimal alignment, and break ties if we need to?</p><h4>Scoring schemes</h4><pre>1. ACCCTGT                   2. ACCCTG-T                  3.  -ACC-CTGT<br>   |||   |                      ||| || |                        |    <br>   ACCTGCT                      ACC-TGCT                      ACCTG-CT-</pre><p>In the example we saw above, each alignment involves a different combination of numbers of matches, mismatches, and gaps.</p><p>Unlike the LCS problem where a subsequence is only evaluated by its length — the longer the better — , in sequence alignment, we often measure the quality of an alignment by defining a <strong>quantitative scoring system</strong> that encompasses the 3 key components of each base-to-base pairing:</p><ul><li><strong>Match reward</strong>: the score added to the overall alignment score whenever there is a base-to-base match pair in our sequence.</li><li><strong>Gap penalty</strong>: the penalty value subtracted from the overall alignment score each time we introduce a gap.</li><li><strong>Mismatch penalty: </strong>the penalty value subtracted from the overall alignment score each time we have a mismatch.</li></ul><h4><strong>How do we formalize this as an algorithm?</strong></h4><p>The algorithmic solution significantly overlaps with the LCS solution in structure. It’s also a 3-step process, known as the Needleman-Wunsch algorithm:</p><ol><li>Initialization (create an <em>m</em> × <em>n</em> matrix, where <em>m</em> and <em>n </em>are the lengths of sequence 1 and sequences 2)</li><li>Fill out the matrix according to the recursive formula given below</li><li>Traceback to find the optimal alignment as well as its length</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/754/1*k9RPHGGeSezp2Fqy4-tK7Q.png" /><figcaption>Image source:<em> Understanding Bioinformatics³</em> (Zveibil and Baum, 2007), Eq5.17.</figcaption></figure><p>Before we get to the mathematical and Python formulation of the solution, here’s a quick illustration of the process with the sequences “ACGTGTCAG” and “ATGCTAG”:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/1*EK311ah8d2c03MOqifltpg.gif" /><figcaption>Illustration of Needleman-Wunsch algorithm for aligning two DNA sequences. (Image by author)</figcaption></figure><h4>Python solution</h4><p>Let’s implement the Python solution using a class, GlobalSeqAlign, which handles both filling out the matrix as well as the traceback.</p><p>First, we construct an object containing the 5 pieces of key information: sequence 1, sequence 2, match score, mismatch penalty, and gap penalty.</p><pre>class globalSeqAlign:<br>    def __init__(self, s1, s2, M, m, g):<br>        self.s1 = s1   <br>        self.s2 = s2<br>        self.M = M   <br>        self.m = m   <br>        self.g = g</pre><p>Then, we define a helper function that retrieves the score between two bases depending on whether they’re a match, mismatch, or base-gap pair:</p><pre>    def base_pair_score(self, char1, char2):<br>        if char1 == char2:<br>            return self.M<br>        elif char1 == &#39;-&#39; or char2 == &#39;-&#39;:<br>            return self.g<br>        else:<br>            return self.m</pre><p>Now, we define a function very similar to the LCS function we saw earlier, which uses a <em>m</em> × <em>n</em> matrix, fills it according to the recursive formula, and then traces back to return the optimal alignment that <strong>maximizes the total score</strong>:</p><pre>def optimal_alignment(self, s1, s2): <br>        m = len(s1)  <br>        n = len(s2)<br>        score = [[0 for x in range(n+1)] for x in range(m+1)]<br><br>        # Calculate score table<br>        for i in range(m+1): # Initialize with 0s <br>            score[i][0] = self.g * i<br>        for j in range(n+1): # Initialize with 0s<br>            score[0][j] = self.g * j<br>        for i in range(1, m+1): # Fill remaining cells based on recursive formula above<br>            for j in range(1, n+1):<br>                match = score[i-1][j-1] + self.base_pair_score(s1[j-1], s2[i-1]) <br>                delete = score[i-1][j] + self.g<br>                insert = score[i][j-1] + self.g<br>                score[i][j] = max(match, delete, insert)<br><br>        # Traceback, beginning from bottom-right cell<br>        align1 = &quot;&quot;<br>        align2 = &quot;&quot;<br>        i = m<br>        j = n<br>        <br>        while i &gt; 0 and j &gt; 0:<br>            score_curr = score[i][j]<br>            score_diag = score[i-1][j-1]<br>            score_up = score[i][j-1]<br>            score_left = score[i-1][j]<br><br>            if score_curr == score_diag + self.base_pair_score(s1[j-1], s2[i-1]): # match <br>                align1 += s1[j-1]<br>                align2 += s2[i-1]<br>                i -= 1<br>                j -= 1<br>            elif score_curr == score_up + self.g: # upward <br>                align1 += s1[j-1]<br>                align2 += &#39;-&#39;<br>                j -= 1<br>            elif score_curr == score_left + self.g: # leftward <br>                align1 += &#39;-&#39;<br>                align2 += s2[i-1]<br>                i -= 1<br>        while j &gt; 0:<br>            align1 += s1[j-1]<br>            align2 += &#39;-&#39;<br>            j -= 1<br>        while i &gt; 0:<br>            align1 += &#39;-&#39;<br>            align2 += s2[i-1]<br>            i -= 1<br><br>        return(align1[::-1], align2[::-1]) # Reverse order</pre><p>Once we have the optimal alignment, we can then proceed with the analysis quantifying how well the sequences match.</p><h4>Quantifying similarity: percentage similarity</h4><p>One of the simplest ways to measure the “level of similarity” is through <em>percentage similarity. </em>We take the optimal alignment, look at its length, and divide it by the total length of the matched regions.</p><p>For example:</p><pre>Seq 1:  ACACAGTCAT<br>        |||| |||||<br>Seq 2:  ACACTGTCAT</pre><p>There are 9 matches out of the 10 total pairs, which yields a 90% similarity. There are many other interesting ways to analyze the quality of an alignment, but the underlying mechanism of sequence alignment remains the same.</p><h3>LCS &amp; Global Sequence Alignment Comparison</h3><p>Now that we have walked through both problems and their solutions in detail, let’s look at LCS and global sequence alignment side by side.</p><h4>Similarities</h4><ul><li><strong>Objective</strong>: both problems find and maximize the similarities and common elements in the input sequences.</li><li><strong>Algorithmic approach</strong>: both problems can be solved using dynamic programming, which involves a DP matrix/table, filling out the matrix, and tracing back to produce the sequences/alignments.</li><li><strong>Scoring scheme</strong>: both problems have scores associated with matches, mismatches (and gaps) in sequence matching. These scores are explicitly and implicitly used in the algorithm to retrieve the optimal subsequence/alignment.</li></ul><h4>Differences</h4><ul><li><strong>Scoring systems:<br>- </strong>LCS automatically adopts a scoring scheme of match score = 1, mismatch/gap = 0;<br>- Global sequence alignment has a more complex scoring scheme defined by match score = A, mismatch penalty = B, gap penalty = C.</li><li><strong>Gap Handling:<br>- </strong>LCS usually treats gaps equal to mismatches because by definition of subsequences, we <em>only keep </em>the<em> matches;<br>-</em> Global sequence alignment usually assigns gaps penalty score, different from the mismatch penalty if there is a preference for mismatch/gap.</li><li><strong>Length of Alignment</strong>: <br>- LCS is concerned with finding a <strong>segment</strong> common to all inputs, disregarding the elements that are not part of this segment;<br>- Global sequence alignment matches the <em>entire</em> given sequences, even if it means inserting gaps if the input sequences differ in length.</li></ul><p>Here’s a summary table of the points above:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jYIkWFcJx3iZL1LIqNXx7w.png" /><figcaption>(Image by author)</figcaption></figure><h3>Conclusion</h3><p>Thanks for sticking with me this far 😼! In this article, we focused on one specific dynamic programming problem — the Longest Common Subsequence — and did a side-by-side comparison with its application in computational biology for Sequence Alignment.</p><p>Later in this series, we’ll also be looking at other topics, such as Hidden Markov Models, Gaussian Mixture Models, and Classification algorithms, and how they solve specific problems in computation biology. Happy coding ✌🏼!</p><p>[1] Baba, K., Nakatoh, T., &amp; Minami, T. (2017). Plagiarism detection using document similarity based on distributed representation. <em>Procedia Computer Science</em>, <em>111</em>, 382–387. <a href="https://doi.org/10.1016/j.procs.2017.06.038">https://doi.org/10.1016/j.procs.2017.06.038</a></p><p>[2] Cormen, T. H. (Ed.). (2009). <em>Introduction to algorithms</em> (3rd ed). MIT Press.</p><p>[3] Zvelebil, M. J., &amp; Baum, J. O. (2008). <em>Understanding bioinformatics</em>. Garland Science.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3499c24d2ac8" width="1" height="1" alt=""><hr><p><a href="https://pub.towardsai.net/from-bits-to-biology-1-using-lcs-algorithm-for-global-sequence-alignment-in-computational-biology-3499c24d2ac8">From Bits to Biology #1: Using LCS Algorithm for Global Sequence Alignment in Computational Biology</a> was originally published in <a href="https://pub.towardsai.net/">Towards AI</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>