mirror of
https://github.com/gsi-upm/soil
synced 2024-11-13 23:12:28 +00:00
Settings models
This commit is contained in:
parent
391ce5e9e0
commit
aaf5f709f1
@ -13,8 +13,8 @@ class BassModel(BaseBehaviour):
|
|||||||
|
|
||||||
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.innovation_prob = environment.innovation_prob
|
self.innovation_prob = environment.environment_params['innovation_prob']
|
||||||
self.imitation_prob = environment.imitation_prob
|
self.imitation_prob = environment.environment_params['imitation_prob']
|
||||||
sentimentCorrelationNodeArray[self.id][self.env.now] = 0
|
sentimentCorrelationNodeArray[self.id][self.env.now] = 0
|
||||||
|
|
||||||
def step(self, now):
|
def step(self, now):
|
||||||
|
@ -21,21 +21,21 @@ class BigMarketModel(BaseBehaviour):
|
|||||||
|
|
||||||
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.enterprises = environment.enterprises
|
self.enterprises = environment.environment_params['enterprises']
|
||||||
self.type = ""
|
self.type = ""
|
||||||
self.number_of_enterprises = len(environment.enterprises)
|
self.number_of_enterprises = len(environment.environment_params['enterprises'])
|
||||||
|
|
||||||
if self.id < self.number_of_enterprises: # Enterprises
|
if self.id < self.number_of_enterprises: # Enterprises
|
||||||
self.state['id']=self.id
|
self.state['id'] = self.id
|
||||||
self.type="Enterprise"
|
self.type = "Enterprise"
|
||||||
self.tweet_probability = environment.tweet_probability_enterprises[self.id]
|
self.tweet_probability = environment.environment_params['tweet_probability_enterprises'][self.id]
|
||||||
else: # normal users
|
else: # normal users
|
||||||
self.state['id']=self.number_of_enterprises
|
self.state['id'] = self.number_of_enterprises
|
||||||
self.type="User"
|
self.type = "User"
|
||||||
self.tweet_probability = environment.tweet_probability_users
|
self.tweet_probability = environment.environment_params['tweet_probability_users']
|
||||||
self.tweet_relevant_probability = environment.tweet_relevant_probability
|
self.tweet_relevant_probability = environment.environment_params['tweet_relevant_probability']
|
||||||
self.tweet_probability_about = environment.tweet_probability_about # List
|
self.tweet_probability_about = environment.environment_params['tweet_probability_about'] # List
|
||||||
self.sentiment_about = environment.sentiment_about # List
|
self.sentiment_about = environment.environment_params['sentiment_about'] # List
|
||||||
|
|
||||||
def step(self, now):
|
def step(self, now):
|
||||||
|
|
||||||
|
@ -13,8 +13,8 @@ class IndependentCascadeModel(BaseBehaviour):
|
|||||||
|
|
||||||
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.innovation_prob = environment.innovation_prob
|
self.innovation_prob = environment.environment_params['innovation_prob']
|
||||||
self.imitation_prob = environment.imitation_prob
|
self.imitation_prob = environment.environment_params['imitation_prob']
|
||||||
self.time_awareness = 0
|
self.time_awareness = 0
|
||||||
sentimentCorrelationNodeArray[self.id][self.env.now] = 0
|
sentimentCorrelationNodeArray[self.id][self.env.now] = 0
|
||||||
|
|
||||||
|
@ -24,8 +24,8 @@ class ControlModelM2(BaseBehaviour):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# Init infected
|
# Init infected
|
||||||
init_states[random.randint(0, settings.number_of_nodes-1)] = {'id':1}
|
init_states[random.randint(0, settings.number_of_nodes-1)] = {'id': 1}
|
||||||
init_states[random.randint(0, settings.number_of_nodes-1)] = {'id':1}
|
init_states[random.randint(0, settings.number_of_nodes-1)] = {'id': 1}
|
||||||
|
|
||||||
# Init beacons
|
# Init beacons
|
||||||
init_states[random.randint(0, settings.number_of_nodes-1)] = {'id': 4}
|
init_states[random.randint(0, settings.number_of_nodes-1)] = {'id': 4}
|
||||||
@ -34,22 +34,23 @@ class ControlModelM2(BaseBehaviour):
|
|||||||
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.prob_neutral_making_denier,
|
self.prob_neutral_making_denier = np.random.normal(environment.environment_params['prob_neutral_making_denier'],
|
||||||
environment.standard_variance)
|
environment.environment_params['standard_variance'])
|
||||||
|
|
||||||
self.prob_infect = np.random.normal(environment.prob_infect, environment.standard_variance)
|
self.prob_infect = np.random.normal(environment.environment_params['prob_infect'],
|
||||||
|
environment.environment_params['standard_variance'])
|
||||||
|
|
||||||
self.prob_cured_healing_infected = np.random.normal(environment.prob_cured_healing_infected,
|
self.prob_cured_healing_infected = np.random.normal(environment.environment_params['prob_cured_healing_infected'],
|
||||||
environment.standard_variance)
|
environment.environment_params['standard_variance'])
|
||||||
self.prob_cured_vaccinate_neutral = np.random.normal(environment.prob_cured_vaccinate_neutral,
|
self.prob_cured_vaccinate_neutral = np.random.normal(environment.environment_params['prob_cured_vaccinate_neutral'],
|
||||||
environment.standard_variance)
|
environment.environment_params['standard_variance'])
|
||||||
|
|
||||||
self.prob_vaccinated_healing_infected = np.random.normal(environment.prob_vaccinated_healing_infected,
|
self.prob_vaccinated_healing_infected = np.random.normal(environment.environment_params['prob_vaccinated_healing_infected'],
|
||||||
environment.standard_variance)
|
environment.environment_params['standard_variance'])
|
||||||
self.prob_vaccinated_vaccinate_neutral = np.random.normal(environment.prob_vaccinated_vaccinate_neutral,
|
self.prob_vaccinated_vaccinate_neutral = np.random.normal(environment.environment_params['prob_vaccinated_vaccinate_neutral'],
|
||||||
environment.standard_variance)
|
environment.environment_params['standard_variance'])
|
||||||
self.prob_generate_anti_rumor = np.random.normal(environment.prob_generate_anti_rumor,
|
self.prob_generate_anti_rumor = np.random.normal(environment.environment_params['prob_generate_anti_rumor'],
|
||||||
environment.standard_variance)
|
environment.environment_params['standard_variance'])
|
||||||
|
|
||||||
def step(self, now):
|
def step(self, now):
|
||||||
|
|
||||||
|
@ -29,22 +29,23 @@ class SpreadModelM2(BaseBehaviour):
|
|||||||
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.prob_neutral_making_denier,
|
self.prob_neutral_making_denier = np.random.normal(environment.environment_params['prob_neutral_making_denier'],
|
||||||
environment.standard_variance)
|
environment.environment_params['standard_variance'])
|
||||||
|
|
||||||
self.prob_infect = np.random.normal(environment.prob_infect, environment.standard_variance)
|
self.prob_infect = np.random.normal(environment.environment_params['prob_infect'],
|
||||||
|
environment.environment_params['standard_variance'])
|
||||||
|
|
||||||
self.prob_cured_healing_infected = np.random.normal(environment.prob_cured_healing_infected,
|
self.prob_cured_healing_infected = np.random.normal(environment.environment_params['prob_cured_healing_infected'],
|
||||||
environment.standard_variance)
|
environment.environment_params['standard_variance'])
|
||||||
self.prob_cured_vaccinate_neutral = np.random.normal(environment.prob_cured_vaccinate_neutral,
|
self.prob_cured_vaccinate_neutral = np.random.normal(environment.environment_params['prob_cured_vaccinate_neutral'],
|
||||||
environment.standard_variance)
|
environment.environment_params['standard_variance'])
|
||||||
|
|
||||||
self.prob_vaccinated_healing_infected = np.random.normal(environment.prob_vaccinated_healing_infected,
|
self.prob_vaccinated_healing_infected = np.random.normal(environment.environment_params['prob_vaccinated_healing_infected'],
|
||||||
environment.standard_variance)
|
environment.environment_params['standard_variance'])
|
||||||
self.prob_vaccinated_vaccinate_neutral = np.random.normal(environment.prob_vaccinated_vaccinate_neutral,
|
self.prob_vaccinated_vaccinate_neutral = np.random.normal(environment.environment_params['prob_vaccinated_vaccinate_neutral'],
|
||||||
environment.standard_variance)
|
environment.environment_params['standard_variance'])
|
||||||
self.prob_generate_anti_rumor = np.random.normal(environment.prob_generate_anti_rumor,
|
self.prob_generate_anti_rumor = np.random.normal(environment.environment_params['prob_generate_anti_rumor'],
|
||||||
environment.standard_variance)
|
environment.environment_params['standard_variance'])
|
||||||
|
|
||||||
def step(self, now):
|
def step(self, now):
|
||||||
|
|
||||||
|
@ -32,20 +32,24 @@ class SISaModel(BaseBehaviour):
|
|||||||
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.neutral_discontent_spon_prob = np.random.normal(environment.neutral_discontent_spon_prob,
|
self.neutral_discontent_spon_prob = np.random.normal(environment.environment_params['neutral_discontent_spon_prob'],
|
||||||
environment.standard_variance)
|
environment.environment_params['standard_variance'])
|
||||||
self.neutral_discontent_infected_prob = np.random.normal(environment.neutral_discontent_infected_prob,
|
self.neutral_discontent_infected_prob = np.random.normal(environment.environment_params['neutral_discontent_infected_prob'],
|
||||||
environment.standard_variance)
|
environment.environment_params['standard_variance'])
|
||||||
self.neutral_content_spon_prob = np.random.normal(environment.neutral_content_spon_prob,
|
self.neutral_content_spon_prob = np.random.normal(environment.environment_params['neutral_content_spon_prob'],
|
||||||
environment.standard_variance)
|
environment.environment_params['standard_variance'])
|
||||||
self.neutral_content_infected_prob = np.random.normal(environment.neutral_content_infected_prob,
|
self.neutral_content_infected_prob = np.random.normal(environment.environment_params['neutral_content_infected_prob'],
|
||||||
environment.standard_variance)
|
environment.environment_params['standard_variance'])
|
||||||
|
|
||||||
self.discontent_neutral = np.random.normal(environment.discontent_neutral, environment.standard_variance)
|
self.discontent_neutral = np.random.normal(environment.environment_params['discontent_neutral'],
|
||||||
self.discontent_content = np.random.normal(environment.discontent_content, environment.variance_d_c)
|
environment.environment_params['standard_variance'])
|
||||||
|
self.discontent_content = np.random.normal(environment.environment_params['discontent_content'],
|
||||||
|
environment.environment_params['variance_d_c'])
|
||||||
|
|
||||||
self.content_discontent = np.random.normal(environment.content_discontent, environment.variance_c_d)
|
self.content_discontent = np.random.normal(environment.environment_params['content_discontent'],
|
||||||
self.content_neutral = np.random.normal(environment.content_neutral, environment.standard_variance)
|
environment.environment_params['variance_c_d'])
|
||||||
|
self.content_neutral = np.random.normal(environment.environment_params['content_neutral'],
|
||||||
|
environment.environment_params['standard_variance'])
|
||||||
|
|
||||||
def step(self, now):
|
def step(self, now):
|
||||||
if self.state['id'] == 0:
|
if self.state['id'] == 0:
|
||||||
|
@ -19,11 +19,11 @@ class SentimentCorrelationModel(BaseBehaviour):
|
|||||||
|
|
||||||
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.outside_effects_prob = environment.outside_effects_prob
|
self.outside_effects_prob = environment.environment_params['outside_effects_prob']
|
||||||
self.anger_prob = environment.anger_prob
|
self.anger_prob = environment.environment_params['anger_prob']
|
||||||
self.joy_prob = environment.joy_prob
|
self.joy_prob = environment.environment_params['joy_prob']
|
||||||
self.sadness_prob = environment.sadness_prob
|
self.sadness_prob = environment.environment_params['sadness_prob']
|
||||||
self.disgust_prob = environment.disgust_prob
|
self.disgust_prob = environment.environment_params['disgust_prob']
|
||||||
self.time_awareness = []
|
self.time_awareness = []
|
||||||
for i in range(4): # In this model we have 4 sentiments
|
for i in range(4): # In this model we have 4 sentiments
|
||||||
self.time_awareness.append(0) # 0-> Anger, 1-> joy, 2->sadness, 3 -> disgust
|
self.time_awareness.append(0) # 0-> Anger, 1-> joy, 2->sadness, 3 -> disgust
|
||||||
|
86
settings.py
86
settings.py
@ -7,56 +7,58 @@ max_time = 50
|
|||||||
num_trials = 1
|
num_trials = 1
|
||||||
timeout = 2
|
timeout = 2
|
||||||
|
|
||||||
# Zombie model
|
environment_params = {
|
||||||
bite_prob = 0.01 # 0-1
|
# Zombie model
|
||||||
heal_prob = 0.01 # 0-1
|
'bite_prob': 0.01, # 0-1
|
||||||
|
'heal_prob': 0.01, # 0-1
|
||||||
|
|
||||||
# Bass model
|
# Bass model
|
||||||
innovation_prob = 0.001
|
'innovation_prob': 0.001,
|
||||||
imitation_prob = 0.005
|
'imitation_prob': 0.005,
|
||||||
|
|
||||||
# Sentiment Correlation model
|
# Sentiment Correlation model
|
||||||
outside_effects_prob = 0.2
|
'outside_effects_prob': 0.2,
|
||||||
anger_prob = 0.06
|
'anger_prob': 0.06,
|
||||||
joy_prob = 0.05
|
'joy_prob': 0.05,
|
||||||
sadness_prob = 0.02
|
'sadness_prob': 0.02,
|
||||||
disgust_prob = 0.02
|
'disgust_prob': 0.02,
|
||||||
|
|
||||||
# Big Market model
|
# Big Market model
|
||||||
## Names
|
## Names
|
||||||
enterprises = ["BBVA", "Santander", "Bankia"]
|
'enterprises': ["BBVA", "Santander", "Bankia"],
|
||||||
## Users
|
## Users
|
||||||
tweet_probability_users = 0.44
|
'tweet_probability_users': 0.44,
|
||||||
tweet_relevant_probability = 0.25
|
'tweet_relevant_probability': 0.25,
|
||||||
tweet_probability_about = [0.15, 0.15, 0.15]
|
'tweet_probability_about': [0.15, 0.15, 0.15],
|
||||||
sentiment_about = [0, 0, 0] # Default values
|
'sentiment_about': [0, 0, 0], # Default values
|
||||||
## Enterprises
|
## Enterprises
|
||||||
tweet_probability_enterprises = [0.3, 0.3, 0.3]
|
'tweet_probability_enterprises': [0.3, 0.3, 0.3],
|
||||||
|
|
||||||
# SISa
|
# SISa
|
||||||
neutral_discontent_spon_prob = 0.04
|
'neutral_discontent_spon_prob': 0.04,
|
||||||
neutral_discontent_infected_prob = 0.04
|
'neutral_discontent_infected_prob': 0.04,
|
||||||
neutral_content_spon_prob = 0.18
|
'neutral_content_spon_prob': 0.18,
|
||||||
neutral_content_infected_prob = 0.02
|
'neutral_content_infected_prob': 0.02,
|
||||||
|
|
||||||
discontent_neutral = 0.13
|
'discontent_neutral': 0.13,
|
||||||
discontent_content = 0.07
|
'discontent_content': 0.07,
|
||||||
variance_d_c = 0.02
|
'variance_d_c': 0.02,
|
||||||
|
|
||||||
content_discontent = 0.009
|
'content_discontent': 0.009,
|
||||||
variance_c_d = 0.003
|
'variance_c_d': 0.003,
|
||||||
content_neutral = 0.088
|
'content_neutral': 0.088,
|
||||||
|
|
||||||
standard_variance = 0.055
|
'standard_variance': 0.055,
|
||||||
|
|
||||||
# Spread Model M2 and Control Model M2
|
# Spread Model M2 and Control Model M2
|
||||||
prob_neutral_making_denier = 0.035
|
'prob_neutral_making_denier': 0.035,
|
||||||
|
|
||||||
prob_infect = 0.075
|
'prob_infect': 0.075,
|
||||||
|
|
||||||
prob_cured_healing_infected = 0.035
|
'prob_cured_healing_infected': 0.035,
|
||||||
prob_cured_vaccinate_neutral = 0.035
|
'prob_cured_vaccinate_neutral': 0.035,
|
||||||
|
|
||||||
prob_vaccinated_healing_infected = 0.035
|
'prob_vaccinated_healing_infected': 0.035,
|
||||||
prob_vaccinated_vaccinate_neutral = 0.035
|
'prob_vaccinated_vaccinate_neutral': 0.035,
|
||||||
prob_generate_anti_rumor = 0.035
|
'prob_generate_anti_rumor': 0.035
|
||||||
|
}
|
||||||
|
31
soil.py
31
soil.py
@ -26,8 +26,8 @@ if settings.network_type == 2:
|
|||||||
# Simulation #
|
# Simulation #
|
||||||
##############
|
##############
|
||||||
|
|
||||||
sim = NetworkSimulation(topology=G, states=init_states, agent_type=ControlModelM2,
|
sim = NetworkSimulation(topology=G, states=init_states, agent_type=ControlModelM2, max_time=settings.max_time,
|
||||||
max_time=settings.max_time, num_trials=settings.num_trials, logging_interval=1.0)
|
num_trials=settings.num_trials, logging_interval=1.0, **settings.environment_params)
|
||||||
|
|
||||||
sim.run_simulation()
|
sim.run_simulation()
|
||||||
|
|
||||||
@ -49,14 +49,14 @@ for time in range(0, settings.max_time):
|
|||||||
value_cured = 0
|
value_cured = 0
|
||||||
value_vaccinated = 0
|
value_vaccinated = 0
|
||||||
real_time = time * settings.timeout
|
real_time = time * settings.timeout
|
||||||
activity= False
|
activity = False
|
||||||
for x in range(0, settings.number_of_nodes):
|
for x in range(0, settings.number_of_nodes):
|
||||||
if attribute_plot in models.networkStatus["agent_%s" % x]:
|
if attribute_plot in models.networkStatus["agent_%s" % x]:
|
||||||
if real_time in models.networkStatus["agent_%s" % x][attribute_plot]:
|
if real_time in models.networkStatus["agent_%s" % x][attribute_plot]:
|
||||||
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
|
||||||
@ -72,12 +72,12 @@ for time in range(0, settings.max_time):
|
|||||||
neutral_values.append(value_neutral)
|
neutral_values.append(value_neutral)
|
||||||
cured_values.append(value_cured)
|
cured_values.append(value_cured)
|
||||||
vaccinated_values.append(value_vaccinated)
|
vaccinated_values.append(value_vaccinated)
|
||||||
activity=False
|
activity = False
|
||||||
|
|
||||||
infected_line = plt.plot(x_values,infected_values,label='Infected')
|
infected_line = plt.plot(x_values, infected_values, label='Infected')
|
||||||
neutral_line = plt.plot(x_values,neutral_values, label='Neutral')
|
neutral_line = plt.plot(x_values, neutral_values, label='Neutral')
|
||||||
cured_line = plt.plot(x_values,cured_values, label='Cured')
|
cured_line = plt.plot(x_values, cured_values, label='Cured')
|
||||||
vaccinated_line = plt.plot(x_values,vaccinated_values, label='Vaccinated')
|
vaccinated_line = plt.plot(x_values, vaccinated_values, label='Vaccinated')
|
||||||
plt.legend()
|
plt.legend()
|
||||||
plt.savefig('control_model.png')
|
plt.savefig('control_model.png')
|
||||||
# plt.show()
|
# plt.show()
|
||||||
@ -88,12 +88,12 @@ plt.savefig('control_model.png')
|
|||||||
#################
|
#################
|
||||||
|
|
||||||
for x in range(0, settings.number_of_nodes):
|
for x in range(0, settings.number_of_nodes):
|
||||||
for attribute in models.networkStatus["agent_%s"%x]:
|
for attribute in models.networkStatus["agent_%s" % x]:
|
||||||
emotionStatusAux=[]
|
emotionStatusAux = []
|
||||||
for t_step in models.networkStatus["agent_%s"%x][attribute]:
|
for t_step in models.networkStatus["agent_%s" % x][attribute]:
|
||||||
prec = 2
|
prec = 2
|
||||||
output = math.floor(models.networkStatus["agent_%s"%x][attribute][t_step] * (10 ** prec)) / (10 ** prec) # 2 decimals
|
output = math.floor(models.networkStatus["agent_%s" % x][attribute][t_step] * (10 ** prec)) / (10 ** prec) # 2 decimals
|
||||||
emotionStatusAux.append((output,t_step,None))
|
emotionStatusAux.append((output, t_step,None))
|
||||||
attributes = {}
|
attributes = {}
|
||||||
attributes[attribute] = emotionStatusAux
|
attributes[attribute] = emotionStatusAux
|
||||||
G.add_node(x, attributes)
|
G.add_node(x, attributes)
|
||||||
@ -104,5 +104,4 @@ print("Done!")
|
|||||||
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,"test.gexf", version="1.2draft")
|
nx.write_gexf(G, "test.gexf", version="1.2draft")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user