Ejemplo n.º 1
0
    def test_sznajd_model(self):
        for g in get_graph():
            model = opn.SznajdModel(g)
            config = mc.Configuration()
            config.add_model_parameter("fraction_infected", 0.2)
            model.set_initial_status(config)
            iterations = model.iteration_bunch(10)
            self.assertEqual(len(iterations), 10)
            iterations = model.iteration_bunch(10, node_status=False)
            self.assertEqual(len(iterations), 10)

        for g in get_directed_graph():
            model = opn.SznajdModel(g)
            config = mc.Configuration()
            config.add_model_parameter("fraction_infected", 0.2)
            model.set_initial_status(config)
            iterations = model.iteration_bunch(10)
            self.assertEqual(len(iterations), 10)
            iterations = model.iteration_bunch(10, node_status=False)
            self.assertEqual(len(iterations), 10)
Ejemplo n.º 2
0
    def test_sznajd_model(self):
        g = nx.complete_graph(100)
        model = opn.SznajdModel(g)
        config = mc.Configuration()
        config.add_model_parameter("percentage_infected", 0.2)
        model.set_initial_status(config)
        iterations = model.iteration_bunch(10)
        self.assertEqual(len(iterations), 10)
        iterations = model.iteration_bunch(10, node_status=False)
        self.assertEqual(len(iterations), 10)

        g = nx.complete_graph(100)
        g = g.to_directed()
        model = opn.SznajdModel(g)
        config = mc.Configuration()
        config.add_model_parameter("percentage_infected", 0.2)
        model.set_initial_status(config)
        iterations = model.iteration_bunch(10)
        self.assertEqual(len(iterations), 10)
        iterations = model.iteration_bunch(10, node_status=False)
        self.assertEqual(len(iterations), 10)
Ejemplo n.º 3
0
    SEIR_trends = SEIRModel.build_trends(SEIR_iterations)
    visualize(SEIRModel, SEIR_trends, sub_dir='epidemics')

    ###############################################################

    voter_model = op.VoterModel(g.copy())
    voter_model.set_initial_status(get_voter_params())
    voter_iterations = voter_model.iteration_bunch(num_iterations)
    voter_trends = voter_model.build_trends(voter_iterations)
    visualize(voter_model, voter_trends, sub_dir='opinions')

    QVoter_model = op.QVoterModel(g.copy())
    QVoter_model.set_initial_status(get_qvoter_params())
    QVoter_iterations = QVoter_model.iteration_bunch(num_iterations)
    QVoter_trends = QVoter_model.build_trends(QVoter_iterations)
    visualize(QVoter_model, QVoter_trends, sub_dir='opinions')

    majority_rule_model = op.MajorityRuleModel(g.copy())
    majority_rule_model.set_initial_status(get_majority_rules_params())
    majority_rule_iterations = majority_rule_model.iteration_bunch(
        num_iterations)
    majority_rule_trends = majority_rule_model.build_trends(
        majority_rule_iterations)
    visualize(majority_rule_model, majority_rule_trends, sub_dir='opinions')

    sznajd_model = op.SznajdModel(g.copy())
    sznajd_model.set_initial_status(get_sznajd_params())
    sznajd_iterations = sznajd_model.iteration_bunch(num_iterations)
    sznajd_trends = sznajd_model.build_trends(sznajd_iterations)
    visualize(sznajd_model, sznajd_trends, sub_dir='opinions')