示例#1
0
def PlotJointDist(pmf1, pmf2, thresh=0.8):
    """Plot the joint distribution of p_correct.

    pmf1, pmf2: posterior distributions
    thresh: lower bound of the range to be plotted
    """
    def Clean(pmf):
        """Removes values below thresh."""
        vals = [val for val in pmf.Values() if val < thresh]
        [pmf.Remove(val) for val in vals]

    Clean(pmf1)
    Clean(pmf2)
    pmf = thinkbayes2.MakeJoint(pmf1, pmf2)

    thinkplot.Figure(figsize=(6, 6))
    thinkplot.Contour(pmf, contour=False, pcolor=True)

    thinkplot.Plot([thresh, 1.0], [thresh, 1.0],
                   color='gray',
                   alpha=0.2,
                   linewidth=4)

    thinkplot.Save(root='sat_joint',
                   xlabel='p_correct Alice',
                   ylabel='p_correct Bob',
                   axis=[thresh, 1.0, thresh, 1.0],
                   formats=['pdf', 'eps'])
示例#2
0
def PlotPosterior(suite, pcolor=False, contour=True):
    """Makes a contour plot.
    
    suite: Suite that maps (mu, sigma) to probability
    """
    thinkplot.Clf()
    thinkplot.Contour(suite.GetDict(), pcolor=pcolor, contour=contour)

    thinkplot.Save(root='variability_posterior_%s' % suite.name,
                   title='Posterior joint distribution',
                   xlabel='Mean height (cm)',
                   ylabel='Stddev (cm)')
示例#3
0
def MakeContourPlot(suite):
    """Plots the posterior joint distribution as a contour plot.

    suite: posterior joint distribution of location
    """
    thinkplot.Contour(suite.GetDict(), contour=False, pcolor=True)

    thinkplot.Save('paintball4',
                xlabel='alpha',
                ylabel='beta',
                axis=[0, 30, 0, 20],
                formats=FORMATS)
示例#4
0
    def PlotJointDist(self):
        """Makes a pcolor plot of the age-size joint distribution."""
        thinkplot.Clf()

        joint = self.cache.GetDistAgeSize()
        thinkplot.Contour(joint, contour=False, pcolor=True)

        thinkplot.Save(root='kidney8',
                       formats=FORMATS,
                       axis=[0, 41, -0.7, 1.31],
                       yticks=MakeLogTicks([0.2, 0.5, 1, 2, 5, 10, 20]),
                       xlabel='ages',
                       ylabel='diameter (cm, log scale)')
示例#5
0
def MakeCrediblePlot(suite):
    """Makes a plot showing several two-dimensional credible intervals.

    suite: Suite
    """
    d = dict((pair, 0) for pair in suite.Values())

    percentages = [75, 50, 25]
    for p in percentages:
        interval = suite.MaxLikeInterval(p)
        for pair in interval:
            d[pair] += 1

    thinkplot.Contour(d, contour=False, pcolor=True)
    pyplot.text(17, 4, '25', color='white')
    pyplot.text(17, 15, '50', color='white')
    pyplot.text(17, 30, '75')

    thinkplot.Save('paintball5',
                   xlabel='alpha',
                   ylabel='beta',
                   formats=FORMATS)
示例#6
0
    # scatterplot of simulated records
    for simulation in simulated_records:
        plt.plot([item[0] for item in simulation], [item[1] for item in simulation], 'or')
    plt.plot([pd.to_datetime(date) for date in dates], records, 'o')
    plt.title("Simulated records")
    plt.xlabel("year")
    plt.ylabel("mph")
    plt.show()

    # pcolor plot of the simulated records
    joint_estimate = thinkbayes2.Joint()
    for simulation in simulated_records:
        for date, record in simulation:
            joint_estimate.Incr((date.value, round(record, 2)))
    thinkplot.Contour(joint_estimate, contour=False, pcolor=True)
    plt.plot([dates[0], pd.to_datetime('2041').value],[13.1094, 13.1094], 'r')
    plt.plot([pd.to_datetime('2041').value, pd.to_datetime('2041').value], [12, 13.1094], 'r')
    plt.plot(dates, records, 'bo')
    plt.title("simulated records joint pmf")
    thinkplot.show()

    year2041 = find_closest(date_range, pd.to_datetime('2041'))
    year2042 = find_closest(date_range, pd.to_datetime('2042'))

    # calculate some summary statistics
    pmf_2hour = joint_estimate.Conditional(0, 1, 13.11)
    cdf_2hour = pmf_2hour.MakeCdf()
    print("probability of 2-hour marathon by 2041: %f" % pmf_2hour.ProbLess(year2042.value))
    print(pd.to_datetime(cdf_2hour.Value(.385445)))
    print("year when we're 90% confident of having ran a 2-hour marathon " + str(pd.to_datetime(cdf_2hour.Value(.9))))