Skip to content

Commit

Permalink
remove wildcard imports from old tutorials
Browse files Browse the repository at this point in the history
  • Loading branch information
arashbm committed Jul 6, 2024
1 parent 3d4b1e4 commit a498bd6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
20 changes: 10 additions & 10 deletions doc/tutorial/networktypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ Start by importing the library:

.. code-block:: python
>>> from pymnet import *
>>> import pymnet
:code:`MultilayerNetwork` is the basic network class in the library – all other types of networks are special cases of it. In order to get a monoplex network object, you can simply construct a :code:`MultilayerNetwork` with 0 aspects.

.. code-block:: python
>>> net = MultilayerNetwork(aspects=0)
>>> net = pymnet.MultilayerNetwork(aspects=0)
You can now start adding nodes to the network with the :code:`add_node` method:

Expand Down Expand Up @@ -105,7 +105,7 @@ By default, all network objects are undirected. Directed network objects can be

.. code-block:: python
>>> dirnet = MultilayerNetwork(aspects=0, directed=True)
>>> dirnet = pymnet.MultilayerNetwork(aspects=0, directed=True)
>>> dirnet[1, 2] = 1
>>> dirnet[1, 2]
1
Expand All @@ -122,7 +122,7 @@ We are now ready to move to more general multilayer networks with an arbitrary

.. code-block:: python
>>> mnet = MultilayerNetwork(aspects=1)
>>> mnet = pymnet.MultilayerNetwork(aspects=1)
Networks of this type are similar to the monoplex ones, but now you have layers in addition to nodes. You can add new layers with the :code:`add_layer` method:

Expand Down Expand Up @@ -163,7 +163,7 @@ You can create networks with arbitrary number of aspects. The syntax for this ty

.. code-block:: python
>>> mnet2 = MultilayerNetwork(aspects=2)
>>> mnet2 = pymnet.MultilayerNetwork(aspects=2)
>>> mnet2[1, 2, "a" ,"b", "x" ,"y"] = 1
>>> mnet2[1, "a", "x"][2, "b", "y"]
1
Expand Down Expand Up @@ -191,7 +191,7 @@ The simplest multiplex network is the one with no coupling edges. You would crea

:code:`MultiplexNetwork`

>>> mplex = MultiplexNetwork(couplings="none")
>>> mplex = pymnet.MultiplexNetwork(couplings="none")

The nodes and edges can be accessed and added as usual:

Expand All @@ -212,7 +212,7 @@ In categorical networks, all the diagonal inter-layer edges are present.

.. code-block:: python
>>> cnet = MultiplexNetwork(couplings="categorical")
>>> cnet = pymnet.MultiplexNetwork(couplings="categorical")
>>> cnet.add_node(1)
>>> cnet.add_layer("a")
>>> cnet.add_layer("b")
Expand All @@ -223,7 +223,7 @@ In ordinal networks, only adjacent layers are connected to each other. In a :cod

.. code-block:: python
>>> onet = MultiplexNetwork(couplings="ordinal")
>>> onet = pymnet.MultiplexNetwork(couplings="ordinal")
>>> onet.add_node("node")
>>> onet.add_layer(1)
>>> onet.add_layer(2)
Expand All @@ -237,7 +237,7 @@ You can also give the coupling strength, i.e. the weight of the inter-layer edge

.. code-block:: python
>>> cnet = MultiplexNetwork(couplings=("categorical", 10))
>>> cnet = pymnet.MultiplexNetwork(couplings=("categorical", 10))
>>> cnet.add_node(1)
>>> cnet.add_layer("a")
>>> cnet.add_layer("b")
Expand All @@ -249,7 +249,7 @@ the following code constructs a multiplex network where the first aspect is cate

.. code-block:: python
>>> conet = MultiplexNetwork(couplings=["categorical", "ordinal"])
>>> conet = pymnet.MultiplexNetwork(couplings=["categorical", "ordinal"])
>>> conet.add_node("node")
>>> conet.add_layer("a", 1)
>>> conet.add_layer("b", 1)
Expand Down
5 changes: 3 additions & 2 deletions doc/tutorial/nx.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Using NetworkX functions

Start by importing the library:

>>> from pymnet import nx, models
>>> from pymnet import nx

You can then run any NetworkX function from the pymnet.nx module. For example, you can produce the Karate Club network with the following command.

Expand All @@ -25,5 +25,6 @@ For the sake of reproducability in the next example, let's explicitly seed the r

You can also pass Pymnet objects as arguments to NetworkX functions in a similar way. This is handy, for example, when analyzing monoplex structures of intra-layer networks of multiplex networks. For example, producing a multiplex network with three Erdos-Renyi intra-layer networks using Pymnet and calculating the number of connected components in each layer can be done with the following command:

>>> {name: nx.number_connected_components(layer) for name, layer in models.er(1000, 3*[0.005]).A.items()}
>>> import pymnet
>>> {name: nx.number_connected_components(layer) for name, layer in pymnet.er(1000, 3*[0.005]).A.items()}
{0: 10, 1: 9, 2: 5}
18 changes: 9 additions & 9 deletions doc/tutorial/visualizing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ Drawing networks with the library is easy and is usually done with the :code:`dr

.. code-block:: python
>>> from pymnet import *
>>> net = models.er_multilayer(5, 2, 0.2)
>>> fig = draw(net)
>>> import pymnet
>>> net = pymnet.er_multilayer(5, 2, 0.2)
>>> fig = pymnet.draw(net)
The first line of this code imports :code:`pymnet`. The second line creates a random node-aligned multilayer network with 5 nodes and 2 layers, where two node-layers are connected to each other with a probability of 0.2. The third line then creates a picture of that network.

Expand All @@ -25,7 +25,7 @@ Alternatively, you can view the network straight away by telling the draw method

.. code-block:: python
>>> fig = draw(net, show=True)
>>> fig = pymnet.draw(net, show=True)
The figure produced looks like this:

Expand All @@ -36,7 +36,7 @@ Multiplex-network figures can also be produced. For example, running the followi

.. code-block:: python
>>> fig = draw(er(10, 3*[0.4]), layout="spring")
>>> fig = pymnet.draw(er(10, 3*[0.4]), layout="spring")
produces the following picture of a multiplex Erdos-Renyi network:

Expand All @@ -47,7 +47,7 @@ There are multiple ways of customizing the figures. For documentation, look at t

.. code-block:: python
>>> fig = draw(er(10, 3*[0.3]),
>>> fig = pymnet.draw(er(10, 3*[0.3]),
layout="circular",
layershape="circle",
nodeColorDict={(0,0):"r", (1,0):"r", (0,1):"r"},
Expand All @@ -65,9 +65,9 @@ If the network is large, then it is often desirable not to plot the coupling edg

.. code-block:: python
>>> net = read_ucinet("bkfrat.dat", couplings="none")
>>> net = transforms.threshold(net, 4)
>>> fig = draw(net,
>>> net = pymnet.read_ucinet("bkfrat.dat", couplings="none")
>>> net = pymnet.transforms.threshold(net, 4)
>>> fig = pymnet.draw(net,
show=True,
layout="spring",
layerColorRule={},
Expand Down

0 comments on commit a498bd6

Please sign in to comment.