Ejemplo n.º 1
0
    def test_p_dist_zero(self):
        """Tests if p_dict = 0 returns disconencted graph with 0 edges"""
        def p_dist(dist):
            return 0

        G = nx.soft_random_geometric_graph(50, 0.25, p_dist=p_dist)
        assert len(G.edges) == 0
Ejemplo n.º 2
0
 def sample_contacts(self):
     "contacts = csr sparse matrix of i, j in contact"
     g = nx.soft_random_geometric_graph(self.N,
                                        radius=self.radius,
                                        p_dist=self.p_dist,
                                        pos=self.pos)
     contacts = nx.to_scipy_sparse_matrix(g)
     return contacts
Ejemplo n.º 3
0
    def test_p_dist_zero(self):
        """Tests if p_dict = 0 returns disconencted graph with 0 edges

        """
        def p_dist(dist):
            return 0

        G = nx.soft_random_geometric_graph(50, 0.25, p_dist=p_dist)
        assert_true(len(G.edges) == 0)
Ejemplo n.º 4
0
def Convolve(vertices, parameters):
    MINFLOAT = 1e-15  #Set a minimum value to remove floating point errors
    prob = parameters[0]
    radius = parameters[1]
    connection = parameters[2]
    geom_prob = parameters[3]
    #All adjacencies are 0 (make certain they are sparse)
    A_SG = sparse.csr_matrix((vertices, vertices))  #soft geometric graph.
    A_ER = sparse.csr_matrix((vertices, vertices))
    A_G = sparse.csr_matrix((vertices, vertices))
    A_BA = sparse.csr_matrix((vertices, vertices))
    A_DP = sparse.csr_matrix((vertices, vertices))  #random dot product graph
    #turn on models one at a time
    if prob >= MINFLOAT:
        #Create Erdos Renyi
        ER = nx.fast_gnp_random_graph(vertices, prob)
        A_ER = nx.adjacency_matrix(ER)
    if radius >= MINFLOAT:
        #Create Geometric
        #G = nx.random_geometric_graph(vertices, radius)
        #A_G = nx.adjacency_matrix(G)
        #create soft geometric graph
        dist = lambda x: geom_prob
        SG = nx.soft_random_geometric_graph(vertices, radius, p_dist=dist)
        A_SG = nx.adjacency_matrix(SG)
    ####
    #code for a multi step soft geometric
    ####
    #if radius_large >= radius:
    #    #define a uniform probability for soft geometric
    #    def uniform(dist):
    #        return soft_prob
    if connection >= MINFLOAT:
        #Create Barabasi-Albert if m > 0; else turn BA off
        BA = nx.barabasi_albert_graph(vertices, connection)
        A_BA = nx.adjacency_matrix(BA)
    #if dimension>= MINFLOAT:
    #    #Create Random Dot product matrix
    #    rows = rand(dimension, vertices)
    #    A_DP = np.matmul(np.transpose(rows), rows)
    #    for i in range(vertices):
    #        A_DP[i,i] = 0
    #    A_DP[A_DP >= .5] = 1
    #    A_DP[A_DP < .5] = 0
    #    A_DP = sparse.csr_matrix(A_DP)

    #Convolve: add adjacency matrices; anything positive gets set to 1
    A = A_ER + A_G + A_BA + A_SG + A_DP
    #Check that adjacency matricx is symmetric
    #Should never see this error
    if not np.array_equal(A.toarray(), A.toarray().transpose()):
        print('Adjacency not symmetric, WARNING: NOT a simple graph')
    A[A > 0] = 1
    return A
Ejemplo n.º 5
0
    def test_p_dist_default(self):
        """Tests default p_dict = 0.5 returns graph with edge count <= RGG with
           same n, radius, dim and positions

        """
        nodes = 50
        dim = 2
        pos = {v: [random.random() for i in range(dim)] for v in range(nodes)}
        RGG = nx.random_geometric_graph(50, 0.25, pos=pos)
        SRGG = nx.soft_random_geometric_graph(50, 0.25, pos=pos)
        assert_true(len(SRGG.edges()) <= len(RGG.edges()))
Ejemplo n.º 6
0
    def test_p_dist_default(self):
        """Tests default p_dict = 0.5 returns graph with edge count <= RGG with
           same n, radius, dim and positions

        """
        nodes = 50
        dim = 2
        pos = {v: [random.random() for i in range(dim)] for v in range(nodes)}
        RGG = nx.random_geometric_graph(50, 0.25, pos=pos)
        SRGG = nx.soft_random_geometric_graph(50, 0.25, pos=pos)
        assert len(SRGG.edges()) <= len(RGG.edges())
Ejemplo n.º 7
0
    def test_p(self):
        """Tests for providing an alternate distance metric to the
        generator.

        """
        # Use the L1 metric.
        def dist(x, y): return sum(abs(a - b) for a, b in zip(x, y))
        G = nx.soft_random_geometric_graph(50, 0.25, p=1)
        for u, v in combinations(G, 2):
            # Adjacent vertices must be within the given distance.
            if v in G[u]:
                assert dist(G.nodes[u]['pos'], G.nodes[v]['pos']) <= 0.25
Ejemplo n.º 8
0
    def test_node_names(self):
        """Tests using values other than sequential numbers as node IDs."""
        import string

        nodes = list(string.ascii_lowercase)
        G = nx.soft_random_geometric_graph(nodes, 0.25)
        assert len(G) == len(nodes)

        for u, v in combinations(G, 2):
            # Adjacent vertices must be within the given distance.
            if v in G[u]:
                assert math.dist(G.nodes[u]["pos"], G.nodes[v]["pos"]) <= 0.25
Ejemplo n.º 9
0
    def test_p(self):
        """Tests for providing an alternate distance metric to the
        generator.

        """
        # Use the L1 metric.
        def dist(x, y): return sum(abs(a - b) for a, b in zip(x, y))
        G = nx.soft_random_geometric_graph(50, 0.25, p=1)
        for u, v in combinations(G, 2):
            # Adjacent vertices must be within the given distance.
            if v in G[u]:
                assert_true(dist(G.nodes[u]['pos'], G.nodes[v]['pos']) <= 0.25)
Ejemplo n.º 10
0
    def test_distances(self):
        """Tests that pairs of vertices adjacent if and only if they are
        within the prescribed radius.

        """
        # Use the Euclidean metric, the default according to the
        # documentation.
        G = nx.soft_random_geometric_graph(50, 0.25)
        for u, v in combinations(G, 2):
            # Adjacent vertices must be within the given distance.
            if v in G[u]:
                assert math.dist(G.nodes[u]["pos"], G.nodes[v]["pos"]) <= 0.25
Ejemplo n.º 11
0
    def test_distances(self):
        """Tests that pairs of vertices adjacent if and only if they are
        within the prescribed radius.

        """
        # Use the Euclidean metric, the default according to the
        # documentation.
        def dist(x, y): return sqrt(sum((a - b) ** 2 for a, b in zip(x, y)))
        G = nx.soft_random_geometric_graph(50, 0.25)
        for u, v in combinations(G, 2):
            # Adjacent vertices must be within the given distance.
            if v in G[u]:
                assert dist(G.nodes[u]['pos'], G.nodes[v]['pos']) <= 0.25
Ejemplo n.º 12
0
    def test_distances(self):
        """Tests that pairs of vertices adjacent if and only if they are
        within the prescribed radius.

        """
        # Use the Euclidean metric, the default according to the
        # documentation.
        def dist(x, y): return sqrt(sum((a - b) ** 2 for a, b in zip(x, y)))
        G = nx.soft_random_geometric_graph(50, 0.25)
        for u, v in combinations(G, 2):
            # Adjacent vertices must be within the given distance.
            if v in G[u]:
                assert_true(dist(G.nodes[u]['pos'], G.nodes[v]['pos']) <= 0.25)
Ejemplo n.º 13
0
    def test_node_names(self):
        """Tests using values other than sequential numbers as node IDs.

        """
        import string
        nodes = list(string.ascii_lowercase)
        G = nx.soft_random_geometric_graph(nodes, 0.25)
        assert len(G) == len(nodes)

        def dist(x, y): return sqrt(sum((a - b) ** 2 for a, b in zip(x, y)))
        for u, v in combinations(G, 2):
            # Adjacent vertices must be within the given distance.
            if v in G[u]:
                assert dist(G.nodes[u]['pos'], G.nodes[v]['pos']) <= 0.25
Ejemplo n.º 14
0
    def test_node_names(self):
        """Tests using values other than sequential numbers as node IDs.

        """
        import string
        nodes = list(string.ascii_lowercase)
        G = nx.soft_random_geometric_graph(nodes, 0.25)
        assert_equal(len(G), len(nodes))

        def dist(x, y): return sqrt(sum((a - b) ** 2 for a, b in zip(x, y)))
        for u, v in combinations(G, 2):
            # Adjacent vertices must be within the given distance.
            if v in G[u]:
                assert_true(dist(G.nodes[u]['pos'], G.nodes[v]['pos']) <= 0.25)
Ejemplo n.º 15
0
    def geo(n, edges, couplings=None):
        """
        Generates a multiplex network where each layer is genereted using the
        same soft geometric network model.

        The intra-layer networks are generated using the networkx function
        soft_random_geometeric_graph.
        
        Parameters
        ----------
        n : int
            Number of nodes
        edges : list of ints
            Approximate number of edges in each layer
        couplings : None or tuple
            The coupling types of the multiplex network object.

        Returns
        -------
        net : MultiplexNetwork
           The multiplex network produced

        Notes
        -----
        Works only with networkX2
        """

        net = MultiplexNetwork(couplings=couplings)
        pos = None
        for layer, m in enumerate(edges):
            net.add_layer(layer)
            r = math.sqrt(2.2 * float(m) / ((n - 1.0) * n) / math.pi)
            netX = networkx.soft_random_geometric_graph(n, r, pos=pos)
            pos = networkx.get_node_attributes(netX, 'pos')
            for node in netX.nodes:
                net.add_node(node)

            for e in netX.edges:
                net[e[0], e[1], layer] = 1

        return net
Ejemplo n.º 16
0
def getGeoGraph():
    G = nx.soft_random_geometric_graph(5000, 0.07)

    neurons = {}
    for i in range(len(G.nodes)):
        x, y = G.node[i]['pos']
        neurons[i] = Node([])
        neurons[i].runActiv = 0
    neurons[250].runActiv = 10
    nx.set_node_attributes(G, neurons, 'node')
    densities = {}
    for edge in G.edges:
        density = random.gauss(0.5, 0.3)
        while density < 0 or density > 1:
            density = random.gauss(0.5, 0.3)
        densities[edge] = density
        neurons[edge[0]].addConnection(Connection(neurons[edge[1]], density))
        neurons[edge[1]].addConnection(Connection(neurons[edge[0]], density))

    nx.set_edge_attributes(G, densities, 'density')
    print(G.nodes(data=True))

    return G
Ejemplo n.º 17
0
 def test_number_of_nodes(self):
     G = nx.soft_random_geometric_graph(50, 0.25, seed=42)
     assert len(G) == 50
     G = nx.soft_random_geometric_graph(range(50), 0.25, seed=42)
     assert len(G) == 50
Ejemplo n.º 18
0
 def test_number_of_nodes(self):
     G = nx.soft_random_geometric_graph(50, 0.25)
     assert_equal(len(G), 50)
     G = nx.soft_random_geometric_graph(range(50), 0.25)
     assert_equal(len(G), 50)
Ejemplo n.º 19
0
 def test_number_of_nodes(self):
     G = nx.soft_random_geometric_graph(50, 0.25)
     assert_equal(len(G), 50)
     G = nx.soft_random_geometric_graph(range(50), 0.25)
     assert_equal(len(G), 50)