solvers.agents
Not for the user: the agent engine: a declared model run as agents (abm)
It also holds the transmission that diseases written as code use, so that both give the same numbers.
Used with: agents; declared and coded modules
Classes
| Name | Description |
|---|---|
| Agents | Runs a graph as agents |
| Transmission | Transmission as agents, the same for a declared disease (Agents, for its transmissions) and one written as code (ss.Disease.transmit(rel_trans=..., rel_sus=...), |
Agents
solvers.agents.Agents(module, sim, solver=None)Runs a graph as agents
It exists so that a declared model can run with individuals, for what compartments cannot hold.
Each state that holds people is a boolean array over agents. A dwell time is sampled when an agent enters a state and the exit is scheduled; rates that depend on the state of the model are drawn each step, with competing rates out of one state resolved in a single draw; and contact-mediated transitions are drawn over the sim’s networks. States that are not people stay plain counts.
Attributes
| Name | Description |
|---|---|
| scale | The number of people each agent stands for |
| total_pop | The number of people the agents stand for now: with dynamic rescaling (rescale=True), each agent starts as one person, so a number of people to seed (init_n=) is a number of agents |
Methods
| Name | Description |
|---|---|
| add_dist | A distribution the engine draws from, registered on its module so the sim initializes it |
| add_from_outside | Make k agents in a state (ss.move() from outside the model), and in each other disease’s first state: in places drawn by the place’s split, and at the other levels as people born (newborn) or arriving are |
| adjusted | The multiplier on a transition for each agent, from the multipliers by level of the stratifications (a strain’s) (1 if there is none), and their susceptibility if it is an acquisition that is not contact-mediated (see transmit() for those) |
| adjusted_rel | The multiplier on rel_trans or rel_sus for each agent (by UID), for those in a state that has the dimension |
| agent_dwell_mean | The mean of a dwell time whose distribution has parameters by group (see varying_dwell()), for each of some agents: worked out once for each set of values, e.g. each age group |
| agent_values | A parameter of a distribution with a value for each group, as a function the distribution calls for the agents it draws for |
| alive_counts | The number of agents alive now, by group: kept from the last census, with those made since |
| by_agent | A value for each level of a dimension, for some agents; sex needs no stratification, since it is people.female (the first level is women) |
| by_group | A value for each level of a dimension becomes a value for each of the agents being evaluated (or for each group, when rates are being worked out by group) |
| by_people | A value read from each person’s own properties (see ss.by.lookup()), for the agents being evaluated (or for uids): looked up for those agents alone, since often few are asked for (e.g. those entering a state), or, for a value by sex, from a table kept for the run |
| by_place | Numbers by group as numbers by place, or None if a group does not say where its people are (when it leaves out the dimension of places) |
| call | As Engine.call(); a function of the sim may give one value per living agent (as sim.people.age does), which is put in place by UID |
| can_infect | Whether a transmission can infect each agent (or the people of each group, without uids): over its routes, a coefficient above 0 in a direction whose susceptible side is theirs |
| census | Count the agents in each state of people, by group, and list those in some of the states: one pass over the agents (threaded for a large population) |
| check_counts | Check the counts kept since the last census against a new one (with STARSIM_CHECK_COUNTS=1, at every step; for testing) |
| count_matrices | The contact matrices that act on a count, as agents use them: over the model’s own groups (see ss.solvers.Mixing.init_pools()) |
| count_stocks | As for the other engines (see Engine.count_stocks()), with the number in each state of people as it has been kept since the last census (see census()) |
| count_weighted | A weighted count ((ss.by(biting=w)*I).n, A.n_infectious): each agent in the states counted by its weight (and infectiousness), in the same place, as local_count() gives it |
| count_weights | What each agent in a state counts as in a count: its own weight, if agents differ, times its weight (and infectiousness) in a weighted count |
| counted | The number in a state of people now, by the group it is counted in (see stock()) |
| define | Create the per-agent states and the distributions |
| eval_for | Evaluate an expression for some agents: a scalar or one value per agent |
| exposure | Under homogeneous mixing: the infectiousness-weighted fraction of people in the state |
| fixed_edges | Cumulative probabilities (one row for each, then each agent: see dest_edges() and branch_edges()) for some agents: if they depend only |
| for_uids | Within eval_for(), a value for each agent in the population (e.g. a parameter modified for some people) is taken for the agents being evaluated, so it combines with the rest of the expression |
| force | Move agents who are in a state a transition leaves from (or in srcs) to a state, counted in the transition’s flow if there is one (as when a treatment cures), with its change of level; dated at the step’s start, or at ti |
| groups | The group of each agent; given a state, the group they are counted in while in it (which leaves out the dimensions the state does not have) |
| held_frac | The fraction holding a product (itn.held_frac): the fraction of the agents in the same place who hold it, each by the protection they have left (or a function of the time since delivery) |
| infect_now | Infect some agents now, from code (ss.Disease.infect()): those in the first state, along its first transmission (with the strain given), counted in its flow, dated as infections are (at the step’s end, the next time point), and logged as seeds |
| init_dwell_mods | See Engine.init_dwell_mods(); and the distributions each set= draws from, before the sim initializes the distributions |
| init_post | Sample the agents into the states |
| is_fixed | Whether a value (an expression of parameters, or a condition) is the same for each person for the whole run, so it can be worked out for |
| is_lifelong | Whether a value by people’s properties is the same for each person for the whole run: by sex alone, with values that do not change in time |
| is_route_fixed | Whether a coefficient of a transmission has the same value on each route for the whole run, so route_beta() keeps it: as is_fixed(), |
| lifelong_mods | Whether modifiers only say who a quantity is for, by something that never changes (e.g. a transition with who=ss.person.female), so each person’s multiplier stays the same for the whole run |
| lifelong_span | The agents (by UID, as start and stop) whose values in a table kept for the run (see lifelong_table()) are to be worked out, if it is read for uids (everyone if None): those made since, and the room for more if the arrays have grown; None if none are |
| lifelong_table | Values for everyone, by UID, kept for the run (see is_lifelong()), from values(uids). The arrays have room for agents not yet made, whose |
| live_counts | The number of agents in each state of people now, by group (not collapsed): kept from the last census (with any changes of group since: see moved_groups()), or counted again |
| local_count | In a model with places: the number in the same place as each agent, or, when the counts are being advanced, as each group |
| members | The agents in a state, as UIDs |
| met_count | The number of people in some states met through the contact matrices: from the agents in each group (counted by their weight, and in a weighted count by theirs in it), as for a compartmental run (see ss.solvers.Mixing.exposure()) |
| modules_changed | A module was added during the run (see ss.Sim.add_module()): the coefficients kept for the run are worked out again |
| move_levels_of | The change of level of a transition with move= or increment=, for the agents it takes to a state |
| move_some | A one-off move from code (ss.move()): a fraction p of the agents in some states (or n people, as a whole number of agents, |
| move_states | Move the agents who are in some states to a state: along a transition (see force()), or along none, as a one-off move, dated at the step’s start (or at ti); returns those moved |
| moved_groups | Some agents’ groups have changed by themselves (e.g. they reached the next age group: see ss.dimensions.Groups.regrouped()): move them between the counts kept by group |
| mult | The multiplier on a quantity for some agents, from its modifiers |
| mult_raw_extra | Whether mult_raw() has a multiplier on a kind of quantity other than its modifiers: the multipliers by level of the stratifications (a strain’s) |
| n_of | The number of people some agents stand for, before the population scale: their number, or, if agents are weighted (people.scale), the sum of their weights |
| never | Whether a rate out of a state is 0 for everyone for the whole run (a factor that is a number or a parameter of 0, with no modifiers), |
| note_counter | Agents add to each person’s own value, so a counter’s levels need not be one apart (see Compartmental.note_counter()) |
| place_newcomers | Put agents made by other modules since the last step (e.g. born of ss.Births or ss.Pregnancy), who are in no state, in the first state |
| place_raw | The place of each agent, as an array indexed by UID |
| prop | A property of people or a condition, in a rate (see ss.expressions.Prop): its value for each agent being evaluated, as it was when first asked for in the step |
| put_first | Put some agents in the first state, and in no other (e.g. fetuses made after the start, whose states would otherwise be their arrays’ defaults) |
| regroup | The groups of some agents (or of anyone, if uids is None) have changed: if any of them are in a state, the counts by group are taken again when next needed |
| round_agents | A number of people as a whole number of agents, rounded at random, so that a fraction of one moves on average what it stands for (e.g. 0.3 people a day) |
| seed | Seed some agents who are in the first state: put them where a new infection puts them, the destinations of the first |
| seed_dist | As agents, an init_prev that chooses who starts infected one by one: a function of the sim (and the agents), or ss.by over a property of people that is not a dimension |
| seed_ti | The time of entering a state for someone put in it at the start: as if they had entered it in the step before the |
| set_count | Set the number in a state that is not people, keeping its split between groups |
| strain_raw | The strain each agent carries, as an array indexed by UID |
| unmodified | Whether a branch (or one destination of a transition) has no modifiers and no multipliers by level of the stratifications |
| varying_dwell | A dwell time whose distribution has parameters with a value for each group (ss.by): the parameters are looked up for each agent, and one draw is made (see Compartmental.varying_dwell()) |
| weighted_count | As counted(), with each agent counted by its weight (people.scale) |
| weighted_events | An outcome weighted per person (e.g. years of life lost by each person’s age): the weight of each person who went through the transition this step, summed by group |
| weights | The number of people each of some agents stands for relative to the others (people.scale), or None if every agent stands for the same number |
| wrote | Some agents have been put in a state of people, or taken out of it, by anything (see ss.BoolState): keep its count by group (each counted once) |
add_dist
solvers.agents.Agents.add_dist(key, dist)A distribution the engine draws from, registered on its module so the sim initializes it
add_from_outside
solvers.agents.Agents.add_from_outside(dst, k, newborn)Make k agents in a state (ss.move() from outside the model), and in each other disease’s first state: in places drawn by the place’s split, and at the other levels as people born (newborn) or arriving are
adjusted
solvers.agents.Agents.adjusted(name, uids)The multiplier on a transition for each agent, from the multipliers by level of the stratifications (a strain’s) (1 if there is none), and their susceptibility if it is an acquisition that is not contact-mediated (see transmit() for those)
adjusted_rel
solvers.agents.Agents.adjusted_rel(kind, state=None)The multiplier on rel_trans or rel_sus for each agent (by UID), for those in a state that has the dimension
agent_dwell_mean
solvers.agents.Agents.agent_dwell_mean(name, uids)The mean of a dwell time whose distribution has parameters by group (see varying_dwell()), for each of some agents: worked out once for each set of values, e.g. each age group
agent_values
solvers.agents.Agents.agent_values(by)A parameter of a distribution with a value for each group, as a function the distribution calls for the agents it draws for
alive_counts
solvers.agents.Agents.alive_counts()The number of agents alive now, by group: kept from the last census, with those made since
by_agent
solvers.agents.Agents.by_agent(by, uids)A value for each level of a dimension, for some agents; sex needs no stratification, since it is people.female (the first level is women)
by_group
solvers.agents.Agents.by_group(by)A value for each level of a dimension becomes a value for each of the agents being evaluated (or for each group, when rates are being worked out by group)
by_people
solvers.agents.Agents.by_people(by, uids=None)A value read from each person’s own properties (see ss.by.lookup()), for the agents being evaluated (or for uids): looked up for those agents alone, since often few are asked for (e.g. those entering a state), or, for a value by sex, from a table kept for the run
by_place
solvers.agents.Agents.by_place(vals)Numbers by group as numbers by place, or None if a group does not say where its people are (when it leaves out the dimension of places)
call
solvers.agents.Agents.call(func, p=None)As Engine.call(); a function of the sim may give one value per living agent (as sim.people.age does), which is put in place by UID
can_infect
solvers.agents.Agents.can_infect(tr, uids=None)Whether a transmission can infect each agent (or the people of each group, without uids): over its routes, a coefficient above 0 in a direction whose susceptible side is theirs
census
solvers.agents.Agents.census(want=())Count the agents in each state of people, by group, and list those in some of the states: one pass over the agents (threaded for a large population)
The counts are then kept up to date as agents enter and leave the states, whatever moves them (see wrote()), so they are counted again only when their groups change (see regroup()).
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| want | list |
the names of the states whose agents to list | () |
Returns a dict of the agents in each state in want.
check_counts
solvers.agents.Agents.check_counts()Check the counts kept since the last census against a new one (with STARSIM_CHECK_COUNTS=1, at every step; for testing)
count_matrices
solvers.agents.Agents.count_matrices()The contact matrices that act on a count, as agents use them: over the model’s own groups (see ss.solvers.Mixing.init_pools())
count_stocks
solvers.agents.Agents.count_stocks()As for the other engines (see Engine.count_stocks()), with the number in each state of people as it has been kept since the last census (see census())
count_weighted
solvers.agents.Agents.count_weighted(states, expr)A weighted count ((ss.by(biting=w)*I).n, A.n_infectious): each agent in the states counted by its weight (and infectiousness), in the same place, as local_count() gives it
count_weights
solvers.agents.Agents.count_weights(expr, state, uids)What each agent in a state counts as in a count: its own weight, if agents differ, times its weight (and infectiousness) in a weighted count
counted
solvers.agents.Agents.counted(state)The number in a state of people now, by the group it is counted in (see stock())
define
solvers.agents.Agents.define()Create the per-agent states and the distributions
eval_for
solvers.agents.Agents.eval_for(expr, uids)Evaluate an expression for some agents: a scalar or one value per agent
exposure
solvers.agents.Agents.exposure(state)Under homogeneous mixing: the infectiousness-weighted fraction of people in the state
fixed_edges
solvers.agents.Agents.fixed_edges(key, fixed, edges, uids)Cumulative probabilities (one row for each, then each agent: see dest_edges() and branch_edges()) for some agents: if they depend only on fixed values (fixed, see is_fixed()), from a table for everyone kept for the run, else from edges(uids)
for_uids
solvers.agents.Agents.for_uids(val)Within eval_for(), a value for each agent in the population (e.g. a parameter modified for some people) is taken for the agents being evaluated, so it combines with the rest of the expression
force
solvers.agents.Agents.force(uids, tr, dst, srcs=None, ti=None)Move agents who are in a state a transition leaves from (or in srcs) to a state, counted in the transition’s flow if there is one (as when a treatment cures), with its change of level; dated at the step’s start, or at ti
groups
solvers.agents.Agents.groups(uids, state=None)The group of each agent; given a state, the group they are counted in while in it (which leaves out the dimensions the state does not have)
held_frac
solvers.agents.Agents.held_frac(expr)The fraction holding a product (itn.held_frac): the fraction of the agents in the same place who hold it, each by the protection they have left (or a function of the time since delivery)
infect_now
solvers.agents.Agents.infect_now(uids, strain=None)Infect some agents now, from code (ss.Disease.infect()): those in the first state, along its first transmission (with the strain given), counted in its flow, dated as infections are (at the step’s end, the next time point), and logged as seeds
init_dwell_mods
solvers.agents.Agents.init_dwell_mods()See Engine.init_dwell_mods(); and the distributions each set= draws from, before the sim initializes the distributions
init_post
solvers.agents.Agents.init_post()Sample the agents into the states
is_fixed
solvers.agents.Agents.is_fixed(x)Whether a value (an expression of parameters, or a condition) is the same for each person for the whole run, so it can be worked out for everyone once (see fixed_edges()): numbers, parameters with no modifiers whose values are numbers or values by sex (see is_lifelong()), conditions on sex, and functions marked with ss.lifelong()
is_lifelong
solvers.agents.Agents.is_lifelong(by)Whether a value by people’s properties is the same for each person for the whole run: by sex alone, with values that do not change in time
is_route_fixed
solvers.agents.Agents.is_route_fixed(x)Whether a coefficient of a transmission has the same value on each route for the whole run, so route_beta() keeps it: as is_fixed(), with a value by route (a dict by network name) or by direction (ss.peract) of such values, and rates and durations of numbers
lifelong_mods
solvers.agents.Agents.lifelong_mods(mods)Whether modifiers only say who a quantity is for, by something that never changes (e.g. a transition with who=ss.person.female), so each person’s multiplier stays the same for the whole run
lifelong_span
solvers.agents.Agents.lifelong_span(key, vals, uids=None)The agents (by UID, as start and stop) whose values in a table kept for the run (see lifelong_table()) are to be worked out, if it is read for uids (everyone if None): those made since, and the room for more if the arrays have grown; None if none are
lifelong_table
solvers.agents.Agents.lifelong_table(key, values, uids=None)Values for everyone, by UID, kept for the run (see is_lifelong()), from values(uids). The arrays have room for agents not yet made, whose values (e.g. their sex) are not known until they are, so those of agents made since are worked out when they are needed: when the table is read for them (uids, or everyone if None)
live_counts
solvers.agents.Agents.live_counts()The number of agents in each state of people now, by group (not collapsed): kept from the last census (with any changes of group since: see moved_groups()), or counted again
local_count
solvers.agents.Agents.local_count(states)In a model with places: the number in the same place as each agent, or, when the counts are being advanced, as each group
members
solvers.agents.Agents.members(state)The agents in a state, as UIDs
Read from the state’s array directly rather than through the living agents (.uids), which is several times faster for a large population: anyone who has died has already left every state (see die()).
met_count
solvers.agents.Agents.met_count(states, expr)The number of people in some states met through the contact matrices: from the agents in each group (counted by their weight, and in a weighted count by theirs in it), as for a compartmental run (see ss.solvers.Mixing.exposure())
modules_changed
solvers.agents.Agents.modules_changed()A module was added during the run (see ss.Sim.add_module()): the coefficients kept for the run are worked out again
move_levels_of
solvers.agents.Agents.move_levels_of(tr, dst, uids)The change of level of a transition with move= or increment=, for the agents it takes to a state
move_some
solvers.agents.Agents.move_some(
srcs,
dst,
p=None,
n=None,
uids=None,
where=None,
outside=None,
)A one-off move from code (ss.move()): a fraction p of the agents in some states (or n people, as a whole number of agents, rounded at random; or of uids, those given; or of those for whom where holds), chosen at random, to a state; or to and from outside the model (dst or srcs empty, and for people, outside: ‘dead’ and ‘outside’, or ‘unborn’ and ‘outside’), as agents who die (or leave) at the end of the step, or are made now; returns the number of people moved
move_states
solvers.agents.Agents.move_states(uids, srcs, dst, tr=None, ti=None)Move the agents who are in some states to a state: along a transition (see force()), or along none, as a one-off move, dated at the step’s start (or at ti); returns those moved
moved_groups
solvers.agents.Agents.moved_groups(uids, before, after)Some agents’ groups have changed by themselves (e.g. they reached the next age group: see ss.dimensions.Groups.regrouped()): move them between the counts kept by group
mult
solvers.agents.Agents.mult(kind, name, uids)The multiplier on a quantity for some agents, from its modifiers
mult_raw_extra
solvers.agents.Agents.mult_raw_extra(kind)Whether mult_raw() has a multiplier on a kind of quantity other than its modifiers: the multipliers by level of the stratifications (a strain’s)
n_of
solvers.agents.Agents.n_of(uids)The number of people some agents stand for, before the population scale: their number, or, if agents are weighted (people.scale), the sum of their weights
never
solvers.agents.Agents.never(tr)Whether a rate out of a state is 0 for everyone for the whole run (a factor that is a number or a parameter of 0, with no modifiers), so it moves nobody: it is not drawn, as for a transition with no driver, and declaring it leaves the draws of the others as they were
note_counter
solvers.agents.Agents.note_counter(strat, what)Agents add to each person’s own value, so a counter’s levels need not be one apart (see Compartmental.note_counter())
place_newcomers
solvers.agents.Agents.place_newcomers()Put agents made by other modules since the last step (e.g. born of ss.Births or ss.Pregnancy), who are in no state, in the first state
place_raw
solvers.agents.Agents.place_raw()The place of each agent, as an array indexed by UID
prop
solvers.agents.Agents.prop(cond)A property of people or a condition, in a rate (see ss.expressions.Prop): its value for each agent being evaluated, as it was when first asked for in the step
put_first
solvers.agents.Agents.put_first(uids)Put some agents in the first state, and in no other (e.g. fetuses made after the start, whose states would otherwise be their arrays’ defaults)
regroup
solvers.agents.Agents.regroup(uids=None)The groups of some agents (or of anyone, if uids is None) have changed: if any of them are in a state, the counts by group are taken again when next needed
round_agents
solvers.agents.Agents.round_agents(n)A number of people as a whole number of agents, rounded at random, so that a fraction of one moves on average what it stands for (e.g. 0.3 people a day)
seed
solvers.agents.Agents.seed(uids, log=True)Seed some agents who are in the first state: put them where a new infection puts them, the destinations of the first transmission in its fractions, as init_prev does; returns those seeded
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| uids | uids | the agents; those not in the first state are left where they are | required |
| log | bool |
whether to record them as seeds in an ss.infection_log |
True |
seed_dist
solvers.agents.Agents.seed_dist()As agents, an init_prev that chooses who starts infected one by one: a function of the sim (and the agents), or ss.by over a property of people that is not a dimension
seed_ti
solvers.agents.Agents.seed_ti(name)The time of entering a state for someone put in it at the start: as if they had entered it in the step before the first, so that a seed with a dwell of d steps is a source for d steps, as anyone who enters later is. Contacts (a network, a mixing pool, or beta*I well mixed) are made after the step’s state changes, and a rate (beta*I.n) reads the people at its start, so a source by contact entered at 0 (in the first step’s contacts, leaving at the start of the second), and anyone else at -1 if they are where an infection puts people (in the first step’s rates, then counted at the start only, as under the ODE), else at 0
set_count
solvers.agents.Agents.set_count(state, value)Set the number in a state that is not people, keeping its split between groups
strain_raw
solvers.agents.Agents.strain_raw()The strain each agent carries, as an array indexed by UID
unmodified
solvers.agents.Agents.unmodified(kind, name)Whether a branch (or one destination of a transition) has no modifiers and no multipliers by level of the stratifications
varying_dwell
solvers.agents.Agents.varying_dwell(name, tr, raw, dw, to_unit)A dwell time whose distribution has parameters with a value for each group (ss.by): the parameters are looked up for each agent, and one draw is made (see Compartmental.varying_dwell())
weighted_count
solvers.agents.Agents.weighted_count(state)As counted(), with each agent counted by its weight (people.scale)
weighted_events
solvers.agents.Agents.weighted_events(key, weight, integer)An outcome weighted per person (e.g. years of life lost by each person’s age): the weight of each person who went through the transition this step, summed by group
weights
solvers.agents.Agents.weights(uids)The number of people each of some agents stands for relative to the others (people.scale), or None if every agent stands for the same number
wrote
solvers.agents.Agents.wrote(name, entered, left)Some agents have been put in a state of people, or taken out of it, by anything (see ss.BoolState): keep its count by group (each counted once)
Transmission
solvers.agents.Transmission(module, sim)Transmission as agents, the same for a declared disease (Agents, for its transmissions) and one written as code (ss.Disease.transmit(rel_trans=..., rel_sus=...), through its engine, ss.solvers.Undeclared): who can transmit and be infected, with the modifiers and products on rel_trans and rel_sus applied (current_value()); who is infected over a network (over_network()); and who infected whom (first_infections())
Where the two differ, the caller says how:
- Hazard or probability.
over_network()takes the chance of an edge in the step, and scales its hazard by every other factor (the edge’s weight and acts,rel_trans,rel_sus, and the modifiers). A declared disease gives 1 − exp(−β·dt) from its rate, or, on a network with acts, works out a hazard per act (Agents.transmit_acts()); one written as code gives its beta as the probability in the step, converting a rate the same way (ss.Rate.to_prob()). - Order and attribution. The routes are taken in the order of
sim.networks, and on each, p1 to p2 and then p2 to p1; someone reached by several is infected by the first (first_infections()), which is the source in the infection log. With strains, every strain is passed on in one pass, and someone reached by several is infected by one of them drawn at random, whose strain they take (pick_sources()), and then only if they are not protected against it (unprotected()): declared or written as code, by the same code. - Random numbers. Each edge’s is drawn by its source and target from the disease’s
trans_rng, so the same disease, by the same name, gives the same edges the same numbers, declared or written as code; and so are the draws of who infects whom, and of protection, which are keyed by the step alone (step_draw()).
Methods
| Name | Description |
|---|---|
| code_betas | The beta of a disease written as code (beta, by default its parameter beta) for each of the sim’s networks (by name), as a pair (p1 to p2, p2 to p1), checked against them (see ss.Disease.transmit()) |
| code_route | The transmission of a disease written as code along a single network (or other route): see ss.Disease.transmit() |
| current_value | rel_sus or rel_trans (kind) of every agent (by UID), times the factors (e.g. whether each is susceptible), with the modifiers and products active on it applied; may be the array itself, so it is not to be changed |
| first_infections | Each agent infected, once, with who infected them and over which route: the first of pairs to reach them. Each pair is the sources, the |
| over_network | Who is infected over a network in the step: an edge from u to v transmits with probability 1 − exp(−H), where H is the hazard of |
| over_routes | The infections over each of the sim’s routes in turn (code_route()), each a tuple of targets, sources, and network IDs: see ss.Disease.transmit() |
| pick_sources | With strains, each agent reached in the step, once, with who infected them and the rest of that pair’s values: one of those who reached |
| route_mult | The multiplier on a transmission over a route, as a function of the edges and of the people who would be infected (see ss.connectors.route_mult()); name is that of a declared disease’s transmission, or rel_sus for a disease written as code |
| step_draw | Uniforms for some agents from one of the transmission’s distributions (self.dists[key]), keyed by the step alone, so the same agents get the same numbers, declared or written as code; without common random numbers, its next draws |
| strain_cases | The infections of a disease written as code with strains (ss.AgentDisease(strains=...)), as for a declared disease’s: every strain in |
| unprotected | Which of some agents reached by a strain are infected by it: each with the chance kept, the fraction of the force of infection of the strain that reaches them (1 − their protection against it), drawn from protect_<name> |
code_betas
solvers.agents.Transmission.code_betas(beta=None)The beta of a disease written as code (beta, by default its parameter beta) for each of the sim’s networks (by name), as a pair (p1 to p2, p2 to p1), checked against them (see ss.Disease.transmit())
code_route
solvers.agents.Transmission.code_route(i, route, betas, rel_trans, rel_sus)The transmission of a disease written as code along a single network (or other route): see ss.Disease.transmit()
On a network, each edge transmits with probability 1 − (1 − net_beta())^(rel_trans·rel_sus·modifiers), the modifiers being those of the network’s contacts and of rel_sus on the route (ss.modify(..., network=)) (see ss.Network.transmit()), as for a declared disease run as agents, by the same code (over_network()), with beta as the probability in the step. The modifiers of rel_trans and rel_sus (including products) are applied here.
current_value
solvers.agents.Transmission.current_value(kind, *factors)rel_sus or rel_trans (kind) of every agent (by UID), times the factors (e.g. whether each is susceptible), with the modifiers and products active on it applied; may be the array itself, so it is not to be changed
first_infections
solvers.agents.Transmission.first_infections(pairs)Each agent infected, once, with who infected them and over which route: the first of pairs to reach them. Each pair is the sources, the targets, and the index of the route (one, or one for each), and any more values (e.g. a strain); returns the targets (sorted), and for each, the source (ss.dtypes.int_nan where not known), the route, and the more values, of the first pair to reach them
over_network
solvers.agents.Transmission.over_network(
i,
route,
rel_trans,
rel_sus,
betas,
name,
)Who is infected over a network in the step: an edge from u to v transmits with probability 1 − exp(−H), where H is the hazard of the network’s chance net_beta(beta) (with the edge’s weight, and acts if it has them), times rel_trans[u], rel_sus[v], and the modifiers on the route for v: every factor scales the hazard, so a contact infects at most once in the step, wherever an effect is put (see ss.Network.transmit()), as for a declared disease on a network with acts (see transmit_acts())
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| i | int |
the index of the route in sim.networks, recorded for who infected whom |
required |
| route | ss.Network |
the network | required |
| rel_trans | array |
the effective transmissibility of each agent, by UID (0 if not infectious) | required |
| rel_sus | array |
the effective susceptibility of each agent, by UID (0 if not susceptible) | required |
| betas | list |
the probability of transmission over an edge in the step, p1 to p2 and p2 to p1: each a number (0 for none, so no random numbers are drawn), a rate (ss.Rate.to_prob()), or an array of one for each of the network’s directions by sides (see ss.peract) |
required |
| name | str |
what the modifiers on the route are under (see route_mult()) |
required |
Returns
| Name | Type | Description |
|---|---|---|
| A list of (sources, targets, i), for each direction that transmits |
over_routes
solvers.agents.Transmission.over_routes(rel_trans, rel_sus, betamap)The infections over each of the sim’s routes in turn (code_route()), each a tuple of targets, sources, and network IDs: see ss.Disease.transmit()
pick_sources
solvers.agents.Transmission.pick_sources(pairs, name)With strains, each agent reached in the step, once, with who infected them and the rest of that pair’s values: one of those who reached them, each as likely (the first to happen is as likely to be any of them), drawn from pick_<name>. Each pair is the sources, the targets, the index of the route (one, or one for each), and any more values (e.g. a strain), as for first_infections()
route_mult
solvers.agents.Transmission.route_mult(name, route)The multiplier on a transmission over a route, as a function of the edges and of the people who would be infected (see ss.connectors.route_mult()); name is that of a declared disease’s transmission, or rel_sus for a disease written as code
step_draw
solvers.agents.Transmission.step_draw(key, uids)Uniforms for some agents from one of the transmission’s distributions (self.dists[key]), keyed by the step alone, so the same agents get the same numbers, declared or written as code; without common random numbers, its next draws
strain_cases
solvers.agents.Transmission.strain_cases(rel_trans, rel_sus, betamap)The infections of a disease written as code with strains (ss.AgentDisease(strains=...)), as for a declared disease’s: every strain in one pass, at the infectiousness of the strain each carries (rel_trans of ss.Strains); each new case is infected by one of those who reached them, at random (pick_sources()), whose strain they take, unless protected against it (dis.strain_sus(), unprotected())
Returns
| Name | Type | Description |
|---|---|---|
| The new cases, and for each the source, the route, and the index of the strain |
unprotected
solvers.agents.Transmission.unprotected(name, uids, kept)Which of some agents reached by a strain are infected by it: each with the chance kept, the fraction of the force of infection of the strain that reaches them (1 − their protection against it), drawn from protect_<name>
Functions
| Name | Description |
|---|---|
| agent_solver | How a declared module’s agents are stepped, one of the steps of ss.solvers.abm() (‘midstep’, ‘wholestep’, or ‘events’): its own |
agent_solver
solvers.agents.agent_solver(module, sim, why=False)How a declared module’s agents are stepped, one of the steps of ss.solvers.abm() (‘midstep’, ‘wholestep’, or ‘events’): its own (ss.Disease(..., solver=ss.solvers.abm(step=...))), if it has one; else the sim’s, if it names a step (ss.Sim(solver=ss.solvers.abm(step=...))); else what its class suggests (suggested_solver = ss.solvers.abm(step='wholestep') in the class body); else ‘midstep’. With why=True, also where it came from: 'own', 'sim', 'suggested', or 'default'.