Esempio n. 1
0
def generate_die_roll_sum_distribution(number_of_rolls, number_of_dice):
    values = []

    die_or_dice = "Die"
    if number_of_dice > 1: die_or_dice = "Dice"

    logging.info("Rolling " + str(number_of_dice) + " " + die_or_dice + " " +
                 str(number_of_rolls) + " times")

    # execute number_of_rolls rolls of number_of_dice dice and accumulate the sum of the values
    for i in range(0, number_of_rolls):
        sum = 0
        for d in range(0, number_of_dice):
            sum += random.randint(1, 6)

        values.extend([sum])

    # plot the output
    charting.plot_distribution("dice_rolls.png",
                               "Roll Distribution - " + str(number_of_dice) +
                               " " + die_or_dice + ", " +
                               str(number_of_rolls) + " rolls",
                               "Sum of Values",
                               bucket_size=1,
                               data=values,
                               show_bucket_values=True,
                               color='#59799e',
                               normalize=True)
Esempio n. 2
0
def generate_die_roll_sum_distribution(number_of_rolls, number_of_dice):
    values = []

    die_or_dice = "Die"
    if number_of_dice > 1: die_or_dice = "Dice"

    logging.info("Rolling " + str(number_of_dice) + " " + die_or_dice + " " + str(number_of_rolls) + " times");

    # execute number_of_rolls rolls of number_of_dice dice and accumulate the sum of the values
    for i in range(0, number_of_rolls):
        sum = 0
        for d in range(0, number_of_dice):
            sum += random.randint(1,6)

        values.extend([sum])

    # plot the output
    charting.plot_distribution("dice_rolls.png",
                               "Roll Distribution - " + str(number_of_dice) + " " + die_or_dice + ", " + str(number_of_rolls) + " rolls",
                               "Sum of Values",
                               bucket_size=1,
                               data=values,
                               show_bucket_values=True,
                               color='#59799e',
                               normalize=True)
Esempio n. 3
0
def generate_poisson_distributed_pdf(number_of_samples, lam):

    # generate number_of_samples random numbers with a Poisson dist
    values = numpy.random.poisson(lam, number_of_samples).tolist()

    # plot the distribution
    charting.plot_distribution("poisson_distribution.png",
                               "Poisson Distribution - " + str(number_of_samples) + ", lambda = " + str(lam),
                               "Likelihoods",
                               bucket_size=1,
                               data=values,
                               show_bucket_values=True,
                               color='#59799e',
                               normalize=True);
Esempio n. 4
0
def generate_uniformly_distributed_pdf(number_of_samples):
    values = []

    # generate uniformly distributed random values
    for i in range(0, number_of_samples):
        values.extend([random.random()])

    # plot the distribution
    charting.plot_distribution("uniform_distribution.png",
                               "Uniform Distribution (" + str(number_of_samples) + ")",
                               "Likelihoods",
                               num_buckets=10,
                               data=values,
                               show_bucket_values=True,
                               color='#59799e',
                               normalize=True);
Esempio n. 5
0
def generate_gaussian_distributed_pdf(number_of_samples, mean, std_dev):
    values = []

    # generate gaussian distribution with mean and standard deviation
    for i in range(0, number_of_samples):
        values.extend([random.gauss(mean, std_dev)])

    # chart the output
    charting.plot_distribution("gaussian_distribution.png",
                               "Gaussian Distribution (" + str(number_of_samples) + ", mean = " + str(mean) + ", stnd dev = " + str(std_dev) + ")",
                               "Likelihoods",
                               num_buckets=10+int(std_dev*10),
                               data=values,
                               show_bucket_values=True,
                               color='#59799e',
                               normalize=True);
Esempio n. 6
0
def generate_poisson_distributed_pdf(number_of_samples, lam):

    # generate number_of_samples random numbers with a Poisson dist
    values = numpy.random.poisson(lam, number_of_samples).tolist()

    # plot the distribution
    charting.plot_distribution("poisson_distribution.png",
                               "Poisson Distribution - " +
                               str(number_of_samples) + ", lambda = " +
                               str(lam),
                               "Likelihoods",
                               bucket_size=1,
                               data=values,
                               show_bucket_values=True,
                               color='#59799e',
                               normalize=True)
Esempio n. 7
0
def generate_uniformly_distributed_pdf(number_of_samples):
    values = []

    # generate uniformly distributed random values
    for i in range(0, number_of_samples):
        values.extend([random.random()])

    # plot the distribution
    charting.plot_distribution("uniform_distribution.png",
                               "Uniform Distribution (" +
                               str(number_of_samples) + ")",
                               "Likelihoods",
                               num_buckets=10,
                               data=values,
                               show_bucket_values=True,
                               color='#59799e',
                               normalize=True)
Esempio n. 8
0
def generate_gaussian_distributed_pdf(number_of_samples, mean, std_dev):
    values = []

    # generate gaussian distribution with mean and standard deviation
    for i in range(0, number_of_samples):
        values.extend([random.gauss(mean, std_dev)])

    # chart the output
    charting.plot_distribution(
        "gaussian_distribution.png",
        "Gaussian Distribution (" + str(number_of_samples) + ", mean = " +
        str(mean) + ", stnd dev = " + str(std_dev) + ")",
        "Likelihoods",
        num_buckets=10 + int(std_dev * 10),
        data=values,
        show_bucket_values=True,
        color='#59799e',
        normalize=True)