def makePosteriorPlot(suite):
    """Plots the posterior marginal distributions for alpha and beta.

    suite: posterior joint distribution of location
    """
    marginal_alpha = suite.marginal(0)
    marginal_alpha.name = 'PMF(alpha)'
    marginal_beta = suite.marginal(1)
    marginal_beta.name = 'PMF(beta)'

    print("\n(ALPHA, BETA): Shooter locations: ")
    print('alpha CI', marginal_alpha.credibleInterval(50))
    print('beta CI', marginal_beta.credibleInterval(50))

    thinkplot.prePlot(num=2)

    #thinkplot.Pmf(marginal_alpha)
    #thinkplot.Pmf(marginal_beta)

    thinkplot.cdf(thinkbayes.makeCdfFromPmf(marginal_alpha))
    thinkplot.cdf(thinkbayes.makeCdfFromPmf(marginal_beta))

    thinkplot.save('paintball2_posteriorMarginalDist_for_alpha_and_beta',
                   xlabel='Distance',
                   ylabel='Prob',
                   loc=4,
                   formats=FORMATS)
예제 #2
0
def plotCoefVariation(suites):
    """Plot the posterior distributions for CV.

    suites: map from label to Pmf of CVs.
    """
    thinkplot.clf()
    thinkplot.prePlot(num=2)

    pmfs = {}
    for label, suite in suites.iteritems():
        pmf = coefVariation(suite)
        print('CV posterior mean', pmf.mean())
        cdf = thinkbayes.makeCdfFromPmf(pmf, label)
        thinkplot.cdf(cdf)

        pmfs[label] = pmf

    thinkplot.save(root='variability_cv',
                   xlabel='Coefficient of variation',
                   ylabel='Probability')

    print('female bigger',
          thinkbayes.pmfProbGreater(pmfs['female'], pmfs['male']))
    print('male bigger', thinkbayes.pmfProbGreater(pmfs['male'],
                                                   pmfs['female']))
예제 #3
0
    def plotPosteriors(self, other):
        """Plots posterior distributions of efficacy.

        self, other: Sat objects.
        """
        thinkplot.clf()
        thinkplot.prePlot(num=2)

        cdf1 = thinkbayes.makeCdfFromPmf(self, 'posterior %d' % self.score)
        cdf2 = thinkbayes.makeCdfFromPmf(other, 'posterior %d' % other.score)

        thinkplot.cdfs([cdf1, cdf2])
        thinkplot.save(xlabel='efficacy',
                       ylabel='CDF',
                       axis=[0, 4.6, 0.0, 1.0],
                       root='sat_5_posteriors_eff',
                       formats=['pdf'])
예제 #4
0
def plotMarginals(suite):
    """Plots marginal distributions from a joint distribution.

    suite: joint distribution of mu and sigma.
    """
    thinkplot.clf()

    pyplot.subplot(1, 2, 1)
    pmf_m = suite.marginal(0)
    cdf_m = thinkbayes.makeCdfFromPmf(pmf_m)
    thinkplot.cdf(cdf_m)

    pyplot.subplot(1, 2, 2)
    pmf_s = suite.marginal(1)
    cdf_s = thinkbayes.makeCdfFromPmf(pmf_s)
    thinkplot.cdf(cdf_s)

    thinkplot.show()
예제 #5
0
    def calibrateDifficulty(self):
        """Make a plot showing the model distribution of raw scores."""
        thinkplot.clf()
        thinkplot.prePlot(num=2)

        cdf = thinkbayes.makeCdfFromPmf(self.raw, name='data')
        thinkplot.cdf(cdf)

        efficacies = thinkbayes.makeGaussianPmf(0, 1.5, 3)
        pmf = self.makeRawScoreDist(
            efficacies)  # mixture model of raw score, prob = p1 * p2
        cdf = thinkbayes.makeCdfFromPmf(pmf, name='model')
        thinkplot.cdf(cdf)

        thinkplot.save(root='sat_2_calibrate',
                       xlabel='raw score',
                       ylabel='CDF',
                       formats=['pdf'])
예제 #6
0
    def generateSampleGaps(self, n):
        """Generates a random sample of gaps seen by passengers.

        n: sample size

        Returns: sequence of values
        """
        cdf_zb = thinkbayes.makeCdfFromPmf(self.pmf_zb)
        sample = cdf_zb.sample(n)
        return sample
예제 #7
0
    def generateSampleWaitTimes(self, n):
        """Generates a random sample of wait times.

        n: sample size

        Returns: sequence of values
        """
        cdf_y = thinkbayes.makeCdfFromPmf(self.pmf_y)
        sample = cdf_y.sample(n)
        return sample
예제 #8
0
def plotPriorDist(pmf):
    """Plot the prior distribution of p_correct.

    pmf: prior
    """
    thinkplot.clf()
    thinkplot.prePlot(num=1)

    cdf1 = thinkbayes.makeCdfFromPmf(pmf, 'prior')
    thinkplot.cdf(cdf1)
    thinkplot.save(root='sat_1_prior',
                   xlabel='p_correct',
                   ylabel='CDF',
                   formats=['pdf'])  # ['pdf', 'eps'])
예제 #9
0
def main():
    comparePriors()

    dataset = [30, 60, 90]

    thinkplot.clf()
    thinkplot.prePlot(num=3)

    for high in [500, 1000, 2000]:
        suite = makePosterior(high, dataset, Train2)
        print(high, suite.mean())
    # TODO: doesn't work:
    thinkplot.save(root='train3',
                   xlabel='Number of trains',
                   ylabel='Probability')

    interval = percentile(suite, 5), percentile(suite, 95)
    print(interval)

    cdf = thinkbayes.makeCdfFromPmf(suite)
    interval = cdf.percentile(5), cdf.percentile(95)
    print(interval)