Esempio n. 1
0
    def test_zero_vanilla(self):
        mixes = {
            'Bowl 1': Bowl(dict(Vanilla=0, Chocolate=10)),
            'Bowl 2': Bowl(dict(Vanilla=20, Chocolate=20)),
        }

        hypos = ['Bowl 1', 'Bowl 2']
        pmf = Cookie(hypos, mixes)

        # we're saying that this is the data
        pmf.Update('Vanilla')
        self.assertAlmostEquals(pmf.d['Bowl 1'], 0.0)
        self.assertAlmostEquals(pmf.d['Bowl 2'], 1)
Esempio n. 2
0
def main():
    hypos = ['Bowl 1', 'Bowl 2']
    bowls = {
        'Bowl 1': Bowl(dict(Vanilla=30, Chocolate=10)),
        'Bowl 2': Bowl(dict(Vanilla=20, Chocolate=20)),
    }

    pmf = Cookie(hypos, bowls)

    # we're saying that this is the data
    pmf.Update('Vanilla')

    for hypo, prob in pmf.Items():
        print hypo, prob

    print pmf.bowls['Bowl 1']
    print pmf.bowls['Bowl 2']
Esempio n. 3
0
    def test_remove2(self):
        """ simplifies to book example
        """
        mixes = {
            'Bowl 1': Bowl(dict(Vanilla=1, Chocolate=10)),
            'Bowl 2': Bowl(dict(Vanilla=2, Chocolate=20)),
        }

        hypos = ['Bowl 1', 'Bowl 2']
        pmf = Cookie(hypos, mixes)

        # remove two vanilla cookies
        pmf.Update('Vanilla')
        pmf.Update('Vanilla')

        # This is saying that if you pick two vanilla cookies from one bowl, it must be Bowl2.
        # This is different than saying that you pick two cookies from unknown bowls, they're both vanilla,
        # and they both came from bowl 2
        self.assertAlmostEquals(pmf.d['Bowl 1'], 0)
        self.assertAlmostEquals(pmf.d['Bowl 2'], 1)
Esempio n. 4
0
def get_ball():
    # 初始化Pygame、设置和屏幕对象
    pygame.init()
    b_settings = Settings()
    screen = pygame.display.set_mode(
        (b_settings.screen_width, b_settings.screen_height))
    pygame.display.set_caption("get ball")

    # 创建一个球和一个碗
    bowl = Bowl(b_settings, screen)
    ball = Ball(b_settings, screen)
    stats = GameStats(b_settings)

    # 开始主循环
    while True:
        gf.check_events(bowl)
        if stats.game_active:
            bowl.update()
            gf.update_ball(b_settings, stats, bowl, ball)
        gf.update_screen(b_settings, screen, bowl, ball)
Esempio n. 5
0
def main():

    mybowl1 = Bowl("Bowl 1", 30, 10)
    mybowl2 = Bowl("Bowl 2", 20, 20)

    pmf = Cookie(mybowl1, mybowl2)

    pmf.Update('vanilla')

    for hypo, prob in pmf.Items():
        print(hypo, prob)

    pmf.take_cookie("vanilla", "Bowl 1")

    print(pmf.mixes)

    pmf.Update("vanilla")

    for hypo, prob in pmf.Items():
        print(hypo, prob)
Esempio n. 6
0
class Cookie(Pmf):
    """A map from string bowl ID to probablity."""

    bowls = {
            'Bowl 1': Bowl({ 'vanilla' : 30 , 'chocolate' : 10 }) ,
            'Bowl 2': Bowl({ 'vanilla' : 20 , 'chocolate' : 20 })
            }

    def __init__(self, hypos):
        """Initialize self.

        hypos: sequence of string bowl IDs
        """
        Pmf.__init__(self)
        for hypo in hypos:
            self.Set(hypo, 1)
        self.Normalize()

    def Update(self, data):
        """Updates the PMF with new data.

        data: string cookie type
        """
        for hypo in self.Values():
            like = self.Likelihood(data, hypo)
            self.Mult(hypo, like)
        self.Normalize()

    def Likelihood(self, data, hypo):
        """The likelihood of the data under the hypothesis.

        data: string cookie type
        hypo: string bowl ID
        """
        bowl = self.bowls[hypo]
        like = bowl.probability_of_flavors()[data]
        bowl.pick_a_cookie(data, like)
        bowl.print_state()
        return like
Esempio n. 7
0
            if not bot_configuration["port"][1] and check(parts[1], "port"):
                bot_configuration["port"][0] = int(parts[1])
                bot_configuration["port"][1] = True

        elif parts[0] == 'channel':
            if not bot_configuration["channel"][1] and check(
                    parts[1], "channel"):
                bot_configuration["channel"][0] = parts[1]
                bot_configuration["channel"][1] = True

        elif parts[0] == 'tellfile':
            if not bot_configuration["tellfile"][1] and check(
                    parts[1], "tellfile"):
                bot_configuration["tellfile"][0] = parts[1] + '/tellfile.db'
                bot_configuration["tellfile"][1] = True

        elif parts[0] == 'ssl':
            if not bot_configuration['ssl'][1]:
                bot_configuration['ssl'][0] = parts[1] == 'True'
                bot_configuration['ssl'][1] = True

# Complete mandatory config info
complete_missing(bot_configuration)
print(bot_configuration)

bowl = Bowl(host=bot_configuration["host"][0], port=bot_configuration["port"][0], nick=bot_configuration["nick"][0],\
        realname=bot_configuration["realname"][0], channel=bot_configuration["channel"][0], tellfile=bot_configuration["tellfile"][0],\
        ssl=bot_configuration['ssl'][0])

bowl.connect()