@@ -34,7 +34,7 @@ as *Monte Carlo sampling* methods. In Monte Carlo methods, the key
3434idea is to take many * samples* , which will then allow you to estimate
3535the solution.
3636
37- ### What, exactly, is sampling ?
37+ ### What is Sampling ?
3838
3939The term * sampling* means generating random values from some
4040probability distribution. For example, the value you get from rolling
@@ -64,7 +64,7 @@ under many different weather conditions, multiple times, which would
6464allow you to see under which conditions the airplane is most likely to
6565fail.
6666
67- ### Programming with samples and probabilities
67+ ### Programming with Samples and Probabilities
6868
6969As with most applications in computer science, you can make design
7070decisions when programming with samples and probabilities that will
@@ -77,7 +77,7 @@ evaluating probabilities, working in "log-space", allowing
7777reproducibility, and separating the process of generating samples from
7878the specific application.
7979
80- #### A brief aside about notation
80+ #### A Brief Aside About Notation
8181
8282Typically when we talk about probability distributions, we will use
8383mathematical notation like $p(x)$ to indicate that $p$ is the
@@ -104,7 +104,7 @@ to get a sample at places where the probability is higher). In
104104mathematical notation, we would write this as $x\sim p$, to indicate
105105that $x$ is sampled proportional to $p$.
106106
107- ## Sampling magical items
107+ ## Sampling Magical Items
108108
109109As a simple example to demonstrate the various design decisions
110110involved with programming with probabilities, let's imagine we're
@@ -136,7 +136,7 @@ bonus is distributed across the stats. Conveniently, the probability
136136distributions of the bonus and the way that it is distributed are both
137137instances of the * multinomial distribution* .
138138
139- ## The multinomial distribution
139+ ## The Multinomial Distribution
140140
141141The multinomial distribution is used when you have several possible
142142outcomes, and you want to characterize the probability of each of
@@ -156,7 +156,7 @@ green and one blue).
156156Note: the code in this section is also located in the file
157157` multinomial.py ` .
158158
159- ### The ` MultinomialDistribution ` class
159+ ### The ` MultinomialDistribution ` Class
160160
161161In general, there are two use cases for a distribution: we might want
162162to * sample* from that distribution, and we might want to * evaluate the
@@ -245,7 +245,7 @@ as well).
245245Before we get into the rest of the class, I want to briefly go over
246246two points related to the constructor.
247247
248- #### Descriptive vs. mathematic variable names
248+ #### Descriptive vs. Mathematic Variable Names
249249
250250Usually, programmers are encouraged to use descriptive variable names:
251251for example, it would be considered better practice to use the names
@@ -301,7 +301,7 @@ than `numpy` is significantly clearer:
301301>> > np.sqrt(np.sum(np.dot(np.array(a), np.array(b))))
302302```
303303
304- ### Sampling from a multinomial distribution
304+ ### Sampling from a Multinomial Distribution
305305
306306Taking a sample from a multinomial distribution is actually fairly
307307straightforward, because NumPy provides us with a function that
@@ -314,7 +314,7 @@ does it: `np.random.multinomial`.
314314Despite the fact that this function already exists, there are a few
315315design decisions surrounding it that we can make.
316316
317- #### Seeding the random number generator
317+ #### Seeding the Random Number Generator
318318
319319Even though we do want to draw a * random* sample, we sometimes want
320320our results to be reproducible: even though the numbers seem random,
@@ -375,7 +375,7 @@ sampler from the `RandomState` object itself.
375375> is easier to find out whether there is nondeterminism coming from
376376> somewhere other than your own code.*
377377
378- #### What's a parameter ?
378+ #### What's a Parameter ?
379379
380380Once we've decided whether to use ` np.random.multinomial ` or
381381` rso.multinomial ` , sampling is just a matter of calling the
@@ -427,7 +427,7 @@ def sample(self, n):
427427 return x
428428```
429429
430- ### Evaluating the multinomial PMF
430+ ### Evaluating the Multinomial PMF
431431
432432Although we don't explicitly need to compute the probability of the
433433magical items that we generate, it is almost always a good idea to
@@ -449,7 +449,7 @@ compute the PMF.
449449Finally, in many cases, your particular use case will dictate that you
450450implement the PMF or PDF from the beginning, anyway.
451451
452- #### The multinomial PMF equation
452+ #### The Multinomial PMF Equation
453453
454454Formally, the multinomial distribution has the following equation:
455455
473473p(\mathbf{x}; \mathbf{p}) = \frac{\Gamma((\sum_{i=1}^k x_i)+1)}{\Gamma(x_1+1)\cdots{}\Gamma(x_k+1)}p_1^{x_1}\cdots{}p_k^{x_k},
474474$$
475475
476- #### Working in "log-space "
476+ #### Working in "Log-Space "
477477
478478Before getting into the actual code needed to implement the equation
479479above, I want to emphasize one of the * the most important design
@@ -559,7 +559,7 @@ out of log-space, but we at least maintain *some* information about
559559the probabilities---enough to compare them, for example---that would
560560otherwise be lost.
561561
562- #### Writing the PMF code
562+ #### Writing the PMF Code
563563
564564Now that we have seen the importance of working in log-space, we can
565565actually write our function to compute the log-PMF:
@@ -695,7 +695,7 @@ results in a `nan` value (even though we can see that it
695695should be 1 ). But, because we do the computation in log- space, it' s
696696not an issue and we don' t need to worry about it!
697697
698- # # Sampling magical items, revisited
698+ # # Sampling Magical Items, Revisited
699699
700700Now that we have written our multinomial functions, we can put them to
701701work to generate our magical items. To do this, we will
@@ -972,7 +972,7 @@ And, if we want, we can evaluate the probability of a sampled item:
9729720.0069444444444444441
973973```
974974
975- # # Estimating attack damage
975+ # # Estimating Attack Damage
976976
977977We' ve seen one application of sampling: generating
978978random items that monsters drop. I mentioned earlier that sampling can
@@ -1002,7 +1002,7 @@ following scheme:
100210024 . Repeat steps 1 - 3 many times. This will result in an approximation
10031003 to the distribution over damage.
10041004
1005- # ## Implementing a distribution over damage
1005+ # ## Implementing a Distribution Over Damage
10061006
10071007The class `DamageDistribution` (also in `rpg.py` ) shows an
10081008implementation of this scheme:
@@ -1085,7 +1085,7 @@ look at the strength stat of those items, and from that compute the
10851085number of dice to roll. Finally, we roll the dice (again relying on
10861086our trusty multinomial functions) and compute the damage from that.
10871087
1088- # ### What happened to evaluating probabilities ?
1088+ # ### What Happened to Evaluating Probabilities ?
10891089
10901090You may have noticed that we didn' t include a `log_pmf` or `pmf`
10911091function in our `DamageDistribution` . This is because we actually do
@@ -1105,7 +1105,7 @@ difficult to compute exactly). So, rather than having a method for the
11051105PMF , we' ll show in the next section how we can approximate the
11061106distribution with many samples.
11071107
1108- # ## Approximating the distribution
1108+ # ## Approximating the Distribution
11091109
11101110Now we have the machinery to answer our question from earlier: If the
11111111player has two items, and we want the player to be able to defeat the
@@ -1120,8 +1120,8 @@ and `rso` that we created earlier:
11201120>> > damage_dist = DamageDistribution(2 , item_dist, num_hits = 3 , rso = rso)
11211121```
11221122
1123- Now we can draw a bunch of samples, and compute the 50th percentile
1124- (that is , the damage value that is greater than 50 % of the samples):
1123+ Now we can draw a bunch of samples, and compute the 50th percentile
1124+ (the damage value that is greater than 50 % of the samples):
11251125
11261126```python
11271127>> > samples = np.array([damage_dist.sample() for i in xrange (100000 )])
0 commit comments