tempnet.synth_temp_network#
# # flow stability # # Copyright (C) 2021 Alexandre Bovet <alexandre.bovet@maths.ox.ac.uk> # # This program is free software; you can redistribute it and/or modify it under # the terms of the GNU Lesser General Public License as published by the Free # Software Foundation; either version 3 of the License, or (at your option) any # later version. # # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # details. # # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>.
Classes#
Random variables from distributions |
|
Individual agent class. |
|
SynthTempNetwork: a class for an agent based model |
Functions#
|
Return a time-dependent block-probability function for 3 groups. |
Module Contents#
- class tempnet.synth_temp_network.Distro(loc=0.0, scale=1, dist_type='exponential')[source]#
Random variables from distributions
The loc and scale values are the default values used, but they can also be changed when calling Distro.draw_val(loc,scale)
- Parameters:
- dist_type = 'exponential'#
- loc = 0.0#
- scale = 1#
- class tempnet.synth_temp_network.Individual(ID, inter_distro_loc=0, inter_distro_scale=1, inter_distro_type='exponential', inter_distro_mod_func=None, activ_distro_loc=0, activ_distro_scale=5, activ_distro_type='exponential', activ_distro_mod_func=None, group=0)[source]#
Individual agent class.
- Parameters:
ID (int)
individual (ID of the)
- inter_distro_loc: float
Location (mean) of the interactions (i.e. events) durations
- inter_distro_scale: float
Scale (standard-deviation) of the interactions (i.e. events) durations
- inter_distro_type: string
Type of distribution function of the interactions durations. Can be “exponential”.
- inter_distro_mod_func: function
function that take an argument time and returns a tuple (loc, scale) used as parameters for drawing time-dependent interaction durations.
- activ_distro_loc: float
Location (mean) of the inter-activation (i.e. inter-events) durations
- activ_distro_scale: float
Scale (standard-deviation) of the inter-activation (i.e. inter-events) durations
- activ_distro_type: string
Type of distribution function of the inter-activation durations. Can be “exponential”.
- activ_distro_mod_func: function
function that take an argument time and returns a tuple (loc, scale) used as parameters for drawing time-dependent inter-activation durations.
- group: int
ID of the group to which the individual belongs to.
- draw_activ_time(time=None)[source]#
Draws a activation time from activ_distro.
If time is provided, computes the loc and scale parameters using activ_distro_mod_func(time). Otherwise, loc and scale are taken as the initialized values.
- draw_inter_duration(time=None)[source]#
Draws a interaction duration time from inter_distro.
If time is provided, computes the loc and scale parameters using inter_distro_mod_func(time). Otherwise, loc and scale are taken as the initialized values.
- ID#
- activ_distro#
- all_IDs = []#
- all_groups = []#
- group = 0#
- inter_distro#
- t = 0#
- class tempnet.synth_temp_network.SynthTempNetwork(individuals, t_start=0.0, t_end=200.0, num_interactions_per_activation=1, next_event_method='random_uniform', inter_group_probs=None, block_prob_mod_func=None)[source]#
SynthTempNetwork: a class for an agent based model generating a continuous time synthetic temporal network
Alexandre Bovet 2019
- Parameters:
individuals (list)
instances (List of Individual)
network. (i.e. the nodes of the)
group. (Individual have a group id. There are N individuals and Ngroups)
t_start (float)
t_end (float)
- t_start: float
Starting time of the simulation
- t_end: float
Ending time of the simulation
- num_interactions_per_activation: int
Number of interactions generated each time an individual is activated
- next_event_method: string
Method to choose the individual to interact with. Can be
- ‘random_uniform’ (default):
uniform probability to choose any other individuals.
- ‘block_probs’:
probabilities given by a block matrix inter_group_probs.
- ‘block_probs_mod’:
probabilities given by a time-dependent function block_prob_mod_func.
- inter_group_probs: Ngroups x Ngroups numpy array
Contains the probabilities of inter-group interactions.
- block_prob_mod_func: function
Functions that depend on t such that block_prob_mod_func(t) returns an inter_group_probs matrix.
Usage:#
The simulation is run by calling self.run(). All the events are stored in 4 lists: self.indiv_sources, self.indiv_targets, self.start_times and self.end_times.
- static Event(time, indiv_id, event_type='activation', partner=None, is_canceled=False)[source]#
Arguments:#
time: float, used to order the events in the priority queue
indiv_id: int, id of the individual
event_type: str, type of event, ‘activation’ (default) or ‘interaction’
- is_canceledbool, =True if the event has been replaced and must be discarded
This parameter is changed through the event_mapper dict.
- put_event(indiv_id, event_type='activation', partner=None, is_instantaneous=False)[source]#
Put an event in the priority queue accorind to the rules event_type can be ‘activation’ or ‘interaction’
- run(save_all_states=False, save_dt_states=False, dt=10.0, verbose=False)[source]#
Run the simulation
- N#
- Ngroups#
- end_times = []#
- event_mapper_activ#
- event_mapper_inter#
- group_to_ids#
- indiv_groups_array#
- indiv_groups_list#
- indiv_ids_array#
- indiv_ids_list#
- indiv_sources = []#
- indiv_targets = []#
- individuals#
- inter_group_probs = None#
- next_event_method = 'random_uniform'#
- num_interactions_per_activation = 1#
- queue#
- start_times = []#
- t_end = 200.0#
- t_start = 0.0#
- tempnet.synth_temp_network.make_step_block_probs(deltat1, deltat2, m1=1.0, p1=1.0)[source]#
Return a time-dependent block-probability function for 3 groups.
The returned function cycles through three phases where different community pairs have elevated cross-community interaction probability.
- Parameters:
- Returns:
block_mod_func – A function
block_mod_func(t)that accepts a float t and returns a 3×3 numpy array of group-level interaction probabilities.- Return type:
callable