1
0
mirror of https://github.com/gsi-upm/soil synced 2024-11-24 11:52:29 +00:00
This commit is contained in:
Tasio Mendez 2017-06-21 13:26:22 +02:00
parent 764177c634
commit 1741a9a865
46 changed files with 81586 additions and 40942 deletions

4
.gitignore vendored
View File

@ -1,5 +1,5 @@
__pycache__/
.idea/
.ipynb_checkpoints/
*.png
*.gexf

BIN
SpreadModelM2_108.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

BIN
SpreadModelM2_327.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

21912
SpreadModelM2_397.gexf Normal file

File diff suppressed because it is too large Load Diff

21912
SpreadModelM2_483.gexf Normal file

File diff suppressed because it is too large Load Diff

21912
SpreadModelM2_716.gexf Normal file

File diff suppressed because it is too large Load Diff

BIN
SpreadModelM2_861.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

17764
data.txt

File diff suppressed because it is too large Load Diff

View File

@ -24,12 +24,12 @@ class ControlModelM2(BaseBehaviour):
"""
# Init infected
init_states[random.randint(0, settings.network_params["number_of_nodes"]-1)] = {'id': 1}
init_states[random.randint(0, settings.network_params["number_of_nodes"]-1)] = {'id': 1}
# init_states[random.randint(0, settings.network_params["number_of_nodes"]-1)] = {'id': 1}
# init_states[random.randint(0, settings.network_params["number_of_nodes"]-1)] = {'id': 1}
# Init beacons
init_states[random.randint(0, settings.network_params["number_of_nodes"]-1)] = {'id': 4}
init_states[random.randint(0, settings.network_params["number_of_nodes"]-1)] = {'id': 4}
# init_states[random.randint(0, settings.network_params["number_of_nodes"]-1)] = {'id': 4}
# init_states[random.randint(0, settings.network_params["number_of_nodes"]-1)] = {'id': 4}
def __init__(self, environment=None, agent_id=0, state=()):
super().__init__(environment=environment, agent_id=agent_id, state=state)

View File

@ -1,2 +1 @@
from .ControlModelM2 import ControlModelM2
from .SpreadModelM2 import SpreadModelM2

View File

@ -1,8 +1,8 @@
import settings
import random
import numpy as np
from ..BaseBehaviour import *
from .. import init_states
from models.BaseBehaviour import *
from models import init_states
class SpreadModelM2(BaseBehaviour):
@ -22,14 +22,13 @@ class SpreadModelM2(BaseBehaviour):
prob_generate_anti_rumor
"""
init_states[random.randint(0, settings.network_params["number_of_nodes"])] = {'id': 1}
init_states[random.randint(0, settings.network_params["number_of_nodes"])] = {'id': 1}
for x in range(settings.environment_params['source']):
init_states[random.randint(0, settings.network_params["number_of_nodes"])] = {'id': 1}
def __init__(self, environment=None, agent_id=0, state=()):
super().__init__(environment=environment, agent_id=agent_id, state=state)
self.prob_neutral_making_denier = np.random.normal(environment.environment_params['prob_neutral_making_denier'],
self.prob_neutral_making_denier = np.random.normal(environment.environment_params['prob_neutral_making_denier']/settings.environment_params['source'],
environment.environment_params['standard_variance'])
self.prob_infect = np.random.normal(environment.environment_params['prob_infect'],
@ -47,16 +46,17 @@ class SpreadModelM2(BaseBehaviour):
self.prob_generate_anti_rumor = np.random.normal(environment.environment_params['prob_generate_anti_rumor'],
environment.environment_params['standard_variance'])
def step(self, now):
if self.state['id'] == 0: # Neutral
self.neutral_behaviour()
elif self.state['id'] == 1: # Infected
self.infected_behaviour()
elif self.state['id'] == 2: # Cured
self.cured_behaviour()
elif self.state['id'] == 3: # Vaccinated
self.vaccinated_behaviour()
# elif self.state['id'] == 2: # Cured
# self.cured_behaviour()
# elif self.state['id'] == 3: # Vaccinated
# self.vaccinated_behaviour()
self.attrs['status'] = self.state['id']
super().step(now)
@ -69,6 +69,12 @@ class SpreadModelM2(BaseBehaviour):
if random.random() < self.prob_neutral_making_denier:
self.state['id'] = 3 # Vaccinated making denier
# Generate anti-rumor
infected_neighbors_2 = self.get_neighboring_agents(state_id=1)
for neighbor in infected_neighbors_2:
if random.random() < self.prob_generate_anti_rumor:
neighbor.state['id'] = 2 # Cured
def infected_behaviour(self):
# Neutral
@ -80,10 +86,10 @@ class SpreadModelM2(BaseBehaviour):
def cured_behaviour(self):
# Vaccinate
neutral_neighbors = self.get_neighboring_agents(state_id=0)
for neighbor in neutral_neighbors:
if random.random() < self.prob_cured_vaccinate_neutral:
neighbor.state['id'] = 3 # Vaccinated
# neutral_neighbors = self.get_neighboring_agents(state_id=0)
# for neighbor in neutral_neighbors:
# if random.random() < self.prob_cured_vaccinate_neutral:
# neighbor.state['id'] = 3 # Vaccinated
# Cure
infected_neighbors = self.get_neighboring_agents(state_id=1)

View File

@ -0,0 +1 @@
from .SpreadModelM2 import SpreadModelM2

View File

@ -3,6 +3,7 @@ from .BaseBehaviour import *
from .BassModel import *
from .BigMarketModel import *
from .IndependentCascadeModel import *
from .ModelM2 import *
from .ControlModelM2 import *
from .SpreadModelM2 import *
from .SentimentCorrelationModel import *
from .SISaModel import *

View File

@ -1,18 +1,18 @@
[
{
"network_type": 1,
"number_of_nodes": 1000,
"max_time": 50,
"num_trials": 1,
"timeout": 2
"number_of_nodes": 500,
"max_time": 30,
"num_trials": 20,
"timeout": 1
},
{
"agent": ["SISaModel","ControlModelM2"],
"agent": ["SpreadModelM2"],
"bite_prob": 0.01,
"heal_prob": 0.01,
"bite_prob": 0,
"heal_prob": 0,
"innovation_prob": 0.001,
"imitation_prob": 0.005,
@ -45,18 +45,18 @@
"variance_c_d": 0.003,
"content_neutral": 0.088,
"standard_variance": 0.055,
"prob_neutral_making_denier": 0.035,
"standard_variance": 1e-15,
"prob_neutral_making_denier": 0.07,
"prob_cured_healing_infected": 0,
"prob_cured_vaccinate_neutral": 0,
"prob_vaccinated_healing_infected": 0,
"prob_vaccinated_vaccinate_neutral": 0,
"prob_generate_anti_rumor": 0.01,
"prob_infect": 0.075,
"prob_infect": 0.0375,
"source": 2
"prob_cured_healing_infected": 0.035,
"prob_cured_vaccinate_neutral": 0.035,
"prob_vaccinated_healing_infected": 0.035,
"prob_vaccinated_vaccinate_neutral": 0.035,
"prob_generate_anti_rumor": 0.035
}
]

Binary file not shown.

BIN
sim_01/log.1.state.pickled Normal file

Binary file not shown.

BIN
sim_01/log.10.state.pickled Normal file

Binary file not shown.

BIN
sim_01/log.11.state.pickled Normal file

Binary file not shown.

BIN
sim_01/log.12.state.pickled Normal file

Binary file not shown.

BIN
sim_01/log.13.state.pickled Normal file

Binary file not shown.

BIN
sim_01/log.14.state.pickled Normal file

Binary file not shown.

BIN
sim_01/log.15.state.pickled Normal file

Binary file not shown.

BIN
sim_01/log.16.state.pickled Normal file

Binary file not shown.

BIN
sim_01/log.17.state.pickled Normal file

Binary file not shown.

BIN
sim_01/log.18.state.pickled Normal file

Binary file not shown.

BIN
sim_01/log.19.state.pickled Normal file

Binary file not shown.

BIN
sim_01/log.2.state.pickled Normal file

Binary file not shown.

BIN
sim_01/log.20.state.pickled Normal file

Binary file not shown.

BIN
sim_01/log.21.state.pickled Normal file

Binary file not shown.

BIN
sim_01/log.22.state.pickled Normal file

Binary file not shown.

BIN
sim_01/log.23.state.pickled Normal file

Binary file not shown.

BIN
sim_01/log.24.state.pickled Normal file

Binary file not shown.

BIN
sim_01/log.25.state.pickled Normal file

Binary file not shown.

BIN
sim_01/log.26.state.pickled Normal file

Binary file not shown.

BIN
sim_01/log.27.state.pickled Normal file

Binary file not shown.

BIN
sim_01/log.28.state.pickled Normal file

Binary file not shown.

BIN
sim_01/log.29.state.pickled Normal file

Binary file not shown.

BIN
sim_01/log.3.state.pickled Normal file

Binary file not shown.

BIN
sim_01/log.4.state.pickled Normal file

Binary file not shown.

BIN
sim_01/log.5.state.pickled Normal file

Binary file not shown.

BIN
sim_01/log.6.state.pickled Normal file

Binary file not shown.

BIN
sim_01/log.7.state.pickled Normal file

Binary file not shown.

BIN
sim_01/log.8.state.pickled Normal file

Binary file not shown.

BIN
sim_01/log.9.state.pickled Normal file

Binary file not shown.

31
soil.py
View File

@ -6,6 +6,7 @@ import networkx as nx
import settings
import models
import math
import random
import json
@ -49,7 +50,7 @@ def visualization(graph_name):
with open('data.txt', 'w') as outfile:
json.dump(models.networkStatus, outfile, sort_keys=True, indent=4, separators=(',', ': '))
nx.write_gexf(G, graph_name+".gexf", version="1.2draft")
nx.write_gexf(G, graph_name+"_"+str(random.randint(0,1000))+".gexf", version="1.2draft")
###########
@ -77,15 +78,15 @@ def results(model_name):
if models.networkStatus["agent_%s" % x][attribute_plot][real_time] == 1: ## Infected
value_infectados += 1
activity = True
if models.networkStatus["agent_%s" % x][attribute_plot][real_time] == 0: ## Neutral
value_neutral += 1
activity = True
# if models.networkStatus["agent_%s" % x][attribute_plot][real_time] == 0: ## Neutral
# value_neutral += 1
# activity = True
if models.networkStatus["agent_%s" % x][attribute_plot][real_time] == 2: ## Cured
value_cured += 1
activity = True
if models.networkStatus["agent_%s" % x][attribute_plot][real_time] == 3: ## Vaccinated
value_vaccinated += 1
activity = True
# if models.networkStatus["agent_%s" % x][attribute_plot][real_time] == 3: ## Vaccinated
# value_vaccinated += 1
# activity = True
if activity:
x_values.append(real_time)
@ -98,13 +99,13 @@ def results(model_name):
fig1 = plt.figure()
ax1 = fig1.add_subplot(111)
infected_line = ax1.plot(x_values, infected_values, label='Infected')
neutral_line = ax1.plot(x_values, neutral_values, label='Neutral')
cured_line = ax1.plot(x_values, cured_values, label='Cured')
vaccinated_line = ax1.plot(x_values, vaccinated_values, label='Vaccinated')
infected_line = ax1.plot(x_values, infected_values, label='Endorses')
# neutral_line = ax1.plot(x_values, neutral_values, label='Neutral')
cured_line = ax1.plot(x_values, cured_values, label='Denies')
# vaccinated_line = ax1.plot(x_values, vaccinated_values, label='Vaccinated')
ax1.legend()
fig1.savefig(model_name + '.png')
# plt.show()
fig1.savefig(model_name + '_' + str(random.randint(0, 1000)) + '.png')
plt.show()
####################
@ -133,12 +134,12 @@ if len(agents) > 1:
num_trials=settings.network_params["num_trials"], logging_interval=1.0, **settings.environment_params)
sim.run_simulation()
print(str(agent))
results(str(agent))
visualization(str(agent))
results(str(agent))
else:
agent = agents[0]
sim = NetworkSimulation(topology=G, states=init_states, agent_type=locals()[agent], max_time=settings.network_params["max_time"],
num_trials=settings.network_params["num_trials"], logging_interval=1.0, **settings.environment_params)
sim.run_simulation()
results(str(agent))
visualization(str(agent))
results(str(agent))

38912
test.gexf

File diff suppressed because it is too large Load Diff