示例#1
0
def _resample(cdf, n=10000):
    sample = cdf._sample(n)
    new_cdf = _13_Cdf._make_cdf_from_list(sample, 'resampled')
    _05_myplot._clf()
    _05_myplot._cdfs([cdf, new_cdf])
    _05_myplot._save(root='resample_cdf',
                     title='CDF',
                     xlabel='weight in oz',
                     ylabel='CDF(x)')
示例#2
0
def _plot_cdfs(samples):
    """Make CDFs showing the distribution of outliers."""
    cdfs = []
    for label, sample in samples.iteritems():
        outliers = [x for x in sample if x < 150]

        cdf = _13_Cdf._make_cdf_from_list(outliers, label)
        cdfs.append(cdf)

    _05_myplot._clf()
    _05_myplot._cdfs(cdfs)
    _05_myplot._save(root='bayes_height_cdfs',
                     title='CDF of height',
                     xlabel='Reported height (cm)',
                     ylabel='CDF')
示例#3
0
def _make_figures(pmf, biased_pmf):
    """Makes figures showing the CDF of the biased and unbiased PMFs"""
    cdf = _13_Cdf._make_cdf_from_pmf(pmf, 'unbiased')
    print('unbiased median', cdf._percentile(50))
    print('percent < 100', cdf._prob(100))
    print('percent < 1000', cdf._prob(1000))

    biased_cdf = _13_Cdf._make_cdf_from_pmf(biased_pmf, 'biased')
    print('biased median', biased_cdf._percentile(50))

    _05_myplot._clf()
    _05_myplot._cdfs([cdf, biased_cdf])
    _05_myplot._save(root='slashdot.logx',
                     xlabel='Number of friends/foes',
                     ylabel='CDF',
                     xscale='log')
示例#4
0
def _make_figures(pool, firsts, others):
    """Creates several figures for the book."""

    # CDF of all ages
    _05_myplot._clf()
    _05_myplot._cdf(pool.age_cdf)
    _05_myplot._save(root='agemodel_age_cdf',
                     title="Distribution of mother's age",
                     xlabel='age (years)',
                     ylabel='CDF',
                     legend=False)

    # CDF of all weights
    _05_myplot._clf()
    _05_myplot._cdf(pool.weight_cdf)
    _05_myplot._save(root='agemodel_weight_cdf',
                     title="Distribution of birth weight",
                     xlabel='birth weight (oz)',
                     ylabel='CDF',
                     legend=False)

    # plot CDFs of birth ages for first babies and others
    _05_myplot._clf()
    _05_myplot._cdfs([firsts.age_cdf, others.age_cdf])
    _05_myplot._save(root='agemodel_age_cdfs',
                     title="Distribution of mother's age",
                     xlabel='age (years)',
                     ylabel='CDF')

    _05_myplot._clf()
    _05_myplot._cdfs([firsts.weight_cdf, others.weight_cdf])
    _05_myplot._save(root='agemodel_weight_cdfs',
                     title="Distribution of birth weight",
                     xlabel='birth weight (oz)',
                     ylabel='CDF')

    # make a scatterplot of ages and weights
    ages, weights = _get_age_weight(pool)
    pyplot.clf()
    # pyplot.scatter(ages, weights, alpha=0.2)
    pyplot.hexbin(ages, weights, cmap=matplotlib.cm.gray_r)
    _05_myplot._save(root='agemodel_scatter',
                     xlabel='Age (years)',
                     ylabel='Birth weight (oz)',
                     legend=False)
示例#5
0
def _make_figure(xmin=100, alpha=1.7, mu=150, sigma=25):
    """
    Makes a figure showing the CDF of height in ParetoWorld.

    Compared to a normal distribution.

    Args:
        xmin:  parameter of the Pareto distribution
        alpha: parameter of the Pareto distribution
        mu:    parameter of the Normal distribution
        sigma: parameter of the Normal distribution
    """
    t1 = [xmin * random.paretovariate(alpha) for i in range(10000)]
    cdf1 = _13_Cdf._make_cdf_from_list(t1, name='pareto')

    t2 = [random.normalvariate(mu, sigma) for i in range(10000)]
    cdf2 = _13_Cdf._make_cdf_from_list(t2, name='normal')

    _05_myplot._clf()
    _05_myplot._cdfs([cdf1, cdf2])
    _05_myplot._save(root='pareto_world2',
                     title='Pareto World',
                     xlabel='height (cm)',
                     ylabel='CDF')