bonus unsolved
This commit is contained in:
parent
ab7f1237d1
commit
fbb16c5572
@ -13,7 +13,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 29,
|
"execution_count": 1,
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"import random\n",
|
"import random\n",
|
||||||
@ -25,7 +25,9 @@
|
|||||||
" # Shuffle the deck of cards\n",
|
" # Shuffle the deck of cards\n",
|
||||||
" random.shuffle(self.cards)\n",
|
" random.shuffle(self.cards)\n",
|
||||||
" # Initialize the prior probability\n",
|
" # Initialize the prior probability\n",
|
||||||
" <code>\n",
|
"\n",
|
||||||
|
" # code missing here\n",
|
||||||
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def draw_card(self, index):\n",
|
" def draw_card(self, index):\n",
|
||||||
" \"\"\"\n",
|
" \"\"\"\n",
|
||||||
@ -58,13 +60,11 @@
|
|||||||
" function name: update_probabilities\n",
|
" function name: update_probabilities\n",
|
||||||
" \"\"\"\n",
|
" \"\"\"\n",
|
||||||
" ### function missing here\n",
|
" ### function missing here\n",
|
||||||
" <code>\n",
|
|
||||||
" \"\"\"\n",
|
" \"\"\"\n",
|
||||||
" Calculate the posterior probability based on the prior probability, likelihood, and marginal likelihood\n",
|
" Calculate the posterior probability based on the prior probability, likelihood, and marginal likelihood\n",
|
||||||
" function name: get_posterior\n",
|
" function name: get_posterior\n",
|
||||||
" \"\"\"\n",
|
" \"\"\"\n",
|
||||||
" ### function missing here\n",
|
" ### function missing here\n",
|
||||||
" <code>\n",
|
|
||||||
"\n",
|
"\n",
|
||||||
" def play_game(self):\n",
|
" def play_game(self):\n",
|
||||||
" while self.cards:\n",
|
" while self.cards:\n",
|
||||||
@ -73,7 +73,6 @@
|
|||||||
" # only one card left\n",
|
" # only one card left\n",
|
||||||
" if len(self.cards) == 1:\n",
|
" if len(self.cards) == 1:\n",
|
||||||
" # code missing here\n",
|
" # code missing here\n",
|
||||||
" <code>\n",
|
|
||||||
" self.cards.pop()\n",
|
" self.cards.pop()\n",
|
||||||
" else:\n",
|
" else:\n",
|
||||||
" index = int(input(f\"Remainder deck: {self.get_remainder()}\\nEnter the index of the card you want to draw:\"))\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",
|
" print(f'You drew a {color} card with value {card}')\n",
|
||||||
"\n",
|
"\n",
|
||||||
" # Calculate the likelihood and marginal likelihood based on the color of the drawn card\n",
|
" # Calculate the likelihood and marginal likelihood based on the color of the drawn card\n",
|
||||||
" <code>\n",
|
"\n",
|
||||||
" # Update the prior probability based on Bayes' rule\n",
|
" # Update the prior probability based on Bayes' rule\n",
|
||||||
" <code>\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 the posterior probabilities\n",
|
||||||
" print(f\"After drawing a {card} card:\")\n",
|
" print(f\"After drawing a {card} card:\")\n",
|
||||||
" print(f\"The probability that the other card is red: {posterior_red:.2f}\")\n",
|
" print(f\"The probability that the other card is red: {posterior_red:.2f}\")\n",
|
||||||
@ -107,7 +108,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": 2,
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
@ -117,19 +118,28 @@
|
|||||||
"1: Unknown\n",
|
"1: Unknown\n",
|
||||||
"2: Unknown\n",
|
"2: Unknown\n",
|
||||||
"3: Unknown\n",
|
"3: Unknown\n",
|
||||||
"You drew a Red card with value R\n",
|
"You drew a Black card with value B\n",
|
||||||
"After drawing a R card:\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 red: 0.00\n",
|
||||||
"The probability that the other card is black: 0.67\n",
|
"The probability that the other card is black: 0.00\n",
|
||||||
"0: Unknown\n",
|
"0: Unknown\n",
|
||||||
"1: Unknown\n",
|
"1: Unknown\n",
|
||||||
"2: Unknown\n",
|
"2: Unknown\n",
|
||||||
"You drew a Black card with value B\n",
|
"You drew a Red card with value R\n",
|
||||||
"After drawing a B card:\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 red: 0.00\n",
|
||||||
"The probability that the other card is black: 0.67\n",
|
"The probability that the other card is black: 0.00\n",
|
||||||
"0: Unknown\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"
|
"deck.play_game()\n"
|
||||||
],
|
],
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"collapsed": false,
|
"collapsed": false
|
||||||
"pycharm": {
|
|
||||||
"is_executing": true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user