def barabasi_albert(n, n_init, k=1, node_names=None, directed=False, temporal=False): """ """ if node_names is None: node_names = [str(x) for x in range(n)] assert len( node_names ) >= n, 'Error: Number of node names not matching degree sequence length' if not temporal: network = Network(directed=directed) else: network = TemporalNetwork() endpoints = [] time = 0 # initial network for i in range(n_init): for j in range(n_init): if i < j: if not temporal: network.add_edge(str(node_names[i]), str(node_names[j])) else: network.add_edge(str(node_names[i]), str(node_names[j]), time, directed=directed) endpoints.append(str(node_names[i])) endpoints.append(str(node_names[j])) for i in range(n_init, n): time += 1 # TODO: for k>1 we can choose different stubs of the same node in one step! targets = _np.random.choice(endpoints, size=k, replace=False) for t in targets: if not temporal: network.add_edge(str(node_names[i]), t) else: network.add_edge(str(node_names[i]), t, time, directed=directed) endpoints.append(str(node_names[i])) endpoints.append(t) return network
def erdoes_renyi_gnm(n, m, node_names=None, self_loops=True, directed=False, temporal=False): """ """ if node_names is None: node_names = [str(x) for x in range(n)] assert len( node_names ) >= n, 'Error: Number of node names not matching degree sequence length' if not temporal: network = Network(directed=directed) else: network = TemporalNetwork() # generate nodes if not temporal: for i in range(n): network.add_node(str(node_names[i])) time = -1 m_current = 0 edges = defaultdict(lambda: False) # add edges while m_current < m: edge = _np.random.choice(n, size=2, replace=self_loops) edge = [node_names[edge[0]], node_names[edge[1]]] if not edges[(edge[0], edge[1])]: edges[(edge[0], edge[1])] = True if not directed: edges[(edge[1], edge[0])] = True if not temporal: m_current += 1 network.add_edge(edge[0], edge[1]) else: time += 1 m_current += 1 network.add_edge(edge[0], edge[1], time, directed=directed) return network
def erdoes_renyi_gnp(n, p, node_names=None, self_loops=True, directed=False, temporal=False): """ """ if node_names is None: node_names = [str(x) for x in range(n)] assert len( node_names ) >= n, 'Error: Number of node names not matching degree sequence length' if not temporal: network = Network(directed=directed) else: network = TemporalNetwork() # make sure that isolated nodes exist if not temporal: for i in range(n): network.add_node(str(node_names[i])) time = -1 # add edges for i in range(n): for j in range(i + 1): if i != j or self_loops: if _np.random.rand() <= p: if not temporal: network.add_edge(node_names[i], node_names[j]) else: time += 1 network.add_edge(node_names[i], node_names[j], time, directed=directed) return network