Skip to content

Numba random

Numba-accelerated random connection builder for intra-group social networks.

Implements the intra_geo_unit and activity_peers network types.

build_activity_peers(world, network_config)

Random connections among people sharing an activity venue.

Required network_config keys

pool_type – must be "activity" pool.activity – activity key in person.activity_map mean_count – target mean connections per person storage_key – key for person.properties

Optional: degree_variants – list of {probability, count} for heterogeneous degree assign_activity – dict with contact_activity_key and activity_key

Source code in may/social_networks/builder_functions/numba_random.py
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
def build_activity_peers(world, network_config: dict) -> None:
    """
    Random connections among people sharing an activity venue.

    Required network_config keys:
        pool_type        – must be "activity"
        pool.activity    – activity key in person.activity_map
        mean_count       – target mean connections per person
        storage_key      – key for person.properties
    Optional:
        degree_variants  – list of {probability, count} for heterogeneous degree
        assign_activity  – dict with contact_activity_key and activity_key
    """
    pool_config = network_config.get("pool", {})
    pool_type = network_config["pool_type"]
    storage_key = network_config["storage_key"]
    activity_config = network_config.get("assign_activity", None)
    n_people = len(list(world.population.people))

    groups = build_pool(world, pool_type, pool_config)
    connection_filters = parse_constraints(network_config.get("constraints", []))
    connection_counts = _build_connection_counts(n_people, network_config)
    _run_random_numba(world, groups, connection_counts, storage_key,
                      connection_filters, activity_config)

build_intra_geo_unit(world, network_config)

Random connections within geographic units at a specified level.

Required network_config keys

pool_type – must be "geographic" pool.level – e.g. "SGU", "MGU" mean_count – target mean connections per person storage_key – key for person.properties

Optional: degree_variants – list of {probability, count} for heterogeneous degree assign_activity – dict with contact_activity_key and activity_key

Source code in may/social_networks/builder_functions/numba_random.py
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
def build_intra_geo_unit(world, network_config: dict) -> None:
    """
    Random connections within geographic units at a specified level.

    Required network_config keys:
        pool_type   – must be "geographic"
        pool.level  – e.g. "SGU", "MGU"
        mean_count  – target mean connections per person
        storage_key – key for person.properties
    Optional:
        degree_variants  – list of {probability, count} for heterogeneous degree
        assign_activity  – dict with contact_activity_key and activity_key
    """
    pool_config = network_config.get("pool", {})
    pool_type = network_config["pool_type"]
    storage_key = network_config["storage_key"]
    activity_config = network_config.get("assign_activity", None)
    n_people = len(list(world.population.people))

    groups = build_pool(world, pool_type, pool_config)
    connection_filters = parse_constraints(network_config.get("constraints", []))
    connection_counts = _build_connection_counts(n_people, network_config)
    _run_random_numba(world, groups, connection_counts, storage_key,
                      connection_filters, activity_config)