Structured Data > QUESTIONS & ANSWERS > University of California, BerkeleyDATA 8lab06_sol ALL ANSWERS CORRECT. GRADED A. (All)

University of California, BerkeleyDATA 8lab06_sol ALL ANSWERS CORRECT. GRADED A.

Document Content and Description Below

Lab 6 Welcome to Lab 6! In this lab, we will learn about sampling strategies. More information about sampling in the textbook can be found here! The data used in this lab will contain salary data ... and statistics for basketball players from the 2014-2015 NBA season. This data was collected from basketball-reference (http://www.basketball-reference.com) and spotrac (http://www.spotrac.com). In [2]: # Run this cell, but please don't change it. # These lines import the Numpy and Datascience modules. import numpy as np from datascience import * # These lines do some fancy plotting magic import matplotlib %matplotlib inline import matplotlib.pyplot as plots plots.style.use('fivethirtyeight') # Don't change this cell; just run it. from client.api.notebook import Notebook ok = Notebook('lab06.ok') _ = ok.auth(inline=True) 1. Dungeons and Dragons and Sampling In the game Dungeons & Dragons, each player plays the role of a fantasy character. A player performs actions by rolling a 20-sided die, adding a "modifier" number to the roll, and comparing the total to a threshold for success. The modifier depends on her character's competence in performing the action. For example, suppose Alice's character, a barbarian warrior named Roga, is trying to knock down a heavy door. She rolls a 20-sided die, adds a modifier of 11 to the result (because her character is good at knocking down doors), and succeeds if the total is greater than 15. Question 1.1 Write code that simulates that procedure. Compute three values: the result of Alice's roll (roll_result), the result of her roll plus Roga's modifier (modified_result), and a boolean value indicating whether the action succeeded (action_succeeded). Do not fill in any of the results manually; the entire simulation should happen in code. Hint: A roll of a 20-sided die is a number chosen uniformly from the array make_array(1, 2, 3, 4, ..., 20). So a roll of a 20-sided die plus 11 is a number chosen uniformly from that array, plus 11. In [5]: possible_rolls = np.arange(1, 20+1, 1) #SOLUTION roll_result = np.random.choice(possible_rolls) #SOLUTION modified_result = roll_result + 11 #SOLUTION action_succeeded = modified_result > 15 #SOLUTION # The next line just prints out your results in a nice way # once you're done. You can delete it if you want. print("On a modified roll of {:d}, Alice's action {}.".format(modified_result, "succeeded" if action_succeeded else "failed")) In [ ]: _ = ok.grade('q1_1') Question 1.2 Run your cell 7 times to manually estimate the chance that Alice succeeds at this action. (Don't use math or an extended simulation.). Your answer should be a fraction. In [ ]: rough_success_chance = 1/7 #SOLUTION In [ ]: _ = ok.grade('q1_2') Suppose we don't know that Roga has a modifier of 11 for this action. Instead, we observe the modified roll (that is, the die roll plus the modifier of 11) from each of 7 of her attempts to knock down doors. We would like to estimate her modifier from these 7 numbers. Question 1.3 Write a Python function called simulate_observations. It should take no arguments, and it should return an array of 7 numbers. Each of the numbers should be the modified roll from one simulation. Then, call your function once to compute an array of 7 simulated modified rolls. Name that array observations. On a modified roll of 20, Alice's action succeeded. [Show More]

Last updated: 1 year ago

Preview 1 out of 9 pages

Reviews( 0 )

$7.00

Add to cart

Instant download

Can't find what you want? Try our AI powered Search

OR

GET ASSIGNMENT HELP
60
0

Document information


Connected school, study & course


About the document


Uploaded On

May 01, 2021

Number of pages

9

Written in

Seller


seller-icon
d.occ

Member since 3 years

227 Documents Sold


Additional information

This document has been written for:

Uploaded

May 01, 2021

Downloads

 0

Views

 60

Document Keyword Tags

Recommended For You

What is Browsegrades

In Browsegrades, a student can earn by offering help to other student. Students can help other students with materials by upploading their notes and earn money.

We are here to help

We're available through e-mail, Twitter, Facebook, and live chat.
 FAQ
 Questions? Leave a message!

Follow us on
 Twitter

Copyright © Browsegrades · High quality services·