<?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 Arthur Arnx on Medium]]></title>
        <description><![CDATA[Stories by Arthur Arnx on Medium]]></description>
        <link>https://medium.com/@artux51?source=rss-4aa81c733935------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*WUe_czIuo3jONzwvY1Jytg.png</url>
            <title>Stories by Arthur Arnx on Medium</title>
            <link>https://medium.com/@artux51?source=rss-4aa81c733935------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 00:57:46 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@artux51/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[About HTTP and Websockets protocols]]></title>
            <link>https://medium.com/@artux51/about-http-and-websockets-protocols-17a0020fe0f1?source=rss-4aa81c733935------2</link>
            <guid isPermaLink="false">https://medium.com/p/17a0020fe0f1</guid>
            <category><![CDATA[websocket]]></category>
            <category><![CDATA[https]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[spring]]></category>
            <dc:creator><![CDATA[Arthur Arnx]]></dc:creator>
            <pubDate>Sat, 22 Oct 2022 21:19:32 GMT</pubDate>
            <atom:updated>2022-10-22T21:19:32.910Z</atom:updated>
            <content:encoded><![CDATA[<h4>And how to add websockets easily to your web application</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*X23DBkEPcxVVTtEx" /><figcaption>Photo by <a href="https://unsplash.com/@larskienle?utm_source=medium&amp;utm_medium=referral">Lars Kienle</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>The HTTP protocol has been around for a while, allowing people to connect to websites with this Application layer protocol from the OSI model, usually coupled with the TCP protocol as the Transport layer.</p><p>The design of HTTP is very simple: a client visiting a website asks the server for the corresponding files, such as the .html, .css or any image or other scripts via requests. The first request will be about the .html file corresponding to the URL entered by the client, which will contains the actual page to be presented and all other information. This file also normally contains references to other files to complete the simple HTML tags.</p><pre>&lt;link rel=&quot;stylesheet&quot; href=&quot;css/blog.css&quot;&gt;</pre><p>Such a reference (this one in the &lt;head&gt; element) will let the client know that other files are needed for the website page to be complete. In this case, the client will send an HTTP request to the server again asking for the blog.css file, located in the css folder from the root of the project.</p><p>As we can see, HTTP is pretty straightforward with a design of one request leading to one response. The message itself contains multiple other metadata but not crucial information for the final client. We for example find the famous HTTP codes (such as 200 (OK) meaning everything went fine, or 404 (Not found) meaning the requested file was not found on the server side), the connection type, the date or the type of the following data (text, image, …).</p><p>Later versions of HTTP (1.1, 2, even 3 following the QUIC protocol) also follow the idea of one response for one request, even if it is mixed with streams for example, or with the keep-alive header to force the usage of one single TCP connection.</p><p>But what if you need to receive multiple responses from one client request, what if you want to acknowledge that the server received the request and later let the client know how the operations are doing ? What if you simply need an asynchronous bi-directional communication between the client and the server ? You maybe do not want to use long- or short-polling.</p><p>Short and long polling are hacky ways of letting an HTTP request wait for a response and/or expect multiple responses (but still needing multiple requests as well). The first one imitates a heartbeat where the client needs to ask the server on a fixed rate in order to always have a request ready to be responded as soon as it can. The second solution leaves the request unanswered to keep the connection to the client and only send the response when the server has one, but the client may be on hold for a long time.</p><figure><img alt="2 schemas of short and long polling, showing (1) recurrent requests with fast responses and (2) one request being responded a long time later" src="https://cdn-images-1.medium.com/max/989/1*1k49nDKaW8jAhDrd1TTUIA.png" /></figure><h4>Here come Websockets</h4><p>Websockets, as the name suggests, are sockets, but not any type of sockets. A specialized kind of socket for communication over the web, but without limiting to HTTP, and without the need for managing ports and sockets generation for the client.</p><p>Those Websockets are first set up with a single HTTP request that contains a specific field: Upgrade: websocket . On the reception of such a request, the server can accept this upgrade and provide the client with all related information such as the protocol to use.</p><p>After that, all communications between the server and the client can happen as with a common socket. Both can send and receive messages and handle them as they want.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/511/1*fYblBZB3u1kd0QPlgKhAtw.png" /></figure><p>Websockets use their own Application layer protocol, different from the HTTP one, but still rely on TCP.</p><p>All this is fairly easy to understand, so let’s see it in practice.</p><h4>Set up the Websockets server</h4><p>Using Spring Boot for a Java application, let’s explore how we can simply set up a websocket endpoint for a simple Rest API. We will see that it is a bit different than the common controllers of Spring.</p><p>We first need a handler for the designated endpoint, added in the configuration class, such as:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5634029e3bfc132a6b48266969cd6755/href">https://medium.com/media/5634029e3bfc132a6b48266969cd6755/href</a></iframe><p>With the handler class:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b4662d6a9f391d0aec27e3f5d2b2a456/href">https://medium.com/media/b4662d6a9f391d0aec27e3f5d2b2a456/href</a></iframe><p>And that’s it for the server side! Given this code, with some other Spring configuration to manage the entire application, our server can receive any message from sockets connected to the endpoint “/v1/api/path/example”.</p><p>We can also use the websockets in a more broadcast way, using for example the annotation <strong>@SendTo(“v1/api/path/example”)</strong> over mapped methods in a Spring controller. This will simply send the return value of the annotated function to all the subscribed sessions via websockets.</p><p>Let’s now see how the client may access it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/39f1fbb1b110ea1963953d687474b853/href">https://medium.com/media/39f1fbb1b110ea1963953d687474b853/href</a></iframe><p>Those three simple lines allow the client class to connect to the endpoint and demanding the upgrade to websockets, done with the HTTP handshake. Also note the <strong>ws://</strong> instead of <strong>http://</strong> specifying the protocol.</p><p>The second line uses our own implementation of the <strong>WebSocketHandler </strong>interface offered by Spring, inside which every methods concerning the state of the websocket’s session are to be described.</p><p>This approach is way easier to use than common sockets. While it indeed limits the application to the websocket protocol, the latter is sufficient for API problematics to simply enhance the HTTP protocol and avoid its limitations. We do not need to manage the implementation of a classic sockets usage.</p><p>After the HTTP handshake is done, the sockets are connecting the client to the server, and we can for example decide to send a first socket message in the <strong>afterConnectionEstablished </strong>method, to which the server’s handler will respond as needed. Then, the responses of the server will be handled by the <strong>handleMessage</strong> method.</p><p>Later on, we can close the socket once we have finished sharing all the information we wanted.</p><p>With this simple setup, we can for example have the client send a simple request to the server, which will first let the client know that it indeed received the request and it is manageable before executing the operations needed that may take a while. With everything done, the server comes back to the client with the result of the operations and the client is able to receive all of it with only one request done. They can easily share text messages, containing for example attributes of objects in a json format.</p><blockquote>Thanks for reading !</blockquote><blockquote>I hope you enjoyed discovering the basics of some of the most important protocols allowing everybody to access the Internet, if you have any question and/or suggestion let me know in the comments.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=17a0020fe0f1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why you should try out Golang]]></title>
            <link>https://medium.com/codex/why-you-should-try-out-golang-7d8628797bb7?source=rss-4aa81c733935------2</link>
            <guid isPermaLink="false">https://medium.com/p/7d8628797bb7</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Arthur Arnx]]></dc:creator>
            <pubDate>Sat, 09 Apr 2022 19:27:52 GMT</pubDate>
            <atom:updated>2022-04-12T01:48:59.706Z</atom:updated>
            <content:encoded><![CDATA[<h4>Golang offers some refreshing aspects compared to older languages, let’s explore a bit of that.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*J89L-8J80-kTBM5p" /><figcaption>Photo by <a href="https://unsplash.com/@rossf?utm_source=medium&amp;utm_medium=referral">Ross Findon</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>The programming langage Golang, or Go, was first developed by Googlers in 2009, and is since being regularly updated to make sure it doesn’t lack the most important features. But let’s focus on the new, before exploring what it still needs to copy from other languages.</p><h4>Concurrency becomes a pleasure (almost)</h4><p>Concurrency in Go (meaning having multiple threads running different operations at the same time) is made very easy thanks to a great feature of the langage, called goroutines. Simply adding the keywork <strong><em>go </em></strong>in front of a function call makes it concurrent, and your code continues executing without waiting for the function to end.</p><pre>go func() {<br>    fmt.Print(1)<br>}()<br>fmt.Print(2)</pre><p>The upper code may print either “1 2” or “2 1”, according to the speed of the two threads (it will most likely print “2 1” since the goroutine will need a small time to start).</p><p>With that, we can start building stronger and more complex distributed and concurrent systems with multiple nodes sharing information between them. To manage the unknown of the concurrency world, Go also make use of channels. They allow goroutines to synchronize, as a replacement of locks.</p><pre>channel := make(chan int)<br>go func() {<br>    i:=&lt;-channel<br>    fmt.Print(&quot;After &quot;, i)<br>}()<br>fmt.Print(&quot;Before &quot;)<br>channel &lt;- 42</pre><p>This time, we know with certainty that the output will be “Before After 42”, because the channel in the goroutine blocks until it receives a value, which is sent only by the main thread after having written “Before”.</p><h4>The error management</h4><p>Although it isn’t appreciated by everyone, I personally think it does the job well without being obnoxious. Here is the thing: Go works with errors like variables. There is no Exception as we can find in Java, Go wants the user to use and return errors and check for their nullness (<strong><em>nil </em></strong>in Go) when needed.</p><pre>result, err := operationWithPossibleError()<br>if err != nil {<br>    fmt.Println(&quot;We have an error here&quot;)<br>    return error<br>}</pre><p>Here when using the operation function, it can possibly return an error if something wrong happened. We receive it as a value and check it right after with this infamous “if err != nil”. Infamous for being used repeatedly in every Go program. However, it permits to keep track of the error easily and simply feels like a try/catch combination.</p><h4>What about performances ?</h4><p>Go being compiled to an executable file, it will be faster than for example Python execution. Compared to Java, Go won’t be able to work on a lot of platform without the help of the JVM, but it will be faster because it doesn’t need to load one at first.</p><p>For the same for loop of 10000000 iterations (1), making a GET request to “www.google.com” (2), or implementing 1000 threads incrementing a counter value and waiting for this value to be 1000 (3), we can observe below the time needed by each languages, in milliseconds.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*mxYvOHPDFs6FqmluFLNObQ.png" /><figcaption>Speed comparison between Go, Java and Python for multiple tasks.</figcaption></figure><blockquote>Note that Python’s for loop is notoriously slow and Jython or Cython would beat that time. In addition, Numpy’s methods should be used when possible to make loop operations over arrays way faster.</blockquote><p>Those examples are not comprehensive but still showcase some strong sides of the language.</p><h4>And more !</h4><ul><li>Go forces the user to write better code, by not allowing to declare an unused variable. According to the Go team, “<a href="https://go.dev/doc/faq#unused_variables_and_imports">the presence of an unused variable may indicate a bug</a>”.</li><li>Go is strongly typed and dynamically typed, meaning it allows creating variables without specifying its type, with the <strong><em>:=</em></strong> statement.</li><li>Go offers the <strong><em>defer</em></strong> statement to copy the idea if Java’s <strong><em>finally</em></strong>. It helps to make sure code is cleaned up at the end of the function in which it is used.</li><li>Talking of cleaning up, Go also has a garbage collector, which doesn’t let you control what happens in the memory but makes the language easier to use.</li><li>Go 1.18 will include generics, adding optional type parameter to type and function declarations</li><li>Go contains a great test framework with everything needed, and the version 1.18 will also include an implementation of fuzzing.</li></ul><blockquote>Fuzzing is a type of test automatically modifying inputs to search for bugs in a program. It is used to find possible vulnerabilities in the program and thus fuzzing in parallel to the tests allows to prevent them.</blockquote><ul><li>Go allows developers to fairly simply post the libraries they coded on GitHub to make them public and available. Anyone can import a public library in their program which makes the distribution easy.</li><li>Some commands are usable by the developer to manage the project, such as<strong><em> go get</em></strong> to download the libraries to import, <strong><em>go build</em></strong> that builds the project to an executable, <strong><em>go fmt</em></strong> (possibly ran at every save) to format the code in a conventional way to enhance its readability, and so on.</li></ul><h4>About the downsides</h4><p>As we have seen, some missing features are being added versions after versions so the language becomes more and more mature.</p><p>However, we can for example talk about the two different ways of declaring a variable, <strong><em>:=</em></strong> and <strong><em>var</em></strong>. They slightly differ, since <strong><em>var </em></strong>allows to only declare a variable without initializing it, while <strong><em>:=</em></strong> can be used with a mix of new and already declared variables.</p><p>Interface implementation feels weird in my opinion, because it doesn’t need to be explicitly written. If a type defines every types defined in an interface, then it implements the latter.</p><p>Go will make you familiar with race conditions, a type of error happening when the same data is reached by different goroutines.</p><pre>array := make([]int, 0)<br>go func() {<br>    array = append(array, 1)<br>}()<br>go func() {<br>    array = append(array, 2)<br>}()</pre><p>For example, running tests on the above piece of code with the flag <strong><em>-race</em></strong> will detect possible race conditions because access to maps or arrays should not be done concurrently, and you quickly will feel the need to create your own types of data structures with thread-safe functions.</p><p>As we have seen earlier, the error handling is pretty special, and its repetitiveness will be either loved or hated by the user.</p><p>When writing Go code, you have to be careful on the capitalization, since it indicates if the function is usable by other packages (or other go files). For example, when reusing Java’s terms, the function<strong> <em>print() </em></strong>is private while <strong><em>Print() </em></strong>is public. You can observe that every function you call from imported packages are capitalized.</p><p>Go allows the usage of pointers, which can be at the same time very useful and confusing in the beginning.</p><p>Finally, the fact that every object has a zero-value leads to possible structs instantiated with none of the fields being defined, while the struct itself is not nil.</p><h4>Is Go popular ?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l8TLXnN3TDY_CP0QjbaJdQ.png" /><figcaption>TIOBE Index for Go</figcaption></figure><p>According to the TIOBE ranking, Golang is placed in March 2022 at the 13th place of the most popular languages. We can see Go has had better days, and the community behind the language is clearly smaller than those of Python, C or Java, respectively top 1,2 and 3 with a rating superior than 10%. However, it is famous enough to have already tons of libraries ready to use and questions about common problems answered over the internet.</p><h4>Final words</h4><p>In the end, every languages have their pros and cons, so does Golang. It doesn’t have the libraries that Python offers for Machine Learning for example, nor the community and wisdom of Java, but Go definitely can be of great use when developing micro-services and distributed systems.</p><blockquote>Thanks for reading !</blockquote><blockquote>I hope you enjoyed discovering some characteristics of Golang, if you have any question and/or suggestion let me know in the comments.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7d8628797bb7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codex/why-you-should-try-out-golang-7d8628797bb7">Why you should try out Golang</a> was originally published in <a href="https://medium.com/codex">CodeX</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[An exploration of Privacy Preserving Federated Learning (with code)]]></title>
            <link>https://medium.com/data-science/an-exploration-of-a-privacy-preserving-federated-learning-system-7944fb284061?source=rss-4aa81c733935------2</link>
            <guid isPermaLink="false">https://medium.com/p/7944fb284061</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[privacy]]></category>
            <category><![CDATA[federated-learning]]></category>
            <category><![CDATA[data-privacy]]></category>
            <dc:creator><![CDATA[Arthur Arnx]]></dc:creator>
            <pubDate>Sun, 06 Mar 2022 17:19:43 GMT</pubDate>
            <atom:updated>2022-04-12T15:23:58.272Z</atom:updated>
            <content:encoded><![CDATA[<h4>To better understand ideas solving some problems of Machine Learning</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*eDptF4jDKQfiy5_D" /><figcaption>Photo by <a href="https://unsplash.com/@jdent?utm_source=medium&amp;utm_medium=referral">Jason Dent</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><strong>Machine Learning, while being a very powerful technology, appears to know some drawbacks. For example the huge need for data and the possible attacks over a neural networks, discussed later, are hopefully to be answered with some Privacy Preserving Federated Learning.</strong></p><h4>What does the title mean ?</h4><p>First of all, let’s quickly discuss what Federated Learning is. Today, machine learning is widely used by anyone who wants to understand their dataset deeper and model some classification/regression tasks. However, to achieve the best model possible, one needs a lot of data, which may be difficult to gather in one place. Thus, what if multiple users with their own slice of data could assemble everything to simulate a big dataset and then obtain a very good model ? That’s the main idea of federated learning.</p><p>Now, what if those users don’t want to share their own data but still want to use an aggregation of the data of everyone to build that nice machine learning model ? For example, one user could be a hospital and the data needed for a cancer detection model simply can’t be sent as it is, since patients would obviously disagree. Even deanonymized data can present a privacy risk.</p><p>One idea could be to not send the exact data, but to add some noise to it, so the receiver doesn’t obtain the real data. However, if we add just a bit too much of noise, our data may become irrelevant and the learning algorithm could not find anything useful. A Federated Learning system is not about directly sharing the data, but only the gradients, or the weights, that each user can calculate using their own data.</p><blockquote><a href="https://towardsdatascience.com/first-neural-network-for-beginners-explained-with-code-4cfd37e06eaf">If you are not comfortable with the idea of weights or gradients, here is a quick introduction to the Neural Networks world.</a></blockquote><p>We now have a system with multiple users that individually update their model before sending it to the others. There is a central server that first sends the initial parameters of the model, and then receives the results of every users. At this point, the server can combine the different models into one, by summing all the received gradients and updates the weights with the averaged new values.</p><figure><img alt="Shows the principle of the Federated Learning algorithms, with the server sending the global model and receiving the local weights." src="https://cdn-images-1.medium.com/max/552/1*JQuaTYiUKpXXj5GEMqFODQ.png" /><figcaption>Image from <a href="https://sparkd.ai/archives/4444">https://sparkd.ai/archives/4444</a>, principle of Federated Learning</figcaption></figure><h4>Is this enough privacy ?</h4><p>The first section introduced a solution to preserve the access to the data of every users. However, the adversarial machine learning domain knows some attacks (white box, black box) that again rise a problem when a user sends its updated weights. Indeed, in short, revealing our model to the world also reveals our data, and since the server and every other participants know the architecture, sending our weights allows them to try a white box attack to retrieve our data.</p><p>To counter this new problem, we can now turn to cryptography, and more precisely to homomorphic encryption. Indeed, this kind of encryption not only transforms our plain text (or weights) into a cipher text, but also allows some basic computations on it. Thus, the server can still aggregate all the received weights into one global update of the main model, without accessing the values. The result of the aggregation done by the server will be readable by the initial senders.</p><p>Homomorphic Encryption requires some mathematical knowledges to fully understand so let’s try to get the main idea. Consider a function <em>f(x) = 2x.</em> This function preserves addition, such that <em>f(x+y) = f(x) + f(y)</em>, but not multiplication. We want our encryption scheme to be fully homomorphic, so it must preserve at least addition and multiplication.</p><p>Various schemes of homomorphic encryption exist, but we will want to use CKKS [1] in our implementation later, since it allows the usage of float numbers, and weights are usually described as such, between 0 and 1. We also want to divide the total by the number of participants <em>n</em>, or multiply by <em>1/n</em>. First the encryption uses public and private keys. An evaluation key is also used to evaluate operations on the cipher texts. The plain and cipher texts spaces are defined over polynomial rings, allowing some important properties for the operations.</p><p>To allow multiple users on the system and the model training, we need to use a multiparty homomorphic encryption version of that previous encryption scheme.</p><p>In conclusion, with current our solution, the data is only used by the owner, and the model weights are always encrypted, thus no glance from the server or steal should be possible, and our data is kept private.</p><h4>Does it really work ?</h4><p>Well, according to <a href="https://arxiv.org/pdf/2009.00349.pdf">this paper</a> [2], yes. The final model obtains an accuracy close to several public approaches for common problems.</p><p>In fact, we follow a parallelized Stochastic Gradient Descent (SGD) algorithm [3]. It is sort of equivalent to a single node SGD with a larger batch size. It should not be confused with “model averaging”, which uses multiple models at once to make a prediction. Here, we finish the training phase with only one model.</p><p>However, we should note that federated learning is vulnerable to poisoning attacks. Indeed, if one the node of the network is compromised and decides to send faulty results, by mistake or for a possible attack, the final model will produce bad results. A simple defense would be to delete the “outlier” weights updates, and possibly ban the responsible node for the rest of the learning phase. This adversary node could be found by trial and error on the combinations of incoming weights, since weights are encrypted and only aggregations of some or all of them is possible. However, this technique is obviously not perfect, since a bad gradient could still fit inside the outlier frontier, or a majority of the nodes could be malicious, leading to a misplaced supposed mean of gradients.</p><p><a href="https://www.ndss-symposium.org/wp-content/uploads/ndss2021_6C-2_24434_paper.pdf">This paper</a> [4] proposes a byzantine-robust federated learning system by bootstrapping trust on the server first. This is done with the server collecting a portion of every dataset of the participants and maintaining its own model, just like other nodes train their weights. For each iteration, the server then assign a “trust score” for every nodes based on the similarity of the node changes with the server changes. However sadly, accessing the weights for the comparison would mean they are not encrypted anymore, so this solution isn’t applicable in our case. Moreover a local model for the server to train requires data we don’t want to share. We thus need to make sure every node is serious and not compromised by our own way.</p><p>The parallelized SGD and its aggregation are the only real differences with classical machine learning, since the rest of the project is about transport of encrypted data. We may witness a longer training time, because an asymmetric encryption as the one we are using is pretty slow, but in return we are using way more data than we could have by ourselves (assuming that other nodes are bringing a relevant amount of data).</p><h4>How can we implement it ?</h4><blockquote><a href="https://github.com/Arnouux/FederatedLearning">Here is a proof of concept in Golang that you may want.</a> Golang allows you to simply import the Github repository as a library and then freely use the functions as you please.</blockquote><p>The whole system is a mix of cryptography, machine learning, and distributed systems. We will need some nodes representing the users (and the server aggregating the values) capable of sending and receiving messages via TCP or UDP. Be aware though that UDP has a message size limit of approximately 65000 bytes, and encrypted messages may become larger than that. The messages would be safer if sent over TCP and secure channels. For now, they are sent in <em>EncryptedChunk </em>packets, or as <em>Result </em>packets when it is the server responding.</p><p>The encryption part of the project will reuse the scheme discovered earlier (CKKS), by using the Golang library <em>lattigo</em>. It allows our node to simply encrypt and decrypt the weights, defined in polynomials.</p><p>Finally, the neural networks are less important, given that the system could be linked to our favorite machine learning library in Python which only requires the decrypted weights to set up the model and run a backpropagation step on it, before retransmitting it to the Go program that will reconnect with the network and encrypt the weights. We mainly need a good representation of the weights, allowing nodes to process their gradient on it.</p><p>Of course, before the learning phase is started, all the nodes have to check that their data match the other’s data, plus the input layer of the decided model architecture, otherwise they wouldn’t be able to train their model. We can observe this preparation phase when using <em>Join</em> and <em>Params</em> packets, respectively sent by a participant and the server.</p><p>With such a system, we can now start a server and multiple other nodes, that will join the server for the federated learning process. Once the server decided the hyper-parameters plus the initial weights, it sends it to all the participants. Each of them will have to follow a gradient descent step and calculate new weights. These weights have to be encrypted before going through the network, so nobody can read them and infer the data used. The server receives all the different weights and aggregates the values before processing their average, giving us one model with slightly trained weights. At this point, we have done one step of our machine learning algorithm, and we can repeat it as much as we want until we obtain the model we wish for.</p><p>[1] <a href="https://eprint.iacr.org/2016/421.pdf">J. Hee Cheon, A. Kim1, M. Kim, and Y. Song. Homomorphic Encryption for Arithmetic of Approximate Numbers. 2016.</a></p><p>[2] <a href="https://arxiv.org/pdf/2009.00349.pdf">S. Sav, A. Pyrgelis, J. R. Troncoso-Pastoriza, D. Froelicher, J-P. Bossuat, J. Sa Sousa, and J-P Hubaux. POSEIDON : Privacy-Preserving Federated Neural Network Learning. 2021.</a></p><p>[3] <a href="https://papers.nips.cc/paper/2010/file/abea47ba24142ed16b7d8fbf2c740e0d-Paper.pdf">M. Zinkevich, M. Weimer, L. Li, and A. Smola. Parallelized stochastic gradient descent. 2010.</a></p><p>[4] <a href="https://www.ndss-symposium.org/wp-content/uploads/ndss2021_6C-2_24434_paper.pdf">X. Cao , M. Fang , J. Liu , N. Zhenqiang Gong. FLTrust: Byzantine-robust Federated Learning via Trust Bootstrapping. 2021.</a></p><blockquote><em>Thanks for reading !</em></blockquote><blockquote><em>I hope you enjoyed discovering a bit of Federated Learning, if you have any question and/or suggestion, let me know in the comments.</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7944fb284061" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/an-exploration-of-a-privacy-preserving-federated-learning-system-7944fb284061">An exploration of Privacy Preserving Federated Learning (with code)</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[All the Steps to Build your first Image Classifier (with code)]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/data-science/all-the-steps-to-build-your-first-image-classifier-with-code-cf244b015799?source=rss-4aa81c733935------2"><img src="https://cdn-images-1.medium.com/max/2600/0*lHGdTjx0RMGJjZ16" width="6000"></a></p><p class="medium-feed-snippet">From creating datasets to testing your program accuracy</p><p class="medium-feed-link"><a href="https://medium.com/data-science/all-the-steps-to-build-your-first-image-classifier-with-code-cf244b015799?source=rss-4aa81c733935------2">Continue reading on TDS Archive »</a></p></div>]]></description>
            <link>https://medium.com/data-science/all-the-steps-to-build-your-first-image-classifier-with-code-cf244b015799?source=rss-4aa81c733935------2</link>
            <guid isPermaLink="false">https://medium.com/p/cf244b015799</guid>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[guides-and-tutorials]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Arthur Arnx]]></dc:creator>
            <pubDate>Fri, 01 Mar 2019 22:29:59 GMT</pubDate>
            <atom:updated>2019-03-02T11:47:38.722Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[First neural network for beginners explained (with code)]]></title>
            <link>https://medium.com/data-science/first-neural-network-for-beginners-explained-with-code-4cfd37e06eaf?source=rss-4aa81c733935------2</link>
            <guid isPermaLink="false">https://medium.com/p/4cfd37e06eaf</guid>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[guides-and-tutorials]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[perceptron]]></category>
            <dc:creator><![CDATA[Arthur Arnx]]></dc:creator>
            <pubDate>Sun, 13 Jan 2019 13:28:56 GMT</pubDate>
            <atom:updated>2019-08-11T09:03:20.174Z</atom:updated>
            <content:encoded><![CDATA[<h4>Understand and create a Perceptron</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JFaUKw9I3bAGcDlW" /><figcaption>Photo by <a href="https://unsplash.com/@clemhlrdt?utm_source=medium&amp;utm_medium=referral">Clément H</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>So you want to create your first artificial neural network, or simply discover this subject, but have no idea where to begin ? Follow this quick guide to understand all the steps !</p><h4>What is a neural network ?</h4><p>Based on nature, neural networks are the usual representation we make of the brain : neurons interconnected to other neurons which forms a network. A simple information transits in a lot of them before becoming an actual thing, like “move the hand to pick up this pencil”.</p><p>The operation of a complete neural network is straightforward : one enter variables as inputs (for example an image if the neural network is supposed to tell what is on an image), and after some calculations, an output is returned (following the first example, giving an image of a cat should return the word “cat”).</p><p>Now, you should know that artificial neural network are usually put on columns, so that a neuron of the column <em>n</em> can only be connected to neurons from columns <em>n-1 </em>and<em> n+1. </em>There are few types of networks that use a different architecture, but we will focus on the simplest for now.</p><p>So, we can represent an artificial neural network like that :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*v1ohAG82xmU6WGsG2hoE8g.png" /><figcaption>Figure 1 — Representation of a neural network</figcaption></figure><p>Neural networks can usually be read from left to right. Here, the first layer is the layer in which inputs are entered. There are 2 internals layers (called hidden layers) that do some math, and one last layer that contains all the possible outputs. Don’t bother with the “+1”s at the bottom of every columns. It is something called “bias” and we’ll talk about that later.</p><blockquote>By the way, the term “deep learning” comes from neural networks that contains several hidden layers, also called “deep neural networks” . The Figure 1 can be considered as one.</blockquote><h4>What does a neuron do ?</h4><p>The operations done by each neurons are pretty simple :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/651/1*UA30b0mJUPYoPvN8yJr2iQ.jpeg" /><figcaption>Figure 2 — Operations done by a neuron</figcaption></figure><p>First, it adds up the value of every neurons from the previous column it is connected to. On the Figure 2, there are 3 inputs (x1, x2, x3) coming to the neuron, so 3 neurons of the previous column are connected to our neuron.</p><p>This value is multiplied, before being added, by another variable called “weight” (w1, w2, w3) which determines the connection between the two neurons. Each connection of neurons has its own weight, and those are the only values that will be modified during the learning process.</p><p>Moreover, a bias value may be added to the total value calculated. It is not a value coming from a specific neuron and is chosen before the learning phase, but can be useful for the network.</p><p>After all those summations, the neuron finally applies a function called “activation function” to the obtained value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JHWL_71qml0kP_Imyx4zBg.png" /><figcaption>Figure 3 — Sigmoid function</figcaption></figure><p>The so-called activation function usually serves to turn the total value calculated before to a number between 0 and 1 (done for example by a sigmoid function shown by Figure 3). Other function exist and may change the limits of our function, but keeps the same aim of limiting the value.</p><p>That’s all a neuron does ! Take all values from connected neurons multiplied by their respective weight, add them, and apply an activation function. Then, the neuron is ready to send its new value to other neurons.</p><p>After every neurons of a column did it, the neural network passes to the next column. In the end, the last values obtained should be one usable to determine the desired output.</p><p>Now that we understand what a neuron does, we could possibly create any network we want. However, there are other operations to implement to make a neural network learn.</p><h4>How does a neural network learn ?</h4><p>Yep, creating variables and making them interact with each other is great, but that is not enough to make the whole neural network learn by itself. We need to prepare a lot of data to give to our network. Those data include the inputs and the output expected from the neural network.</p><p>Let’s take a look at how the learning process works :</p><p>First of all, remember that when an input is given to the neural network, it returns an output. On the first try, it can’t get the right output by its own (except with luck) and that is why, during the learning phase, every inputs come with its label, explaining what output the neural network should have guessed. If the choice is the good one, actual parameters are kept and the next input is given. However, if the obtained output doesn’t match the label, weights are changed. Those are the only variables that can be changed during the learning phase. This process may be imagined as multiple buttons, that are turned into different possibilities every times an input isn’t guessed correctly.</p><p>To determine which weight is better to modify, a particular process, called “backpropagation” is done. We won’t linger too much on that, since the neural network we will build doesn’t use this exact process, but it consists on going back on the neural network and inspect every connection to check how the output would behave according to a change on the weight.</p><p>Finally, there is a last parameter to know to be able to control the way the neural network learns : the “learning rate”. The name says it all, this new value determines on what speed the neural network will learn, or more specifically how it will modify a weight, little by little or by bigger steps. 1 is generally a good value for that parameter.</p><h4>Perceptron</h4><p>Okay, we know the basics, let’s check about the neural network we will create. The one explained here is called a Perceptron and is the first neural network ever created. It consists on 2 neurons in the inputs column and 1 neuron in the output column. This configuration allows to create a simple classifier to distinguish 2 groups. To better understand the possibilities and the limitations, let’s see a quick example (which doesn’t have much interest except to understand) :</p><p>Let’s say you want your neural network to be able to return outputs according to the rules of the “inclusive or”. Reminder :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/269/1*LZGp64tc2qAovsLF4rqKNg.png" /></figure><ul><li>if A is true and B is true, then A or B is true.</li><li>if A is true and B is false, then A or B is true.</li><li>if A is false and B is true, then A or B is true.</li><li>if A is false and B is false, then A or B is false.</li></ul><p>If you replace the “true”s by 1 and the “false”s by 0 and put the 4 possibilities as points with coordinates on a plan, then you realize the two final groups “false” and “true” may be separated by a single line. This is what a Perceptron can do.</p><p>On the other hand, if we check the case of the “exclusive or” (in which the case “true or true” (the point (1,1)) is false), then we can see that a simple line cannot separate the two groups, and a Perceptron isn’t able to deal with this problem.</p><p>So, the Perceptron is indeed not a very efficient neural network, but it is simple to create and may still be useful as a classifier.</p><h4>Creating our own simple neural network</h4><p>Let’s create a neural network from scratch with Python (3.x in the example below).</p><pre><strong>import </strong>numpy, random, os<br>lr = 1 #learning rate<br>bias = 1 #value of bias<br>weights = [random.random(),random.random(),random.random()] #weights generated in a list (3 weights in total for 2 neurons and the bias)</pre><p>The beginning of the program just defines libraries and the values of the parameters, and creates a list which contains the values of the weights that will be modified (those are generated randomly).</p><pre><strong>def</strong> Perceptron(input1, input2, output) :<br>   outputP = input1*weights[0]+input2*weights[1]+bias*weights[2]<br>   <strong>if</strong> outputP &gt; 0 : #activation function (here Heaviside)<br>      outputP = 1<br>   <strong>else</strong> :<br>      outputP = 0<br>   error = output – outputP<br>   weights[0] += error * input1 * lr<br>   weights[1] += error * input2 * lr<br>   weights[2] += error * bias * lr</pre><p>Here we create a function which defines the work of the output neuron. It takes 3 parameters (the 2 values of the neurons and the expected output). “outputP” is the variable corresponding to the output given by the Perceptron. Then we calculate the error, used to modify the weights of every connections to the output neuron right after.</p><pre><strong>for</strong> i in range(50) :<br>   Perceptron(1,1,1) #True or true<br>   Perceptron(1,0,1) #True or false<br>   Perceptron(0,1,1) #False or true<br>   Perceptron(0,0,0) #False or false</pre><p>We create a loop that makes the neural network repeat every situation several times. This part is the learning phase. The number of iteration is chosen according to the precision we want. However, be aware that too much iterations could lead the network to over-fitting, which causes it to focus too much on the treated examples, so it couldn’t get a right output on case it didn’t see during its learning phase.</p><p>However, our case here is a bit special, since there are only 4 possibilities, and we give the neural network all of them during its learning phase. A Perceptron is supposed to give a correct output without having ever seen the case it is treating.</p><pre>x = int(input())<br>y = int(input())<br>outputP = x*weights[0] + y*weights[1] + bias*weights[2]<br><strong>if </strong>outputP &gt; 0 : #activation function<br>   outputP = 1<br><strong>else </strong>:<br>   outputP = 0<br><strong>print</strong>(x, &quot;or&quot;, y, &quot;is : &quot;, outputP)</pre><p>Finally, we can ask the user to enter himself the values to check if the Perceptron is working. This is the testing phase.</p><p>The activation function Heaviside is interesting to use in this case, since it takes back all values to exactly 0 or 1, since we are looking for a false or true result. We could try with a sigmoid function and obtain a decimal number between 0 and 1, normally very close to one of those limits.</p><pre>outputP = 1/(1+numpy.exp(-outputP)) #sigmoid function</pre><p>We could also save the weights that the neural network just calculated in a file, to use it later without making another learning phase. It is done for way bigger project, in which that phase can last days or weeks.</p><p>That’s it ! You’ve done your own complete neural network. You created it, made it learn, and checked its capacities. Your Perceptron can now be modified to use it on another problem. Just change the points given during the iterations, adjust the number of loop if your case is more complex, and just let your Perceptron do the classification.</p><p>Do you want to list 2 types of trees in the nearest forest and be able to determine if a new tree is type A or B ? Chose 2 features that can dissociate both types (for example height and width), and create some points for the Perceptron to place on the plan. Let it deduct a way to separate the 2 groups, and enter any new tree’s point to know which type it is.</p><p>You could later expand your knowledge and see about bigger and deeper neural network, that are very powerful !</p><p>There are multiple aspects we didn’t treat, or just enough for you to get the basics, so don’t hesitate to go further. I would love to write about more complex neural networks so stay tuned !</p><blockquote>Thanks for reading !</blockquote><blockquote>I hope this little guide was useful, if you have any question and/or suggestion, let me know in the comments.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4cfd37e06eaf" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/first-neural-network-for-beginners-explained-with-code-4cfd37e06eaf">First neural network for beginners explained (with code)</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[Quick guide on connected light bulb and Google Home (especially ones from “Nedis” and “MCL Domo”)]]></title>
            <link>https://medium.com/@artux51/quick-guide-on-connected-light-bulb-and-google-home-especially-ones-from-nedis-and-mcl-domo-c8b36cecef98?source=rss-4aa81c733935------2</link>
            <guid isPermaLink="false">https://medium.com/p/c8b36cecef98</guid>
            <category><![CDATA[guides-and-tutorials]]></category>
            <category><![CDATA[google-home]]></category>
            <category><![CDATA[connected-devices]]></category>
            <dc:creator><![CDATA[Arthur Arnx]]></dc:creator>
            <pubDate>Sun, 06 Jan 2019 19:55:32 GMT</pubDate>
            <atom:updated>2022-03-17T07:01:28.237Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*g0QB3hY0_stHkt61lEu79A.jpeg" /></figure><p>Few weeks after I purchased a Google Home mini (I’m a student so I couldn’t afford a bigger one), I decided to extend my collection of connected items with light bulbs, to automate my apartment and to show off to my friends.</p><p>The Philips Hue bulbs seemed (and actually are) pretty simple to associate with Home, but take a look at them on Amazon, remember my financial situation, and you’ll understand why I opted for other brands.</p><p>So at this point, I have one light bulb from Nedis, and one from MCL, both compatible with Google Home, and, to my surprise, compatible with each other. Indeed, the two respective applications, Nedis SmartLife and MCL DOMO, are literally the same application, with only the main theme and colors changing. So, you can add the devices to their own application or both on one, which I did (both on Nedis Smart Life actually).</p><p>To add a device to your account, tap the “+” on the top right corner, then select “Smart bulb”, and light up the bulb you want to add. At that moment, you light should be flashing. If it is not, just turn on and off the light 3 times in a row. When the light is flashing, you can then enter the Wi-Fi password and let the application running for 1 or 2 minutes. If the operation isn’t successful, you should try again and the problem may be solved by itself. Redo this for all lights you want to add.</p><p>After that, you can explore the application and play with your new bulbs by changing their color. You also can arrange every light in the application by specifying the room in which it is. But the job isn’t done yet, since you still can’t use the lights only with the voice. For that, you have to connect it to your Google Home, and that’s what we’ll see right now.</p><p>So on the Home application, in which you already have your Google Home ready, you can add your connected bulbs by taping the “+”s in the main menu of the home. Here, choose the the bottom option for the “already configured devices”. You can then select the application you are using for your light bulbs in the list. In our case, select either “Smart Life” or “MCL DOMO”. Now your lights that are on the application you selected are automatically added to the devices of the home on the main page, and you can finally talk to them !</p><p>IF YOU ARE ENCOUNTERING OTHER PROBLEMS :</p><ul><li>You can’t access the option for the “already configured devices”, or for example the parameters on the account menu. You didn’t activate Google on your phone. Go to your applications, search for Google and activate it.</li><li>You don’t have access to some stuff on the application, like “routines”. Your country, or possibly your phone, hasn’t access to the full Home application. Wait for Google to deploy Home everywhere.</li><li>Your Google Home tells you that the application of the light bulb isn’t available. Make sure the mail address you used to create the account on this application is a member of the home, in the Home application. To simplify, just use one mail address for everything.</li></ul><p>To go further, see IFTTT application. It is very complete and allows you to create simple “If this then that” events. For example, “if it is 6:30 AM, turn on the lights”.</p><blockquote>Thanks for reading !</blockquote><blockquote>If this guide helped you, or you have any question and/or suggestion, let me know in the comments.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c8b36cecef98" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>