<?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 Francesco Di Gangi on Medium]]></title>
        <description><![CDATA[Stories by Francesco Di Gangi on Medium]]></description>
        <link>https://medium.com/@francesco.digangi2801?source=rss-96963b411532------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*yAR_K10xE2VLAZyO_f4jiQ.jpeg</url>
            <title>Stories by Francesco Di Gangi on Medium</title>
            <link>https://medium.com/@francesco.digangi2801?source=rss-96963b411532------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 23:14:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@francesco.digangi2801/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[Queen’s Blood: a journey on the famous card-game and its Artificial Intelligence mechanism.]]></title>
            <link>https://medium.com/@francesco.digangi2801/queens-blood-a-journey-on-the-famous-card-game-and-its-artificial-intelligence-mechanism-01f06126cbc9?source=rss-96963b411532------2</link>
            <guid isPermaLink="false">https://medium.com/p/01f06126cbc9</guid>
            <dc:creator><![CDATA[Francesco Di Gangi]]></dc:creator>
            <pubDate>Thu, 24 Apr 2025 20:31:17 GMT</pubDate>
            <atom:updated>2025-04-24T20:31:17.039Z</atom:updated>
            <content:encoded><![CDATA[<p>Videogames word and AI are closer more than ever, in <em>Final Fantasy 7: Rebirth </em>you have to learn the so-called game “Queen’s Blood” for certain missions during the main quest. In this article Artificial Intelligence in the card-game is analyzed.</p><h3>Ideal case of study: Queen’s Blood</h3><p>Queen’s Blood is a card-game introduced in Final Fantasy VII Rebirth. Players must construct strong decks and arrange cards in the best possible ways on a three-lane playing field in order to win this game, which stands out for its strategic depth. Every game is diverse and difficult since every card has a power value and can influence the field in various ways.</p><p>The point system, special card abilities, and space management turn each game into a strategic puzzle. This structured complexity makes Queen’s Blood perfect as a sandbox for testing predictive models and automated decision-making systems.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Qdzb-qBkPxswoOY3.jpeg" /><figcaption>Credits: GameRant</figcaption></figure><h3>Reinforcement Learning: Intelligent Virtual Adversaries</h3><p>Imagine a virtual opponent who, instead of following fixed rules, learns by playing. That it observes games, makes mistakes, gets better and better each time. This is what enables <strong>reinforcement learning</strong>, a technique that teaches a machine to make decisions through rewards and penalties.</p><p>Applied to <em>Queen’s Blood</em>, this approach could lead to a truly challenging AI opponent. It would make trivial mistakes at first, but game after game it would begin to understand the dynamics of the game: when to block a lane, which cards to place first, how to respond to aggressive strategies. Before long, it would become a worthy rival, capable of surprising even the most experienced players.</p><p>And the interesting thing is that each <strong>AI could develop a different style</strong>, just as human players do.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hTlnZ6Lco_yXEa9Y.png" /><figcaption>Models such as Deep Q-Network (DQN) are good in this context.</figcaption></figure><h3>Machine Learning: Train and Test</h3><p>Another possibility is to use machine learning to <em>analyze how people play</em>. With enough data-thousands of games, perhaps collected anonymously — you can discover patterns, effective moves, recurring mistakes. From there, you can build support systems that can help players improve.</p><p>An intelligent assistant could observe the situation on the field and suggest the most effective moves, even explaining why (<strong>XAI</strong>). This would not just be “advice,” but a real learning tool — a way to bring new players closer and push more experienced ones to experiment.</p><p><em>For example</em>, one might find that many players tend to underestimate a certain card in the early stages of the game, or that there are particularly effective but underutilized combinations. This information, once processed, can be used to build <strong>intelligent suggestion systems</strong>, capable of recommending moves based on real data and not just predefined rules.</p><p>But it doesn’t end there: machine learning can also serve to <strong>personalize the gaming experience.</strong> By analyzing the player’s style-aggressive, cautious, reactive-the AI can adapt dynamically, proposing tailored opponents, calibrated missions, or even interactive tutorials that are modeled on the user’s needs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*rW0_CxqkG1S-A6sS.jpg" /><figcaption>Credits: InstantGamingNew</figcaption></figure><h3>Deep Learning: Can AI understand your strategy?</h3><p>When we talk about <strong>deep learning</strong>, we enter the realm of artificial intelligence that does not just react, but begins to “understand.” Thanks to deep neural networks, it is possible to analyze a game of Queen’s Blood not just as a sequence of moves, but as a <strong>complex strategic plot</strong>.</p><p><strong>Convolutional neural networks (CNNs)</strong>, for example, are perfect for interpreting the game grid as if it were a picture, quickly identifying advantageous configurations or critical situations at a glance. At the same time, sequential models such as <strong>Recurrent Neural Networks (RNNs)</strong> or the more modern <strong>Transformers </strong>can analyze the temporal evolution of games, capturing the meaning of long-term strategies.</p><p>The result is an AI that can learn not only what to do in a given round, but why to do it — and perhaps even<em> when to wait, bluff, or provoke the opponent</em>. This kind of intelligence, capable of integrating context, memory, and abstraction, is very close to the way a skilled player thinks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TI1hsGbTZuD1Orjq.jpg" /><figcaption>Credits: GameSpot</figcaption></figure><h3>Towards a new way of playing</h3><p>The integration of artificial intelligence into games is not just a fad or a technical gimmick. It’s really changing the way we play, learn, and have fun. And in a game like <em>Queen’s Blood</em>, where every move counts, AI can make a difference-both as an opponent and as an ally.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=01f06126cbc9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bloodborne: Can AI Survive in Yharnam?]]></title>
            <link>https://medium.com/@francesco.digangi2801/bloodborne-can-ai-survive-in-yharnam-42a644d723fc?source=rss-96963b411532------2</link>
            <guid isPermaLink="false">https://medium.com/p/42a644d723fc</guid>
            <dc:creator><![CDATA[Francesco Di Gangi]]></dc:creator>
            <pubDate>Sun, 06 Apr 2025 21:42:51 GMT</pubDate>
            <atom:updated>2025-04-06T21:49:53.060Z</atom:updated>
            <content:encoded><![CDATA[<h4>An exploration of artificial intelligence facing the eldritch horrors and game mechanics of FromSoftware’s darkest world.</h4><p>Few games manage to create a world as haunting and atmospheric as <em>Bloodborne</em>. With its labyrinthine streets, grotesque monstrosities, and cryptic lore, it stands out not just for its aesthetics but for the brutal precision of its gameplay. Beneath all that dread and madness lies a carefully crafted AI system — one that governs every creature’s movement, every ambush, every moment where the player feels to hunt or be hunted.</p><p>But how does <em>Bloodborne</em> AI works? What kind of artificial intelligence is behind enemies?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VUgS8X6-SCDrnTgf.jpg" /></figure><h3>Behavior Trees and State Machines</h3><p>At the core of most enemy behaviors in <em>Bloodborne</em> are structures like <strong>finite state machines</strong> and <strong>behavior trees</strong> — two common tools in game AI development.</p><p>A <strong>finite state machine</strong> works by defining a set of states (like <em>idle</em>, <em>chase</em>, <em>attack</em>) and transitions between them based on triggers. A werewolf, for instance, might patrol until it hears the player (making noise for example with its steps or breaking some objects near him), then shift to pursuit, and finally to an aggressive jump once close enough.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/607/0*_jFWRLB4o6vU43hb" /><figcaption>Example of a finite state-machine. Credits to gamedevelopertips.com</figcaption></figure><p><strong>Behavior trees</strong>, on the other hand, allow for more layered and flexible actions. They prioritize decisions, evaluate conditions, and can easily fall back to alternatives. Think of a hunter NPC that first checks if it can parry, then backs off if its health is low, and finally charges when it sees an opening — all controlled by a structured decision tree. More like a very hard boss fight.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/196/0*H-hoaQU5mpBODM66" /><figcaption>Credits to gamedeveloper.com</figcaption></figure><p>These systems don’t make enemies “intelligent” in a human sense, but they do create the illusion of reactive, intentional behavior .</p><h3>They See You: Perception and Sensing</h3><p>If you’ve ever crept behind an enemy in <em>Bloodborne</em>, only to get spotted and chased down within seconds, you’ve met the game’s <strong>perception system</strong> in action.</p><p>Enemies use virtual “vision cones” and <strong>line-of-sight calculations</strong> to detect the player. Others seem to react to sound or even to the player’s aggression level, suggesting some kind of <strong>auditory or proximity-based triggers</strong>. The result is an unpredictable environment where you’re never sure how much time you have before you’re noticed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Aj_v7d5ry9iDVRQS.jpg" /><figcaption>Image from Alien Isolation: system is very similar to the one used in Bloodborne.</figcaption></figure><p>More advanced enemies — especially humanoid NPC hunters — are a different story. They dodge bullets, heal themselves, and use crowd control. Their behavior suggests <strong>more dynamic rule systems</strong>, possibly based on player distance, stamina state, or even predicted movement.</p><p><strong>Father Gascoigne, </strong>first boss in Bloodborne, is a prime example of how the game uses dynamic AI to make boss fights feel unpredictable and intense. At the start of the battle, Gascoigne is relatively calm, relying on slower, more deliberate attacks. This gives the player a chance to read his moves and get a feel for his rhythm — infact in this bossfight you are should understand how parry works in the game. However, as his health drops, his behavior changes significantly. The more wounded he gets, the more aggressive he becomes, with faster attacks and less room to breathe — spoiler alert — till he become a beast.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_CkG76xGqSECmjWN.jpg" /><figcaption>Credits to Screen Rant</figcaption></figure><p>One of the most interesting things about Gascoigne’s AI is how he reacts to the player’s tactics. When his health is low, he will use a <strong>Beast Blood Pellet</strong>, which boosts his damage and makes him a lot more dangerous. This creates an added layer of tension, as players need to decide whether to press their advantage or back off before Gascoigne can power up. His movement also adapts based on where the player is. If you keep your distance, he’ll rush in with fast lunging attacks, but if you’re too close, he becomes more unpredictable, dodging and countering with quick, devastating swipes.</p><h3>Timing is Everything: Responsive and Adaptive Combat</h3><p>One of <em>Bloodborne</em>’s signature features is how enemies rarely feel mechanical. They don’t follow strict patterns — they wait, bait, flank, and punish.</p><p>The enemy AI includes <strong>cooldown systems</strong>, <strong>priority queues</strong>, and internal <strong>decision scoring</strong> — where multiple options are constantly evaluated, and the one with the highest payoff is selected. This creates the feeling that enemies are “reading” your moves.</p><p>For example, when you try to heal, many enemies will rush in. That’s not scripted — it’s probably a high-priority trigger linked to your animation state. Following a very naive implementation of the possible enemy AI system.</p><pre>class EnemyAI:<br>    def __init__(self):<br>        self.health = 100<br>        self.position = (0, 0)  # x, y coordinates<br>        self.player_position = (10, 10)<br>        self.player_health = 50<br>        self.player_healing = False  # True if player is healing<br>        self.cooldown = {&#39;attack&#39;: 0, &#39;dodge&#39;: 0, &#39;heal&#39;: 0}<br><br>    def update(self):<br>        actions = []<br>        <br>        # Check if player is healing, this has a high priority<br>        if self.player_healing:<br>            actions.append((&#39;rush&#39;, 10))  # Highest priority: rush the player while healing<br><br>        # Attack behavior: prioritizing if the player is within range<br>        if self.distance_to_player() &lt; 5:<br>            actions.append((&#39;attack&#39;, 8))  # Attack has a high priority when close<br><br>        # Dodge behavior: prioritize dodging if the player is attacking<br>        if self.is_player_attacking():<br>            actions.append((&#39;dodge&#39;, 7))  # Dodging has a mid-level priority during attacks<br><br>        # Heal: the enemy will heal if it is low on health<br>        if self.health &lt; 30:<br>            actions.append((&#39;heal&#39;, 6))  # Healing is a lower priority when not critical<br><br>        # Default action: idle or move towards the player if none of the above conditions are met<br>        actions.append((&#39;move_towards_player&#39;, 5))<br><br>        # Choose the action with the highest priority<br>        best_action = self.select_action(actions)<br>        self.execute_action(best_action)<br><br>    def select_action(self, actions):<br>        # Sort actions by priority (highest first)<br>        actions.sort(key=lambda x: x[1], reverse=True)<br>        return actions[0][0]  # Return the action with the highest priority<br><br>    def execute_action(self, action):<br>        if action == &#39;rush&#39;:<br>            print(&quot;Enemy rushes towards the player while they are healing!&quot;)<br>            self.move_towards_player()<br>        elif action == &#39;attack&#39;:<br>            print(&quot;Enemy attacks the player!&quot;)<br>            self.attack()<br>        elif action == &#39;dodge&#39;:<br>            print(&quot;Enemy dodges the player&#39;s attack!&quot;)<br>            self.dodge()<br>        elif action == &#39;heal&#39;:<br>            print(&quot;Enemy heals itself!&quot;)<br>            self.heal()<br>        elif action == &#39;move_towards_player&#39;:<br>            print(&quot;Enemy moves towards the player.&quot;)<br>            self.move_towards_player()<br><br>    def distance_to_player(self):<br>        # Simple function to calculate distance (Euclidean distance)<br>        return ((self.position[0] - self.player_position[0]) ** 2 + (self.position[1] - self.player_position[1]) ** 2) ** 0.5<br><br>    def is_player_attacking(self):<br>        # Placeholder for checking if the player is attacking<br>        return True if self.player_health &lt; 50 else False<br><br>    def move_towards_player(self):<br>        # Placeholder for movement logic<br>        pass<br><br>    def attack(self):<br>        # Placeholder for attack logic<br>        self.player_health -= 10  # Example: player loses health on attack<br><br>    def dodge(self):<br>        # Placeholder for dodge logic<br>        pass<br><br>    def heal(self):<br>        # Placeholder for heal logic<br>        self.health = 100  # Example: enemy heals itself completely</pre><h3>Reinforcement Learning</h3><p>Modern <strong>reinforcement learning</strong> — the kind used by OpenAI’s bots in <em>Dota 2</em> or DeepMind’s AlphaStar — allows agents to improve through trial and error. In theory, a <em>Bloodborne</em> boss could adapt to your dodge habits, punish your healing patterns, and change tactics between deaths.</p><p><em>Bloodborne</em> thrives on balance. Its AI is tuned not to <em>win</em>, but to <strong>challenge</strong>. Introducing real-time learning could easily break that fragile equilibrium — thing that the developers of “Callisto Protocol” tried to do. That said, it’s not unthinkable that future games might offer adaptive AI that scales subtly based on how well you’re doing — a kind of dynamic difficulty based on player’s actions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fvWJfvjlkMGbmbGB" /><figcaption>Example of how RL could work. Credits to MDPI.</figcaption></figure><h3>Conclusion: A Strategic Implementation of AI in Bloodborne</h3><p>In the end, the AI in <em>Bloodborne</em> doesn’t need to be cutting-edge or based on complex neural networks. Instead, it relies on more traditional techniques — like decision trees, priority queues, and behavior trees — to create a dynamic and immersive experience. These methods allow enemies to respond to the player’s actions in real-time, making each encounter feel unpredictable and challenging.</p><p>Rather than trying to mimic human intelligence, the game’s AI is designed to enhance the overall experience. It keeps players on edge with reactive enemies that adapt to their movements and strategies. While the AI in <em>Bloodborne</em> might not be intelligent in the way modern machine learning models are, it does exactly what it needs to: it makes the game feel alive, tense, and engaging. In Yharnam, AI may not “survive” in the traditional sense, but it definitely thrives, shaping the brutal and thrilling world that defines <em>Bloodborne</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*8ySLOvdhB9hkigI8" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=42a644d723fc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Few-Shot Learning: A Breakthrough in AI]]></title>
            <link>https://medium.com/@francesco.digangi2801/understanding-few-shot-learning-a-breakthrough-in-ai-3f437f8447e2?source=rss-96963b411532------2</link>
            <guid isPermaLink="false">https://medium.com/p/3f437f8447e2</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[few-shot-learning]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[medical-imaging]]></category>
            <dc:creator><![CDATA[Francesco Di Gangi]]></dc:creator>
            <pubDate>Mon, 09 Sep 2024 15:43:44 GMT</pubDate>
            <atom:updated>2024-09-09T15:43:44.485Z</atom:updated>
            <content:encoded><![CDATA[<p>Few-shot learning (FSL) is rapidly advancing area of artificial intelligence that addresses a fundamental challenge: how can machines learn effectively with only a small number of examples? While traditional machine learning methods require large, well-labeled datasets to perform accurately, few-shot learning aims to perform well even when the available data is minimal — sometimes with as little as one example per category.</p><h3>Key Concepts in Few-Shot Learning</h3><p>At the core of few-shot learning are two key components: the <strong>support set</strong> and the <strong>query set</strong>. The support set is a small, labeled dataset that provides reference points for the model. Unlike in traditional training, where the dataset is large, the support set in few-shot learning is too small to fully train a model. The query set, on the other hand, contains new, unseen samples that the model is tasked with classifying by comparing them against the support set.</p><p>The primary goal of few-shot learning is not simply to memorize images in the training set and generalize to a test set. Instead, the objective is for the model to learn how to recognize <strong>similarities and differences</strong> between objects — learning to learn. This is especially important when encountering classes or objects the model has never seen before.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kS53IcLlvoIk3P6knApAsA.png" /></figure><h3>Few-Shot Learning and Meta-Learning</h3><p>Few-shot learning falls under the umbrella of <strong>meta-learning</strong>, or “learning to learn.” In traditional learning approaches, the model is trained on specific tasks. However, with meta-learning, the model develops the ability to adapt to new tasks quickly with very little data.</p><p>When the support set contains only one example per class, the task becomes <strong>one-shot learning</strong>, a more extreme case of few-shot learning, but one that showcases how a model can generalize from minimal data.</p><h4>Supervised Learning vs. Few-Shot Learning</h4><p>In traditional supervised learning, the model is trained on a large dataset with many examples for each class. After training, the model is tested on unseen data to see how well it generalizes. Few-shot learning, however, works differently:</p><ul><li>Query samples in few-shot learning are often from classes the model has never seen before.</li><li>Rather than simply classifying based on pre-learned patterns, the model compares the query to the support set to establish which class the query belongs to.</li></ul><p><strong>k-way, n-shot Learning</strong></p><p>A common way to describe few-shot learning tasks is through <strong>k-way, n-shot</strong> classification:</p><ul><li><strong>k-way</strong> refers to the number of classes in the support set.</li><li><strong>n-shot</strong> refers to how many samples there are per class.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UFXM6QsquIB3_LLI3ThFww.png" /></figure><p>For instance, in a 6-way, 1-shot task, there are six different classes in the support set, and each class has only one example. This framework makes the task more challenging as the number of classes (k) increases, while increasing the number of shots (n) generally leads to improved accuracy because the model has more examples to work with.</p><h3>Learning Similarity Functions</h3><p>Few-shot learning relies heavily on the idea of learning a <strong>similarity function</strong>, which measures how similar two samples are. The goal is to train the model to give a high similarity score when comparing images from the same class, and a low score when comparing images from different classes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c_JA4FUO3lX_I-4cH4J-Sw.png" /></figure><p>The general process looks like this:</p><ol><li>Train the model on a large dataset to learn a strong similarity function.</li><li>Use that similarity function to compare query samples to support set samples.</li><li>Identify the sample in the support set that is most similar to the query, and predict its class accordingly.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SVIYCU6Bbu8Dh_05TJBfeA.png" /></figure><h3>Applications in Medical Imaging</h3><p>One of the most promising applications of few-shot learning is in the field of medical imaging. In medical environments, data is often scarce due to legal regulations, privacy concerns, and the difficulty of obtaining large, annotated datasets. For example, gathering enough labeled images for tasks like tumor segmentation or disease classification can be challenging and time-consuming.</p><p>Few-shot learning offers a solution by enabling models to learn effectively from only a handful of labeled medical images. By using a small support set, these models can generalize and perform tasks such as identifying diseases or segmenting tumors based on limited data. This has the potential to revolutionize the medical field, where fewer data points are typically available but the need for accurate diagnostics is crucial.</p><h3>Conclusion</h3><p>Few-shot learning represents a shift in how we approach machine learning. Rather than relying on massive amounts of data, this approach empowers models to generalize from minimal examples, making it highly applicable in situations where data is scarce or difficult to obtain. Whether it’s classifying images, recognizing new objects, or advancing medical imaging techniques, few-shot learning opens the door to new possibilities in AI, transforming fields that traditionally struggle with data limitations.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3f437f8447e2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Case Study: The Last of Us Part Two]]></title>
            <link>https://medium.com/@francesco.digangi2801/case-study-the-last-of-us-part-two-72bb2c0b3164?source=rss-96963b411532------2</link>
            <guid isPermaLink="false">https://medium.com/p/72bb2c0b3164</guid>
            <dc:creator><![CDATA[Francesco Di Gangi]]></dc:creator>
            <pubDate>Sat, 03 Feb 2024 12:42:35 GMT</pubDate>
            <atom:updated>2024-02-03T12:42:35.152Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>This article contains spoilers about the game.</strong></p><p>The Last of Us Part Two was released in 2020. Players join Ellie (and Dina) on a path of revenge agianst Abbie, that is a new (and amazing) character introduced in this game.</p><p>The previous chapter (<a href="https://medium.com/@francesco.digangi2801/case-study-the-last-of-us-060610bffe67">Case Study: The Last of Us</a>) was already an improvement for all the games that were released in those years. Overall, it had some issues that Naughty Dog was able to study and improve.</p><p>The following is an examination of how <em>Artificial Intelligence</em> was employed in The Last of Us Part Two.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3jgm3jQoIjSA3Kc8.jpg" /><figcaption>Image credit: TechRadar</figcaption></figure><h3>Gameplay</h3><p>The gameplay is quite similar to the previous chapter, a mix of stealth combat and hard-hitting cover shooter. Players can search through the environments for several reasons, such as cover to avoid being detected or objects to improve his equipment. Of course not always the situation is quiet, but there is a variety of resources and places to explore.</p><p>The game actually introduces small (yet meaningful) changes. The ally system is quite better than the previous one, since now your ally helps you during the fights. There is also the introduction of dogs that can track the player movements. There are also new types of infected such as the Shamblers, and all the enemies (especially the runners) are more aggressive, since they can hunt down the player more effectively and maintain pressure.</p><p>Yet the most significant change is that the player can now fight more than one enemy at once: this had a huge impact on AI systes and their process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ECP4PN5Xq72MjRJf.jpg" /><figcaption>Image credit: Game Rant</figcaption></figure><h3>Combat AI</h3><p>The game was released for PS4 and PS5, this means that the available computational resources were much bigger than the first chapter (PS3) and this had a big impact in two ways.</p><p>Firstly, the number of active NPCs (Non-Playable Characters) — including enemies — is bigger, both during the game and during the cutscenes. To preserve CPU and memory performance, the original game limits the number of what are called NPCs. For example:</p><pre>#define MAX_NPC<br>#in the first version MAX_NPC=8<br>while player_doing_something()<br>  if encounter_npc()<br>    if curr_npcs_number&lt;MAX_NPC<br>        trigger_npc()<br>    else <br>        #usually do_nothing()</pre><p>Of course this is a very simple example of what happens during the game. How this impact the game? Basically you could eliminate some enemies quietly without issed, and then reposition yourself to attack the remaining numbers of enemies.</p><p>In The Last of Us Part Two, the number of active NPCs is significantly increased, ensuring more enemies active during combat. This make the whole game experience much more intense.</p><p>As discussed in previous part, enemies often use a finite state machine, but this is improved in the second chapter: when an emeny is shot by an arrow or shot with a silenced pistol, the NPC does not know immediately but need some time to search and find the body of the other NPC.</p><p>Similarly, the enemies in the original game would search an area and, after a while, if they failed to find the player, just go idle or return to their original place. Now, they never back down from their search behaviour and instead will continue to explore untill they found the player.</p><p>None of these are big additions, but small and simple improvements that actually can improve the gaming experience of the player.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*S8G-Yf0wYSaZuieB.jpeg" /><figcaption>Image credits: aiandgames</figcaption></figure><h3>Melee Systems</h3><p>This is completely renewed from the one seen in the first chapter, where the enemy could not dodge a melee attack. Each of them has three key elements:</p><ul><li>The animation played during the attack.</li><li>The start and end conditions dictate whether the attack is possible and how the NPC should be positioned at the end.</li><li>Lastly, there are the events, the critical moments of the attack. This can include the frames of the animation where a hit can occur, the tracking of the opponent that needs to occur during the swing, and also things like iFrames that dictate when they can’t be hurt during the attack.</li></ul><p>The NPCs now store a collection of melee behaviours and the elements above could be all in one during one simple fight. These give a lot more detail on how a player should approach a fight: the enemy could sprint up to the player, of it can run to a fixed distance nearby and wait a certain period before striking.</p><pre>#NPC behaviour<br>while waiting <br>  if enemies_is_spotted()<br>    action=think(enemy_position) #is the enemy close? is the enemy distant? <br><br>def action_type think(enemy_position):<br>  if enemy_position_is_close()<br>    return run_to_enemy<br>  else<br>      if enemy_position_is_distant():<br>         if shots_available():<br>            return shot_him<br>         else <br>            return hide<br>&#39;&#39;&#39;<br>Please keep in mind that this is a very simplified version<br>&#39;&#39;&#39;</pre><p>Once the enemy approach the player for a melee fight, it still has to continually run calculations to ensure it’s facing in the right direction the player. This might seems easy to think but it needs a lot of computational resources available.</p><p>The very fun (and difficult) part is how to handle nearby geometry. There are specific set of checks know as wall probes that run in the proximity of the player and AI characters during melee combat. Usually there are 8 of them, 4 high and 4 low. Every wall trigger a different action and a different animation.</p><h3>Motion Matching</h3><p>This is a completely new AI component: the animation system. Motion Matching is the name given to a particular type of animation: when a character moves from a walking animation to another given it’s about to run, or climb over geometry, you want to find the best point to blen them together in order to make it seems realistic and smooth.</p><p>Usually it is done by hand, using blend trees and state machines. In The Last of Us Part Two there are over 6000 animation clips handling the movement of AI character, collection around six and a half hours in length.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cYsCqOn0BL2TQXwe.jpg" /><figcaption>Image credits: Push Square</figcaption></figure><h3>The Ambient AI Evolution</h3><p>The AI iteration in The Last of Us Part Two introduces a sophisticated ambient AI system aimed at enhancing the realism of allies and other characters outside of combat situations. This system addresses the challenge of making NPC allies feel alive and realistic, particularly considering the expectations of players accustomed to motion-captured performances in cinematics and cutscenes.</p><p>The gradual expansion of motion capture technology over the years has facilitated the creation of emotionally charged sequences, but transitioning seamlessly between scripted animations and AI-controlled behavior remains a hurdle.</p><p>To tackle this issue, Naughty Dog developed a new ambient ally system specifically tailored for non-combat sequences. Unlike the limited pre-built animations used in previous games, this system introduces <strong>Positional Action Packs (PAPs)</strong> and a range of idle and walking animations to allow characters to move and interact more naturally within the game world.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8k0AztPvIW_r5eUv.jpg" /><figcaption>Image credits: Playstation blog</figcaption></figure><p>Wander Posts serve as points of interest for characters to explore, while an Exploration System determines realistic movement between these points, drawing inspiration from the cover point system used for combat AI in the original game.</p><p>The Exploration System prioritizes nearby points of interest and ensures that characters move in a relaxed, non-linear manner to maintain immersion. Despite occasional imperfections, such as characters appearing to ping-pong between locations, visual cues like special idle animations convey the impression of thoughtful decision-making, enriching the player experience.</p><p>This ambient AI system is showcased in specific sequences throughout the game, such as the Museum flashback with Joel and Ellie and the Aquarium sequence with Abby and Yara, demonstrating its effectiveness in creating dynamic and engaging interactions with NPCs.</p><pre>class Character:<br>  def __init__(self, name):<br>    self.name=name<br>    self.position=(0,0)<br>    self.destination=None<br>  <br>  def update(self):<br>    if self.destination:<br>      move_towards_destination()<br>   else<br>      explore()</pre><h3>Conclusion</h3><p>The release of The Last of Us Part Two marks another stride in Sony’s ongoing commitment to captivating single-player narratives accompanied by stunning visual quality. Throughout this video, it’s evident that artificial intelligence (AI) plays a pivotal role in enhancing established gameplay mechanics, elevating production values, and enhancing the immersive elements that draw players deeper into the storyline. By leveraging AI technology, the game brings players closer to its rich narrative and compelling characters, offering an unforgettable journey through its intricately crafted world.</p><h3>References</h3><ul><li><a href="https://www.youtube.com/watch?v=BghECmeLda0">Analysing the AI of The Last of Us Part II — YouTube</a></li><li><a href="https://www.youtube.com/watch?v=EM_pAigNTK8">The Last of Us Part II Motion Capture — YouTube</a></li><li><a href="https://www.aiandgames.com/">AI and Games</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=72bb2c0b3164" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Case Study: The Last of Us]]></title>
            <link>https://medium.com/@francesco.digangi2801/case-study-the-last-of-us-060610bffe67?source=rss-96963b411532------2</link>
            <guid isPermaLink="false">https://medium.com/p/060610bffe67</guid>
            <dc:creator><![CDATA[Francesco Di Gangi]]></dc:creator>
            <pubDate>Fri, 02 Feb 2024 17:36:08 GMT</pubDate>
            <atom:updated>2024-02-02T17:36:08.255Z</atom:updated>
            <content:encoded><![CDATA[<p>The Last of Us is a 2013 action-adventure-survivor videogame developed by Naughty Dog. There are two chapter of the game:</p><ul><li>The Last of Us 1</li><li>The Last of Us 2</li></ul><p>There is also a DLC that goes deep in the life of <em>Ellie</em>, one of the character in the game that walk with <em>Joel</em>: the main character of the game.</p><p>The Last of Us is one of the most renowned game probably that always been published, not only for his story, but also for his gameplay and for the Artificial Intelligence used for the development.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*f_o4Txl8xTuvZY_5.jpg" /><figcaption>Image credit: HDBlog</figcaption></figure><h3>Artificial Intelligence in The Last of Us</h3><p>Before starting with a more concrete explain of how the different AI character are used in the game, it is good to introduce some theory about what is actually implemented.</p><p>The Last of Us is built using Finite State Machines (FSMs). What are FSMs? They are state triggered by an event, so is an event is not happening potentially the character could do the same thing all over again. This is an important introduction for what we are going to see later.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/547/0*sgvGE77gJ6fxP8HU.png" /><figcaption><strong>Image Credits: AI and Games</strong></figcaption></figure><p>Now, let’s talk about the AI of The Last Of Us. It is build using skills and behaviours, not only for the characters we play, but also (and most importantly) for the enemies.</p><p>The image above shows us Move to Location &lt;-&gt; Play animation and it is the exact definition for skills. This, even if could appear as a basic paradigm, allows the enemy to inspect the area until the player shows up. When the enemy shows up, it plays a trigger event and the enemies start to attack or hide from the player.</p><p>In few words, the actions seems pretty basilar; yet they give us the idea of how a small feature can makes us see how smart the game-world could be.</p><p>About the behaviours, instead, we are talking about something that every user applies different: a user can do a melee attack or stay distant from the enemy. Behaviours are then <em>specific concrete actions</em> that make the enemies understand of we want to approach them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cCM1Ew30F6dwSdmN.png" /><figcaption><strong>Image Credits: HDBlog.it</strong></figcaption></figure><p>Then what are the states of the <em>Finite State machines</em>? Actually, each skills contains a finite state machine that determines an animation or another event. Of course since they are finite, it is not possible to do something that the game does not allow, but there are plenty of different skills and behaviours that are possible to approach, and yet they do not overwhelm the player, in order to give a fantastic game experience.</p><h3>Enemies</h3><p>There are two different type of enemies:</p><ul><li>hunters (human enemies)</li><li>infected (zombie enemies)</li></ul><p>Let’s start our discussion with the human ones.</p><h3>Hunters</h3><p>They are designed to appear as a credible threat of course. They can easily kill you if the difficult is hard enough. They also appear coordinated with the other hunters in the game, to find a way to hunt you down and eliminate the player: basically they act like an Artificial Intelligence version of you!</p><p>The most important thing is that the hunters can detect you in the world, both with vision and with audio.</p><p>This is a very basic pseudocode that should probably explain how the whole enemy system works.</p><pre>while (skill is not happened):<br>    move around the map<br>if skill happened -&gt; attack Joel<br>    is Joel hiding? <br>        hide yourself and look for him<br>    is Joel shooting?<br>        find a cover<br>    is Joel running towards you?<br>        prepare a counter-attack</pre><p>But how is actually implemented?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DwV4L7OJqWCjOEpE.jpg" /><figcaption><strong>Image Credits: Game Developer</strong></figcaption></figure><p>The Last of Us uses a <em>cone</em> that allow the player to be seen by enemies after typically 1 or 2 seconds. Very similar techniques are used in games such as <em>Splinter Cell and Uncharted</em>. In addition to that, enemies also scan the near environment, to understand if there is something standing between them and <em>Joel</em> (such as Anomaly Detection algorithms). Originally a enemy would have run in Joel’s direction without scanning his nearest environment. Eventually, if <em>Joel</em> is spotted, the enemy aims to the chest or to the head. These are the skills of the hunters:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pFIpUPVkkwNjrHQr.png" /><figcaption><strong>Image Credits: Game Developer</strong></figcaption></figure><p>One of the most interesting is the investigation, behaviour used when a Hunter is looking for <em>Joel</em> after a sound such as a breaking bottle or a brick (Joel’s behaviour vs enemy’s behaviour). Search, on the other hand, is when the player has been detected and Hunter already knows that he is nearby. These behaviour rely on four key components:</p><ul><li>Combat Coordination System: gives roles to each character, deciding which behaviour to execute.</li><li>Navigation Map: shows the fastest way to navigate around the world. This show to the NPC a path to look for <em>Joel</em>.</li><li>Exposure Map: sits on top of the navigation map that shows information about what the NPC can see from his current position. This shows to the NPC what is nearby.</li><li>Cover Point System: identifies not only good covers but also specific animation and behaviours. This is called by the NPC to understand where <em>Joel</em> could be.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3PgCY8zLihkwxAoR.jpg" /><figcaption><strong>Image Credits: Game Developer</strong></figcaption></figure><p>In this case, the NPC will move in the white spaces. Once the enemy is spotted, depending on the behaviour of Joel, the enemy will fight you or shoot you, covering behind one of the black spaces (<em>Cover Point System</em>), he is able to find the best cover to make <em>Joel</em> in difficult, based on his position. The enemy can also decide to stand and shoot you, for example, or to approach you. This is decided by the <em>Combat Coordinator System</em></p><h3>The Infected</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/0*M_JKbKvZa2l8ZG1B.jpg" /><figcaption><strong>Image Credits: Pinterest</strong></figcaption></figure><p>In the case of the infected, they are more likely to do melee attacks. On the other hand, their emphasis on sound in much more efficient than the human one. It is significant to say that there are different types of infected:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CxYaGcym2KRua1S4.jpg" /><figcaption><strong>Image Credits: Pinterest</strong></figcaption></figure><p>The clickers specially can hear sound even through walls and start the search phase. Clickers tho, can’t see, so it is possible to apply behaviour that kills them immediately, such as a shot in the head or a molotov. Of course is much more difficult because of the their great reaction to sounds. Since we are talking about one of the clickers’ skills, let’s see that other they can do.</p><p>Infected share some skills, such as sleeping, wander, search, on fire. The last one is the number one skill of an infected. The Wander instead is the last skill, in order of priority: they are allowed to move randomly and interact with the map (throw), but they manintain a history of the effectuated paths, so that they do not come back on the same one, on the other hand if they go for a walk to distance from Joel, they can start the sleep phase again, making much more easier for <em>Joel</em> to kill the enemies.</p><p>Now, let’s focus again on the sounds. How do characters such as the Clicker and the Runner search for the player if they hear something nearby? Infected do not search as hunters. They are less methodical and try to run towards the source of the sound. They stand for some seconds against the source of impact and then start a search path.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RioV_36R4x2leAwN.jpg" /><figcaption><strong>Image Credits: Game Developer</strong></figcaption></figure><p>The infected provide also a completely different combat experience from the Hunters because they can’t shoot. So most of the time, their approach is to try and run to attack <em>Joel</em>. Also, Infected do not have any ability to communicate with one another (the Hunters can), but you might have noticed they sometimes follow each other, either while exploring disturbances or attacking the player.</p><h3>Ellie</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*6mIQJT6s5kRebelp.png" /><figcaption><strong>Image Credits: SpazioGames</strong></figcaption></figure><p>Now, for Ellie the discussion is quite different. She has to follow four guidelines:</p><ul><li>Ensuring she stays close to Joel at all times, and finding points in the world that make sense to do so.</li><li>Giving her useful a sense of utility, be it to identify or attack enemies.</li><li>Making Ellie interesting as a character, given her special animations and audio dialogue.</li><li>And lastly ensuring the authenticity of the experience, by preventing her AI from cheating.</li></ul><p>All the work she does, is because of her ability to have a very specific and good positioning.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QGepQivlNmg1tRfa.jpg" /><figcaption><strong>Image Credits: Ellie: Buddy AI in The Last of Us, Max Dyckhoff, Game AI Pro Vol. 2, chapter 35, 2015</strong></figcaption></figure><p>Ellie searches for the better cover position and follows Joel. Now, when Ellie is hidden, she generates a cover action packs typically used for environmental interactions by the player, such as a suggestion or some ammo. Two animations that are very frequently used are:</p><ul><li>Following in the cover</li><li>Protected in cover</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_hjVgI9sJpzj9Red.jpg" /><figcaption><strong>Image Credits: Ellie: Buddy AI in The Last of Us</strong></figcaption></figure><p>When eventually she has a gun, she only uses if the player is not, trying to save him if he is in danger. If you survive and kill some enemies, she will stop using it. Basically Ellie’s AI does not cheat and tries to give the user most of the work, supporting him when is necessary. Reason why her character is full of “funny” dialogs.</p><h3>Closing</h3><p>I truly hope that this was great for you as much as it was for me, stAI tuned for other curiosities about video games world! Thank you for reading that.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=060610bffe67" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bayes decision and model
evaluation — with example]]></title>
            <link>https://medium.com/@francesco.digangi2801/bayes-decision-and-model-evaluation-with-example-cc92bbd7ccaa?source=rss-96963b411532------2</link>
            <guid isPermaLink="false">https://medium.com/p/cc92bbd7ccaa</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[confusion-matrix]]></category>
            <category><![CDATA[bayes-decision-model]]></category>
            <category><![CDATA[empirical-bayes-risk]]></category>
            <category><![CDATA[classification]]></category>
            <dc:creator><![CDATA[Francesco Di Gangi]]></dc:creator>
            <pubDate>Sun, 24 Jul 2022 10:23:26 GMT</pubDate>
            <atom:updated>2022-07-24T10:23:26.554Z</atom:updated>
            <content:encoded><![CDATA[<h3>Bayes decision and model<br>evaluation — with example</h3><h3>Introduction</h3><p>We are going to start giving two formulas that came from basic probability, the one that defines the <em>accuracy </em>and the one that defines the <em>error rate:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mgf-CxJcaZmLWqZ732vO1A.jpeg" /><figcaption>a is the <strong>accuracy</strong>, e is the <strong>error rate</strong>.</figcaption></figure><p>The accuracy shows how many of the predictions are correct. The error rate the opposite. It is also significant to say that accuracy might be misleading: in fact, an accuracy of the <em>86%</em>. it is <strong>not </strong>a good accuracy. A model that want to achieve a good accuracy, should be <strong>at least</strong> of <em>90% — </em>in some application 90% could not be enough, and it might be needed an accuracy of <em>95%</em>.</p><h3>Model evaluation for classification</h3><p>We will start from the concept of <em>Confusion matrix </em>and then discuss about<em> Bayes decisions </em>and <em>Empirical Bayes risk.</em></p><p>A <em>confusion matrix</em> is not a metric to evaluate a model, but it provides insight into the predictions. It is important to learn confusion matrix in order to comprehend other classification metrics such as <em>precision </em>and <em>recall</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*4aoBTRtjAv1pWp9S6iDhrw.jpeg" /><figcaption><a href="https://www.researchgate.net/profile/Arda-Aras-2"><strong>Arda Can Aras</strong></a>, Explaining what learned models predict</figcaption></figure><p>There are four different accuracy measures:</p><ul><li>False negative rate FNR (false rejection / miss rate)</li><li>False positive rate FPR (false acceptance)</li><li>True positive rate TPR (recall, sensivity)</li><li>True negative rate TNR (specificity)</li></ul><p>Every errors (operations in red) have a cost, such as the correct predictions (operations in green), yet for the correct predictions we usually estimate a cost of 0.</p><p>We can compute then a <em>weighted accuracy, </em>that measures how important are different kind of errors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/519/1*HaPFkuwQaGvJLf6hv0lfCg.png" /></figure><p>It is important to say that a confusion matrix <strong>does not</strong> return a label, but returns a score; from which we can calculate a <strong>decision function</strong>. With that, we can then decide which label assign.</p><p>A <strong>decision function </strong>can be:</p><ul><li>Generative models: log likelihood ratios:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/294/1*vReGeVQhyjB8HAoB768yNQ.png" /></figure><ul><li>Discriminative models: posterior log likelihood ratios:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/294/1*vReGeVQhyjB8HAoB768yNQ.png" /></figure><ul><li>Non probabilistic models: score</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/152/1*DXN3KKeEeMOHgWfL4_9uOQ.png" /></figure><p>But yet we have to understand how to assign a label after we obtained a score. For this, we will use a threshold.</p><p>𝓈≥𝓉 → TP class</p><p>𝓈&lt;𝓉 → TN class</p><p>Where 𝓉 is related to the class and its prior, given by</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/233/1*zUdQYGrnM7KK_qnmU0WtsA.png" /></figure><h3>Bayes Decisions</h3><p>We might understood that each action will have a cost, and the goal of the classifier is to allow us to choose the best action to perform. The cost may be related to the sample, but actually depends on the class (since the sample belongs to the class).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VQZDvmdVEpfcMv9O0hiE_A.png" /></figure><p>We use a recognizer ℛ to identify the class, since it is unknown.</p><p>Let’s see an example on how to compute the cost properly. Let’s assume that we already have a matrix with costs and a prior vector.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7LR95R_QyihWU-56OgFJcw.jpeg" /></figure><p>Each row of matrix 𝒞 identifies a class, so we have three classes. We then compute the posterior probability of a sample.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bhOClklushfsLpu04om7uQ.jpeg" /></figure><p>At this point, we can compute the costs</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qXvdqozQAAMAtxJV_bsKZQ.jpeg" /></figure><p>From the results, we can see that class 2 would fit better.</p><p>Another interesting thing is the <em>Empirical Bayes Risk</em>, that would represents the single cost for each class and then a sum, in order to obtain a complete cost that we would pay. This is also called <strong>Detection Cost Function (DCF)</strong>.</p><p>There is a slight difference tho. We calculate the <em>Empirical Bayes Risk </em>as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/578/1*SGF9s8kNw5-OtnU1S7tRoQ.png" /></figure><p>Let’s see another example on this.</p><p>Let’s consider again the 3-class problem with cost matrix and priors given:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1002/1*u2xlSEwUE_ScakQUPCM5Hw.jpeg" /></figure><p>And let’s assume we obtain the following confusion matrix:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TLQ33KU8yZDWNC0bMoDfAw.jpeg" /></figure><p>So for example, for the class 1 we will have π1=0.3, N1=205+145+50=400.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2V1kWDYXZtmm_dT5UKyyww.png" /></figure><p>This is our <em>Empirical Bayes Risk</em> for class 1. We compute the same for class 2 and 3.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*77gY1y44U6ySKJDmeUq5zQ.jpeg" /></figure><p>And finally:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*HpmcKOvs2DLokiMPwrAnHg.png" /></figure><h3>Conclusion</h3><p>We have seen that every action has its consequences, reason why we should always keep in mind the costs for our classification for our dataset. Of course, if a cost is too high we shall do again all the calculation or select other options; yet if the cost seems reasonable, we probably found our implementation.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cc92bbd7ccaa" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>