1
0
mirror of https://github.com/gsi-upm/soil synced 2024-11-22 11:12:29 +00:00

Settings modules

This commit is contained in:
Tasio Mendez 2017-04-21 13:55:42 +02:00
parent dd4ce15a3d
commit f29f5fa5bf
11 changed files with 262 additions and 210 deletions

View File

@ -2,8 +2,6 @@ import settings
from nxsim import BaseNetworkAgent from nxsim import BaseNetworkAgent
from .. import networkStatus from .. import networkStatus
settings.init()
class BaseBehaviour(BaseNetworkAgent): class BaseBehaviour(BaseNetworkAgent):
@ -35,6 +33,6 @@ class BaseBehaviour(BaseNetworkAgent):
for stamp, attrs in self._attrs.items(): for stamp, attrs in self._attrs.items():
for a in attrs: for a in attrs:
if a not in final: if a not in final:
final[a] = {} final[a] = {}
final[a][stamp] = attrs[a] final[a][stamp] = attrs[a]
return final return final

View File

@ -1,10 +1,7 @@
import settings
import random import random
from ..BaseBehaviour import * from ..BaseBehaviour import *
from .. import sentimentCorrelationNodeArray from .. import sentimentCorrelationNodeArray
settings.init()
class BassModel(BaseBehaviour): class BassModel(BaseBehaviour):
""" """
@ -16,9 +13,9 @@ 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 = settings.innovation_prob self.innovation_prob = environment.innovation_prob
self.imitation_prob = settings.imitation_prob self.imitation_prob = environment.imitation_prob
sentimentCorrelationNodeArray[self.id][self.env.now]=0 sentimentCorrelationNodeArray[self.id][self.env.now] = 0
def step(self, now): def step(self, now):
self.behaviour() self.behaviour()
@ -26,10 +23,10 @@ class BassModel(BaseBehaviour):
def behaviour(self): def behaviour(self):
# Outside effects # Outside effects
if random.random() < settings.innovation_prob: if random.random() < self.innovation_prob:
if self.state['id'] == 0: if self.state['id'] == 0:
self.state['id'] = 1 self.state['id'] = 1
sentimentCorrelationNodeArray[self.id][self.env.now]=1 sentimentCorrelationNodeArray[self.id][self.env.now] = 1
else: else:
pass pass
@ -40,9 +37,9 @@ class BassModel(BaseBehaviour):
if self.state['id'] == 0: if self.state['id'] == 0:
aware_neighbors = self.get_neighboring_agents(state_id=1) aware_neighbors = self.get_neighboring_agents(state_id=1)
num_neighbors_aware = len(aware_neighbors) num_neighbors_aware = len(aware_neighbors)
if random.random() < (settings.imitation_prob*num_neighbors_aware): if random.random() < (self.imitation_prob*num_neighbors_aware):
self.state['id'] = 1 self.state['id'] = 1
sentimentCorrelationNodeArray[self.id][self.env.now]=1 sentimentCorrelationNodeArray[self.id][self.env.now] = 1
else: else:
pass pass

View File

@ -1,9 +1,6 @@
import settings
import random import random
from ..BaseBehaviour import * from ..BaseBehaviour import *
settings.init()
class BigMarketModel(BaseBehaviour): class BigMarketModel(BaseBehaviour):
""" """
@ -22,45 +19,44 @@ class BigMarketModel(BaseBehaviour):
sentiment_about [Array] sentiment_about [Array]
""" """
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 = settings.enterprises self.enterprises = environment.enterprises
self.type = "" self.type = ""
self.number_of_enterprises = len(settings.enterprises) self.number_of_enterprises = len(environment.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 = settings.tweet_probability_enterprises[self.id] self.tweet_probability = environment.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 = settings.tweet_probability_users self.tweet_probability = environment.tweet_probability_users
self.tweet_relevant_probability = settings.tweet_relevant_probability self.tweet_relevant_probability = environment.tweet_relevant_probability
self.tweet_probability_about = settings.tweet_probability_about # List self.tweet_probability_about = environment.tweet_probability_about # List
self.sentiment_about = settings.sentiment_about # List self.sentiment_about = environment.sentiment_about # List
def step(self, now): def step(self, now):
if(self.id < self.number_of_enterprises): # Enterprise if self.id < self.number_of_enterprises: # Enterprise
self.enterpriseBehaviour() self.enterpriseBehaviour()
else: # Usuario else: # Usuario
self.userBehaviour() self.userBehaviour()
for i in range(self.number_of_enterprises): # So that it never is set to 0 if there are not changes (logs) for i in range(self.number_of_enterprises): # So that it never is set to 0 if there are not changes (logs)
self.attrs['sentiment_enterprise_%s'% self.enterprises[i]] = self.sentiment_about[i] self.attrs['sentiment_enterprise_%s'% self.enterprises[i]] = self.sentiment_about[i]
super().step(now) super().step(now)
def enterpriseBehaviour(self): def enterpriseBehaviour(self):
if random.random()< self.tweet_probability: # Tweets if random.random()< self.tweet_probability: # Tweets
aware_neighbors = self.get_neighboring_agents(state_id=self.number_of_enterprises) #Nodes neighbour users aware_neighbors = self.get_neighboring_agents(state_id=self.number_of_enterprises) # Nodes neighbour users
for x in aware_neighbors: for x in aware_neighbors:
if random.uniform(0,10) < 5: if random.uniform(0,10) < 5:
x.sentiment_about[self.id] += 0.1 # Increments for enterprise x.sentiment_about[self.id] += 0.1 # Increments for enterprise
else: else:
x.sentiment_about[self.id] -= 0.1 # Decrements for enterprise x.sentiment_about[self.id] -= 0.1 # Decrements for enterprise
# Establecemos limites # Establecemos limites
if x.sentiment_about[self.id] > 1: if x.sentiment_about[self.id] > 1:
@ -72,8 +68,8 @@ class BigMarketModel(BaseBehaviour):
def userBehaviour(self): def userBehaviour(self):
if random.random() < self.tweet_probability: # Tweets if random.random() < self.tweet_probability: # Tweets
if random.random() < self.tweet_relevant_probability: # Tweets something relevant if random.random() < self.tweet_relevant_probability: # Tweets something relevant
# Tweet probability per enterprise # Tweet probability per enterprise
for i in range(self.number_of_enterprises): for i in range(self.number_of_enterprises):
random_num = random.random() random_num = random.random()
@ -90,7 +86,7 @@ class BigMarketModel(BaseBehaviour):
self.userTweets("positive",i) self.userTweets("positive",i)
def userTweets(self,sentiment,enterprise): def userTweets(self,sentiment,enterprise):
aware_neighbors = self.get_neighboring_agents(state_id=self.number_of_enterprises) #Nodes neighbours users aware_neighbors = self.get_neighboring_agents(state_id=self.number_of_enterprises) # Nodes neighbours users
for x in aware_neighbors: for x in aware_neighbors:
if sentiment == "positive": if sentiment == "positive":
x.sentiment_about[enterprise] +=0.003 x.sentiment_about[enterprise] +=0.003

View File

@ -1,10 +1,7 @@
import settings
import random import random
import numpy as np import numpy as np
from ..BaseBehaviour import * from ..BaseBehaviour import *
settings.init()
class SISaModel(BaseBehaviour): class SISaModel(BaseBehaviour):
""" """
@ -35,19 +32,20 @@ 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(settings.neutral_discontent_spon_prob, self.neutral_discontent_spon_prob = np.random.normal(environment.neutral_discontent_spon_prob,
settings.standard_variance) environment.standard_variance)
self.neutral_discontent_infected_prob = np.random.normal(settings.neutral_discontent_infected_prob, self.neutral_discontent_infected_prob = np.random.normal(environment.neutral_discontent_infected_prob,
settings.standard_variance) environment.standard_variance)
self.neutral_content_spon_prob = np.random.normal(settings.neutral_content_spon_prob, settings.standard_variance) self.neutral_content_spon_prob = np.random.normal(environment.neutral_content_spon_prob,
self.neutral_content_infected_prob = np.random.normal(settings.neutral_content_infected_prob, environment.standard_variance)
settings.standard_variance) self.neutral_content_infected_prob = np.random.normal(environment.neutral_content_infected_prob,
environment.standard_variance)
self.discontent_neutral = np.random.normal(settings.discontent_neutral, settings.standard_variance) self.discontent_neutral = np.random.normal(environment.discontent_neutral, environment.standard_variance)
self.discontent_content = np.random.normal(settings.discontent_content, settings.variance_d_c) self.discontent_content = np.random.normal(environment.discontent_content, environment.variance_d_c)
self.content_discontent = np.random.normal(settings.content_discontent, settings.variance_c_d) self.content_discontent = np.random.normal(environment.content_discontent, environment.variance_c_d)
self.content_neutral = np.random.normal(settings.content_neutral, settings.standard_variance) self.content_neutral = np.random.normal(environment.content_neutral, environment.standard_variance)
def step(self, now): def step(self, now):
if self.state['id'] == 0: if self.state['id'] == 0:

View File

@ -1,10 +1,7 @@
import settings
import random import random
from ..BaseBehaviour import * from ..BaseBehaviour import *
from .. import sentimentCorrelationNodeArray from .. import sentimentCorrelationNodeArray
settings.init()
class IndependentCascadeModel(BaseBehaviour): class IndependentCascadeModel(BaseBehaviour):
""" """
@ -16,23 +13,23 @@ 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 = settings.innovation_prob self.innovation_prob = environment.innovation_prob
self.imitation_prob = settings.imitation_prob self.imitation_prob = environment.imitation_prob
self.time_awareness = 0 self.time_awareness = 0
sentimentCorrelationNodeArray[self.id][self.env.now]=0 sentimentCorrelationNodeArray[self.id][self.env.now] = 0
def step(self,now): def step(self, now):
self.behaviour() self.behaviour()
super().step(now) super().step(now)
def behaviour(self): def behaviour(self):
aware_neighbors_1_time_step=[] aware_neighbors_1_time_step = []
# Outside effects # Outside effects
if random.random() < settings.innovation_prob: if random.random() < self.innovation_prob:
if self.state['id'] == 0: if self.state['id'] == 0:
self.state['id'] = 1 self.state['id'] = 1
sentimentCorrelationNodeArray[self.id][self.env.now]=1 sentimentCorrelationNodeArray[self.id][self.env.now] = 1
self.time_awareness = self.env.now #To know when they have been infected self.time_awareness = self.env.now # To know when they have been infected
else: else:
pass pass
@ -46,9 +43,9 @@ class IndependentCascadeModel(BaseBehaviour):
if x.time_awareness == (self.env.now-1): if x.time_awareness == (self.env.now-1):
aware_neighbors_1_time_step.append(x) aware_neighbors_1_time_step.append(x)
num_neighbors_aware = len(aware_neighbors_1_time_step) num_neighbors_aware = len(aware_neighbors_1_time_step)
if random.random() < (settings.imitation_prob*num_neighbors_aware): if random.random() < (self.imitation_prob*num_neighbors_aware):
self.state['id'] = 1 self.state['id'] = 1
sentimentCorrelationNodeArray[self.id][self.env.now]=1 sentimentCorrelationNodeArray[self.id][self.env.now] = 1
else: else:
pass pass

View File

@ -4,8 +4,6 @@ import numpy as np
from ..BaseBehaviour import * from ..BaseBehaviour import *
from .. import init_states from .. import init_states
settings.init()
class ControlModelM2(BaseBehaviour): class ControlModelM2(BaseBehaviour):
""" """
@ -36,16 +34,22 @@ 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(settings.prob_neutral_making_denier, settings.standard_variance) self.prob_neutral_making_denier = np.random.normal(environment.prob_neutral_making_denier,
environment.standard_variance)
self.prob_infect = np.random.normal(settings.prob_infect, settings.standard_variance) self.prob_infect = np.random.normal(environment.prob_infect, environment.standard_variance)
self.prob_cured_healing_infected = np.random.normal(settings.prob_cured_healing_infected, settings.standard_variance) self.prob_cured_healing_infected = np.random.normal(environment.prob_cured_healing_infected,
self.prob_cured_vaccinate_neutral = np.random.normal(settings.prob_cured_vaccinate_neutral, settings.standard_variance) environment.standard_variance)
self.prob_cured_vaccinate_neutral = np.random.normal(environment.prob_cured_vaccinate_neutral,
environment.standard_variance)
self.prob_vaccinated_healing_infected = np.random.normal(settings.prob_vaccinated_healing_infected, settings.standard_variance) self.prob_vaccinated_healing_infected = np.random.normal(environment.prob_vaccinated_healing_infected,
self.prob_vaccinated_vaccinate_neutral = np.random.normal(settings.prob_vaccinated_vaccinate_neutral, settings.standard_variance) environment.standard_variance)
self.prob_generate_anti_rumor = np.random.normal(settings.prob_generate_anti_rumor, settings.standard_variance) self.prob_vaccinated_vaccinate_neutral = np.random.normal(environment.prob_vaccinated_vaccinate_neutral,
environment.standard_variance)
self.prob_generate_anti_rumor = np.random.normal(environment.prob_generate_anti_rumor,
environment.standard_variance)
def step(self, now): def step(self, now):
@ -69,7 +73,7 @@ class ControlModelM2(BaseBehaviour):
# Infected # Infected
infected_neighbors = self.get_neighboring_agents(state_id=1) infected_neighbors = self.get_neighboring_agents(state_id=1)
if len(infected_neighbors)>0: if len(infected_neighbors) > 0:
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

View File

@ -4,8 +4,6 @@ import numpy as np
from ..BaseBehaviour import * from ..BaseBehaviour import *
from .. import init_states from .. import init_states
settings.init()
class SpreadModelM2(BaseBehaviour): class SpreadModelM2(BaseBehaviour):
""" """
@ -25,22 +23,28 @@ class SpreadModelM2(BaseBehaviour):
prob_generate_anti_rumor prob_generate_anti_rumor
""" """
init_states[random.randint(0, settings.number_of_nodes)] = {'id':1} init_states[random.randint(0, settings.number_of_nodes)] = {'id': 1}
init_states[random.randint(0, settings.number_of_nodes)] = {'id':1} init_states[random.randint(0, settings.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(settings.prob_neutral_making_denier, settings.standard_variance) self.prob_neutral_making_denier = np.random.normal(environment.prob_neutral_making_denier,
environment.standard_variance)
self.prob_infect = np.random.normal(settings.prob_infect, settings.standard_variance) self.prob_infect = np.random.normal(environment.prob_infect, environment.standard_variance)
self.prob_cured_healing_infected = np.random.normal(settings.prob_cured_healing_infected, settings.standard_variance) self.prob_cured_healing_infected = np.random.normal(environment.prob_cured_healing_infected,
self.prob_cured_vaccinate_neutral = np.random.normal(settings.prob_cured_vaccinate_neutral, settings.standard_variance) environment.standard_variance)
self.prob_cured_vaccinate_neutral = np.random.normal(environment.prob_cured_vaccinate_neutral,
environment.standard_variance)
self.prob_vaccinated_healing_infected = np.random.normal(settings.prob_vaccinated_healing_infected, settings.standard_variance) self.prob_vaccinated_healing_infected = np.random.normal(environment.prob_vaccinated_healing_infected,
self.prob_vaccinated_vaccinate_neutral = np.random.normal(settings.prob_vaccinated_vaccinate_neutral, settings.standard_variance) environment.standard_variance)
self.prob_generate_anti_rumor = np.random.normal(settings.prob_generate_anti_rumor, settings.standard_variance) self.prob_vaccinated_vaccinate_neutral = np.random.normal(environment.prob_vaccinated_vaccinate_neutral,
environment.standard_variance)
self.prob_generate_anti_rumor = np.random.normal(environment.prob_generate_anti_rumor,
environment.standard_variance)
def step(self, now): def step(self, now):
@ -60,7 +64,7 @@ class SpreadModelM2(BaseBehaviour):
# Infected # Infected
infected_neighbors = self.get_neighboring_agents(state_id=1) infected_neighbors = self.get_neighboring_agents(state_id=1)
if len(infected_neighbors)>0: if len(infected_neighbors) > 0:
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

View File

@ -1,10 +1,7 @@
import settings
import random import random
from ..BaseBehaviour import * from ..BaseBehaviour import *
from .. import sentimentCorrelationNodeArray from .. import sentimentCorrelationNodeArray
settings.init()
class SentimentCorrelationModel(BaseBehaviour): class SentimentCorrelationModel(BaseBehaviour):
""" """
@ -22,15 +19,15 @@ 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 = settings.outside_effects_prob self.outside_effects_prob = environment.outside_effects_prob
self.anger_prob = settings.anger_prob self.anger_prob = environment.anger_prob
self.joy_prob = settings.joy_prob self.joy_prob = environment.joy_prob
self.sadness_prob = settings.sadness_prob self.sadness_prob = environment.sadness_prob
self.disgust_prob = settings.disgust_prob self.disgust_prob = environment.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
sentimentCorrelationNodeArray[self.id][self.env.now]=0 sentimentCorrelationNodeArray[self.id][self.env.now] = 0
def step(self, now): def step(self, now):
self.behaviour() self.behaviour()
@ -38,10 +35,10 @@ class SentimentCorrelationModel(BaseBehaviour):
def behaviour(self): def behaviour(self):
angry_neighbors_1_time_step=[] angry_neighbors_1_time_step = []
joyful_neighbors_1_time_step=[] joyful_neighbors_1_time_step = []
sad_neighbors_1_time_step=[] sad_neighbors_1_time_step = []
disgusted_neighbors_1_time_step=[] disgusted_neighbors_1_time_step = []
angry_neighbors = self.get_neighboring_agents(state_id=1) angry_neighbors = self.get_neighboring_agents(state_id=1)
for x in angry_neighbors: for x in angry_neighbors:
@ -67,18 +64,18 @@ class SentimentCorrelationModel(BaseBehaviour):
disgusted_neighbors_1_time_step.append(x) disgusted_neighbors_1_time_step.append(x)
num_neighbors_disgusted = len(disgusted_neighbors_1_time_step) num_neighbors_disgusted = len(disgusted_neighbors_1_time_step)
anger_prob= settings.anger_prob+(len(angry_neighbors_1_time_step)*settings.anger_prob) anger_prob = self.anger_prob+(len(angry_neighbors_1_time_step)*self.anger_prob)
joy_prob= settings.joy_prob+(len(joyful_neighbors_1_time_step)*settings.joy_prob) joy_prob = self.joy_prob+(len(joyful_neighbors_1_time_step)*self.joy_prob)
sadness_prob = settings.sadness_prob+(len(sad_neighbors_1_time_step)*settings.sadness_prob) sadness_prob = self.sadness_prob+(len(sad_neighbors_1_time_step)*self.sadness_prob)
disgust_prob = settings.disgust_prob+(len(disgusted_neighbors_1_time_step)*settings.disgust_prob) disgust_prob = self.disgust_prob+(len(disgusted_neighbors_1_time_step)*self.disgust_prob)
outside_effects_prob= settings.outside_effects_prob outside_effects_prob = self.outside_effects_prob
num = random.random() num = random.random()
if(num<outside_effects_prob): if num<outside_effects_prob:
self.state['id'] = random.randint(1,4) self.state['id'] = random.randint(1,4)
sentimentCorrelationNodeArray[self.id][self.env.now]=self.state['id'] #It is stored when it has been infected for the dynamic network sentimentCorrelationNodeArray[self.id][self.env.now]=self.state['id'] # It is stored when it has been infected for the dynamic network
self.time_awareness[self.state['id']-1] = self.env.now self.time_awareness[self.state['id']-1] = self.env.now
self.attrs['sentiment'] = self.state['id'] self.attrs['sentiment'] = self.state['id']
@ -95,13 +92,11 @@ class SentimentCorrelationModel(BaseBehaviour):
self.time_awareness[self.state['id']-1] = self.env.now self.time_awareness[self.state['id']-1] = self.env.now
elif (num<sadness_prob+anger_prob+joy_prob and num>joy_prob+anger_prob): elif (num<sadness_prob+anger_prob+joy_prob and num>joy_prob+anger_prob):
self.state['id'] = 3 self.state['id'] = 3
sentimentCorrelationNodeArray[self.id][self.env.now]=3 sentimentCorrelationNodeArray[self.id][self.env.now]=3
self.time_awareness[self.state['id']-1] = self.env.now self.time_awareness[self.state['id']-1] = self.env.now
elif (num<disgust_prob+sadness_prob+anger_prob+joy_prob and num>sadness_prob+anger_prob+joy_prob): elif (num<disgust_prob+sadness_prob+anger_prob+joy_prob and num>sadness_prob+anger_prob+joy_prob):
self.state['id'] = 4 self.state['id'] = 4
sentimentCorrelationNodeArray[self.id][self.env.now]=4 sentimentCorrelationNodeArray[self.id][self.env.now]=4
self.time_awareness[self.state['id']-1] = self.env.now self.time_awareness[self.state['id']-1] = self.env.now

View File

@ -1,103 +1,62 @@
# settings.py # General configuration
def init():
global number_of_nodes
global max_time
global num_trials
global bite_prob
global network_type
global heal_prob
global innovation_prob
global imitation_prob
global timeout
global outside_effects_prob
global anger_prob
global joy_prob
global sadness_prob
global disgust_prob
global tweet_probability_users
global tweet_relevant_probability
global tweet_probability_about
global sentiment_about
global tweet_probability_enterprises
global enterprises
global neutral_discontent_spon_prob
global neutral_discontent_infected_prob
global neutral_content_spon_prob
global neutral_content_infected_prob
global discontent_content
global discontent_neutral
global content_discontent
global content_neutral
global variance_d_c
global variance_c_d
global standard_variance
global prob_neutral_making_denier
global prob_infect
global prob_cured_healing_infected
global prob_cured_vaccinate_neutral
global prob_vaccinated_healing_infected
global prob_vaccinated_vaccinate_neutral
global prob_generate_anti_rumor
network_type=1 # Network settings
number_of_nodes=1000 network_type = 1
max_time=50 number_of_nodes = 1000
num_trials=1 max_time = 50
timeout=2 num_trials = 1
timeout = 2
#Zombie model # Zombie model
bite_prob=0.01 # 0-1 bite_prob = 0.01 # 0-1
heal_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_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
prob_infect = 0.075
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

104
settings_org.py Normal file
View File

@ -0,0 +1,104 @@
# settings.py
def init():
global number_of_nodes
global max_time
global num_trials
global bite_prob
global timeout
global network_type
global heal_prob
global innovation_prob
global imitation_prob
global outside_effects_prob
global anger_prob
global joy_prob
global sadness_prob
global disgust_prob
global tweet_probability_users
global tweet_relevant_probability
global tweet_probability_about
global sentiment_about
global tweet_probability_enterprises
global enterprises
global neutral_discontent_spon_prob
global neutral_discontent_infected_prob
global neutral_content_spon_prob
global neutral_content_infected_prob
global discontent_content
global discontent_neutral
global content_discontent
global content_neutral
global variance_d_c
global variance_c_d
global standard_variance
global prob_neutral_making_denier
global prob_infect
global prob_cured_healing_infected
global prob_cured_vaccinate_neutral
global prob_vaccinated_healing_infected
global prob_vaccinated_vaccinate_neutral
global prob_generate_anti_rumor
# Network settings
network_type = 1
number_of_nodes = 1000
max_time = 50
num_trials = 1
timeout = 2
# Zombie model
bite_prob = 0.01 # 0-1
heal_prob = 0.01 # 0-1
# Bass model
innovation_prob = 0.001
imitation_prob = 0.005
# Sentiment Correlation model
outside_effects_prob = 0.2
anger_prob = 0.06
joy_prob = 0.05
sadness_prob = 0.02
disgust_prob = 0.02
# Big Market model
## Names
enterprises = ["BBVA", "Santander", "Bankia"]
## Users
tweet_probability_users = 0.44
tweet_relevant_probability = 0.25
tweet_probability_about = [0.15, 0.15, 0.15]
sentiment_about = [0, 0, 0] # Default values
## Enterprises
tweet_probability_enterprises = [0.3, 0.3, 0.3]
# SISa
neutral_discontent_spon_prob = 0.04
neutral_discontent_infected_prob = 0.04
neutral_content_spon_prob = 0.18
neutral_content_infected_prob = 0.02
discontent_neutral = 0.13
discontent_content = 0.07
variance_d_c = 0.02
content_discontent = 0.009
variance_c_d = 0.003
content_neutral = 0.088
standard_variance = 0.055
# Spread Model M2 and Control Model M2
prob_neutral_making_denier = 0.035
prob_infect = 0.075
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

20
soil.py
View File

@ -8,7 +8,6 @@ import models
import math import math
import json import json
settings.init() # Loads all the data from settings
#################### ####################
# Network creation # # Network creation #
@ -17,11 +16,12 @@ settings.init() # Loads all the data from settings
if settings.network_type == 0: if settings.network_type == 0:
G = nx.complete_graph(settings.number_of_nodes) G = nx.complete_graph(settings.number_of_nodes)
if settings.network_type == 1: if settings.network_type == 1:
G = nx.barabasi_albert_graph(settings.number_of_nodes,10) G = nx.barabasi_albert_graph(settings.number_of_nodes, 10)
if settings.network_type == 2: if settings.network_type == 2:
G = nx.margulis_gabber_galil_graph(settings.number_of_nodes, None) G = nx.margulis_gabber_galil_graph(settings.number_of_nodes, None)
# More types of networks can be added here # More types of networks can be added here
############## ##############
# Simulation # # Simulation #
############## ##############
@ -29,12 +29,13 @@ if settings.network_type == 2:
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, num_trials=settings.num_trials, logging_interval=1.0) max_time=settings.max_time, num_trials=settings.num_trials, logging_interval=1.0)
sim.run_simulation() sim.run_simulation()
########### ###########
# Results # # Results #
########### ###########
x_values = [] x_values = []
infected_values = [] infected_values = []
neutral_values = [] neutral_values = []
@ -52,16 +53,16 @@ for time in range(0, settings.max_time):
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
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
@ -79,20 +80,19 @@ 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()
################# #################
# Visualization # # Visualization #
################# #################
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