tempnet.synth_temp_network ========================== .. py:module:: tempnet.synth_temp_network .. autoapi-nested-parse:: # # flow stability # # Copyright (C) 2021 Alexandre Bovet # # 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 . Classes ------- .. autoapisummary:: tempnet.synth_temp_network.Distro tempnet.synth_temp_network.Individual tempnet.synth_temp_network.SynthTempNetwork Functions --------- .. autoapisummary:: tempnet.synth_temp_network.make_step_block_probs Module Contents --------------- .. py:class:: Distro(loc = 0.0, scale = 1, dist_type = 'exponential') 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)` :param loc: Location parameter value of a SciPy distribution object :param scale: Scale parameter value of a SciPy distribution object :param dist_type: The type of distribution that will be drawn from Currently, only `"exponential"` (the default) is supported .. py:method:: draw_val(loc=None, scale=None) .. py:attribute:: dist_type :value: 'exponential' .. py:attribute:: loc :value: 0.0 .. py:attribute:: scale :value: 1 .. py:class:: 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) Individual agent class. :param ID: :type ID: int :param ID of the individual: 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. .. py:method:: draw_activ_time(time=None) 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. .. py:method:: draw_inter_duration(time=None) 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. .. py:attribute:: ID .. py:attribute:: activ_distro .. py:attribute:: all_IDs :value: [] .. py:attribute:: all_groups :value: [] .. py:attribute:: group :value: 0 .. py:attribute:: inter_distro .. py:attribute:: t :value: 0 .. py:class:: 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) SynthTempNetwork: a class for an agent based model generating a continuous time synthetic temporal network Alexandre Bovet 2019 :param individuals: :type individuals: list :param List of Individual instances: :param i.e. the nodes of the network.: :param Individual have a group id. There are N individuals and Ngroups group.: 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`. .. py:method:: Event(time, indiv_id, event_type='activation', partner=None, is_canceled=False) :staticmethod: 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_canceled : bool, =True if the event has been replaced and must be discarded This parameter is changed through the event_mapper dict. .. py:method:: get_new_partner(indiv_id, current_partner=None) Compute the next partner .. py:method:: initialize_events() Put one activation event in the queue for each individual .. py:method:: put_event(indiv_id, event_type='activation', partner=None, is_instantaneous=False) Put an event in the priority queue accorind to the rules event_type can be 'activation' or 'interaction' .. py:method:: run(save_all_states=False, save_dt_states=False, dt=10.0, verbose=False) Run the simulation :param save_all_states: saves the positions in `all_states` for each new event :type save_all_states: bool :param save_dt_states: saves the positions in `saved_states` at a constant frequency given by `dt` :type save_dt_states: bool :param dt: record period for `saved_states' :type dt: float :param verbose: verbose mode shows the progress :type verbose: bool .. py:attribute:: N .. py:attribute:: Ngroups .. py:attribute:: end_times :value: [] .. py:attribute:: event_mapper_activ .. py:attribute:: event_mapper_inter .. py:attribute:: group_to_ids .. py:attribute:: indiv_groups_array .. py:attribute:: indiv_groups_list .. py:attribute:: indiv_ids_array .. py:attribute:: indiv_ids_list .. py:attribute:: indiv_sources :value: [] .. py:attribute:: indiv_targets :value: [] .. py:attribute:: individuals .. py:attribute:: inter_group_probs :value: None .. py:attribute:: next_event_method :value: 'random_uniform' .. py:attribute:: num_interactions_per_activation :value: 1 .. py:attribute:: queue .. py:attribute:: start_times :value: [] .. py:attribute:: t_end :value: 200.0 .. py:attribute:: t_start :value: 0.0 .. py:function:: make_step_block_probs(deltat1, deltat2, m1 = 1.0, p1 = 1.0) 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. :param deltat1: Duration of each *within-community* (identity-block) phase. :type deltat1: float :param deltat2: Duration of each *cross-community exchange* phase. :type deltat2: float :param m1: Within-community interaction probability (default 1.0). :type m1: float :param p1: Cross-community interaction probability for the active pair (default 1.0). :type p1: float :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. :rtype: callable