<?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"><channel><title><![CDATA[Giovanni Gorgone]]></title><description><![CDATA[Giovanni Gorgone]]></description><link>https://giovannigorgone.it</link><generator>RSS for Node</generator><lastBuildDate>Thu, 16 Apr 2026 10:18:00 GMT</lastBuildDate><atom:link href="https://giovannigorgone.it/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Build your own prediction software]]></title><description><![CDATA[Can computers do predictions? Yes.How do they do them?Well, let’s roll up our sleeves!
First of all, what is a prediction?A prediction is a statement about something that has not happened yet. For example, a prediction is saying the result of a socce...]]></description><link>https://giovannigorgone.it/build-your-own-prediction-software</link><guid isPermaLink="true">https://giovannigorgone.it/build-your-own-prediction-software</guid><category><![CDATA[Machine Learning]]></category><category><![CDATA[AI]]></category><dc:creator><![CDATA[Giovanni Gorgone]]></dc:creator><pubDate>Sun, 04 Jun 2023 10:22:57 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/5qRWQEdK7Sg/upload/6ad1678ccefd3f1d958f7493987aa21e.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Can computers do predictions? Yes.<br />How do they do them?<br />Well, let’s roll up our sleeves!</p>
<p>First of all, what is a <strong>prediction</strong>?<br />A prediction is a statement about something that has not happened yet. For example, a prediction is saying the result of a soccer match before it finishes.<br />In my hometown (Napoli) you can hear a recurring prediction, usually in late September:</p>
<blockquote>
<p><em>“Chist è l’anno buon!” (This is “the good” year!)</em></p>
</blockquote>
<p>This is about the local soccer team trying to win the soccer league. Sadly last time this happened was 30 years ago.</p>
<p>I know what you are thinking. You are wondering if there is a way to make more accurate predictions. You can do it if you know the law.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1685873722379/88e2c033-a25d-487b-8734-c043fdf586b7.png" alt class="image--center mx-auto" /></p>
<p><em>No, you don’t have to be a lawyer.</em></p>
<p>Let’s try this: suppose that a triangle has the base measuring <strong>10</strong> cm, and its height is <strong>5</strong> cm. Predict his area.</p>
<p>Correct! The area is <strong>25</strong> cm². Did you measure the area? No? How did you do that? Ahh, I see you know the law. You did (<strong>10</strong> x <strong>5</strong>)/2 = <strong>25</strong>.</p>
<p>What computers can do is something related to this. With machine learning computers can extract a law from inputs and output. In the triangle example, 10 and 5 are the inputs, 25 is the output. <strong>The more (inputs, output) couples a computer can learn from, the more accurate will be the law it will extract.</strong> That’s because there can be a lot of laws, or relationships, between inputs and output.<br />If I’d come to you asking what’s the relationship between <strong>10</strong>, <strong>5</strong> and <strong>25</strong>, you could have answered me (<strong>10</strong> x 2) + <strong>5</strong> = <strong>25</strong>.<br />This is a correct answer, but it is not the correct relationship for our purpose of calculating the area of each triangle. If we use this relationship to predict the area of each triangle, we will be wrong for sure. That’s the point. Computers can find one common law, or relationship, that binds every (input, output) couple you gave it.</p>
<p>1 | 1<br />2 | 4<br />3 | 9</p>
<p>Can you find the common relation between inputs and outputs?<br />I’m sure you can!<br />( x | x² )</p>
<p>What do we do now? We will find a dataset, we will train and test a regressor model, and then we do a prediction with it.</p>
<p><strong>dataset</strong>: a set of (input, output) couples<br /><strong>regressor model</strong>: a piece of code that can extract a common relation between elements in a dataset<br /><strong>train</strong>: let the regressor model search for the common relation between the elements in a dataset<br /><strong>test</strong>: check that the relation found by the regressor model is correct</p>
<p>You will need Xcode with Create ML, python 3 and a clone of <a target="_blank" href="https://github.com/ggorgone/gearDurability">this</a> repository I made for you ❤.</p>
<h1 id="heading-what-we-will-predict"><strong>What we will predict</strong></h1>
<p>We want to predict the <strong>durability of a gear</strong>. We start with some <strong>features</strong> of gears:</p>
<ul>
<li><p><strong>number of teeth</strong>: integer number between 10 and 50</p>
</li>
<li><p><strong>heat dissipation</strong>: floating point number between 0.2 and 0.8</p>
</li>
<li><p><strong>viscosity of lubricant</strong>: integer number between 1 and 5</p>
</li>
<li><p><strong>temperature</strong>: floating point number between 18 and 120</p>
</li>
</ul>
<p>These four are the inputs, durability is the output. The file training.csv in the repository contains enough data to start.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1685869450533/d761ee99-9bdc-4a79-b650-3647a743cf06.webp" alt class="image--center mx-auto" /></p>
<p><em>testing.csv file contains 160k rows and each row contains one (inputs, output) couple</em></p>
<p>The file testing.csv is very similar to training.csv. Its purpose is to let the computer verify its acquired knowledge. The computer extracts a common relation involving data contained in training.csv, and then verifies that the extracted relation works with the data contained in testing.csv .<br />Basically, the computer <strong>studies</strong>, <strong>takes a recap quiz</strong> on what it just studied and then <strong>checks how many correct/wrong answers</strong> it gave.</p>
<p>The file predict.csv contains our question. We want a prediction for the durability of a gear that has 30 teeth, with a heat dissipation value of 0.7, lubricated with a 4 stars premium oil, operating at 53° Celsius.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1685869609909/5f117f6d-68f0-40d0-b864-2fe34691e5f7.webp" alt class="image--center mx-auto" /></p>
<p><em>predict.csv should not contain durability. We are asking for a prediction of that!</em></p>
<h1 id="heading-step-1"><strong>Step 1</strong></h1>
<p>Open Xcode, in the menu bar search for<br /><em>Xcode -&gt; Open developer tool -&gt;</em> <a target="_blank" href="https://developer.apple.com/documentation/createml"><em>Create ML</em></a> and then<br /><em>File -&gt; New Project</em></p>
<p>We will use the Tabular Regressor.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1685869843201/b80bfb5d-5d0b-4aaf-81ed-277715fb6f01.webp" alt class="image--center mx-auto" /></p>
<h1 id="heading-step-2"><strong>Step 2</strong></h1>
<p>It’s time for our model to study. Select the training and testing files, click on Select Features and be sure you are telling the model to use all of the inputs.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1685869913686/345f15f4-95c4-45f2-a205-b32bdd17760b.webp" alt class="image--center mx-auto" /></p>
<p><em>Training and testing will require time</em></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1685869980035/22051d62-292f-485b-915c-fcdab4038e15.webp" alt class="image--center mx-auto" /></p>
<p><em>Predict durability using number_of_tooth, heat_dissipation, . . .</em></p>
<p>As soon as you click on the play button in the upper part of the screen the model will start its training, and after that, it will start testing itself.</p>
<h1 id="heading-step-3"><strong>Step 3</strong></h1>
<p>Our model is now ready. In the Metrics, we can see how the model evaluated his freshly acquired knowledge. It’s measuring the errors it made, <a target="_blank" href="https://developer.apple.com/documentation/createml/mlregressormetrics">the lower the better</a>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1685870106103/76335691-56d7-453f-828e-a6e0ec852bfb.webp" alt class="image--center mx-auto" /></p>
<p><em>Congratulations! Your model is now graduated!</em></p>
<p>Now its time for answering our question. Click on the Output rectangle, then drag and drop the file predict.csv in the left section or add it trough the plus button in the lower left corner. As soon as you add the file, the model will give you the prediction.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1685870179718/55a74c55-b16e-4ed2-8c83-7138e5c0d212.webp" alt class="image--center mx-auto" /></p>
<p><em>Abracain!</em></p>
<h1 id="heading-bonus-step"><strong>Bonus step</strong></h1>
<p>How can we be sure that the prediction is accurate? Usually, it’s not an easy check. We should somehow snoop inside the model and check that it found the right relation between inputs and output. This time we have an easiest way to do this.</p>
<p>30 x 0.7 x 4 / 53 = <strong>1.58</strong> very close to the prediction <strong>1.40</strong></p>
<p>If the correct relation is the one that gave us <strong>1.58</strong>, we can be satisfied by the prediction the model made. <strong>I can assure you that this is the correct relation because I used it for generating data.</strong></p>
<p>Let’s look inside the <a target="_blank" href="http://dataGenerator.py">dataGenerator.py</a> file:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1685870369165/b0b2d7ec-0a1e-4c73-9ecb-0eb2411217ed.webp" alt class="image--center mx-auto" /></p>
<p>As you can see, the output is bound to inputs by that relation. And our model predicted a value not far from the one we can obtain by applying that relation.</p>
<h1 id="heading-wrap-up"><strong>Wrap up</strong></h1>
<p><a target="_blank" href="http://dataGenerator.py">dataGenerator.py</a> represents a gear simulator. It will produce datasets made by gears features and their durability. We used them to train a model. The model learned how the gear simulator works and can predict the outputs of the simulator.</p>
<p>The model looking at simulator inputs and output is able to replicate the simulator. Think about it.</p>
<p><strong>Suppose that we never had the simulator and that we collected our data only from experiments and measurements. Now we can build a simulator using the trained model.</strong></p>
<p>Can computers predict the future? Yes, but you have to tell them the past.</p>
<h1 id="heading-references"><strong>References</strong></h1>
<p>Don’t forget to checkout the code repository to do everything by yourself.</p>
<ul>
<li><p>Code <a target="_blank" href="https://github.com/ggorgone/gearDurability">repository</a></p>
</li>
<li><p>Create ML <a target="_blank" href="https://developer.apple.com/documentation/createml">documentation</a></p>
</li>
</ul>
<p><em>I wrote this article as part of a project done at the Apple Developer Academy in Naples (Italy) in 2020.</em></p>
]]></content:encoded></item><item><title><![CDATA[Legge di Hyrum]]></title><description><![CDATA[Stai facendo una modifica al codice, piccola, innocua. Ti fermi, sai che farai arrabbiare qualcuno. Mai provato questa sensazione? E’ esattamente ciò che prevede la legge di Hyrum:
“Non importa cosa espone un contratto, dato un numero sufficientement...]]></description><link>https://giovannigorgone.it/legge-di-hyrum</link><guid isPermaLink="true">https://giovannigorgone.it/legge-di-hyrum</guid><category><![CDATA[Tutorial]]></category><category><![CDATA[clean code]]></category><category><![CDATA[Software Engineering]]></category><category><![CDATA[software architecture]]></category><dc:creator><![CDATA[Giovanni Gorgone]]></dc:creator><pubDate>Mon, 03 Apr 2023 23:15:23 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/sms5WiXXxTA/upload/9b30f2c57af0434b9680f24c4aa6cb41.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Stai facendo una modifica al codice, piccola, innocua. Ti fermi, sai che farai arrabbiare qualcuno. Mai provato questa sensazione? E’ esattamente ciò che prevede la legge di Hyrum:</p>
<p><em>“Non importa cosa espone un contratto, dato un numero sufficientemente grande di utenti di un’API, essi faranno affidamento su tutti gli aspetti osservabili del sistema esposto, anche su quelli non esplicitati nel contratto stesso.”</em></p>
<p>Per comprenderla al meglio, analizziamo gli elementi coinvolti.</p>
<p><strong>Cosa è un’API? Un’API è il confine tra utente e prodotto/servizio.</strong></p>
<p>L’API di un telecomando della TV è composta dai suoi pulsanti. Essi vengono usati dagli utenti, i quali non han bisogno di sapere cosa succede all’interno del telecomando. Quel che succede all’interno del telecomando è chiamata “implementazione”. Qual’è il vantaggio di questa distinzione? Il vantaggio è che l’implementazione può cambiare senza che l’utente debba preoccuparsene.</p>
<p><strong>Il contratto di un API è l’insieme di garanzie sul prodotto/servizio fornite all’utente.</strong></p>
<p>Semplificando, il telecomando in questione ci garantisce di avere un pulsante di accensione e spegnimento, due pulsanti per aumentare e diminuire il volume, due pulsanti per passare al canale precedente e successivo.</p>
<p>Supponiamo che la prima implementazione del telecomando non abbia controlli sulla carica delle batterie. Quando la carica è bassa il telecomando continua a funzionare a patto che ci si avvicini alla ricevente. Nella seconda implementazione il telecomando smette di funzionare se la carica delle batterie è inferiore al 25%.</p>
<p>Anche se questi aspetti non rientrano nel contratto, con un numero sufficientemente grande di utenti, avremo il seguente scenario:</p>
<p>un utente della <strong>prima implementazione</strong> intuisce che se il telecomando non funziona, può avvicinarsi alla ricevente per farlo funzionare. Se il telecomando continua a non funzionare, allora deve sostituire le batterie.</p>
<p>Lo stesso utente, passando alla <strong>seconda implementazione</strong> si aspetta lo stesso comportamento. Se il telecomando non funziona si avvicina alla ricevente per farlo funzionare. Il telecomando però continua a non funzionare perché in questo caso l’implementazione è basata sul livello di carica e non sulla distanza dalla ricevente. L’utente conclude erroneamente che il telecomando o la ricevente non funzionino, ma non che le batterie siano scariche.</p>
<p>Siamo nell’ipotesi della legge di Hyrum: un utente di un’API sta facendo affidamento su un comportamento osservabile del sistema, anche se il contratto dell’API non da garanzie su di esso.</p>
<p>Nell’ambito dell’ingegneria del software questa legge è anche conosciuta come “Legge delle interfacce implicite”. E’ bene tenerla in considerazione durante l’evoluzione di un sistema che deve garantire <strong>retrocompatibilità</strong>. Infatti sia le modifiche al contratto (interfaccia esplicita), che quelle fatte agli altri comportamenti del sistema osservabili dagli utenti (interfaccia implicita) possono farla perdere.</p>
<p>E’ possibile mitigare gli effetti di questa legge in due modi: il fornitore di un API dovrebbe limitare l’esposizione di comportamenti osservabili del sistema non esplicitati nel contratto, e l’utente dovrebbe fare affidamento solo sul contratto dell’API. In questo modo sarà più facile introdurre cambiamenti in un sistema.</p>
<p><a target="_blank" href="https://www.hyrumslaw.com">https://www.hyrumslaw.com</a></p>
]]></content:encoded></item><item><title><![CDATA[Hyrum’s law]]></title><description><![CDATA[You are making a small, harmless change to the code. You stop, you know that you'll upset someone. Have you ever felt this way? This is exactly what Hyrum's law states:  
“With a sufficient number of users of an API, it does not matter what you promi...]]></description><link>https://giovannigorgone.it/hyrums-law</link><guid isPermaLink="true">https://giovannigorgone.it/hyrums-law</guid><category><![CDATA[Tutorial]]></category><category><![CDATA[clean code]]></category><category><![CDATA[Software Engineering]]></category><category><![CDATA[software architecture]]></category><dc:creator><![CDATA[Giovanni Gorgone]]></dc:creator><pubDate>Mon, 03 Apr 2023 23:12:30 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/sms5WiXXxTA/upload/9b30f2c57af0434b9680f24c4aa6cb41.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>You are making a small, harmless change to the code. You stop, you know that you'll upset someone. Have you ever felt this way? This is exactly what Hyrum's law states:  </p>
<p><em>“With a sufficient number of users of an API, it does not matter what you promise in the contract: all observable behaviors of your system will be depended on by somebody.”</em>  </p>
<p>To understand it better, let's analyze the elements involved.</p>
<p><strong>What is an API? An API is the boundary between the user and the product/service.</strong></p>
<p>The API of a TV remote control is composed of its buttons. They are used by users who don't need to know what's happening inside the remote control. What happens inside the remote control is called "implementation". What's the advantage of this distinction? The advantage is that the implementation can change without the user having to worry about it.</p>
<p><strong>The contract of an API is the set of guarantees about the product/service provided to the user.</strong></p>
<p>Simply put, the remote control in question guarantees us to have an on/off button, two buttons to increase and decrease the volume, two buttons to switch to the previous and to the next channel.</p>
<p>Suppose the first implementation of the remote control doesn't have battery charge controls. When the charge is low, the remote control continues to work as long as you get close to the receiver. In the second implementation, the remote control stops working if the battery charge is less than 25%.</p>
<p>Even though these aspects are not covered by the contract, with a sufficiently large number of users, we will have the following scenario:</p>
<p>a user of the <strong>first implementation</strong> guesses that if the remote control doesn't work, he can approach the receiver to make it work. If the remote control continues not to work, then he must replace the batteries.</p>
<p>The same user, switching to the <strong>second implementation</strong> expects the same behavior. If the remote control doesn't work, he approaches the receiver to make it work. However, the remote control still doesn't work because in this case the implementation is based on the battery level and not the distance from the receiver. The user incorrectly concludes that the remote control or the receiver doesn’t work, but not that the batteries are dead.</p>
<p>That’s a case of Hyrum's Law: an API user is relying on one observable system behavior, even though the API contract doesn't guarantee it.</p>
<p>In software engineering, this law is also known as the "Law of implicit interfaces". It should be considered during the evolution of a system that needs to ensure <strong>backward compatibility</strong>. Both changes to the contract (explicit interface), and changes to other observable system behaviors (implicit interface) can break it.</p>
<p>The effects of this law can be mitigated in two ways: the API provider should limit exposure of observable system behaviors not described in the contract, and the user should rely only on the API contract. This makes it easier to introduce changes in a system.</p>
<p><a target="_blank" href="https://www.hyrumslaw.com">https://www.hyrumslaw.com</a></p>
]]></content:encoded></item></channel></rss>