From fbb16c5572457bdaee157eac0786a096be51cf1e Mon Sep 17 00:00:00 2001 From: ligerfotis Date: Tue, 28 Mar 2023 21:55:24 +0200 Subject: [PATCH] bonus unsolved --- assignment 3/bonus_unsloved.ipynb | 49 ++++++++++++++++++------------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/assignment 3/bonus_unsloved.ipynb b/assignment 3/bonus_unsloved.ipynb index a10c05a..431d143 100644 --- a/assignment 3/bonus_unsloved.ipynb +++ b/assignment 3/bonus_unsloved.ipynb @@ -13,7 +13,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 1, "outputs": [], "source": [ "import random\n", @@ -25,7 +25,9 @@ " # Shuffle the deck of cards\n", " random.shuffle(self.cards)\n", " # Initialize the prior probability\n", - " \n", + "\n", + " # code missing here\n", + "\n", "\n", " def draw_card(self, index):\n", " \"\"\"\n", @@ -58,13 +60,11 @@ " function name: update_probabilities\n", " \"\"\"\n", " ### function missing here\n", - " \n", " \"\"\"\n", " Calculate the posterior probability based on the prior probability, likelihood, and marginal likelihood\n", " function name: get_posterior\n", " \"\"\"\n", " ### function missing here\n", - " \n", "\n", " def play_game(self):\n", " while self.cards:\n", @@ -73,7 +73,6 @@ " # only one card left\n", " if len(self.cards) == 1:\n", " # code missing here\n", - " \n", " self.cards.pop()\n", " else:\n", " index = int(input(f\"Remainder deck: {self.get_remainder()}\\nEnter the index of the card you want to draw:\"))\n", @@ -81,9 +80,11 @@ " print(f'You drew a {color} card with value {card}')\n", "\n", " # Calculate the likelihood and marginal likelihood based on the color of the drawn card\n", - " \n", + "\n", " # Update the prior probability based on Bayes' rule\n", - " \n", + " # code missing here\n", + " posterior_red = 0 # you must calculate this value\n", + " posterior_black = 0 # you must calculate this value\n", " # Print the posterior probabilities\n", " print(f\"After drawing a {card} card:\")\n", " print(f\"The probability that the other card is red: {posterior_red:.2f}\")\n", @@ -107,7 +108,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "outputs": [ { "name": "stdout", @@ -117,19 +118,28 @@ "1: Unknown\n", "2: Unknown\n", "3: Unknown\n", - "You drew a Red card with value R\n", - "After drawing a R card:\n", - "The probability that the other card is red: 0.33\n", - "The probability that the other card is black: 0.67\n", + "You drew a Black card with value B\n", + "After drawing a B card:\n", + "The probability that the other card is red: 0.00\n", + "The probability that the other card is black: 0.00\n", "0: Unknown\n", "1: Unknown\n", "2: Unknown\n", - "You drew a Black card with value B\n", - "After drawing a B card:\n", - "The probability that the other card is red: 0.33\n", - "The probability that the other card is black: 0.67\n", + "You drew a Red card with value R\n", + "After drawing a R card:\n", + "The probability that the other card is red: 0.00\n", + "The probability that the other card is black: 0.00\n", "0: Unknown\n", - "1: Unknown\n" + "1: Unknown\n", + "You drew a Red card with value R\n", + "After drawing a R card:\n", + "The probability that the other card is red: 0.00\n", + "The probability that the other card is black: 0.00\n", + "0: Unknown\n", + "After drawing a B card:\n", + "The probability that the other card is red: 0.00\n", + "The probability that the other card is black: 0.00\n", + "The deck is empty.\n" ] } ], @@ -138,10 +148,7 @@ "deck.play_game()\n" ], "metadata": { - "collapsed": false, - "pycharm": { - "is_executing": true - } + "collapsed": false } }, {