示例#1
0
class Finder(object):
    def __init__(self):
        self.lh = Lighthouse(.25, .75)
        x = np.linspace(0, 1, 99)
        y = np.linspace(0, 1, 99)
        pdf = {(xi, yi): 1 for xi in x for yi in y}
        likelihood = lambda x, (d, m): d / (d**2 + (x - m)**2)
        self.bayes = Bayes(pdf, likelihood)

    def solve_stuff(self):
        for datum in self.lh.dataset:
            self.bayes.update(datum)

    def print_distribution(self):
        self.bayes.print_distribution()
示例#2
0
class Finder(object):

    def __init__(self):
        self.lh = Lighthouse(.25,.75)
        x = np.linspace(0, 1, 99)
        y = np.linspace(0, 1, 99)
        pdf = {(xi,yi):1 for xi in x for yi in y}
        likelihood = lambda x, (d, m): d / (d**2 + (x-m)**2 )
        self.bayes = Bayes(pdf, likelihood)

    def solve_stuff(self):
        for datum in self.lh.dataset:
            self.bayes.update(datum)

    def print_distribution(self):
        self.bayes.print_distribution()
示例#3
0
    Returns:
        likelihood (float): the probability of the roll given the die.
    """
    if roll in range(1, die + 1):
        return 1 / die
    else:
        return 0


if __name__ == '__main__':
    uniform_prior = {4: .08, 6: .12, 8: .16, 12: .24, 20: .40}
    unbalanced_prior = {}

    die_bayes_1 = Bayes(uniform_prior.copy(), die_likelihood)
    experiment = [
        8, 2, 1, 2, 5, 8, 2, 4, 3, 7, 6, 5, 1, 6, 2, 5, 8, 8, 5, 3, 4, 2, 4, 3,
        8, 8, 7, 8, 8, 8, 5, 5, 1, 3, 8, 7, 8, 5, 2, 5, 1, 4, 1, 2, 1, 3, 1, 3,
        1, 5
    ]

    experiment2 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
    experiment3 = [20, 20, 20, 20, 20, 20, 20, 20, 20, 20]

    for idx, roll in enumerate(experiment3):
        print('roll#={} dic rolled={}'.format(idx + 1, roll))
        die_bayes_1.update(roll)
        die_bayes_1.print_distribution()
        #unbalanced_prior = die_bayes_1.prior
        print('*' * 32)
示例#4
0
uniform_prior = {4: 0.2, 6: 0.2, 8: 0.2, 12: 0.2, 20: 0.2}
unbalanced_prior = {4: 0.08, 6: 0.12, 8: 0.16, 12: 0.24, 20: 0.4}

d = [
    8, 2, 1, 2, 5, 8, 2, 4, 3, 7, 6, 5, 1, 6, 2, 5, 8, 8, 5, 3, 4, 2, 4, 3, 8,
    8, 7, 8, 8, 8, 5, 5, 1, 3, 8, 7, 8, 5, 2, 5, 1, 4, 1, 2, 1, 3, 1, 3, 1, 5
]

set1 = [1, 1, 1, 3, 1, 2]
set2 = [10, 10, 10, 10, 8, 8]

print('What are the posteriors if we started with the uniform prior?')
bayes_uniform = Bayes(uniform_prior.copy(), likelihood_func=likelihood_func)
bayes_uniform.update(8)
bayes_uniform.print_distribution()

print('What are the posteriors if we started with the unbalanced prior?')
bayes_unbalanced = Bayes(unbalanced_prior.copy(),
                         likelihood_func=likelihood_func)
bayes_unbalanced.update(8)
bayes_unbalanced.print_distribution()

print(
    'How different were these two posteriors (the uniform from the unbalanced)?'
)
for k, v in bayes_unbalanced.posterior.items():
    print("{} : {}".format(
        k, bayes_uniform.posterior[k] - bayes_unbalanced.posterior[k]))

print('\nApplying this set of data to the function:\n', d)