def PredictiveDist(self, label='pred'): """Computes the distribution of goals scored in a game. returns: new Pmf (mixture of Poissons) """ # TODO: fill this in lam = 1 pred = thinkbayes2.MakePoissonPmf(lam, 15) return pred
def _test1(show=0): # 已知r, 求n的分布 即泊松分布 r = 150 # MakePoissonPmf: 存在一个上限(无极限), 需要归一化 pmf = thinkbayes2.MakePoissonPmf(r, 2 * r, 1) if show: thinkplot.Clf() thinkplot.Pmf(pmf) thinkplot.Show(title="test1", xlabel='Event Count', ylabel='Probality') print("Total: ", pmf.Total()) return pmf
def MakeGoalPmf(suite, high=10): """Makes the distribution of goals scored, given distribution of lam. suite: distribution of goal-scoring rate high: upper bound returns: Pmf of goals per game """ metapmf = thinkbayes2.Pmf() for lam, prob in suite.Items(): pmf = thinkbayes2.MakePoissonPmf(lam, high) metapmf.Set(pmf, prob) mix = thinkbayes2.MakeMixture(metapmf, label=suite.label) return mix
def PredRemaining(self, rem_time, score): """Plots the predictive distribution for final number of goals. rem_time: remaining time in the game in minutes score: number of goals already scored """ metapmf = thinkbayes2.Pmf( ) #PMF about PMFS. probabilities of pmf values for lam, prob in self.Items(): #loop through probabilities of lamdas lt = lam * rem_time / 60 pmf = thinkbayes2.MakePoissonPmf(lt, 20) metapmf[pmf] = prob mix = thinkbayes2.MakeMixture(metapmf) mix += score return mix
def PredRemaining(self, rem_time, score): """Plots the predictive distribution for final number of goals. rem_time: remaining time in the game in minutes score: number of goals already scored """ metapmf = thinkbayes2.Pmf() for lam, prob in self.Items(): lt = lam * rem_time / 90 pred = thinkbayes2.MakePoissonPmf(lt, 15) metapmf[pred] = prob #thinkplot.Pdf(pred, color='gray', alpha=0.1, linewidth=0.5) mix = thinkbayes2.MakeMixture(metapmf) mix += score thinkplot.Hist(mix) thinkplot.Show()
def PredRemaining(self, rem_time, score): """Plots the predictive distribution for final number of goals. rem_time: remaining time in the game in minutes score: number of goals already scored """ # TODO: fill this in # lam = goals / game lam_total = 0 for lam, prob in self.Items(): goals_in_remaining_time = lam * rem_time / 90 # convert to goals in remaining time lam_total += lt * prob pmf = thinkbayes2.MakePoissonPmf(goals_in_remaining_time, 12) pmf += score thinkplot.Pmf(pmf) thinkplot.Show()
def PredRemaining(self, rem_time, score): """Plots the predictive distribution for final number of goals. rem_time: remaining time in the game in minutes score: number of goals already scored """ metapmf = thinkbayes2.Pmf( ) #PMF about PMFS. probabilities of pmf values for lam, prob in self.Items(): #loop through probabilities of lamdas #print(lam,prob) lt = lam * rem_time / 60 pmf = thinkbayes2.MakePoissonPmf(lt, 20) #thinkplot.Pdf(pmf,linewidth=1,alpha=0.2,color='purple') metapmf[pmf] = prob mix = thinkbayes2.MakeMixture(metapmf) mix += score #shift by 2 because we've already seen 2 return mix
def __init__(self, r, label='Detecter'): pmf = thinkbayes2.MakePoissonPmf(r, 500, 2) thinkbayes2.Suite.__init__(self, pmf, r)