mirror of
https://github.com/gsi-upm/soil
synced 2024-11-13 23:12:28 +00:00
Settings modules
This commit is contained in:
parent
dd4ce15a3d
commit
f29f5fa5bf
@ -2,8 +2,6 @@ import settings
|
||||
from nxsim import BaseNetworkAgent
|
||||
from .. import networkStatus
|
||||
|
||||
settings.init()
|
||||
|
||||
|
||||
class BaseBehaviour(BaseNetworkAgent):
|
||||
|
||||
|
@ -1,10 +1,7 @@
|
||||
import settings
|
||||
import random
|
||||
from ..BaseBehaviour import *
|
||||
from .. import sentimentCorrelationNodeArray
|
||||
|
||||
settings.init()
|
||||
|
||||
|
||||
class BassModel(BaseBehaviour):
|
||||
"""
|
||||
@ -16,9 +13,9 @@ class BassModel(BaseBehaviour):
|
||||
|
||||
def __init__(self, environment=None, agent_id=0, state=()):
|
||||
super().__init__(environment=environment, agent_id=agent_id, state=state)
|
||||
self.innovation_prob = settings.innovation_prob
|
||||
self.imitation_prob = settings.imitation_prob
|
||||
sentimentCorrelationNodeArray[self.id][self.env.now]=0
|
||||
self.innovation_prob = environment.innovation_prob
|
||||
self.imitation_prob = environment.imitation_prob
|
||||
sentimentCorrelationNodeArray[self.id][self.env.now] = 0
|
||||
|
||||
def step(self, now):
|
||||
self.behaviour()
|
||||
@ -26,10 +23,10 @@ class BassModel(BaseBehaviour):
|
||||
|
||||
def behaviour(self):
|
||||
# Outside effects
|
||||
if random.random() < settings.innovation_prob:
|
||||
if random.random() < self.innovation_prob:
|
||||
if self.state['id'] == 0:
|
||||
self.state['id'] = 1
|
||||
sentimentCorrelationNodeArray[self.id][self.env.now]=1
|
||||
sentimentCorrelationNodeArray[self.id][self.env.now] = 1
|
||||
else:
|
||||
pass
|
||||
|
||||
@ -40,9 +37,9 @@ class BassModel(BaseBehaviour):
|
||||
if self.state['id'] == 0:
|
||||
aware_neighbors = self.get_neighboring_agents(state_id=1)
|
||||
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
|
||||
sentimentCorrelationNodeArray[self.id][self.env.now]=1
|
||||
sentimentCorrelationNodeArray[self.id][self.env.now] = 1
|
||||
|
||||
else:
|
||||
pass
|
||||
|
@ -1,9 +1,6 @@
|
||||
import settings
|
||||
import random
|
||||
from ..BaseBehaviour import *
|
||||
|
||||
settings.init()
|
||||
|
||||
|
||||
class BigMarketModel(BaseBehaviour):
|
||||
"""
|
||||
@ -22,28 +19,27 @@ class BigMarketModel(BaseBehaviour):
|
||||
sentiment_about [Array]
|
||||
"""
|
||||
|
||||
|
||||
def __init__(self, environment=None, agent_id=0, state=()):
|
||||
super().__init__(environment=environment, agent_id=agent_id, state=state)
|
||||
self.enterprises = settings.enterprises
|
||||
self.enterprises = environment.enterprises
|
||||
self.type = ""
|
||||
self.number_of_enterprises = len(settings.enterprises)
|
||||
self.number_of_enterprises = len(environment.enterprises)
|
||||
|
||||
if self.id < self.number_of_enterprises: # Enterprises
|
||||
self.state['id']=self.id
|
||||
self.type="Enterprise"
|
||||
self.tweet_probability = settings.tweet_probability_enterprises[self.id]
|
||||
self.tweet_probability = environment.tweet_probability_enterprises[self.id]
|
||||
else: # normal users
|
||||
self.state['id']=self.number_of_enterprises
|
||||
self.type="User"
|
||||
self.tweet_probability = settings.tweet_probability_users
|
||||
self.tweet_relevant_probability = settings.tweet_relevant_probability
|
||||
self.tweet_probability_about = settings.tweet_probability_about # List
|
||||
self.sentiment_about = settings.sentiment_about # List
|
||||
self.tweet_probability = environment.tweet_probability_users
|
||||
self.tweet_relevant_probability = environment.tweet_relevant_probability
|
||||
self.tweet_probability_about = environment.tweet_probability_about # List
|
||||
self.sentiment_about = environment.sentiment_about # List
|
||||
|
||||
def step(self, now):
|
||||
|
||||
if(self.id < self.number_of_enterprises): # Enterprise
|
||||
if self.id < self.number_of_enterprises: # Enterprise
|
||||
self.enterpriseBehaviour()
|
||||
else: # Usuario
|
||||
self.userBehaviour()
|
||||
@ -55,7 +51,7 @@ class BigMarketModel(BaseBehaviour):
|
||||
def enterpriseBehaviour(self):
|
||||
|
||||
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:
|
||||
if random.uniform(0,10) < 5:
|
||||
x.sentiment_about[self.id] += 0.1 # Increments for enterprise
|
||||
@ -90,7 +86,7 @@ class BigMarketModel(BaseBehaviour):
|
||||
self.userTweets("positive",i)
|
||||
|
||||
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:
|
||||
if sentiment == "positive":
|
||||
x.sentiment_about[enterprise] +=0.003
|
||||
|
@ -1,10 +1,7 @@
|
||||
import settings
|
||||
import random
|
||||
import numpy as np
|
||||
from ..BaseBehaviour import *
|
||||
|
||||
settings.init()
|
||||
|
||||
|
||||
class SISaModel(BaseBehaviour):
|
||||
"""
|
||||
@ -35,19 +32,20 @@ class SISaModel(BaseBehaviour):
|
||||
def __init__(self, environment=None, agent_id=0, state=()):
|
||||
super().__init__(environment=environment, agent_id=agent_id, state=state)
|
||||
|
||||
self.neutral_discontent_spon_prob = np.random.normal(settings.neutral_discontent_spon_prob,
|
||||
settings.standard_variance)
|
||||
self.neutral_discontent_infected_prob = np.random.normal(settings.neutral_discontent_infected_prob,
|
||||
settings.standard_variance)
|
||||
self.neutral_content_spon_prob = np.random.normal(settings.neutral_content_spon_prob, settings.standard_variance)
|
||||
self.neutral_content_infected_prob = np.random.normal(settings.neutral_content_infected_prob,
|
||||
settings.standard_variance)
|
||||
self.neutral_discontent_spon_prob = np.random.normal(environment.neutral_discontent_spon_prob,
|
||||
environment.standard_variance)
|
||||
self.neutral_discontent_infected_prob = np.random.normal(environment.neutral_discontent_infected_prob,
|
||||
environment.standard_variance)
|
||||
self.neutral_content_spon_prob = np.random.normal(environment.neutral_content_spon_prob,
|
||||
environment.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_content = np.random.normal(settings.discontent_content, settings.variance_d_c)
|
||||
self.discontent_neutral = np.random.normal(environment.discontent_neutral, environment.standard_variance)
|
||||
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_neutral = np.random.normal(settings.content_neutral, settings.standard_variance)
|
||||
self.content_discontent = np.random.normal(environment.content_discontent, environment.variance_c_d)
|
||||
self.content_neutral = np.random.normal(environment.content_neutral, environment.standard_variance)
|
||||
|
||||
def step(self, now):
|
||||
if self.state['id'] == 0:
|
||||
|
@ -1,10 +1,7 @@
|
||||
import settings
|
||||
import random
|
||||
from ..BaseBehaviour import *
|
||||
from .. import sentimentCorrelationNodeArray
|
||||
|
||||
settings.init()
|
||||
|
||||
|
||||
class IndependentCascadeModel(BaseBehaviour):
|
||||
"""
|
||||
@ -16,23 +13,23 @@ class IndependentCascadeModel(BaseBehaviour):
|
||||
|
||||
def __init__(self, environment=None, agent_id=0, state=()):
|
||||
super().__init__(environment=environment, agent_id=agent_id, state=state)
|
||||
self.innovation_prob = settings.innovation_prob
|
||||
self.imitation_prob = settings.imitation_prob
|
||||
self.innovation_prob = environment.innovation_prob
|
||||
self.imitation_prob = environment.imitation_prob
|
||||
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()
|
||||
super().step(now)
|
||||
|
||||
def behaviour(self):
|
||||
aware_neighbors_1_time_step=[]
|
||||
aware_neighbors_1_time_step = []
|
||||
# Outside effects
|
||||
if random.random() < settings.innovation_prob:
|
||||
if random.random() < self.innovation_prob:
|
||||
if self.state['id'] == 0:
|
||||
self.state['id'] = 1
|
||||
sentimentCorrelationNodeArray[self.id][self.env.now]=1
|
||||
self.time_awareness = self.env.now #To know when they have been infected
|
||||
sentimentCorrelationNodeArray[self.id][self.env.now] = 1
|
||||
self.time_awareness = self.env.now # To know when they have been infected
|
||||
else:
|
||||
pass
|
||||
|
||||
@ -46,9 +43,9 @@ class IndependentCascadeModel(BaseBehaviour):
|
||||
if x.time_awareness == (self.env.now-1):
|
||||
aware_neighbors_1_time_step.append(x)
|
||||
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
|
||||
sentimentCorrelationNodeArray[self.id][self.env.now]=1
|
||||
sentimentCorrelationNodeArray[self.id][self.env.now] = 1
|
||||
else:
|
||||
pass
|
||||
|
||||
|
@ -4,8 +4,6 @@ import numpy as np
|
||||
from ..BaseBehaviour import *
|
||||
from .. import init_states
|
||||
|
||||
settings.init()
|
||||
|
||||
|
||||
class ControlModelM2(BaseBehaviour):
|
||||
"""
|
||||
@ -36,16 +34,22 @@ class ControlModelM2(BaseBehaviour):
|
||||
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(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_vaccinate_neutral = np.random.normal(settings.prob_cured_vaccinate_neutral, settings.standard_variance)
|
||||
self.prob_cured_healing_infected = np.random.normal(environment.prob_cured_healing_infected,
|
||||
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_vaccinate_neutral = np.random.normal(settings.prob_vaccinated_vaccinate_neutral, settings.standard_variance)
|
||||
self.prob_generate_anti_rumor = np.random.normal(settings.prob_generate_anti_rumor, settings.standard_variance)
|
||||
self.prob_vaccinated_healing_infected = np.random.normal(environment.prob_vaccinated_healing_infected,
|
||||
environment.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):
|
||||
|
||||
@ -69,7 +73,7 @@ class ControlModelM2(BaseBehaviour):
|
||||
|
||||
# Infected
|
||||
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:
|
||||
self.state['id'] = 3 # Vaccinated making denier
|
||||
|
||||
|
@ -4,8 +4,6 @@ import numpy as np
|
||||
from ..BaseBehaviour import *
|
||||
from .. import init_states
|
||||
|
||||
settings.init()
|
||||
|
||||
|
||||
class SpreadModelM2(BaseBehaviour):
|
||||
"""
|
||||
@ -25,22 +23,28 @@ class SpreadModelM2(BaseBehaviour):
|
||||
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=()):
|
||||
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_vaccinate_neutral = np.random.normal(settings.prob_cured_vaccinate_neutral, settings.standard_variance)
|
||||
self.prob_cured_healing_infected = np.random.normal(environment.prob_cured_healing_infected,
|
||||
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_vaccinate_neutral = np.random.normal(settings.prob_vaccinated_vaccinate_neutral, settings.standard_variance)
|
||||
self.prob_generate_anti_rumor = np.random.normal(settings.prob_generate_anti_rumor, settings.standard_variance)
|
||||
self.prob_vaccinated_healing_infected = np.random.normal(environment.prob_vaccinated_healing_infected,
|
||||
environment.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):
|
||||
|
||||
@ -60,7 +64,7 @@ class SpreadModelM2(BaseBehaviour):
|
||||
|
||||
# Infected
|
||||
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:
|
||||
self.state['id'] = 3 # Vaccinated making denier
|
||||
|
||||
|
@ -1,10 +1,7 @@
|
||||
import settings
|
||||
import random
|
||||
from ..BaseBehaviour import *
|
||||
from .. import sentimentCorrelationNodeArray
|
||||
|
||||
settings.init()
|
||||
|
||||
|
||||
class SentimentCorrelationModel(BaseBehaviour):
|
||||
"""
|
||||
@ -22,15 +19,15 @@ class SentimentCorrelationModel(BaseBehaviour):
|
||||
|
||||
def __init__(self, environment=None, agent_id=0, state=()):
|
||||
super().__init__(environment=environment, agent_id=agent_id, state=state)
|
||||
self.outside_effects_prob = settings.outside_effects_prob
|
||||
self.anger_prob = settings.anger_prob
|
||||
self.joy_prob = settings.joy_prob
|
||||
self.sadness_prob = settings.sadness_prob
|
||||
self.disgust_prob = settings.disgust_prob
|
||||
self.time_awareness=[]
|
||||
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
|
||||
sentimentCorrelationNodeArray[self.id][self.env.now]=0
|
||||
self.outside_effects_prob = environment.outside_effects_prob
|
||||
self.anger_prob = environment.anger_prob
|
||||
self.joy_prob = environment.joy_prob
|
||||
self.sadness_prob = environment.sadness_prob
|
||||
self.disgust_prob = environment.disgust_prob
|
||||
self.time_awareness = []
|
||||
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
|
||||
sentimentCorrelationNodeArray[self.id][self.env.now] = 0
|
||||
|
||||
def step(self, now):
|
||||
self.behaviour()
|
||||
@ -38,10 +35,10 @@ class SentimentCorrelationModel(BaseBehaviour):
|
||||
|
||||
def behaviour(self):
|
||||
|
||||
angry_neighbors_1_time_step=[]
|
||||
joyful_neighbors_1_time_step=[]
|
||||
sad_neighbors_1_time_step=[]
|
||||
disgusted_neighbors_1_time_step=[]
|
||||
angry_neighbors_1_time_step = []
|
||||
joyful_neighbors_1_time_step = []
|
||||
sad_neighbors_1_time_step = []
|
||||
disgusted_neighbors_1_time_step = []
|
||||
|
||||
angry_neighbors = self.get_neighboring_agents(state_id=1)
|
||||
for x in angry_neighbors:
|
||||
@ -67,18 +64,18 @@ class SentimentCorrelationModel(BaseBehaviour):
|
||||
disgusted_neighbors_1_time_step.append(x)
|
||||
num_neighbors_disgusted = len(disgusted_neighbors_1_time_step)
|
||||
|
||||
anger_prob= settings.anger_prob+(len(angry_neighbors_1_time_step)*settings.anger_prob)
|
||||
joy_prob= settings.joy_prob+(len(joyful_neighbors_1_time_step)*settings.joy_prob)
|
||||
sadness_prob = settings.sadness_prob+(len(sad_neighbors_1_time_step)*settings.sadness_prob)
|
||||
disgust_prob = settings.disgust_prob+(len(disgusted_neighbors_1_time_step)*settings.disgust_prob)
|
||||
outside_effects_prob= settings.outside_effects_prob
|
||||
anger_prob = self.anger_prob+(len(angry_neighbors_1_time_step)*self.anger_prob)
|
||||
joy_prob = self.joy_prob+(len(joyful_neighbors_1_time_step)*self.joy_prob)
|
||||
sadness_prob = self.sadness_prob+(len(sad_neighbors_1_time_step)*self.sadness_prob)
|
||||
disgust_prob = self.disgust_prob+(len(disgusted_neighbors_1_time_step)*self.disgust_prob)
|
||||
outside_effects_prob = self.outside_effects_prob
|
||||
|
||||
num = random.random()
|
||||
|
||||
if(num<outside_effects_prob):
|
||||
if num<outside_effects_prob:
|
||||
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.attrs['sentiment'] = self.state['id']
|
||||
|
||||
@ -95,13 +92,11 @@ class SentimentCorrelationModel(BaseBehaviour):
|
||||
self.time_awareness[self.state['id']-1] = self.env.now
|
||||
elif (num<sadness_prob+anger_prob+joy_prob and num>joy_prob+anger_prob):
|
||||
|
||||
|
||||
self.state['id'] = 3
|
||||
sentimentCorrelationNodeArray[self.id][self.env.now]=3
|
||||
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):
|
||||
|
||||
|
||||
self.state['id'] = 4
|
||||
sentimentCorrelationNodeArray[self.id][self.env.now]=4
|
||||
self.time_awareness[self.state['id']-1] = self.env.now
|
||||
|
139
settings.py
139
settings.py
@ -1,103 +1,62 @@
|
||||
# settings.py
|
||||
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
|
||||
# General configuration
|
||||
|
||||
network_type=1
|
||||
number_of_nodes=1000
|
||||
max_time=50
|
||||
num_trials=1
|
||||
timeout=2
|
||||
# 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
|
||||
# Zombie model
|
||||
bite_prob = 0.01 # 0-1
|
||||
heal_prob = 0.01 # 0-1
|
||||
|
||||
#Bass model
|
||||
innovation_prob=0.001
|
||||
imitation_prob=0.005
|
||||
# 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
|
||||
# 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]
|
||||
# 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
|
||||
# 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
|
||||
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
|
||||
content_discontent = 0.009
|
||||
variance_c_d = 0.003
|
||||
content_neutral = 0.088
|
||||
|
||||
standard_variance = 0.055
|
||||
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
|
||||
# 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
|
||||
|
104
settings_org.py
Normal file
104
settings_org.py
Normal 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
20
soil.py
@ -8,7 +8,6 @@ import models
|
||||
import math
|
||||
import json
|
||||
|
||||
settings.init() # Loads all the data from settings
|
||||
|
||||
####################
|
||||
# Network creation #
|
||||
@ -17,11 +16,12 @@ settings.init() # Loads all the data from settings
|
||||
if settings.network_type == 0:
|
||||
G = nx.complete_graph(settings.number_of_nodes)
|
||||
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:
|
||||
G = nx.margulis_gabber_galil_graph(settings.number_of_nodes, None)
|
||||
# More types of networks can be added here
|
||||
|
||||
|
||||
##############
|
||||
# Simulation #
|
||||
##############
|
||||
@ -29,12 +29,13 @@ if settings.network_type == 2:
|
||||
sim = NetworkSimulation(topology=G, states=init_states, agent_type=ControlModelM2,
|
||||
max_time=settings.max_time, num_trials=settings.num_trials, logging_interval=1.0)
|
||||
|
||||
|
||||
sim.run_simulation()
|
||||
|
||||
|
||||
###########
|
||||
# Results #
|
||||
###########
|
||||
|
||||
x_values = []
|
||||
infected_values = []
|
||||
neutral_values = []
|
||||
@ -52,16 +53,16 @@ for time in range(0, settings.max_time):
|
||||
for x in range(0, settings.number_of_nodes):
|
||||
if attribute_plot in models.networkStatus["agent_%s" % x]:
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
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')
|
||||
plt.legend()
|
||||
plt.savefig('control_model.png')
|
||||
#plt.show()
|
||||
# plt.show()
|
||||
|
||||
|
||||
#################
|
||||
# Visualization #
|
||||
#################
|
||||
|
||||
|
||||
for x in range(0, settings.number_of_nodes):
|
||||
for attribute in models.networkStatus["agent_%s"%x]:
|
||||
emotionStatusAux=[]
|
||||
for t_step in models.networkStatus["agent_%s"%x][attribute]:
|
||||
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))
|
||||
attributes = {}
|
||||
attributes[attribute] = emotionStatusAux
|
||||
|
Loading…
Reference in New Issue
Block a user