示例#1
0
def main():
    hypos = numpy.linspace(0, 12, 201)

    # start with a prior based on a pseudo observation
    # chosen to yield the right prior mean
    suite1 = Soccer(hypos, label='Germany')
    suite1.Update(0.34)
    suite2 = suite1.Copy(label='Argentina')

    # update with the results of World Cup 2014 final
    suite1.Update(1)
    suite2.Update(0)

    print('posterior mean Germany', suite1.Mean())
    print('posterior mean Argentina', suite2.Mean())

    # plot the posteriors
    thinkplot.PrePlot(2)
    thinkplot.Pdfs([suite1, suite2])
    thinkplot.Show()

    # TODO: compute posterior prob Germany is better than Argentina

    # TODO: compute the Bayes factor of the evidence

    # compute predictive distributions for goals scored in a rematch
    pred1 = suite1.PredictiveDist(label='Germany')
    pred2 = suite2.PredictiveDist(label='Argentina')
    
    # plot the predictive distributions
    thinkplot.PrePlot(2)
    thinkplot.Pdfs([pred1, pred2])
    thinkplot.Show()
示例#2
0
 def PlotBeliefs(self):
     """ Plots prior and posterior beliefs to console
     """
     thinkplot.Clf()
     thinkplot.PrePlot(num=2)
     thinkplot.Pdfs([self.prior, self.posterior])
     thinkplot.decorate(xlabel='price ($)', ylabel='PMF')
示例#3
0
def Specific_Character(House, Gender, Class, ksweep, lamsweep, Title=''):
    """Knits many function together to produce a prediction for a given house, gender and class
	The house can be any key in hd, class can be 'Noble' or 'Small' or 'All' , and the gender can 
	be 'M' or 'F' or 'All'.  This also needs to make a linspace for k and lambda, so ksweep and 
	lsweep are lists of the form [lower limit, upper limit, number of points].  You can also 
	choose what to title your graph."""
    hd = PrepData()  #Get the data
    alive, dead = char_lists(hd, House, Gender,
                             Class)  #Sort by alive/dead for given attributes
    introductions, lifetimes = ages(alive, dead)  #Get ages and lifespans
    sf, haz = SurvivalHaz(introductions, lifetimes)  #Use kaplan-meyer
    lam = thinkbayes2.MakeUniformPmf(lamsweep[0], lamsweep[1],
                                     lamsweep[2])  #Our uniform priors
    k = thinkbayes2.MakeUniformPmf(ksweep[0], ksweep[1], ksweep[2])
    k, lam = MakeDistr(introductions, lifetimes, k, lam)  #Get our posterior

    thinkplot.PrePlot(2)
    thinkplot.Pdfs([k, lam])
    plt.xlabel('Value')
    plt.ylabel('Probability')
    plt.title('Posterior Distributions')
    print('If these distributions look chopped off, adjust kweep and lsweep')
    thinkplot.Show()

    mk = k.Mean()
    ml = lam.Mean()
    kl, kh = k.Percentile(5), k.Percentile(95)
    ll, lh = lam.Percentile(5), lam.Percentile(95)
    CredIntPlt(sf, kl, kh, ll, lh, House, mk, ml, Title)
    plt.show()
示例#4
0
 def PlotBeliefs(self, root):
     """Plots prior and posterior beliefs.
     root: string filename root for saved figure
     """
     thinkplot.Clf()
     thinkplot.PrePlot(num=2)
     thinkplot.Pdfs([self.prior, self.posterior])
     thinkplot.Save(root=root,
                    xlabel='price ($)',
                    ylabel='PMF',
                    formats=FORMATS)
示例#5
0
def main():
    exam = Exam()

    alice = Sat(exam)
    alice.label = 'alice'
    alice.Update(780)

    bob = Sat(exam)
    bob.label = 'bob'
    bob.Update(760)

    print('Prob Alice is "smarter":', PmfProbGreater(alice, bob))
    print('Prob Bob is "smarter":', PmfProbGreater(bob, alice))

    thinkplot.PrePlot(2)
    thinkplot.Pdfs([alice, bob])
    thinkplot.Show(xlabel='x',
                   ylabel='Probability',
                   loc='upper left',
                   xlim=[0.7, 1.02])
示例#6
0
def MakePlots(player1, player2):
    """Generates two plots.

    price1 shows the priors for the two players
    price2 shows the distribution of diff for the two players
    """

    # plot the prior distribution of price for both players
    thinkplot.Clf()
    thinkplot.PrePlot(num=2)
    pmf1 = player1.PmfPrice()
    pmf1.label = 'showcase 1'
    pmf2 = player2.PmfPrice()
    pmf2.label = 'showcase 2'
    thinkplot.Pdfs([pmf1, pmf2])
    thinkplot.Save(root='price1',
                   xlabel='price ($)',
                   ylabel='PDF',
                   formats=FORMATS)

    # plot the historical distribution of underness for both players
    thinkplot.Clf()
    thinkplot.PrePlot(num=2)
    cdf1 = player1.CdfDiff()
    cdf1.label = 'player 1'
    cdf2 = player2.CdfDiff()
    cdf2.label = 'player 2'

    print('Player median', cdf1.Percentile(50))
    print('Player median', cdf2.Percentile(50))

    print('Player 1 overbids', player1.ProbOverbid())
    print('Player 2 overbids', player2.ProbOverbid())

    thinkplot.Cdfs([cdf1, cdf2])
    thinkplot.Save(root='price2',
                   xlabel='diff ($)',
                   ylabel='CDF',
                   formats=FORMATS)