Skip to content

Commit

Permalink
[skip ci] docs built of 991e83d
Browse files Browse the repository at this point in the history
  • Loading branch information
ci-doc-deploy-bot committed Aug 27, 2023
1 parent e215f67 commit 7d68aaa
Show file tree
Hide file tree
Showing 67 changed files with 1,294 additions and 991 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
121 changes: 74 additions & 47 deletions _sources/content/algorithms/assortativity/correlation.ipynb

Large diffs are not rendered by default.

50 changes: 28 additions & 22 deletions _sources/content/algorithms/assortativity/correlation.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,29 @@ language_info:
version: 3.8.5
---

# Node assortativity coefficients and correlation measures
# Node Assortativity Coefficients and Correlation Measures

In this tutorial, we will go through the theory of [assortativity](https://en.wikipedia.org/wiki/Assortativity) and its measures.
In this tutorial, we will explore the theory of assortativity [^1] and its measures.

Specifically, we'll focus on assortativity measures available in NetworkX at [algorithms/assortativity/correlation.py](https://github.com/networkx/networkx/blob/main/networkx/algorithms/assortativity/correlation.py):
We'll focus on assortativity measures available in NetworkX at [`algorithms/assortativity/correlation.py`](https://github.com/networkx/networkx/blob/main/networkx/algorithms/assortativity/correlation.py):
* Attribute assortativity
* Numeric assortativity
* Degree assortativity

as well as mixing matrices, which are closely releated to assortativity measures.
as well as mixing matrices, which are closely related to assortativity measures.

## Import packages

```{code-cell} ipython3
import networkx as nx
import matplotlib.pyplot as plt
import pickle
import copy
import random
import warnings
%matplotlib inline
```

## Assortativity

Expand Down Expand Up @@ -80,7 +93,7 @@ Pearson correlation coefficient.

Here the property $P(v)$ is a nominal property assigned to each node.
As defined above we calculate the normalized mixing matrix $e$ and from that we
define the attribute assortativity coefficient [^1] as below.
define the attribute assortativity coefficient [^2] as below.

From here onwards we will use subscript notation to denote indexing, for eg. $P_i = P[i]$ and $e_{ij} = e[i][j]$

Expand All @@ -93,7 +106,7 @@ It is implemented as `attribute_assortativity_coefficient`.
Here the property $P(v)$ is a numerical property assigned to each
node and the definition of the normalized mixing
matrix $e$, $\sigma_a$, and $\sigma_b$ are same as above.
From these we define numeric assortativity coefficient [^1] as below.
From these we define numeric assortativity coefficient [^2] as below.

$$ r = \frac{\sum\limits_{i,j}P_i P_j(e_{ij} -a_i b_j)}{\sigma_a\sigma_b} $$

Expand All @@ -105,7 +118,7 @@ When it comes to measuring degree assortativity for directed networks we have
more options compared to assortativity w.r.t a property because we have 2 types
of degrees, namely in-degree and out-degree.
Based on the 2 types of degrees we can measure $2 \times 2 =4$ different types
of degree assortativity [^2]:
of degree assortativity [^3]:

1. r(in,in) : Measures tendency of having a directed edge (u,v) such that, in-degree(u) = in-degree(v).
2. r(in,out) : Measures tendency of having a directed edge (u,v) such that, in-degree(u) = out-degree(v).
Expand All @@ -130,25 +143,14 @@ It is implemented as `degree_assortativity_coefficient` and
`scipy.stats.pearsonr` to calculate the assortativity coefficient which makes
it potentally faster.

## Example
## Assortativity Example

```{code-cell} ipython3
%matplotlib inline
import networkx as nx
import matplotlib.pyplot as plt
import pickle
import copy
import random
import warnings
warnings.filterwarnings("ignore")
```
+++

Illustrating how value of assortativity changes

```{code-cell} ipython3
gname = "g2"
# loading the graph
G = nx.read_graphml(f"data/{gname}.graphml")
with open(f"data/pos_{gname}", "rb") as fp:
pos = pickle.load(fp)
Expand Down Expand Up @@ -261,6 +263,10 @@ are drawn.

+++

[^1]: M. E. J. Newman, Mixing patterns in networks <https://doi.org/10.1103/PhysRevE.67.026126>
## References

[^1]: [Wikipedia, Assortativity](https://en.wikipedia.org/wiki/Assortativity)

[^2]: M. E. J. Newman, Mixing patterns in networks <https://doi.org/10.1103/PhysRevE.67.026126>

[^2]: Foster, J.G., Foster, D.V., Grassberger, P. & Paczuski, M. Edge direction and the structure of networks <https://doi.org/10.1073/pnas.0912671107>
[^3]: Foster, J.G., Foster, D.V., Grassberger, P. & Paczuski, M. Edge direction and the structure of networks <https://doi.org/10.1073/pnas.0912671107>
127 changes: 67 additions & 60 deletions _sources/content/algorithms/dag/index.ipynb

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions _sources/content/algorithms/dag/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,24 @@ language_info:
# Directed Acyclic Graphs & Topological Sort

In this tutorial, we will explore the algorithms related to a directed acyclic graph
(or a "dag" as it is sometimes called) implemented in networkx under `networkx/algorithms/dag.py`.
(or a "DAG" as it is sometimes called) implemented in NetworkX under [`networkx/algorithms/dag.py`](https://github.com/networkx/networkx/blob/main/networkx/algorithms/dag.py).

First of all, we need to understand what a directed graph is.

## Directed Graph

### Example
## Import packages

```{code-cell} ipython3
%matplotlib inline
import networkx as nx
import matplotlib.pyplot as plt
```
import inspect
```{code-cell} ipython3
triangle_graph = nx.from_edgelist([(1, 2), (2, 3), (3, 1)], create_using=nx.DiGraph)
%matplotlib inline
```

## Example: Directed Graphs

```{code-cell} ipython3
triangle_graph = nx.DiGraph([(1, 2), (2, 3), (3, 1)])
nx.draw_planar(
triangle_graph,
with_labels=True,
Expand Down Expand Up @@ -75,7 +74,6 @@ clothing_graph = nx.read_graphml(f"data/clothing_graph.graphml")

```{code-cell} ipython3
plt.figure(figsize=(12, 12), dpi=150)
nx.draw_planar(
clothing_graph,
arrowsize=12,
Expand Down Expand Up @@ -164,7 +162,7 @@ Then, a topological sort gives an order in which to perform the jobs.

A closely related application of topological sorting algorithms
was first studied in the early 1960s in the context of the
[PERT technique](https://en.wikipedia.org/wiki/Program_evaluation_and_review_technique)
PERT technique [^1]
for scheduling in project management.
In this application, the vertices of a graph represent the milestones of a project,
and the edges represent tasks that must be performed between one milestone and another.
Expand Down Expand Up @@ -343,8 +341,6 @@ We need to check this while the `while` loop is running.
Combining all of the above gives the current implementation of the `topological_generations()` function in NetworkX.

```{code-cell} ipython3
import inspect
print(inspect.getsource(nx.topological_generations))
```

Expand All @@ -353,3 +349,7 @@ Let's finally see what the result will be on the `clothing_graph`.
```{code-cell} ipython3
list(nx.topological_generations(clothing_graph))
```

## References

[^1]: [Wikipedia, PERT Technique](https://en.wikipedia.org/wiki/Program_evaluation_and_review_technique)
145 changes: 87 additions & 58 deletions _sources/content/algorithms/euler/euler.ipynb

Large diffs are not rendered by default.

24 changes: 17 additions & 7 deletions _sources/content/algorithms/euler/euler.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ kernelspec:

# Euler's Algorithm

In this tutorial, we will explore the Euler's algorithm and its implementation in NetworkX under `networkx/algorithms/euler.py`.
+++

In this tutorial, we will explore Euler's algorithm and its implementation in NetworkX under [`networkx/algorithms/euler.py`](https://github.com/networkx/networkx/blob/main/networkx/algorithms/euler.py).

## Import package

```{code-cell}
import networkx as nx
```

## Seven Bridges of Königsberg

Expand All @@ -37,8 +45,7 @@ In order to have a clear look, we should first simplify the map a little.
Euler observed that the choice of route inside each land mass is irrelevant. The only thing that matters is the sequence of bridges to be crossed. This observation allows us to abstract the problem even more. In the graph below, blue vertices represent the land masses and edges represent the bridges that connect them.

```{code-cell}
import networkx as nx
# Create graph
G = nx.DiGraph()
G.add_edge("A", "B", label="a")
G.add_edge("B", "A", label="b")
Expand All @@ -50,6 +57,7 @@ G.add_edge("C", "D", label="g")
positions = {"A": (0, 0), "B": (1, -2), "C": (1, 2), "D": (2, 0)}
# Visualize graph
nx.draw_networkx_nodes(G, pos=positions, node_size=500)
nx.draw_networkx_edges(
G, pos=positions, edgelist=[("A", "D"), ("B", "D"), ("C", "D")], arrowstyle="-"
Expand All @@ -73,9 +81,10 @@ Note that every Euler Circuit is also an Euler Path.

### Euler's Method

Euler[^2] denoted land masses of the town by capital letters $A$, $B$, $C$ and $D$ and bridges by lowercase $a$, $b$, $c$, $d$, $e$, $f$ and $g$. Let's draw the graph based on this node and edge labels.
Euler [^2] denoted land masses of the town by capital letters $A$, $B$, $C$ and $D$ and bridges by lowercase $a$, $b$, $c$, $d$, $e$, $f$ and $g$. Let's draw the graph based on this node and edge labels.

```{code-cell}
# Design and draw graph
edge_labels = nx.get_edge_attributes(G, "label")
nx.draw_networkx_nodes(G, pos=positions, node_size=500)
Expand Down Expand Up @@ -117,7 +126,7 @@ Euler generalized the method he applied for Königsberg problem as follows:
- If there are two vertices with odd degree, then they are the starting and ending vertices.
- If there are no vertices with odd degree, any vertex can be starting or ending vertex and the graph has also an Euler Circuit.

## NetworkX Implementation of Euler's Algorithm
## Euler's Algorithm in NetworkX

NetworkX implements several methods using the Euler's algorithm. These are:
- **is_eulerian** : Whether the graph has an Eulerian circuit
Expand Down Expand Up @@ -282,5 +291,6 @@ Euler's algorithm is essential for anyone or anything that uses paths. Some exam

## References

[^1]: <https://en.wikipedia.org/wiki/Seven_Bridges_of_K%C3%B6nigsberg>
[^2]: Euler, Leonhard, ‘Solutio problematis ad geometriam situs pertinentis’ (1741), Eneström 53, MAA Euler Archive.
[^1]: [Wikipedia, Seven Bridge of Konigsberg](https://en.wikipedia.org/wiki/Seven_Bridges_of_K%C3%B6nigsberg)

[^2]: Euler, Leonhard, ‘Solutio problematis ad geometriam situs pertinentis’ (1741), Eneström 53, MAA Euler Archive.
Loading

0 comments on commit 7d68aaa

Please sign in to comment.