Question: Python programming! Problem Statement A probability distribution can be represented in Python as a dictionary, where the keys are the possible outcomes and the values
Python programming!
Problem Statement A probability distribution can be represented in Python as a dictionary, where the keys are the possible outcomes and the values are their probabilities. For example, the dictionary ("heads " : 0.5, "tails". .5) can be used to represent the probability distribution of a fair coin flip We want to do two things with this representation of a probability distribution. Calculating with disjoint additivity (10 points) Our second task is to calculate the probability of a set of outcomes. Write a function called set-prob. Your function should take two parameters: a dictionary of the form described above, and a Python set object. Your function should return the real number between 0 and 1 which is the probability of the event corresponding to the set You may assume that the dictionary passed as input will follow Kolmogorov's laws, and also that the elements of the set will be elements of the dictionary. Bonus: For 1 extra point, write a function that will take a dictionary and one or more sets, and return the probability of any of those events occurring. (Hint: which set-theoretic operation corresponds to the logical OR?) Simulating a random process (20 points) Our first task is to simulate the experience whose probability distribution is described by a dictionary. Write a function called simulate. Your function should take one parameter, which is a dictionary of the form described above. Your function should return a randomly chosen outcome (dictionary key) according to the probability distribution described by the dictionary. You may use random.random() to generate random numbers from [0,1), but no other source of randomness You may assume that the dictionary passed as input will follow Kolmogorov's laws: that is, the keys represent mutually exclusive outcomes and the values sum to 1 Bonus: For 1 extra point, write a function that wll handle, in a reasonable way, a dictionary whose values do not sum to 1 Problem Statement A probability distribution can be represented in Python as a dictionary, where the keys are the possible outcomes and the values are their probabilities. For example, the dictionary ("heads " : 0.5, "tails". .5) can be used to represent the probability distribution of a fair coin flip We want to do two things with this representation of a probability distribution. Calculating with disjoint additivity (10 points) Our second task is to calculate the probability of a set of outcomes. Write a function called set-prob. Your function should take two parameters: a dictionary of the form described above, and a Python set object. Your function should return the real number between 0 and 1 which is the probability of the event corresponding to the set You may assume that the dictionary passed as input will follow Kolmogorov's laws, and also that the elements of the set will be elements of the dictionary. Bonus: For 1 extra point, write a function that will take a dictionary and one or more sets, and return the probability of any of those events occurring. (Hint: which set-theoretic operation corresponds to the logical OR?) Simulating a random process (20 points) Our first task is to simulate the experience whose probability distribution is described by a dictionary. Write a function called simulate. Your function should take one parameter, which is a dictionary of the form described above. Your function should return a randomly chosen outcome (dictionary key) according to the probability distribution described by the dictionary. You may use random.random() to generate random numbers from [0,1), but no other source of randomness You may assume that the dictionary passed as input will follow Kolmogorov's laws: that is, the keys represent mutually exclusive outcomes and the values sum to 1 Bonus: For 1 extra point, write a function that wll handle, in a reasonable way, a dictionary whose values do not sum to 1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
