def test_AllPassiveMonsters_WithRando(self): wimpy = WimpyHypothesis() rando = RandoHypothesis() self.setUpDecisioner(wimpy, rando) # First we will start with the basic training case # which is the first 100 in the range for i in range(101): monster = Monster(0, [randint(1, 100)], 'passive') # Get the guess from the decisioner for the first 100, # we expect every guess to be 1 self.assertTrue(self.decisioner.get_guess(monster.color)) # Then we will update from this guess self.decisioner.update(monster.color, 1, monster.action(True)) for i in range(5000): monster = Monster(0, [randint(1, 100)], 'aggressive') self.decisioner.get_guess(monster.color) # Then we will update from this guess self.decisioner.update(monster.color, 1, 1) # Flipping a coin is better than doing nothing self.assertGreater(rando.fitness(), wimpy.fitness()) # Randomness should be near-even in distribution self.assertGreater(rando.fitness(), 0.4) self.assertGreater(0.6, rando.fitness())
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
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( 1), # lonliest number universe, interesting but not a good idea
def setUp(self): self._hypothesis = RandoHypothesis()