Improved docs
Fixed several bugs Added convenience methods in soil.analysishistory 0.10
Before Width: | Height: | Size: 8.5 KiB After Width: | Height: | Size: 7.0 KiB |
Before Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 5.3 KiB |
After Width: | Height: | Size: 17 KiB |
After Width: | Height: | Size: 17 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 19 KiB |
@ -1,17 +0,0 @@
|
|||||||
default_state: {}
|
|
||||||
environment_agents: []
|
|
||||||
environment_params: {prob_neighbor_spread: 0.0, prob_tv_spread: 0.01}
|
|
||||||
interval: 1
|
|
||||||
max_time: 20
|
|
||||||
name: Sim_prob_0
|
|
||||||
network_agents:
|
|
||||||
- agent_type: NewsSpread
|
|
||||||
state: {has_tv: false}
|
|
||||||
weight: 1
|
|
||||||
- agent_type: NewsSpread
|
|
||||||
state: {has_tv: true}
|
|
||||||
weight: 2
|
|
||||||
network_params: {generator: erdos_renyi_graph, n: 500, p: 0.1}
|
|
||||||
num_trials: 1
|
|
||||||
states:
|
|
||||||
- {has_tv: true}
|
|
@ -1,20 +0,0 @@
|
|||||||
import soil
|
|
||||||
import random
|
|
||||||
|
|
||||||
class NewsSpread(soil.agents.FSM):
|
|
||||||
@soil.agents.default_state
|
|
||||||
@soil.agents.state
|
|
||||||
def neutral(self):
|
|
||||||
r = random.random()
|
|
||||||
if self['has_tv'] and r < self.env['prob_tv_spread']:
|
|
||||||
return self.infected
|
|
||||||
return
|
|
||||||
|
|
||||||
@soil.agents.state
|
|
||||||
def infected(self):
|
|
||||||
prob_infect = self.env['prob_neighbor_spread']
|
|
||||||
for neighbor in self.get_neighboring_agents(state_id=self.neutral.id):
|
|
||||||
r = random.random()
|
|
||||||
if r < prob_infect:
|
|
||||||
neighbor.state['id'] = self.infected.id
|
|
||||||
return
|
|
@ -0,0 +1,138 @@
|
|||||||
|
---
|
||||||
|
default_state: {}
|
||||||
|
load_module: newsspread
|
||||||
|
environment_agents: []
|
||||||
|
environment_params:
|
||||||
|
prob_neighbor_spread: 0.0
|
||||||
|
prob_tv_spread: 0.01
|
||||||
|
interval: 1
|
||||||
|
max_time: 30
|
||||||
|
name: Sim_all_dumb
|
||||||
|
network_agents:
|
||||||
|
- agent_type: DumbViewer
|
||||||
|
state:
|
||||||
|
has_tv: false
|
||||||
|
weight: 1
|
||||||
|
- agent_type: DumbViewer
|
||||||
|
state:
|
||||||
|
has_tv: true
|
||||||
|
weight: 1
|
||||||
|
network_params:
|
||||||
|
generator: barabasi_albert_graph
|
||||||
|
n: 500
|
||||||
|
m: 5
|
||||||
|
num_trials: 50
|
||||||
|
---
|
||||||
|
default_state: {}
|
||||||
|
load_module: newsspread
|
||||||
|
environment_agents: []
|
||||||
|
environment_params:
|
||||||
|
prob_neighbor_spread: 0.0
|
||||||
|
prob_tv_spread: 0.01
|
||||||
|
interval: 1
|
||||||
|
max_time: 30
|
||||||
|
name: Sim_half_herd
|
||||||
|
network_agents:
|
||||||
|
- agent_type: DumbViewer
|
||||||
|
state:
|
||||||
|
has_tv: false
|
||||||
|
weight: 1
|
||||||
|
- agent_type: DumbViewer
|
||||||
|
state:
|
||||||
|
has_tv: true
|
||||||
|
weight: 1
|
||||||
|
- agent_type: HerdViewer
|
||||||
|
state:
|
||||||
|
has_tv: false
|
||||||
|
weight: 1
|
||||||
|
- agent_type: HerdViewer
|
||||||
|
state:
|
||||||
|
has_tv: true
|
||||||
|
weight: 1
|
||||||
|
network_params:
|
||||||
|
generator: barabasi_albert_graph
|
||||||
|
n: 500
|
||||||
|
m: 5
|
||||||
|
num_trials: 50
|
||||||
|
---
|
||||||
|
default_state: {}
|
||||||
|
load_module: newsspread
|
||||||
|
environment_agents: []
|
||||||
|
environment_params:
|
||||||
|
prob_neighbor_spread: 0.0
|
||||||
|
prob_tv_spread: 0.01
|
||||||
|
interval: 1
|
||||||
|
max_time: 30
|
||||||
|
name: Sim_all_herd
|
||||||
|
network_agents:
|
||||||
|
- agent_type: HerdViewer
|
||||||
|
state:
|
||||||
|
has_tv: true
|
||||||
|
id: infected
|
||||||
|
weight: 1
|
||||||
|
- agent_type: HerdViewer
|
||||||
|
state:
|
||||||
|
has_tv: true
|
||||||
|
id: neutral
|
||||||
|
weight: 1
|
||||||
|
network_params:
|
||||||
|
generator: barabasi_albert_graph
|
||||||
|
n: 500
|
||||||
|
m: 5
|
||||||
|
num_trials: 50
|
||||||
|
---
|
||||||
|
default_state: {}
|
||||||
|
load_module: newsspread
|
||||||
|
environment_agents: []
|
||||||
|
environment_params:
|
||||||
|
prob_neighbor_spread: 0.0
|
||||||
|
prob_tv_spread: 0.01
|
||||||
|
prob_neighbor_cure: 0.1
|
||||||
|
interval: 1
|
||||||
|
max_time: 30
|
||||||
|
name: Sim_wise_herd
|
||||||
|
network_agents:
|
||||||
|
- agent_type: HerdViewer
|
||||||
|
state:
|
||||||
|
has_tv: true
|
||||||
|
id: infected
|
||||||
|
weight: 1
|
||||||
|
- agent_type: WiseViewer
|
||||||
|
state:
|
||||||
|
has_tv: true
|
||||||
|
weight: 1
|
||||||
|
network_params:
|
||||||
|
generator: barabasi_albert_graph
|
||||||
|
n: 500
|
||||||
|
m: 5
|
||||||
|
num_trials: 50
|
||||||
|
---
|
||||||
|
default_state: {}
|
||||||
|
load_module: newsspread
|
||||||
|
environment_agents: []
|
||||||
|
environment_params:
|
||||||
|
prob_neighbor_spread: 0.0
|
||||||
|
prob_tv_spread: 0.01
|
||||||
|
prob_neighbor_cure: 0.1
|
||||||
|
interval: 1
|
||||||
|
max_time: 30
|
||||||
|
name: Sim_all_wise
|
||||||
|
network_agents:
|
||||||
|
- agent_type: WiseViewer
|
||||||
|
state:
|
||||||
|
has_tv: true
|
||||||
|
id: infected
|
||||||
|
weight: 1
|
||||||
|
- agent_type: WiseViewer
|
||||||
|
state:
|
||||||
|
has_tv: true
|
||||||
|
weight: 1
|
||||||
|
network_params:
|
||||||
|
generator: barabasi_albert_graph
|
||||||
|
n: 500
|
||||||
|
m: 5
|
||||||
|
network_params:
|
||||||
|
generator: barabasi_albert_graph
|
||||||
|
n: 500
|
||||||
|
m: 5
|
||||||
|
num_trials: 50
|
@ -0,0 +1,79 @@
|
|||||||
|
from soil.agents import BaseAgent,FSM, state, default_state
|
||||||
|
import random
|
||||||
|
import logging
|
||||||
|
|
||||||
|
|
||||||
|
class DumbViewer(FSM):
|
||||||
|
'''
|
||||||
|
A viewer that gets infected via TV (if it has one) and tries to infect
|
||||||
|
its neighbors once it's infected.
|
||||||
|
'''
|
||||||
|
defaults = {
|
||||||
|
'prob_neighbor_spread': 0.5,
|
||||||
|
'prob_neighbor_cure': 0.25,
|
||||||
|
}
|
||||||
|
|
||||||
|
@default_state
|
||||||
|
@state
|
||||||
|
def neutral(self):
|
||||||
|
r = random.random()
|
||||||
|
if self['has_tv'] and r < self.env['prob_tv_spread']:
|
||||||
|
self.infect()
|
||||||
|
return
|
||||||
|
|
||||||
|
@state
|
||||||
|
def infected(self):
|
||||||
|
for neighbor in self.get_neighboring_agents(state_id=self.neutral.id):
|
||||||
|
prob_infect = self.env['prob_neighbor_spread']
|
||||||
|
r = random.random()
|
||||||
|
if r < prob_infect:
|
||||||
|
self.set_state(self.infected.id)
|
||||||
|
neighbor.infect()
|
||||||
|
return
|
||||||
|
|
||||||
|
def infect(self):
|
||||||
|
self.set_state(self.infected)
|
||||||
|
|
||||||
|
class HerdViewer(DumbViewer):
|
||||||
|
'''
|
||||||
|
A viewer whose probability of infection depends on the state of its neighbors.
|
||||||
|
'''
|
||||||
|
|
||||||
|
level = logging.DEBUG
|
||||||
|
|
||||||
|
def infect(self):
|
||||||
|
infected = self.count_neighboring_agents(state_id=self.infected.id)
|
||||||
|
total = self.count_neighboring_agents()
|
||||||
|
prob_infect = self.env['prob_neighbor_spread'] * infected/total
|
||||||
|
self.debug('prob_infect', prob_infect)
|
||||||
|
r = random.random()
|
||||||
|
if r < prob_infect:
|
||||||
|
self.set_state(self.infected.id)
|
||||||
|
|
||||||
|
class WiseViewer(HerdViewer):
|
||||||
|
'''
|
||||||
|
A viewer that can change its mind.
|
||||||
|
'''
|
||||||
|
@state
|
||||||
|
def cured(self):
|
||||||
|
prob_cure = self.env['prob_neighbor_cure']
|
||||||
|
for neighbor in self.get_neighboring_agents(state_id=self.infected.id):
|
||||||
|
r = random.random()
|
||||||
|
if r < prob_cure:
|
||||||
|
try:
|
||||||
|
neighbor.cure()
|
||||||
|
except AttributeError:
|
||||||
|
self.debug('Viewer {} cannot be cured'.format(neighbor.id))
|
||||||
|
return
|
||||||
|
|
||||||
|
def cure(self):
|
||||||
|
self.set_state(self.cured.id)
|
||||||
|
|
||||||
|
@state
|
||||||
|
def infected(self):
|
||||||
|
prob_cure = self.env['prob_neighbor_cure']
|
||||||
|
r = random.random()
|
||||||
|
if r < prob_cure:
|
||||||
|
self.cure()
|
||||||
|
return
|
||||||
|
return super().infected()
|