Random Generators

Random Number Generator

class trecs.random.generators.Generator(seed=None, bit_generator=None)[source]

Wrapper around numpy.random.Generator. Please see the Numpy documentation for more details.

Parameters
  • seed (int, optional) –

  • bit_generator (numpy.random.BitGenerator, optional) – numpy.random.BitGenerator. Please see Numpy’s BitGenerator documentation for more details.

Social Graph Generator

class trecs.random.generators.SocialGraphGenerator[source]

Thin wrapper around the Networkx random graph generators. We use this static class to generate random network adjacency matrices.

By default, it generates a binomial graph, but it can generate any other random graph included in the Networkx API. Please refer to the Networkx documentation.

static generate_random_graph(num, *args, **kwargs)[source]

Note: to change type of graph, please include the graph_type parameter.

Parameters

num (int) – Number of nodes in the graph. This is equivalent to the number of users in the system.

Returns

Adjacency matrix – Size |U|x|U|.

Return type

numpy.ndarray

Raises

ValueError – If num is not an integer.

Examples

A minimal use case:

>>> from trecs.random import SocialGraphGenerator
>>> num = 1000 # <-- number of nodes (users)
>>> graph = SocialGraphGenerator.generate_random_graph(num=num)
>>> graph # <-- 1000x1000 binomial adjacency matrix

Changing random graph generator (e.g., with the random_regular_graph):

>>> from networkx.generators.random_graphs import random_regular_graph
>>> rrg = random_regular_graph
>>> d = 30 # <-- degree, also required by random_regular_graph
>>> graph = SocialGraphGenerator.generate_random_graph(num=num, d=d, graph_type=rrg)