コード例 #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()
コード例 #2
0
ファイル: test_guessing_game.py プロジェクト: CogSys/cog-abm
    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()
コード例 #3
0
ファイル: test_guessing_game.py プロジェクト: CogSys/cog-abm
    def test_lexicon_sample_storage_adequacy(self):
        game = DiscriminationGame()

        the_agent = SteelsClassificationAgent()

        iris = datasets.load_iris()
        the_environment = environment.Environment(iris.data, iris.target)

        the_agent.add_sample(1, the_environment)
        self.lexicon_and_sample_storage_adequacy(the_agent)

        the_agent.forget()
        self.lexicon_and_sample_storage_adequacy(the_agent)

        category = the_agent.predict(the_environment.get_sample(1))
        self.lexicon_and_sample_storage_adequacy(the_agent)

        word = the_agent.find_word_for_category(category)
        self.lexicon_and_sample_storage_adequacy(the_agent)

        the_agent.forget()
        self.lexicon_and_sample_storage_adequacy(the_agent)

        game.learning_after_game(the_agent, 2, the_environment, category, True)
        self.lexicon_and_sample_storage_adequacy(the_agent)

        for _ in range(1000):
            the_agent.forget()
            self.lexicon_and_sample_storage_adequacy(the_agent)

        assert_equal(0, the_agent.sample_storage.get_categories_size())
        assert_equal(0, the_agent.lexicon.get_categories_size())