<?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 grégory châtel on Medium]]></title>
        <description><![CDATA[Stories by grégory châtel on Medium]]></description>
        <link>https://medium.com/@chatel-gregory?source=rss-56d8e184a72a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*SOFFFpvJXjG0IYKaoI4KOg.jpeg</url>
            <title>Stories by grégory châtel on Medium</title>
            <link>https://medium.com/@chatel-gregory?source=rss-56d8e184a72a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 01:31:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@chatel-gregory/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[A book a week]]></title>
            <link>https://chatel-gregory.medium.com/a-book-a-week-a28d1dff42c9?source=rss-56d8e184a72a------2</link>
            <guid isPermaLink="false">https://medium.com/p/a28d1dff42c9</guid>
            <category><![CDATA[mindfulness]]></category>
            <category><![CDATA[reading]]></category>
            <category><![CDATA[life-hacking]]></category>
            <category><![CDATA[challenge]]></category>
            <category><![CDATA[lifestyle]]></category>
            <dc:creator><![CDATA[grégory châtel]]></dc:creator>
            <pubDate>Sun, 29 Nov 2020 12:37:29 GMT</pubDate>
            <atom:updated>2020-11-29T12:37:29.051Z</atom:updated>
            <content:encoded><![CDATA[<p>In this blog post, I will explain how I started the habit of reading one book a week, the reasons I did it and the benefits I’ve noticed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8A2u7VBgU8arzX2e2k_EvQ.jpeg" /><figcaption>Static reading session.</figcaption></figure><h3>Disclaimer</h3><p>I would like to start with a few warnings. I am a data scientist and <strong>very OCD</strong> when I do things. I <strong>LOVE </strong>logging things about my life and going back to the data latter. You absolutely do not need to do any of this to try this habit, I simply enjoy it a lot. If you would like to read more books, my hope that some of the ideas explained below will be helpful to you.</p><h3>Getting to read more</h3><p>During the past few years, I have tried to reduce the number of things I own as a mindful practice. I’ve found that letting go of superfluous items improved my mood and overall happiness. A step in this path have been trying to transition from physical to electronic books by buying an eBook reader. After a while, I noticed that my reader provided a ton of interesting information like reading time estimation and book completion percentage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lsdqEpICAqMol_z_h3vCzg.png" /><figcaption>Book statistics available on Kindle eBook reader.</figcaption></figure><p>As I was transitioning to eBooks, I noticed I was paying more and more attention to these statistics. A side effect of having a book available to me everywhere I went was that I gradually started to switch from scrolling the Internet to reading a few pages while waiting or travelling. I realized that I was going through books faster than usual.</p><p>At the same time, I became more and more conscious of the amount of time I was spending on YouTube. I decided to try shifting some of this time to reading book.</p><p>Over the years, I’ve heard various people talking about reading one book every single week but it always seemed like a crazy time investment and something totally unrealistic. Then I heard David Goggins discussing about how he approached getting the world record for number of pull-ups in 24 hours.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FoTrlRR-WB8o%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DoTrlRR-WB8o&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FoTrlRR-WB8o%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/85a4303c1c59323b6f15517baeb77c28/href">https://medium.com/media/85a4303c1c59323b6f15517baeb77c28/href</a></iframe><blockquote>I’m going right to a pen and paper. I’m doing the math man.</blockquote><blockquote>- David Goggins.</blockquote><h3>14%</h3><p>As a slightly less extreme version of Goggins’ process, I did the math too.</p><p>I started by estimating my reading speed in terms of <strong>locs</strong> or <strong>locations</strong>. Locations are the way Kindle readers indicate book positions, just as a page numbers would with physical books. It is used to deal with the fact that when you can to modify the font, margin size and line spaces of a book, page number becomes irrelevant. From what I’ve found on the internet, a location roughly corresponds to 125 characters or 23 words. Depending on the book, I’ve estimated that <em>I usually</em> <em>read 5 to 7 locs a minute</em>. The big advantage of using location over page number is that you can get a pretty good idea of the time it will take to read a book.</p><p><strong>To read 100% of a book in 7 days, you need to read around 14% of it daily.</strong> Combining this information with the length of book and my reading speed, I can get a pretty good idea of the time I need to spend reading everyday. Let’s take an example. The book “Snuff” by Chuck Palahniuk is 2198 location long and let’s say I read it at a speed of 6 loc/mn. This gives us a reading time of around 366 minutes which, divided by 7, tells me that I should spend around 52 minutes reading daily. Not bad!</p><h3>Staying on track</h3><p>In order to monitor how I am doing, I track my book progress in a simple note taking app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*pWYcz5jQ7DPwULzY7ehhcQ.png" /><figcaption>Logging reading progress.</figcaption></figure><p>In this list, I have the book name, the position at which I will stop reading it (usually before the notes and appendix sections), the daily progress goal and its length in locations. This allows me to know whether I’m falling behind and keep track of how long each book took to read.</p><p>Using this statistics, I fill a table of the book I have completed along with thoughts and opinions I have as I finish it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*96TkHbYAZIjG098_7RzQdA.png" /><figcaption>Completed book table.</figcaption></figure><p>I find the process of completing a book and reformulating the main takeaways in my own words very satisfying.</p><h3>Getting off track</h3><p>While everything that have explained so far is very rigid, I mainly use all of these tools track my read habit as I would track runs with an application like Strava. My goal is to read a book a week <strong>on average</strong>. During some weeks I will read more than one if I’m super into it and during others I will progress a lot slower. Since the beginning of my tracking I have actually read more books than one per week.</p><h3>Summary</h3><p>As I’ve said in the disclaimer, I am very obsessive when it comes to tracking things but it works quite well for me to make new habits stick. The main takeaway of this post is that, when you properly think about it and plan accordingly, reading a book a week is very achievable goal for most people.</p><h4>Reading a book a week is very achievable goal for most people.</h4><p>If that’s something that you might be interested in, I hope that my ramblings have helped push you in this direction.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a28d1dff42c9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Genetic Algorithms from scratch]]></title>
            <link>https://chatel-gregory.medium.com/genetic-algorithms-from-scratch-be38f85352db?source=rss-56d8e184a72a------2</link>
            <guid isPermaLink="false">https://medium.com/p/be38f85352db</guid>
            <category><![CDATA[problems]]></category>
            <category><![CDATA[visualization]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[genetic-algorithm]]></category>
            <dc:creator><![CDATA[grégory châtel]]></dc:creator>
            <pubDate>Sat, 09 Sep 2017 12:56:44 GMT</pubDate>
            <atom:updated>2017-09-09T13:36:14.883Z</atom:updated>
            <content:encoded><![CDATA[<p>While I was studying Computer Science at university, I came across genetic algorithms, a way to find very good approximations to hard problems. This family of algorithm is inspired by <a href="https://en.wikipedia.org/wiki/Evolution">biological evolution</a> in which a population evolves from one generation to the next one by selecting the fittest individuals, reproducing and mutating.</p><p>I was and still am amazed by how such a simple idea could help to solve (and by solving I mean finding a good approximation) problems this complicated. Here are a few examples of problems that can be tackled with this method:</p><ul><li>The <a href="https://en.wikipedia.org/wiki/Travelling_salesman_problem">Travelling Salesman Problem</a>: You have to find an order to visit a set of cities that have the lowest gas consumed possible.</li><li>Scheduling problem: You are playing a real time strategy video game and you want to have a specific set of units as soon as possible. The goal is to find the most efficient build order to achieve this task. Some people applied <a href="http://lbrandy.com/blog/2010/11/using-genetic-algorithms-to-find-starcraft-2-build-orders/">this concept to Starcraft 2</a>.</li><li>Evolving a population of creature to complete a specific task like <a href="https://www.youtube.com/watch?v=xcIBoPuNIiw">walking</a> or <a href="https://www.youtube.com/watch?v=U4B1yceNUik">jumping</a>.</li></ul><p>In this blog post, we will build a very simple genetic algorithm to find a reasonable solution to the Traveling Salesman Problem (TSP).</p><p>First, let’s state the TSP properly. The input of this problem is a set of cities which looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/767/1*xpmuyS43BZOLREGux6D6AQ.png" /><figcaption>The 40 cities we want to visit.</figcaption></figure><p>From that, we want to find an itinerary that goes through these cities using as little gas as possible. A good solution for this problem could look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*yrWsi20qZaKMSzvLw3HWvQ.png" /><figcaption>An efficient itinerary to visit each of the 40 cities of the problem.</figcaption></figure><p>To be precise, we try to find an itinerary that minimizes the sum of Euclidean distances between consecutive cities.</p><p>It is important to note that the solution presented above is not <strong>THE</strong> best one for this problem. The TSP is what computer scientists call a <a href="https://en.wikipedia.org/wiki/NP-hardness">NP-hard problem</a> which means that there <a href="https://en.wikipedia.org/wiki/P_versus_NP_problem">probably</a> does not exist a polynomial algorithm to solve it. Genetics Algorithms do not provide exact solutions but <a href="https://en.wikipedia.org/wiki/Heuristic_(computer_science)">heuristics</a> (approximate solution). In a sense, we are trading accuracy for speed, which is great since there are a lot of super hard problems where a good solution is enough to work with.</p><p>Now that the problem is properly stated, let’s do the parallel between biological concepts and elements of the Traveling Salesman Problem.</p><p>When trying to apply genetic algorithms, the first thing to do is to build a mapping between a list of biological concepts and details of our problem. The evolutionary elements are the following ones:</p><ul><li><strong>Individual</strong>: an individual of our specie.</li><li><strong>Population</strong>: a group of individual which will evolve over time.</li><li><strong>Fitness measure</strong>: a way to quantify how adapted an individual is to its environment.</li><li><strong>Reproduction</strong>: an operation that creates a new individual from two parents in a way that he takes characteristics from both his parents.</li><li><strong>Selection</strong>: a way to choose which individual will reproduce.</li><li><strong>Mutation</strong>: a operation that slightly modifies an individual in order to keep diversity in the genome of the population and find creative ways to increase fitness that other individuals do not possess.</li></ul><p>Now, let’s build this mapping!</p><p>In our case, an <strong>individual</strong> will be an itinerary (the order of visit) that goes through each of the cities. The<strong> population</strong> will be a set of individuals, in our case, itineraries. The <strong>fitness measure</strong> of an individual is the total distance traveled in this path. This metric should represent what we want to optimize for our problem.</p><p>Now the more interesting concepts:</p><ul><li>We define the <strong>reproduction</strong> of two path as follows: we take the order of visit of half the cities from the first path and the order of visit of the other half from the second path. Let’s see it on an example.</li></ul><p>First path = [A, F, G, C, D, H, B, E]</p><p>Second path = [E, D, C, B, F, H, G, A]</p><p>We select 4 cities from the first path: [F, G, H, E]</p><p>and the remaining 4 from the second one: [D, C, B, A]</p><p>new individual = [F, G, H, E, D, C, B, A]</p><p>There are many different ways to define the reproduction of two paths, this is the one I chose.</p><ul><li>To <strong>select </strong>individuals for reproduction, we chose the first one from the top 15% fittest individuals and the second one randomly. Once again, there are many different ways to select individuals, I chose this one because it is really simple and powerful enough.</li><li>In our case, the mutation consists in taking a random slice of the itinerary and reversing it. Let’s see it on an example:</li></ul><p>Individual = [F, G, H, E, D, C, B, A]</p><p>We randomly choose a slice: [D, C, B]</p><p>And reverse it: [B, C, D]</p><p>The mutated individual is then: [F, G, H, E, B, C, D, A]</p><p>As always, there are many possible choices for the mutation. I thought of this one while trying to solve a pattern that reproduction did not seem able to deal with (crosses between paths).</p><p>Now that we have our mapping, we can implement the core of our genetic algorithm.</p><p>The pseudo-code of the algorithm is the following:</p><pre>population = randomly create initial population()<br>for each generation:<br>    survivors number = population size - number of reproduction -<br>                       number of mutation<br>    new population = top &#39;survivors number&#39; fittest of population</pre><pre>    for &#39;number of reproduction&#39; times:<br>        first individual = select individual from top 15% fittest<br>        second individual = randomly select an individual <br>        new individual = reproduce(first individual, second<br>                                   invidual)<br>        new population = new population + new individual</pre><pre>    for &#39;number of mutation&#39; times:<br>        individual to mutate = randomly select an individual<br>        new individual = mutate(individual to mutate)<br>        new population = new population + new individual</pre><p>And that’s all!</p><p>To conclude, here is a short video showing the fittest individual for each generation of the population on a run of our Genetic Algorithm:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FsHDOa0K6-Kk%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DsHDOa0K6-Kk&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FsHDOa0K6-Kk%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/da5bb79bb6da066da159c9987cd2cb24/href">https://medium.com/media/da5bb79bb6da066da159c9987cd2cb24/href</a></iframe><p>You can find the code used to generate the pictures of this post and the genetic algorithm implementation <a href="https://github.com/rodgzilla/simple_genetic_algorithm/blob/master/genetic_algorithm.py">on my GitHub</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be38f85352db" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Adversarial examples in deep learning]]></title>
            <link>https://medium.com/data-science/adversarial-examples-in-deep-learning-be0b08a94953?source=rss-56d8e184a72a------2</link>
            <guid isPermaLink="false">https://medium.com/p/be0b08a94953</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[adversarial]]></category>
            <category><![CDATA[towards-data-science]]></category>
            <dc:creator><![CDATA[grégory châtel]]></dc:creator>
            <pubDate>Tue, 13 Jun 2017 15:57:40 GMT</pubDate>
            <atom:updated>2019-09-24T14:41:56.850Z</atom:updated>
            <content:encoded><![CDATA[<p>This post will contain essentially the same information as <a href="https://github.com/rodgzilla/Deep-learning-presentation/blob/master/adversarial_samples/gchatel_adversarial_samples.pdf">the talk</a> I gave during the last <a href="https://www.meetup.com/Deep-Learning-Paris-Meetup/">Deep Learning Paris Meetup</a>. I feel that as more and more fields start to use deep learning in critical systems, it is important to bring awareness on how neural networks can be fooled to produce strange and potentially dangerous behaviors. The goal of this post is not to be as mathematically precise and exhaustive as possible but to give you a basic understanding of adversarial examples and hopefully to sensibilize you to one of the problems of modern day deep learning.</p><p>This blog post and more informations about machine learning security are available at the following address: <a href="https://www.mlsecurity.ai/blog">mlsecurity.ai/blog</a>.</p><p>Before starting this post, I would also like to mention that I am not part of the researchers who did this work. I am just a really curious guy from the fast.ai MOOC who’s passionate about deep learning.</p><p>So first, what are adversarial examples?</p><p>An adversarial example is a sample of <strong>input data</strong> which has been modified <strong>very slightly</strong> in a way that is intended to cause a machine learning to misclassify it.</p><p>An example should help anchor the idea.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/952/1*UK7fXksTKW095uwH8sFL0Q.png" /><figcaption>An image classified as “suit” by the VGG16 neural network (left), a perturbation created specifically using the image on the left (middle) and the resulting perturbed image classified as a wig (right).</figcaption></figure><p>In this figure, we can see that the classification of the perturbed image (rightmost) is clearly absurd. We can also notice that the difference between the original and modified images is <strong>very slight</strong><em>.</em></p><p>With article like <a href="https://www.wired.com/2017/03/californias-finally-ready-truly-driverless-cars/">“California’s finally ready for truly driverless cars”</a> or <a href="https://www.nytimes.com/2016/10/26/us/pentagon-artificial-intelligence-terminator.html">“The Pentagon’s ‘Terminator Conundrum’: Robots That Could Kill on Their Own”</a>, applications of adversarial examples are not exactly hard to come up with…</p><p>In this post I will first explain how such images are created and then go through the main defenses that have been published. For more details and more rigorous information, please refer to the research papers referenced.</p><p>First, a quick reminder on <strong>gradient descent</strong>. Gradient descent is an optimization algorithm used to find a local minimum of a differentiable function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*yzIUvZMFY-7AapEghRyh5A.png" /><figcaption>A curve and a tangent to this curve.</figcaption></figure><p>In the figure on the left, you can see a simple curve. Suppose that we want to find a local minimum (a value of <em>x </em>for which<em> f(x) </em>is locally minimal).</p><p>The gradient descent consists in the following steps: first pick an initial value for <em>x, </em>then compute the derivative <em>f’</em> of <em>f </em>according to x and evaluate it for our initial guess. <em>f’(x)</em> is the slope of the tangent to the curve at <em>x. </em>According to the sign of this slope, we know whether we have to increase or decrease<em> x </em>to make<em> f(x) </em>decrease. In the example on the left, the slope is negative so we should increase the value of <em>x</em> to make <em>f(x)</em> decrease. As the tangent is a good approximation of the curve in a tiny neighborhood, the value change applied to x is very small to ensure that we do not jump too far.</p><p>Now, we can use this algorithm to train machine learning models.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/1*R5vobcX_n1SdtBO4hNi9QQ.png" /><figcaption>A set of data points and a linear model initialized randomly.</figcaption></figure><p>Suppose that we have a set of points and we want to find a line that is a reasonable approximation for these values.</p><p>Our machine learning model will be the line <em>y = ax + b</em> and the model parameters will be<em> a </em>and<em> b</em>.</p><p>Now to use the gradient descent, we are going to define a function of which we will want to find a local minimum. This is our <strong>loss function</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/485/1*UyJCJvv2ONvCbECDG2sJhg.png" /></figure><p>This loss takes a data point <em>x</em>, its corresponding value <em>y</em> and the model parameters <em>a</em> and <em>b</em>. The loss is the squared difference of the real value <em>y</em> and <em>ax + b, </em>the prediction of our model. The bigger the difference between the real and predicted values is, the bigger the value of the loss function will be. Intuitively, we chose the squaring operation to penalize big differences between real and predicted values more than small ones.</p><p>Now we compute the derivative of our function <em>L</em> according to the parameters of the model <em>a</em> and <em>b</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*6GznZHLNygeaBL2fGvreJw.png" /></figure><p>And as before, we can evaluate this derivatives with our current values of <em>a</em> and <em>b</em> for each data point <em>(x, y)</em>, which will give us the slopes of the tangents to the loss function and use these slopes to update <em>a</em> and <em>b</em> in order to minimize <em>L.</em></p><p>OK, that’s cool and all but that’s not how we’re going to generate our adversarial examples…</p><p>Well, in fact it is exactly how we are going to do it. Suppose now that the model is fixed (you can’t change <em>a</em> and <em>b</em>) and you want to increase the value of the loss. The only thing left to modify are the data points <em>(x, y)</em>. As modifying the <em>y</em>s does not really make sense, we will modify the <em>x</em>s.</p><p>We could just replace the x by random values and the loss value would increase by a tremendous amount but that’s not really subtle, in particular, it would be really obvious to a human plotting the data points. To make our changes in a way that is not obviously detected by an observer, we will compute the derivative of the loss function according to <em>x.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/343/1*eRKqOYuNV2v01rjlxbZ-DQ.png" /></figure><p>And now, just as before, we can evaluate this derivative on our data points, get the slope of the tangent and update the <em>x</em> values by a small amount accordingly. The loss will increase and, as we are modifying all the points by a small amount, our perturbation will be hard to detect.</p><p>Well that was a very simple model that we’ve just messed with, deep learning is much more complicated than that…</p><p>Guess what? It’s not. Everything we just did has a direct equivalent in the world of deep learning. When we are training a neural network to classify images, the loss function is usually a categorical cross entropy, the model parameters are the weights of the network and the inputs are the pixel values of the image.</p><p>The basic algorithm of adversarial sample generation, called <strong>Fast Gradient Sign Method</strong> (from <a href="https://arxiv.org/abs/1412.6572">this paper</a>), is exactly what I described above. Let’s explain it and run it on an example.</p><p>Let <em>x</em> be the original image, <em>y</em> the class of <em>x</em>, <em>θ</em> the weights of the network and <em>L(θ, x, y)</em> the loss function used to train the network.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/195/1*MkXlLqkfUHDk--wTO6zviQ.png" /></figure><p>First, we compute the gradient of the loss function according to the input pixels. The <em>∇ </em>operator is just a concise mathematical way of taking the derivatives of a function according to many of its parameters. You can think of as a matrix of shape <em>[width, height, channels] </em>containing the <strong>slopes of the tangents</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/392/1*UvZ269E0pO81wkEZSpXJDg.png" /></figure><p>As before, we are only interested in the sign of the slopes to know if we want to increase or decrease the pixel values. We multiply these signs by a very small value <em>ε </em>to ensure that we do not go too far on the loss function surface and that the perturbation will be imperceptible. This will be our <strong>perturbation</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/199/1*zjY45116ogs82Ynzjnqjkg.png" /></figure><p>Our final image is just our original image to which we add the perturbation <em>η.</em></p><p>Let’s run it on an example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z-iezcSRYcgjselNQ6LI5g.png" /><figcaption>FGSM applied to an image. The original is classified as ‘king penguin’ with 100% confidence and the perturbed one is classified as ‘tripod’ with 71% confidence.</figcaption></figure><p>The family of attack where you are able to use compute gradients using the target model are called <strong>white-box attacks</strong>.</p><p>Now you could tell me that the attack I’ve just presented is not really realistic as you’re unlikely to get access to the gradients of the loss function on a self-driving car. Researchers thought exactly the same thing and, in <a href="https://arxiv.org/abs/1602.02697">this paper</a>, they found a way to deal with it.</p><p>In a more realistic context, you would want to attack a system having only access to its outputs. The problem with this is that you would not be able to apply the <em>FGSM</em> algorithm anymore as you would not have access to the network itself.</p><p>The solution proposed is to train a new neural network <em>M’ </em>to solve the same classification task as the target model <em>M</em>. Then, when <em>M’</em> is trained, use it to generate adversarial samples using <em>FGSM</em> (which we now can do since it is our own network) and ask <em>M</em> to classify them.</p><p><strong>What they found is that <em>M</em> will very often misclassify adversarial samples generated using <em>M’</em></strong>. Moreover, if we do not have access to a proper training set for <em>M’</em>, we can build one using <em>M</em> predictions as truth values. The authors call this synthetic inputs. This is an excerpt of their article in which they describe their attack on the MetaMind network to which they did not have access:</p><p><em>“After labeling 6,400 synthetic inputs to train our substitute (an order of magnitude smaller than the training set used by MetaMind) we find that their DNN misclassifies adversarial examples crafted with our substitute at a rate of 84.24%”.</em></p><p>This kind of attack is called <strong>black-box attack </strong>as you see the target model as a black-box.</p><p>So, even when the attacker does not have access to the internals of the model he can still produce adversarial sample that will fool it but still, this attack context is not realistic either. In a real scenario, the attacker would not be allowed to provide its own image files, the neural network would take camera pictures as input. That’s the problem the authors of <a href="https://arxiv.org/abs/1607.02533">this article</a> are trying to solve.</p><p>What they noticed is that when you print adversarial samples which have been generated with a high-enough <em>ε </em>and then take a picture of the print and classify it, the neural network is still fooled a significant portion of the time. The authors recorded a video to showcase their results:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FzQ_uMenoBCk%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DzQ_uMenoBCk&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FzQ_uMenoBCk%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/a02178ad8f91bb83debd3a7937892eef/href">https://medium.com/media/a02178ad8f91bb83debd3a7937892eef/href</a></iframe><p><em>“We used images taken from a cell-phone camera as a input to an Inception v3 image classification neural network. We showed that in such a set-up, a significant fraction of adversarial images crafted using the original network are misclassified </em><strong><em>even when fed to the classifier through the camera</em></strong><em>.”</em></p><p>Now that the potential for an attack in a realistic context seems reasonable, let’s review a few defense strategies.</p><p>The first idea that comes to mind when trying to defend adversarial examples is usually to generate a lot of them and run more training passes on the network with these images and the correct class as targets. This strategy is called <strong>adversarial training</strong>.</p><p>While this strategy improves robustness to <em>FGSM </em>attacks, it has multiple downside:</p><ul><li>It does not help against more sophisticated white-box attacks like <a href="https://arxiv.org/abs/1705.07204"><em>RAND+FGSM</em></a>, which, as explained in the article, we cannot use to adversarially train a network.</li><li>It does not help against black-box attacks either.</li></ul><p>This last point is quite surprising but true and have been observed in multiple contexts. The reasons of this behavior are explored in <a href="https://arxiv.org/abs/1705.07204">this paper</a>. Proper white-box defense is something that we do not know how to do perfectly as I’m writing this post. As the authors note, the fact that adversarially trained networks are still vulnerable to black-box attacks is often not taken into account in articles that presents new defense strategies.</p><p>While white-box defense seems like a difficult problem, the hypothesis that the attacker has access to the model weights is big. Researchers tried to produce networks that are robust to black-box attacks in <a href="https://arxiv.org/abs/1705.07204">this paper</a>.</p><p>Since adversarially trained networks are still vulnerable to black-box attacks, the authors propose <strong>Ensemble Adversarial Training</strong>, a strategy which consists in adversarially training a model using modified samples from an ensemble of other models (usually 2 to 5). For example, they train a model to classify MNIST digits using adversarial examples crafted using 5 other pre-trained models. The error rate goes from 15.5% for an adversarially trained model to 3.9% for an ensemble adversarially trained model for a black-box attack.</p><p>This algorithm is the best so far at black-box defense.</p><p>As a conclusion on the defense part, I will cite a <a href="http://www.cleverhans.io/security/privacy/ml/2017/02/15/why-attacking-machine-learning-is-easier-than-defending-it.html">blog post</a> from I. Goodfellow and N. Papernot:</p><p><em>“Most defenses against adversarial examples that have been proposed so far just do not work very well at all, but the ones that do work are not adaptive. This means it is like they are playing a game of whack-a-mole: they close some vulnerabilities, but leave others open.”</em></p><p>I hope you have enjoyed reading this blog post. If you notice any spelling or mathematical mistake, don’t hesitate to leave a comment.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be0b08a94953" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/adversarial-examples-in-deep-learning-be0b08a94953">Adversarial examples in deep learning</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[What do deep neural networks understand of fractals ?]]></title>
            <link>https://medium.com/aboveintelligent/what-do-deep-neural-networks-understand-of-fractals-2ae354911601?source=rss-56d8e184a72a------2</link>
            <guid isPermaLink="false">https://medium.com/p/2ae354911601</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[fractals]]></category>
            <category><![CDATA[neural-networks]]></category>
            <dc:creator><![CDATA[grégory châtel]]></dc:creator>
            <pubDate>Thu, 27 Apr 2017 15:36:54 GMT</pubDate>
            <atom:updated>2017-04-27T15:36:54.703Z</atom:updated>
            <content:encoded><![CDATA[<p>A few months ago, I started the <a href="http://fast.ai/">fast.ai</a> deeplearning MOOC (which is awesome by the way). During this course, I learned how to use, tune and create neural networks but I still lack <em>intuition </em>on network architectures. I decided to run a little experiment to clarify my ideas and I think it could be interesting to some people.</p><p>All the code used to produce this post is available on <a href="https://github.com/rodgzilla/machine_learning_mandelbrot_neural_network">Github</a>.</p><p>A neural network is often seen as a black box that approximates a function based on a few example computations. The more complex the neural network, the more complicated the functions it can approximate. That seems easy enough to grasp but what troubled me is the lack of quantifier: how complex does a neural network need to be to approximate a given function ?</p><p>Intuitively, a neural network simply computes a big function that contains <a href="https://en.wikipedia.org/wiki/Linear_combination">linear combinations</a> of variables interwoven with functions that add non-linearities. The internal parameters of this network are then tuned to get a network that fit our use case. The three main parameters for a simple neural network are:</p><ul><li>the number of layers which corresponds to the number of linear combinations that will be computed,</li><li>the number of nodes in each of the layer which corresponds to the number of inputs of each of these linear combinations</li><li>the activation function used to add non-linearity into the network.</li></ul><p>Sure, the <a href="https://en.wikipedia.org/wiki/Universal_approximation_theorem">universal approximation theorem</a> essentially tells us that this kind of neural network can approximate basically anything with a single layer between the inputs and the outputs given enough nodes. That’s not really useful in practice as this does not give us any idea on the number of nodes necessary (<a href="https://www.quora.com/What-is-the-implication-of-the-Universal-Approximation-Theorem-over-deep-learning-methodology">among other reasons</a>).</p><p>To see a bit clearer in this world, I chose to take a very complicated function and ask various neural networks what they understand of it. The function that I chose to approximate comes from the world of fractal geometry and I will now give an outline of its computation.</p><p>What interest us is whether this sequence diverges (the norm of each term goes to infinity) or not for a complex number <em>c</em> when <em>n </em>goes to infinity:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/304/1*TIDXHjKQ5recMA_2aJCIlA.png" /></figure><p>This function might seem strange but it is in fact well known, not as itself but as what it allows to draw: the <a href="https://en.wikipedia.org/wiki/Mandelbrot_set">Mandelbrot set</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7mnkvrn_sgL2XHkQmWZSew.png" /><figcaption>The mandelbrot set (image from wikipedia.org)</figcaption></figure><p>In this image, each pixel corresponds to a complex number: the <em>x </em>and<em> y </em>coordinates gives us respectively the real and imaginary part of the complex number. To get the color of the pixel <em>(x, y)</em>, we first find the associated complex number <em>c</em> and use it to compute the <em>z</em> sequence presented above. If this sequence diverges, the pixel is white and if not, the pixel is black.</p><p>I will not get into the details on how to test if a sequence diverges as there is a ton of excellent tutorial on this on the Internet. Here, we are just going to assume that we know how to do it.</p><p>The function that we are trying to approximate is the following one:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/435/1*pduRzM_fcsGrtTDS0cLWSw.png" /></figure><p>To build the data set we will use to train the network we take a lot of complex numbers and compute their images by the function <em>f</em>. The goal of the network will be to approximate <em>f</em> as well as possible (<em>i.e.</em> the color of the pixel in the image).</p><p>I have created three grids, one for each the following activation functions (the non-linear bits of the network): <a href="https://en.wikipedia.org/wiki/Sigmoid_function">sigmoid</a>, <a href="https://en.wikipedia.org/wiki/Hyperbolic_function#Hyperbolic_tangent">hyperbolic tangent</a> and <a href="https://en.wikipedia.org/wiki/Rectifier_(neural_networks)">rectified linear unit</a>.</p><p>First, the results for the networks with the sigmoid activativations:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TWeXtsUKa6ASRQ4JZBUWNw.png" /><figcaption>Mandelbrot set approximation using various neural networks with sigmoid activations</figcaption></figure><p>These result are pretty bad, to say the least. We can see that as the number of layers and number of nodes in each layer increases, the network gets confused and do not manage to leave the <a href="https://en.wikipedia.org/wiki/Local_optimum">local optimum</a> that it found. This could be due to the fact that the sigmoid activations tend to produce <a href="http://neuralnetworksanddeeplearning.com/chap5.html#the_vanishing_gradient_problem">unstable gradients</a>.</p><p>Now the results for the hyperbolic tangent:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aAXdpUAcCAjLZnCK3cKhxg.png" /><figcaption>Mandelbrot set approximation using various neural networks with hyperbolic tangent activations</figcaption></figure><p>Already, we can see that the images produced are much better. In particular, we can also note that the depth (the number of layer) of the network seems to have a much larger impact than its width (the number of node in each layer).</p><p>And finally the results for the rectified linear unit:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZYSUqFTv7LxubaBtQtQCUA.png" /><figcaption>Mandelbrot set approximation using various neural networks with rectified linear unit activations</figcaption></figure><p>These images are also really good approximations of the Mandelbrot and we can note something really interesting. For smaller networks, the images produced are much more angular than with the hyperbolic tangent. I suppose that this phenomenon is due to the angle in the activation function:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*I3m4X5zMlOhhK8W3j3Pvkw.png" /><figcaption>rectified linear unit graph (from datascience.stackexchange.com)</figcaption></figure><p>As a conclusion, we can see that neural networks are capable of producing reasonable approximation of the Mandelbrot set. We can also note that the depth of a network increase its computation power much faster than the number of node in each of the layers.</p><p>To finish, we also validate that sigmoid activation, which were used at the beginning of the neural networks developments, are not used anymore for a good reason.</p><p>If you have any question, think that I missed something important or find an obvious mistake, do not hesitate to leave a comment.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2ae354911601" width="1" height="1" alt=""><hr><p><a href="https://medium.com/aboveintelligent/what-do-deep-neural-networks-understand-of-fractals-2ae354911601">What do deep neural networks understand of fractals ?</a> was originally published in <a href="https://medium.com/aboveintelligent">Above Intelligent™ — Latest in Artificial Intelligence</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>