Ejemplo n.º 1
0
    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()
Ejemplo n.º 2
0
    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()