Пример #1
0
 def test_nodal_pathlengths_conn(self):
     mean_path_lengths = metrics.nodal_pathlengths(self.g)
     desired = 1.0 / (self.n_nodes - 1) * np.array([
         1 + 1 + 2 + 3, 1 + 1 + 2 + 3, 1 + 1 + 1 + 2, 2 + 2 + 1 + 1,
         3 + 3 + 2 + 1
     ])
     npt.assert_array_almost_equal(mean_path_lengths, desired)
Пример #2
0
 def test_nodal_pathlengths_conn(self):
     mean_path_lengths = metrics.nodal_pathlengths(self.g)
     desired = 1.0 / (self.n_nodes - 1) * np.array([1 + 1 + 2 + 3,
                                                    1 + 1 + 2 + 3,
                                                    1 + 1 + 1 + 2,
                                                    2 + 2 + 1 + 1,
                                                    3 + 3 + 2 + 1])
     npt.assert_array_almost_equal(mean_path_lengths, desired)
Пример #3
0
 def test_nodal_pathlengths_disconn(self):
     self.g.remove_edge(2, 3)
     # Now all nodes still have at least one edge, but not all nodes are
     # reachable from all others.
     path_lengths = metrics.nodal_pathlengths(self.g)
     # Distances for all node pairs:
     # 0-1: 1    1-2: 1    2-3: Inf  3-4: 1
     # 0-2: 1    1-3: Inf  2-4: Inf
     # 0-3: Inf  1-4: Inf
     # 0-4: Inf
     desired = (1.0 / (self.n_nodes - 1) * np.array([
         1 + 1 + np.inf + np.inf, 1 + 1 + np.inf + np.inf, 1 + 1 + np.inf +
         np.inf, np.inf + np.inf + np.inf + 1, np.inf + np.inf + np.inf + 1
     ]))
     npt.assert_array_almost_equal(path_lengths, desired)
Пример #4
0
 def test_nodal_pathlengths_disconn(self):
     self.g.remove_edge(2, 3)
     # Now all nodes still have at least one edge, but not all nodes are
     # reachable from all others.
     path_lengths = metrics.nodal_pathlengths(self.g)
     # Distances for all node pairs:
     # 0-1: 1    1-2: 1    2-3: Inf  3-4: 1
     # 0-2: 1    1-3: Inf  2-4: Inf
     # 0-3: Inf  1-4: Inf
     # 0-4: Inf
     desired = (1.0 / (self.n_nodes - 1) *
                np.array([1 + 1 + np.inf + np.inf,
                          1 + 1 + np.inf + np.inf,
                          1 + 1 + np.inf + np.inf,
                          np.inf + np.inf + np.inf + 1,
                          np.inf + np.inf + np.inf + 1]))
     npt.assert_array_almost_equal(path_lengths, desired)