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

SISa model implemented

This commit is contained in:
JesusMSM 2016-04-18 12:23:24 +02:00
parent 77f2f1c91b
commit 9aebacd4c7
6 changed files with 2818 additions and 16846 deletions

9764
data.txt

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,5 @@
from nxsim import BaseNetworkAgent
import numpy as np
import random
import settings
@ -55,6 +56,73 @@ class ComportamientoBase(BaseNetworkAgent):
final[a][stamp] = attrs[a]
return final
class SISaModel(ComportamientoBase):
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.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.content_discontent = np.random.normal(settings.content_discontent,settings.variance_c_d)
self.content_neutral = np.random.normal(settings.content_neutral,settings.standard_variance)
def step(self, now):
if self.state['id'] == 0:
self.neutral_behaviour()
if self.state['id'] == 1:
self.discontent_behaviour()
if self.state['id'] == 2:
self.content_behaviour()
self.attrs['status'] = self.state['id']
super().step(now)
def neutral_behaviour(self):
#Spontaneus effects
if random.random() < self.neutral_discontent_spon_prob:
self.state['id'] = 1
if random.random() < self.neutral_content_spon_prob:
self.state['id'] = 2
#Infected
discontent_neighbors = self.get_neighboring_agents(state_id=1)
if random.random() < len(discontent_neighbors)*self.neutral_discontent_infected_prob:
self.state['id'] = 1
content_neighbors = self.get_neighboring_agents(state_id=2)
if random.random() < len(content_neighbors)*self.neutral_content_infected_prob:
self.state['id'] = 2
def discontent_behaviour(self):
#Healing
if random.random() < self.discontent_neutral:
self.state['id'] = 0
#Superinfected
content_neighbors = self.get_neighboring_agents(state_id=2)
if random.random() < len(content_neighbors)*self.discontent_content:
self.state['id'] = 2
def content_behaviour(self):
#Healing
if random.random() < self.content_neutral:
self.state['id'] = 0
#Superinfected
discontent_neighbors = self.get_neighboring_agents(state_id=1)
if random.random() < len(discontent_neighbors)*self.content_discontent:
self.state['id'] = 1
class BigMarketModel(ComportamientoBase):
def __init__(self, environment=None, agent_id=0, state=()):
@ -81,6 +149,8 @@ class BigMarketModel(ComportamientoBase):
self.enterpriseBehaviour()
else: # Usuario
self.userBehaviour()
for i in range(self.number_of_enterprises): # Para que nunca este a 0 si no ha habido cambios(logs)
self.attrs['sentiment_enterprise_%s'% self.enterprises[i]] = self.sentiment_about[i]
super().step(now)

View File

@ -20,12 +20,23 @@ def init():
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
network_type=1
number_of_nodes=50
max_time=500
num_trials=1
timeout=1
timeout=20
#Zombie model
bite_prob=0.01 # 0-1
@ -53,3 +64,19 @@ def init():
##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.02

Binary file not shown.

21
soil.py
View File

@ -1,6 +1,7 @@
from models import *
from nxsim import NetworkSimulation
from nxsim import BaseLoggingAgent
import numpy
from matplotlib import pyplot as plt
import networkx as nx
import settings
import models
@ -26,7 +27,7 @@ if settings.network_type == 2:
# Simulation #
##############
sim = NetworkSimulation(topology=G, states=init_states, agent_type=BigMarketModel,
sim = NetworkSimulation(topology=G, states=init_states, agent_type=SISaModel,
max_time=settings.max_time, num_trials=settings.num_trials, logging_interval=1.0)
@ -35,10 +36,22 @@ sim.run_simulation()
###########
# Results #
###########
x_values = []
y_values = []
for time in range(0, settings.max_time):
value = settings.sentiment_about[0]
real_time = time * settings.timeout
for x in range(0, settings.number_of_nodes):
if "sentiment_enterprise_BBVA" in models.networkStatus["agente_%s" % x]:
if real_time in models.networkStatus["agente_%s" % x]["sentiment_enterprise_BBVA"]:
value += models.networkStatus["agente_%s" % x]["sentiment_enterprise_BBVA"][real_time]
trial = BaseLoggingAgent.open_trial_state_history(dir_path='sim_01', trial_id=0)
status_census = [sum([1 for node_id, state in g.items() if state['id'] == 1]) for t,g in trial.items()]
x_values.append(real_time)
y_values.append(value)
plt.plot(x_values,y_values)
#plt.show()
#################

9780
test.gexf

File diff suppressed because it is too large Load Diff