def main():
    results = _10_relay._read_results()
    speeds = _10_relay._get_speeds(results)

    # plot the distribution of actual speeds
    pmf = _04_Pmf._make_pmf_from_list(speeds, 'actual speeds')

    # myplot.Clf()
    # myplot.Hist(pmf)
    # myplot.Save(root='observed_speeds',
    #             title='PMF of running speed',
    #             xlabel='speed (mph)',
    #             ylabel='probability')

    # plot the biased distribution seen by the observer
    biased = _bias_pmf(pmf, 7.5, name='observed speeds')

    _05_myplot._clf()
    _05_myplot._hist(biased)
    _05_myplot._save(root='observed_speeds',
                     title='PMF of running speed',
                     xlabel='speed (mph)',
                     ylabel='probability')

    cdf = _13_Cdf._make_cdf_from_pmf(biased)

    _05_myplot._clf()
    _05_myplot._cdf(cdf)
    _05_myplot._save(root='observed_speeds_cdf',
                     title='CDF of running speed',
                     xlabel='speed (mph)',
                     ylabel='cumulative probability')
Beispiel #2
0
def _plot_ages(resp):
    """Plot the distribution of ages."""
    ages = [r.age for r in resp.records]
    cdf = _13_Cdf._make_cdf_from_list(ages)
    _05_myplot._clf()
    _05_myplot._cdf(cdf)
    _05_myplot._show()
Beispiel #3
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)')
Beispiel #4
0
def _make_example():
    """Make a simple example CDF."""
    t = [2, 1, 3, 2, 5]
    cdf = _13_Cdf._make_cdf_from_list(t)
    _05_myplot._clf()
    _05_myplot._cdf(cdf)
    _05_myplot._save(root='example_cdf',
                     title='CDF',
                     xlabel='x',
                     ylabel='CDF(x)',
                     axis=[0, 6, 0, 1],
                     legend=False)
def _log_cdf_time_interval():
    timeInterval = _calc_time_interval()
    pmf = _04_Pmf._make_pmf_from_list(timeInterval, "baby birth interval")
    cdf = _13_Cdf._make_cdf_from_pmf(pmf, "baby birth interval")
    _05_myplot._clf()
    _05_myplot._cdf(cdf, complement=True, xscale="linear", yscale="log")
    _05_myplot._save(
        root="baby_birth_interval_logccdf",
        title="LogCCDF of baby birth interval",
        xlabel="interval(minutes)",
        ylabel="LogCCdf",
    )
Beispiel #6
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')
Beispiel #7
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')
Beispiel #8
0
def _make_cdfs(lens):
    cdf = _13_Cdf._make_cdf_from_list(lens, 'slashdot')

    _05_myplot._clf()
    _05_myplot._cdf(cdf)
    _05_myplot._save(root='slashdot.logx',
                     xlabel='Number of friends/foes',
                     ylabel='CDF',
                     xscale='log')

    _05_myplot._clf()
    _05_myplot._cdf(cdf, complement=True)
    _05_myplot._save(root='slashdot.loglog',
                     xlabel='Number of friends/foes',
                     ylabel='CDF',
                     xscale='log',
                     yscale='log')
Beispiel #9
0
def _make_figures(pool, firsts, others):
    """Creates several figures for the book."""

    # plot PMFs of birth weights for first babies and others
    _05_myplot._clf()
    _05_myplot._hist(firsts.weight_pmf, linewidth=0, color='blue')
    _05_myplot._hist(others.weight_pmf, linewidth=0, color='orange')
    _05_myplot._save(root='nsfg_birthwgt_pmf',
                     title='Birth weight PMF',
                     xlabel='weight (ounces)',
                     ylabel='probability')

    # plot CDFs of birth weights for first babies and others
    _05_myplot._clf()
    _05_myplot._cdf(firsts.weight_cdf, linewidth=2, color='blue')
    _05_myplot._cdf(others.weight_cdf, linewidth=2, color='orange')
    _05_myplot._save(root='nsfg_birthwgt_cdf',
                     title='Birth weight CDF',
                     xlabel='weight (ounces)',
                     ylabel='probability',
                     axis=[0, 200, 0, 1])
def _cdf_time_interval():
    timeInterval = _calc_time_interval()
    pmf = _04_Pmf._make_pmf_from_list(timeInterval, "baby birth interval")
    _05_myplot._clf()
    _05_myplot._hist(pmf)
    _05_myplot._save(
        root="baby_birth_interval_pmf",
        title="PMF of baby birth interval",
        xlabel="interval(minutes)",
        ylabel="probability",
    )

    cdf = _13_Cdf._make_cdf_from_pmf(pmf)

    _05_myplot._clf()
    _05_myplot._cdf(cdf)
    _05_myplot._save(
        root="baby_birth_interval_cdf",
        title="CDF of baby birth interval",
        xlabel="interval(minutes)",
        ylabel="cumulative probability",
    )
Beispiel #11
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')
Beispiel #12
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)
def _make_figures():
    pops = _21_populations._read_data()
    print(len(pops))

    cdf = _13_Cdf._make_cdf_from_list(pops, 'populations')

    _05_myplot._clf()
    _05_myplot._cdf(cdf)
    _05_myplot._save(root='populations',
                     title='City/Town Populations',
                     xlabel='population',
                     ylabel='CDF',
                     legend=False)

    _05_myplot._clf()
    _05_myplot._cdf(cdf)
    _05_myplot._save(root='populations_logx',
                     title='City/Town Populations',
                     xlabel='population',
                     ylabel='CDF',
                     xscale='log',
                     legend=False)

    _05_myplot._clf()
    _05_myplot._cdf(cdf, complement=True)
    _05_myplot._save(root='populations_loglog',
                     title='City/Town Populations',
                     xlabel='population',
                     ylabel='Complementary CDF',
                     yscale='log',
                     xscale='log',
                     legend=False)

    t = [math.log(x) for x in pops]
    t.sort()
    _17_rankit._make_normal_plot(t, 'populations_rankit')