Esempio n. 1
0
 def check(method, directed):
     SP1, pred = shortest_path(directed_G,
                               directed=directed,
                               overwrite=False,
                               return_predecessors=True)
     SP2 = construct_dist_matrix(directed_G, pred, directed=directed)
     assert_array_almost_equal(SP1, SP2)
Esempio n. 2
0
 def check(method, directed):
     SP1, pred = shortest_path(directed_G,
                               directed=directed,
                               overwrite=False,
                               return_predecessors=True)
     SP2 = construct_dist_matrix(directed_G, pred, directed=directed)
     assert_array_almost_equal(SP1, SP2)
Esempio n. 3
0
def test_construct_shortest_path():
    SP_res = {True: directed_SP,
              False: undirected_SP}
    for method in methods:
        for directed in (True, False):
            SP1, pred = shortest_path(directed_G,
                                      directed=directed,
                                      overwrite=False,
                                      return_predecessors=True)
            SP2 = construct_dist_matrix(directed_G, pred, directed=directed)

            yield (assert_array_almost_equal, SP1, SP2)
Esempio n. 4
0
def test_construct_shortest_path():
    SP_res = {True: directed_SP,
              False: undirected_SP}
    for method in methods:
        for directed in (True, False):
            SP1, pred = shortest_path(directed_G,
                                      directed=directed,
                                      overwrite=False,
                                      return_predecessors=True)
            SP2 = construct_dist_matrix(directed_G, pred, directed=directed)

            yield (assert_array_almost_equal, SP1, SP2)
    def geoDistDistribution(self, which='array', printd=False):
        '''
        Computation of the geodesic distances.
        Input:
            - which (string): if 'array', then the distances are returned as an array, 
                              otherwise, if 'mean', the average distance is returned
            - printd (bool): if set to true, then the average distance is printed
        Output:
            - distances (numpy.array): array of the numerical distances between nodes
            - dmean (numpy.float64): mean distance
        '''

        import scipy.sparse.csgraph as csg

        A = self.computeAdjMatrix('pruned')

        Asparse = csg.csgraph_from_dense(A)
        Dmatrix, predecessors = csg.shortest_path(Asparse,
                                                  return_predecessors=True,
                                                  method='D')
        Dmatrix = csg.construct_dist_matrix(A, predecessors, directed=False)
        distances = Dmatrix[Dmatrix != np.inf]

        # self.introduce()
        # print('Connected components = {}'.format(csg.connected_components(Asparse)))
        # print('Done with distances')

        if which == 'array':

            return distances

        elif which == 'mean':

            dmean = distances.mean()
            # if printd: print('<d> = {:.4f}'.format(dmean))

            return dmean