def test_simulation_of_discrimination_game(self): # Network construction. agents = {} for _ in range(10): agent = SteelsAgent() agent.set_fitness("DG", StandardFitness()) agents[agent.get_id()] = agent topology = generate_topology("clique", agents_names=agents.keys()) changes = {1: "clique"} network = Network(agents, {"clique": topology}, changes) # Interaction construction. interactions = BehaviorSwitcher({"DG": DiscriminationGame()}, {1: "DG"}) # Environment construction. irises = datasets.load_iris() environment = Environment(irises.data, irises.target) environments = BehaviorSwitcher({"global": environment}, {1: "global"}) # Results construction. result = StandardResult(100) # Condition construction. condition = IterationCondition(1000) # Simulation construction. self.simulation = Simulation(network, interactions, environments, result, condition)
def fit(self, x, y): """ Fit the steels classifier according to the given training data. :param list x: samples. :param list y: samples' classes. """ environment = Environment(x, y) agents = {} if self.classifiers is None: for _ in range(15): agent = SteelsClassificationAgent(alpha=self.alpha) agents[agent.id] = agent else: for classifier in self.classifiers: agent = SteelsClassificationAgent(classifier=classifier, alpha=self.alpha) agents[agent.id] = agent for agent in agents.values(): agent.set_fitness("DG", CurrentFitness()) agent.set_fitness("GG", CurrentFitness()) network = Network(agents, {1: generate_topology(self.topology, agents_names=agents.keys())}) self.simulation = Simulation( network, self.interactions, BehaviorSwitcher(environment), SteelsClassifierResults(), self.condition ) self.result = self.simulation.run()
def test_flu_game(self): """ Flu game simulates flu expanding through social network. """ # Network construction. agents = {} for _ in range(100): agent = Agent() agent.set_fitness("infected", InfectedFitness()) agents[agent.get_id()] = agent for agent in agents: agents[agent].update_fitness_measure("infected", True) break topology = generate_topology("clique", agents_names=agents.keys()) changes = {1: "clique"} network = Network(agents, {"clique": topology}, changes) # Interaction construction. interactions = BehaviorSwitcher({ "infection": InfectInteraction() }, {1: "infection"}) # Environment construction. environment = BehaviorSwitcher({}, {}) # Results construction. result = StandardResult(1) # Condition construction. condition = AllInfected() # Simulation construction. self.simulation = Simulation(network, interactions, environment, result, condition) simulation_result = self.simulation.run()
def test_guessing_game(): agents = {} for _ in range(10): the_agent = SteelsClassificationAgent() the_agent.set_fitness("DG", fitness.StandardFitness()) the_agent.set_fitness("GG", fitness.StandardFitness()) agents[the_agent.get_id] = the_agent topology = generate_topology("clique", agents_names=agents.keys()) complete_network = network.Network(agents, {"g": topology}) iris = datasets.load_iris() the_environment = environment.Environment(iris.data, iris.target) sim = simulation.Simulation(complete_network, BehaviorSwitcher({"a": GuessingGame()}), BehaviorSwitcher({"a": the_environment}), result.StandardResult(), condition.IterationCondition(3200)) sim.run()