x
, y
: coordinates.move(deltaX, deltaY)
: move self with deltaX, deltaYgetX()
, getY()
distFrom(otherLocation)
: check the distance between current location with otherLocationdrunks
: list of drunk objectsaddDrunk(drunk, loc)
: add a drunk with its location into Fields’ drunks
moveDrunk(drunk)
: move the drunk’s location
getLoc(drunk)
: get the drunk’s location
name
: it’s nametakeStep()
: move one step to left/right/up/down directiontakeStep()
: move two steps towards south, the others are the same with UsualDrunk1 | def walk(f, d, numSteps): |
1 | def getFinalLocs(numSteps, numTrials, dClass): |
Population
: a set of examplesSample
: a proper subset of a populationGoal
: Estimate some statistic about the population based on statistics about the sampleKey fact
: If the sample is random, it tends to exhibit the same properties as the population from which it is drawnHow many samples do we need to look at before we can have justified confidence in our answer?
variance is measure of how much spread there is in the possible different outcomes, which can help us to justify.
standard deviation tells us what fraction of the values are close to the mean. If many values are relatively close to the mean, the standard deviation is relatively small.
$\sigma(X) = \sqrt{\frac{1}{\lvert{X}\rvert}\sum_{x\in{X}}{(x-\mu)^{2}}}$
1 | def stdDev(X): |
For example, flip coins exponentially, from 2^4 to 2^20, each times we flip 20 times to get the mean values with standard deviation function.
1 | #Page 160, Figure 12.4 |
Conclusion
1 | #Page 163, Figure 12.7 |
abs(heads – tails)
is independent of the number of flips. As the numbers of tails goes up, the mean of abs(heads – tails)
also keep growing, which proves Gambler’s Fallacy that abs(heads – tails)
will never be even, only gets bigger.A histogram is a plot designed to show the distribution of values in a set of data.
1 | vals = [1, 200] #guarantee that values will range from 1 to 200 for i in range(1000): |
formula of normal distribution: $f(x)=\frac{1}{\sigma\sqrt{2\pi}}*e^{-\frac{(x-\mu)^2}{2\sigma^2}}$ ( μ is the mean, σ the standard deviation)
Normal distributions are frequently used in constructing probabilistic models for three reasons:
1 | def flip(numFlips): |
empirical rule for normal distributions:
For example:
95%
: 2 standard deviation52%
: i.e. 0.52, the mean4%
: i.e. 0.04. 1 standard deviation is 0.02Normal distributions can be easily generated by calling random.gauss(mu, sigma)
, which returns a randomly chosen floating point number from a normal distribution with mean mu
and standard deviation sigma
.
gauss
is short for Gaussian Distribution
which is the same as Normal Distribution
.