def test_unweighted_consistency_er(self): net = models.er(10, [0.9, 0.1]) net = models.er(10, [0.1, 0.3]) net = models.er(10, [0.4, 0.6, 0.5, 0.3]) for i in range(1): net = models.er(10, list(map(lambda x: random.random(), range(5)))) self.test_unweighted_consistency(net) self.test_symmetric_aw(net) net = pymnet.net.MultiplexNetwork([('categorical', 1.0)]) net[1, 9, 1, 1] = 1 net[2, 9, 1, 1] = 1 net[2, 4, 1, 1] = 1 net[5, 8, 0, 0] = 1 self.test_unweighted_consistency(net) net = pymnet.net.MultiplexNetwork([('categorical', 1.0)]) #net.add_node(1) net.add_layer(1) net.add_layer(2) net.add_layer(3) net.add_layer(4) net[1, 2, 1, 1] = 1 net[1, 3, 1, 1] = 1 net[2, 3, 1, 1] = 1 self.test_unweighted_consistency(net)
def test_comparison_random_relabel_mplex_single_aspect_fast( self, backend="nx"): """Test that multiplex networks are isomorphic to randomly relabeled ones. Single aspect version. """ nnodes = [4] nlayers = [4] ps = [0.5] repeats = 5 for nodes in nnodes: for layers in nlayers: for p in ps: for r in range(repeats): net = models.er(nodes, layers * [p]) #node isomorphism self._test_comparison_random_relabel(net, [0], backend) #layer isomorphism self._test_comparison_random_relabel(net, [1], backend) #node-layer isomorphism self._test_comparison_random_relabel( net, [0, 1], backend)
def test_multiplex_erdosrenyi(self): net = models.er(10, 0.5) net2 = models.er(10, [0.4, 0.6]) #test that there are some links but not all self.assertTrue(1 < len(list(net.edges)) < 10 * 9 / 2.) self.assertTrue(1 < len(list(net2.A[1].edges)) < 10 * 9 + 10) net3 = models.er(10, edges=[30, 45]) self.assertEqual(len(net3.A[0].edges), 30) self.assertEqual(len(net3.A[1].edges), 45) net4 = models.er([range(10), range(5, 15)], edges=[30, 45]) self.assertEqual(len(net4.A[0].edges), 30) self.assertEqual(len(net4.A[1].edges), 45) self.assertEqual(set(net4.A[0]), set(range(10))) self.assertEqual(set(net4.A[1]), set(range(5, 15))) net5 = models.er([range(10), range(5, 15)], edges=30) self.assertEqual(len(net5.A[0].edges), 30) self.assertEqual(len(net5.A[1].edges), 30) self.assertEqual(set(net5.A[0]), set(range(10))) self.assertEqual(set(net5.A[1]), set(range(5, 15)))
def test_mplex_fr_layout(self): from pymnet import models mplex=models.er(10,2*[0.2]) fig=visuals.draw(mplex,layout="fr") fig.savefig(os.path.join(self.figdirpath,"mplex_er100_fr.png"))
def test_dijkstra_monoplex_compare(self): n=models.er(100,0.1) d,f=diagnostics.dijkstra(n,[1]) self.assertEqual(d, nx.shortest_path_length(n,1))