Exemplo n.º 1
0
def main():
	maleRates = [0.52, 0.38, 0.39, 1.01, 2.63]
	femaleRates = [50, 20.5]
	pdfMale = thinkbayes2.EstimatedPdf(maleRates)
	pdfFemale = thinkbayes2.EstimatedPdf(femaleRates)
	low, high = 0, 100
	n = 1001
	xs = numpy.linspace(low, high, n)
	pmfMale = pdfMale.MakePmf(steps=xs)
	pmfFemale = pdfFemale.MakePmf(steps=xs)

	thinkplot.Pdf(pdfMale, label='Male Prior')
	thinkplot.Pdf(pdfFemale, label='Female Prior')
	thinkplot.show()
Exemplo n.º 2
0
def RunSimpleProcess(gap_times, lam=0.0333, num_passengers=15, plot=True):
    """Runs the basic analysis and generates figures.

    gap_times: sequence of float
    lam: arrival rate in passengers per second
    num_passengers: int number of passengers on the platform
    plot: boolean, whether to generate plots

    Returns: WaitTimeCalculator, ElapsedTimeEstimator
    """
    global UPPER_BOUND
    UPPER_BOUND = 1200

    cdf_z = thinkbayes2.Cdf(gap_times).Scale(1.0 / 60)
    print('CI z', cdf_z.CredibleInterval(90))

    xs = MakeRange(low=10)

    pdf_z = thinkbayes2.EstimatedPdf(gap_times)
    pmf_z = pdf_z.MakePmf(xs=xs, label="z")

    wtc = WaitTimeCalculator(pmf_z, inverse=False)

    if plot:
        wtc.PlotPmfs()
        wtc.MakePlot()

    ete = ElapsedTimeEstimator(wtc, lam, num_passengers)

    if plot:
        ete.MakePlot()

    return wtc, ete
Exemplo n.º 3
0
def TestGte():
    """Tests the GapTimeEstimator."""
    random.seed(17)

    xs = [60, 120, 240]

    gap_times = [60, 60, 60, 60, 60, 120, 120, 120, 240, 240]

    # distribution of gap time (z)
    pdf_z = thinkbayes2.EstimatedPdf(gap_times)
    pmf_z = pdf_z.MakePmf(xs=xs, label="z")

    wtc = WaitTimeCalculator(pmf_z, inverse=False)

    lam = 0.0333
    n = 100
    passenger_data = wtc.GenerateSamplePassengers(lam, n)

    pcounts = [0, 0, 0]

    ite = GapTimeEstimator(xs, pcounts, passenger_data)

    thinkplot.Clf()

    # thinkplot.Cdf(wtc.pmf_z.MakeCdf(label="actual z"))
    thinkplot.Cdf(wtc.pmf_zb.MakeCdf(label="actual zb"))
    ite.MakePlot()
Exemplo n.º 4
0
def main():
	maleRates = [0.52, 0.38, 0.39, 1.01, 2.63, 30]
	femaleRates = [50, 20.5, 40, 30, 45]
	pdfMale = thinkbayes2.EstimatedPdf(maleRates)
	pdfFemale = thinkbayes2.EstimatedPdf(femaleRates)
	low, high = 0, 100
	n = 1001
	xs = numpy.linspace(low, high, n)
	pmfMale = MakePmfTest(pdfMale,steps=xs)
	pmfFemale = MakePmfTest(pdfFemale,steps=xs)

	pmfMale.Normalize()
	pmfFemale.Normalize()

	thinkplot.Pdf(pmfMale, label='Male Prior')
	thinkplot.Pdf(pmfFemale, label='Female Prior')
	thinkplot.show()
Exemplo n.º 5
0
    def __init__(self, prices, bids, diffs):
        """Construct the Player.
        prices: sequence of prices
        bids: sequence of bids
        diffs: sequence of underness (negative means over)
        """
        self.pdf_price = thinkbayes2.EstimatedPdf(prices)
        self.cdf_diff = thinkbayes2.MakeCdfFromList(diffs)

        mu = 0
        sigma = numpy.std(diffs)
        self.pdf_error = thinkbayes2.NormalPdf(mu, sigma)
Exemplo n.º 6
0
def RunLoop(gap_times, nums, lam=0.0333):
    """Runs the basic analysis for a range of num_passengers.

    gap_times: sequence of float
    nums: sequence of values for num_passengers
    lam: arrival rate in passengers per second

    Returns: WaitMixtureEstimator
    """
    global UPPER_BOUND
    UPPER_BOUND = 4000

    thinkplot.Clf()

    RandomSeed(18)

    # resample gap_times
    n = 220
    cdf_z = thinkbayes2.Cdf(gap_times)
    sample_z = cdf_z.Sample(n)
    pmf_z = thinkbayes2.Pmf(sample_z)

    # compute the biased pmf and add some long delays
    cdf_zp = BiasPmf(pmf_z).MakeCdf()
    sample_zb = numpy.append(cdf_zp.Sample(n), [1800, 2400, 3000])

    # smooth the distribution of zb
    pdf_zb = thinkbayes2.EstimatedPdf(sample_zb)
    xs = MakeRange(low=60)
    pmf_zb = pdf_zb.MakePmf(xs=xs)

    # unbias the distribution of zb and make wtc
    pmf_z = UnbiasPmf(pmf_zb)
    wtc = WaitTimeCalculator(pmf_z)

    probs = []
    for num_passengers in nums:
        ete = ElapsedTimeEstimator(wtc, lam, num_passengers)

        # compute the posterior prob of waiting more than 15 minutes
        cdf_y = ete.pmf_y.MakeCdf()
        prob = 1 - cdf_y.Prob(900)
        probs.append(prob)

        # thinkplot.Cdf(ete.pmf_y.MakeCdf(label=str(num_passengers)))

    thinkplot.Plot(nums, probs)
    thinkplot.Save(
        root='redline5',
        xlabel='Num passengers',
        ylabel='P(y > 15 min)',
        formats=FORMATS,
    )
Exemplo n.º 7
0
def GenerateSampleData(gap_times, lam=0.0333, n=10):
    """Generates passenger data based on actual gap times.

    gap_times: sequence of float
    lam: arrival rate in passengers per second
    n: number of simulated observations
    """
    xs = MakeRange(low=10)
    pdf_z = thinkbayes2.EstimatedPdf(gap_times)
    pmf_z = pdf_z.MakePmf(xs=xs, label="z")

    wtc = WaitTimeCalculator(pmf_z, inverse=False)
    passenger_data = wtc.GenerateSamplePassengers(lam, n)
    return wtc, passenger_data