コード例 #1
0
def make_ccdf_plot(die, offset=0, sd=None):
    if sd is None:
        gaussian = Die.gaussian(die)
    else:
        gaussian = Die.gaussian(die.mean(), sd)

    print('KS: %0.2f%%' % (die.ks_stat(gaussian) * 100.0))
    print('Above end: %0.2f%%' % ((gaussian > die.max_outcome()) * 100.0))
    gaussian_clipped = gaussian.clip(die)
    for outcome, die_chance, gaussian_chance in zip(die.outcomes(), die.ccdf(),
                                                    gaussian_clipped.ccdf()):
        print(
            '%d: %0.2f%%, %0.2f%%, %0.3f, %0.3f, %+0.2f%%' %
            (outcome, 100.0 * die_chance, 100.0 * gaussian_chance, die_chance /
             gaussian_chance, gaussian_chance / die_chance, 100.0 *
             (gaussian_chance - die_chance)))

    fig = plt.figure(figsize=figsize)
    ax = plt.subplot(111)
    ax.grid()

    ax.plot(die.outcomes() + offset, die.ccdf() * 100.0, marker='.')
    ax.plot(gaussian.outcomes() + offset, gaussian.ccdf() * 100.0, marker='.')
    ax.set_ylim(bottom=0, top=100)
    ax.set_ylabel('Chance (%) of rolling at least')

    return ax
コード例 #2
0
def make_pmf_plot(die, offset=0, sd=None):
    if sd is None:
        gaussian = Die.gaussian(die)
    else:
        gaussian = Die.gaussian(die.mean(), sd)

    print('Var:', die.variance())
    print('MAD median:', die.mad_median())

    fig = plt.figure(figsize=figsize)
    ax = plt.subplot(111)
    ax.grid()

    print('Gaussian mode:', gaussian.mode())

    ax.plot(die.outcomes() + offset, die.pmf() * 100.0, marker='.')
    ax.plot(gaussian.outcomes() + offset, gaussian.pmf() * 100.0, marker='.')

    ax.set_ylim(bottom=0)
    ax.set_ylabel('Chance (%) of rolling exactly')

    return ax
コード例 #3
0
def make_mos_plot(die, offset=0, sd=None):
    if sd is None:
        gaussian = Die.gaussian(die)
    else:
        gaussian = Die.gaussian(die.mean(), sd)

    fig = plt.figure(figsize=figsize)
    ax = plt.subplot(111)
    ax.grid()

    x = numpy.arange(min(0, die.min_outcome()), die.max_outcome() + 1)
    y_die = [die.margin_of_success(t).mean() for t in x]
    y_gaussian = [gaussian.margin_of_success(t).mean() for t in x]

    ax.plot(x + offset, y_die, marker='.')
    ax.plot(x + offset, y_gaussian, marker='.')

    ax.set_xlim(left=x[0], right=x[-1])

    ax.set_ylim(bottom=0)
    ax.set_ylabel('Mean margin of success')

    return ax
コード例 #4
0
def objective(sd):
    gaussian = Die.gaussian(10.5, sd)
    return Die.d20.ks_stat(gaussian)
コード例 #5
0
ax.legend(['d20', 'd20 + d6 - 3.5', 'd20 + d12 - 6.5', 'd20 + d20 - 10.5'])
plt.savefig('output/add_small_die_ccdf.png', dpi=dpi, bbox_inches="tight")

# Coin flips.

for coin_count in range(1, 11):
    fig = plt.figure(figsize=figsize)
    ax = plt.subplot(111)
    ax.grid()

    x = numpy.linspace(-3, 3, 1001)
    y = numpy.exp(-0.5 * numpy.square(x)) / numpy.sqrt(2 * numpy.pi)
    ax.plot(x, y, linestyle=':')

    coins = Die.d(coin_count, 2)
    gaussian = Die.gaussian(coins)
    ks = coins.ks_stat(gaussian) * 100.0
    print('KS %d: %0.2f%%' % (coin_count, ks))
    ax.plot((coins.outcomes() - coins.mean()) / coins.standard_deviation(),
            coins.pmf() * coins.standard_deviation(),
            marker='.')

    ax.set_xlim(-3, 3)
    ax.set_xlabel('Deviation from mean in SDs')
    ax.set_ylabel('Normalized probability')
    ax.set_ylim(0, 0.4)
    ax.set_title('%d coin(s): KS = %0.2f%%' % (coin_count, ks))

    plt.savefig('output/frames/frame_%03d.png' % (coin_count - 1),
                dpi=dpi,
                bbox_inches="tight")