1
0
mirror of https://github.com/gsi-upm/soil synced 2025-07-05 20:42:22 +00:00
soil/soil/agents/IndependentCascadeModel.py
J. Fernando Sánchez 2869b1e1e6 Clean-up
* Removed old/unnecessary models
* Added a `simulation.{iter_}from_py` method to load simulations from python
files
* Changed tests of examples to run programmatic simulations
* Fixed programmatic examples
2022-11-13 20:31:05 +01:00

30 lines
766 B
Python

from . import Agent, state, default_state
class IndependentCascadeModel(Agent):
"""
Settings:
innovation_prob
imitation_prob
"""
time_awareness = 0
sentimentCorrelation = 0
# Outside effects
@default_state
@state
def outside(self):
if self.prob(self.model.innovation_prob):
self.sentimentCorrelation = 1
self.time_awareness = self.model.now # To know when they have been infected
return self.imitate
@state
def imitate(self):
aware_neighbors = self.get_neighbors(state_id=1, time_awareness=self.now-1)
if self.prob(self.model.imitation_prob * len(aware_neighbors)):
self.sentimentCorrelation = 1
return self.outside