def test_with_all_hypothesis(self):
        brave = BraveHypothesis()
        wimpy = WimpyHypothesis()

        knn3 = KNearestNeighbors(3)
        knn5 = KNearestNeighbors(5)
        knn7 = KNearestNeighbors(7)
        knn11 = KNearestNeighbors(11)

        rando = RandoHypothesis()
        prob = SimpleProbabilityHypothesis()

#        drP3 = OptimusPerceptron(11)
#        drP5 = DrPerceptron(5)
#        drP7 = DrPerceptron(7)
#        drP11 = DrPerceptron(11)
#
        self.setUpDecisioner(brave,
                             wimpy,
                             knn3,
                             knn5,
                             knn7,
                             knn11,
                             rando,
                             prob,
#                             drP3,
#                             drP5,
#                             drP7,
#                             drP11,
                            )

        def create_monster():
            color = randint(1, 100)

            if color < 70:
                if random() >= 0.3:
                    return Monster(0, [color], 'passive')
                return Monster(1, [color], 'aggressive')
            else:
                if random() >= 0.7:
                    return Monster(0, [color], 'passive')
                return Monster(1, [color], 'aggressive')

        for i in range(100):
            monster = create_monster()
            self.decisioner.update(monster.color, 1, monster.action(True))

        maximum_value = 1000.0
        actual_value = 0.0

        for i in range(1000):
            monster = create_monster()

            guess = self.decisioner.get_guess(monster.color)
            outcome = monster.action(guess)
            self.decisioner.update(monster.color, guess, outcome)

            maximum_value -= monster._aggressive
            actual_value += outcome
class SimpleProbabilityHypothesisTest(unittest.TestCase):

    def setUp(self):
        self.hypothesis = SimpleProbabilityHypothesis()

    def tearDown(self):
        self.hypothesis = None

    def test_half_probability(self):
        self.run_tests_probability_p(0.99)

    def run_tests_probability_p(self, p):
        # Train inital period
        for i in range(100):
            monster = create_monster(p)
            self.hypothesis.update(monster.color, 1, monster.action(True))

        for x in range(500):
            monster = create_monster(p)
            guess = self.hypothesis.get_guess(monster.color)
            outcome = monster.action(guess)
            self.hypothesis.update(monster.color, guess, outcome)

        err = abs(self.hypothesis.p_value() - p)
        self.assertGreater(0.05, err)
Example #3
0
class SimpleProbabilityHypothesisTest(unittest.TestCase):
    def setUp(self):
        self.hypothesis = SimpleProbabilityHypothesis()

    def tearDown(self):
        self.hypothesis = None

    def test_half_probability(self):
        self.run_tests_probability_p(0.99)

    def run_tests_probability_p(self, p):
        # Train inital period
        for i in range(100):
            monster = create_monster(p)
            self.hypothesis.update(monster.color, 1, monster.action(True))

        for x in range(500):
            monster = create_monster(p)
            guess = self.hypothesis.get_guess(monster.color)
            outcome = monster.action(guess)
            self.hypothesis.update(monster.color, guess, outcome)

        err = abs(self.hypothesis.p_value() - p)
        self.assertGreater(0.05, err)
Example #4
0
 def setUp(self):
     self.hypothesis = SimpleProbabilityHypothesis()
Example #5
0
 hyps = [
     BraveHypothesis(),
     WimpyHypothesis(),
     KNearestNeighbors(3),
     KNearestNeighbors(5),
     KNearestNeighbors(7),
     KNearestNeighbors(11),
     KNearestNeighbors(17),
     KNearestNeighbors(23),
     KNearestNeighbors(29),
     KNearestNeighbors(31),
     KNearestNeighbors(37),
     KNearestNeighbors(41),
     KNearestNeighbors(43),
     KNearestNeighbors(47),
     SimpleProbabilityHypothesis(),
     RandoHypothesis(),
     OptimusPerceptron(47),  # mod 47 universe
     OptimusPerceptron(43),  # mod 43 universe
     OptimusPerceptron(41),  # mod 41 universe
     OptimusPerceptron(37),  # mod 37 universe
     OptimusPerceptron(31),  # mod 31 universe
     OptimusPerceptron(29),  # mod 29 universe
     OptimusPerceptron(23),  # mod 23 universe
     OptimusPerceptron(17),  # mod 17 universe
     OptimusPerceptron(11),  # mod 11 universe
     OptimusPerceptron(7),  # mod 7 universe
     OptimusPerceptron(5),  # mod 5 universe
     OptimusPerceptron(3),  # mod 3 universe
     OptimusPerceptron(2),  # even universe
     OptimusPerceptron(
 def setUp(self):
     self.hypothesis = SimpleProbabilityHypothesis()