test
Tasio Mendez 7 years ago
parent 764177c634
commit 1741a9a865

4
.gitignore vendored

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

18142
data.txt

File diff suppressed because it is too large Load Diff

@ -24,12 +24,12 @@ class ControlModelM2(BaseBehaviour):
""" """
# Init infected # 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 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=()): def __init__(self, environment=None, agent_id=0, state=()):
super().__init__(environment=environment, agent_id=agent_id, state=state) super().__init__(environment=environment, agent_id=agent_id, state=state)

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

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

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

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

@ -1,18 +1,18 @@
[ [
{ {
"network_type": 1, "network_type": 1,
"number_of_nodes": 1000, "number_of_nodes": 500,
"max_time": 50, "max_time": 30,
"num_trials": 1, "num_trials": 20,
"timeout": 2 "timeout": 1
}, },
{ {
"agent": ["SISaModel","ControlModelM2"], "agent": ["SpreadModelM2"],
"bite_prob": 0.01, "bite_prob": 0,
"heal_prob": 0.01, "heal_prob": 0,
"innovation_prob": 0.001, "innovation_prob": 0.001,
"imitation_prob": 0.005, "imitation_prob": 0.005,
@ -45,18 +45,18 @@
"variance_c_d": 0.003, "variance_c_d": 0.003,
"content_neutral": 0.088, "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.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

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

38912
test.gexf

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save