move(deltaX, deltaY): move self with deltaX, deltaY
distFrom(otherLocation): check the distance between current location with otherLocation
drunks: list of drunk objects
addDrunk(drunk, loc): add a drunk with its location into Fields’
moveDrunk(drunk): move the drunk’s
getLoc(drunk): get the drunk’s
name: it’s name
takeStep(): move one step to left/right/up/down direction
takeStep(): move two steps towards south, the others are the same with UsualDrunk
def walk(f, d, numSteps):
def getFinalLocs(numSteps, numTrials, dClass):
Population: a set of examples
Sample: a proper subset of a population
Goal: Estimate some statistic about the population based on statistics about the sample
Key fact: If the sample is random, it tends to exhibit the same properties as the population from which it is drawn
How 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.
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.
#Page 160, Figure 12.4
#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.
vals = [1, 200] #guarantee that values will range from 1 to 200 for i in range(1000):
formula of normal distribution: ( μ is the mean, σ the standard deviation)
Normal distributions are frequently used in constructing probabilistic models for three reasons:
empirical rule for normal distributions:
95%: 2 standard deviation
52%: i.e. 0.52, the mean
4%: i.e. 0.04. 1 standard deviation is 0.02
Normal 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
gaussis short for
Gaussian Distributionwhich is the same as