4.1 Simulating equally likely outcomes
Consider again two rolls of a fair four-sided and let \(X\) be the sum and \(Y\) the larger of the two rolls (or the common value if a tie).
In the previous chapter we used a box model to specify the probability space correspoding to pairs of rolls of a four-sided die.
When tickets are equally likely and sampled with replacement, a Discrete Uniform model can also be used.
Think of a DiscreteUniform(a, b) probability space corresponding to a spinner with sectors of equal area labeled with integer values from a to b (inclusive).
For example, the spinner in Figure 3.2 corresponds to DiscreteUniform(1, 4).
In the following, \(U\) represents the result of a single roll of a fair four-sided die. The default mapping function in RV is the identity, so U = RV(P) represents71 \(U(\omega) = \omega\).
P = DiscreteUniform(a = 1, b = 4)
U = RV(P)
U.sim(10000).plot()
plt.show()
For two rolls the probability space corresponds to spinning the DiscreteUniform spinner twice, which is coded72 as DiscreteUniform(a = 1, b = 4) ** 2. The first line below has the same effect73 as BoxModel([1, 2, 3, 4], size = 2, replace = True).
P = DiscreteUniform(a = 1, b = 4) ** 2
X = RV(P, sum)
Y = RV(P, max)
(X & Y).sim(10000).plot(['tile', 'marginal'])
plt.show()Figure 4.1: Tile and impulse plot visualization of the simulation-based approximate joint and marginal distributions of the sum (\(X\)) and larger (\(Y\)) of two rolls of a fair four-sided die.
For technical reasons, Symbulate will not plot simulated outcomes from a
ProbabilitySpace, only simulated realizations of anRV. Essentially, as mentioned in earlier sections, probability space outcomes can be anything — not necessarily numbers — and so there are too many potential situations and plots for Symbulate to handle with a singleplotcommand. In contrast, simulated realizations ofRVare numbers (or vectors of numbers) which facilitates plotting. Plotting simulated outcomes from a probability spacePwith numerical outcomes can be achieved by first definingX = RV(P)and then simulating and plotting values ofX. That is, replaceP.sim(10000).plot()withRV(P).sim(10000).plot(). However, this only works if the outcomes ofPare numerical.↩︎For now you can interpret
DiscreteUniform(a = 1, b = 4)as a spinner with four quarters labeled 1, 2, 3, 4, and** 2as “spin the spinner twice”. In Python,**represents exponentiation; e.g.,2 ** 5 = 32. SoDiscreteUniform(a = 1, b = 4) ** 2is equivalent toDiscreteUniform(a = 1, b = 4) * DiscreteUniform(a = 1, b = 4). Future sections will reveal why the product*notation is natural for independent spins of spinners.↩︎BoxModelassumes equally likely tickets by default, but there are options for non-equally likely cases.↩︎