Suppose you're on a game show, and you're given the choice of three doors: Behind one door is a car; behind the others, goats. You pick a door, say No. 1, and the host, who knows what's behind the doors, opens another door, say No. 3, which has a goat. He then says to you, "Do you want to pick door No. 2?" Is it to your advantage to switch your choice?
In [9]:
#your code here
In [26]:
# Your true distance
import numpy as np
import pymc as pm
import math
import matplotlib.pyplot as plt
import random
import scipy as sci
%matplotlib inline
def noisyDistance(x, y, noiseSigma):
return np.sqrt(((x - y) ** 2).sum()) + sci.stats.norm.rvs(0, noiseSigma)
def generateData(landscapeSize, numCommTowers, noiseSigma):
towersTrueLocation = [np.array([random.random() * landscapeSize, random.random()* landscapeSize]) for i in range(0, numCommTowers)]
yourTrueLocation = np.array([random.random() * landscapeSize, random.random() * landscapeSize ])
noisyDistances = [noisyDistance(i, yourTrueLocation, noiseSigma) for i in towersTrueLocation]
return (towersTrueLocation, yourTrueLocation, noisyDistances)
def drawLandscape(landscapeSize, towersTrueLocation, yourTrueLocation, estimatedLocations = None):
plt.xlim(0, landscapeSize)
plt.ylim(0, landscapeSize)
for i in towersTrueLocation:
plt.scatter(i[0], i[1], marker='+')
plt.scatter(yourTrueLocation[0], yourTrueLocation[1], marker='*', color = 'red')
if estimatedLocations is not None:
for i in estimatedLocations:
plt.scatter(i[0], i[1], marker='o')
In [25]:
(towersTrueLocation, yourTrueLocation, noisyDistances) = generateData(10000, 25, 50)
drawLandscape(10000, towersTrueLocation, yourTrueLocation)
print ("True towers locations: ", towersTrueLocation, "\n")
print ("Your true location: ", yourTrueLocation, "\n")
print ("Noisy distances: ", noisyDistances)
In [27]:
# Your code here
In [69]:
from matplotlib.pyplot import hist
from numpy.random import normal
import random
data = [normal(55, 5) for i in xrange(100)]
data += [normal(85, 5) for i in xrange(100)]
random.shuffle(data)
hist(data, 20)
Out[69]:
In [68]:
#your code here