Exemplo n.º 1
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')
Exemplo n.º 2
0
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')
Exemplo n.º 3
0
    def testMakePmfFromCdf(self):
        t = [1, 2, 2, 3, 5]
        pmf = _04_Pmf._make_pmf_from_list(t)
        self.checkPmf(pmf)

        cdf = _13_Cdf._make_cdf_from_pmf(pmf)
        pmf2 = _04_Pmf._make_pmf_from_cdf(cdf)
        self.checkPmf(pmf2)
Exemplo n.º 4
0
def _plot_marginals(suite):
    """Plot the marginal distributions for a 2-D joint distribution."""
    pmf_m, pmf_s = _compute_marginals(suite)

    pyplot.clf()
    pyplot.figure(1, figsize=(7, 4))

    pyplot.subplot(1, 2, 1)
    cdf_m = _13_Cdf._make_cdf_from_pmf(pmf_m, 'mu')
    _05_myplot._cdf(cdf_m)
    pyplot.xlabel('Mean height (cm)')
    pyplot.ylabel('CDF')

    pyplot.subplot(1, 2, 2)
    cdf_s = _13_Cdf._make_cdf_from_pmf(pmf_s, 'sigma')
    _05_myplot._cdf(cdf_s)
    pyplot.xlabel('Std Dev height (cm)')
    pyplot.ylabel('CDF')

    _05_myplot._save(root='bayes_height_marginals_%s' % suite.name)
Exemplo n.º 5
0
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",
    )
Exemplo n.º 6
0
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",
    )
Exemplo n.º 7
0
def _plot_coef_variation(suites):
    """
    Plot the posterior distributions for CV.

    Args:
        suites: map from label to Pmf of CVs.
    """
    pyplot.clf()

    pmfs = {}
    for label, suite in suites.iteritems():
        pmf = _compute_coef_variation(suite)
        cdf = _13_Cdf._make_cdf_from_pmf(pmf, label)
        _05_myplot._cdf(cdf)

        pmfs[label] = pmf

    _05_myplot._save(root='bayes_height_cv',
                     title='Coefficient of variation',
                     xlabel='cv',
                     ylabel='CDF')

    print('female bigger', _prob_bigger(pmfs['female'], pmfs['male']))
    print('male bigger', _prob_bigger(pmfs['male'], pmfs['female']))