Exemplo n.º 1
0
def processScoresTeamwise(pairs):
    """Average number of goals for each team.

    pairs: map from (team1, team2) to (score1, score2)
    """
    # map from team to list of goals scored
    goals_scored = {}
    for key, entries in pairs.iteritems():
        t1, t2 = key
        for entry in entries:
            g1, g2 = entry
            goals_scored.setdefault(t1, []).append(g1)
            goals_scored.setdefault(t2, []).append(g2)

    # make a list of average goals scored
    lams = []
    for key, goals in iter(goals_scored):
        lam = thinkstats.mean(goals)
        lams.append(lam)

    # make the distribution of average goals scored
    cdf = thinkbayes.makeCdfFromList(lams)
    thinkplot.cdf(cdf)
    thinkplot.show()

    mu, var = thinkstats.meanAndVariance(lams)
    print('mu, sig', mu, math.sqrt(var))
Exemplo n.º 2
0
def process_noise(signal, root='red'):
    wave = signal.make_wave(duration=0.5, framerate=11025)

    # 0: waveform
    segment = wave.segment(duration=0.1)
    segment.plot(linewidth=1, alpha=0.5)
    thinkplot.save(root=root+'noise0',
                   xlabel='time (s)',
                   ylabel='amplitude')

    spectrum = wave.make_spectrum()

    # 1: spectrum
    spectrum.plot_power(linewidth=1, alpha=0.5)
    thinkplot.save(root=root+'noise1',
                   xlabel='frequency (Hz)',
                   ylabel='power density')

    slope, _, _, _, _ = spectrum.estimate_slope()
    print 'estimated slope', slope

    # 2: integrated spectrum
    integ = spectrum.make_integrated_spectrum()
    integ.plot_power()
    thinkplot.save(root=root+'noise2',
                   xlabel='frequency (Hz)',
                   ylabel='normalized power')

    # 3: log-log spectral density
    spectrum.plot_power(low=1, linewidth=1, alpha=0.5)
    thinkplot.save(root=root+'noise3',
                   xlabel='frequency (Hz)',
                   ylabel='power density',
                   xscale='log',
                   yscale='log')

    # 4: CDF of power density
    cdf = thinkstats2.MakeCdfFromList(spectrum.power)
    thinkplot.cdf(cdf)
    thinkplot.save(root=root+'noise4',
                   xlabel='power density',
                   ylabel='CDF')

    # 5: CCDF of power density, log-y
    thinkplot.cdf(cdf, complement=True)
    thinkplot.save(root=root+'noise5',
                   xlabel='power density',
                   ylabel='log(CCDF)',
                   yscale='log')

    thinkstats2.NormalProbabilityPlot(spectrum.real, label='real',
                                      data_color='#253494')
    thinkstats2.NormalProbabilityPlot(spectrum.imag-50, label='imag-50', 
                                      data_color='#1D91C0')
    thinkplot.save(root=root+'noise6',
                   xlabel='normal sample',
                   ylabel='power density')
Exemplo n.º 3
0
def process_noise(signal, root='red'):
    wave = signal.make_wave(duration=0.5, framerate=11025)

    # 0: waveform
    segment = wave.segment(duration=0.1)
    segment.plot(linewidth=1, alpha=0.5)
    thinkplot.save(root=root + 'noise0', xlabel='time (s)', ylabel='amplitude')

    spectrum = wave.make_spectrum()

    # 1: spectrum
    spectrum.plot_power(linewidth=1, alpha=0.5)
    thinkplot.save(root=root + 'noise1',
                   xlabel='frequency (Hz)',
                   ylabel='power density')

    slope, _, _, _, _ = spectrum.estimate_slope()
    print 'estimated slope', slope

    # 2: integrated spectrum
    integ = spectrum.make_integrated_spectrum()
    integ.plot_power()
    thinkplot.save(root=root + 'noise2',
                   xlabel='frequency (Hz)',
                   ylabel='normalized power')

    # 3: log-log spectral density
    spectrum.plot_power(low=1, linewidth=1, alpha=0.5)
    thinkplot.save(root=root + 'noise3',
                   xlabel='frequency (Hz)',
                   ylabel='power density',
                   xscale='log',
                   yscale='log')

    # 4: CDF of power density
    cdf = thinkstats2.MakeCdfFromList(spectrum.power)
    thinkplot.cdf(cdf)
    thinkplot.save(root=root + 'noise4', xlabel='power density', ylabel='CDF')

    # 5: CCDF of power density, log-y
    thinkplot.cdf(cdf, complement=True)
    thinkplot.save(root=root + 'noise5',
                   xlabel='power density',
                   ylabel='log(CCDF)',
                   yscale='log')

    thinkstats2.NormalProbabilityPlot(spectrum.real,
                                      label='real',
                                      data_color='#253494')
    thinkstats2.NormalProbabilityPlot(spectrum.imag - 50,
                                      label='imag-50',
                                      data_color='#1D91C0')
    thinkplot.save(root=root + 'noise6',
                   xlabel='normal sample',
                   ylabel='power density')
Exemplo n.º 4
0
def plot_power_density(root, spectrum):
    """
    """
    # 4: CDF of power density
    cdf = thinkstats2.MakeCdfFromList(spectrum.power)
    thinkplot.cdf(cdf)
    thinkplot.save(root=root + 'noise4', xlabel='power density', ylabel='CDF')

    # 5: CCDF of power density, log-y
    thinkplot.cdf(cdf, complement=True)
    thinkplot.save(root=root + 'noise5',
                   xlabel='power density',
                   ylabel='log(CCDF)',
                   yscale='log')
Exemplo n.º 5
0
def plot_power_density(root, spectrum):
    """
    """
    # 4: CDF of power density
    cdf = thinkstats2.MakeCdfFromList(spectrum.power)
    thinkplot.cdf(cdf)
    thinkplot.save(root=root+'noise4',
                   xlabel='power density',
                   ylabel='CDF')

    # 5: CCDF of power density, log-y
    thinkplot.cdf(cdf, complement=True)
    thinkplot.save(root=root+'noise5',
                   xlabel='power density',
                   ylabel='log(CCDF)',
                   yscale='log')