You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/chapters/01-networkrepresentations.html
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -444,7 +444,7 @@ <h3 class="anchored" data-anchor-id="networks-as-graphs">Networks as Graphs</h3>
444
444
</div>
445
445
</div>
446
446
<divclass="page-columns page-full"><p>Here’s an example of a famous graph: the Zachary Karate Club. Each node represents a member of a university karate club, and each edge represents a friendly social relationship between them. This graph is supplied by <code>networkx</code>, the Python software package that we’ll use throughout these notes for network analysis. </p><divclass="no-row-height column-margin column-container"><spanclass="margin-aside">The code in this collapsed cell imports packages and sets up various plotting options</span></div></div>
<h3class="anchored" data-anchor-id="computing-with-degrees">Computing with Degrees</h3>
466
466
<divclass="page-columns page-full"><p>Let’s grab some sample data. We’ll use the <em>Les Miserables</em> network, which is a network of coappearances of characters in the book <em>Les Miserables</em> by Victor Hugo. Nodes represent characters and edges represent characters who appear within the same chapter. This data set is supplied as a built-in example in NetworkX, and for this reason we’ll use it several times throughout these notes. </p><divclass="no-row-height column-margin column-container"><spanclass="margin-aside">This hidden code cell imports several packages and defines an <code>unweight</code> function which we’ll use to convert the network from its native weighted format to an unweighted format.</span></div></div>
<h4class="anchored" data-anchor-id="degrees-from-the-adjacency-matrix">Degrees from the Adjacency Matrix</h4>
508
508
<divclass="page-columns page-full"><p>One way to compute the degrees of the nodes in a graph is to use the adjacency matrix, as directly described by <ahref="#def-degree" class="quarto-xref">Definition <span>2.1</span></a>. With convenient functions from NetworkX and NumPy, this is a two-liner: </p><divclass="no-row-height column-margin column-container"><spanclass="margin-aside">For undirected graphs, we could equally do <code>np.sum(A, axis = 0)</code> because <spanclass="math inline">\(\mathbf{A}\)</span> is a symmetric matrix. When we discuss directed graphs soon, it will become necessary to be careful!</span></div></div>
<p>The result is a <code>DegreeView</code> object which behaves much like a Python dictionary (and which can be easily converted to a dictionary using the <code>dict</code> constructor).</p>
524
524
<p>Let’s take a moment to compare the first few nodes to make sure that our two methods agree:</p>
<spanid="cb6-3"><ahref="#cb6-3" aria-hidden="true" tabindex="-1"></a><spanclass="cf">if</span> i <spanclass="op"><</span><spanclass="dv">5</span>:</span>
@@ -617,7 +617,7 @@ <h3 class="anchored" data-anchor-id="degree-in-directed-graphs">Degree in direct
617
617
</div>
618
618
</div>
619
619
<p>Let’s calculate the in-degrees of the nodes in the Hamilton network using the adjacency matrix and compare to the networkx built-ins.</p>
@@ -665,7 +665,7 @@ <h3 class="anchored" data-anchor-id="degree-in-directed-graphs">Degree in direct
665
665
</div>
666
666
</div>
667
667
<p>Some special cases of regular graphs are <strong>lattices</strong> (e.g., a square lattice is 4-regular) and the <strong>complete graph</strong> where every node is connected to every other node (which is <spanclass="math inline">\((n-1)\)</span>-regular).</p>
@@ -1021,7 +1021,7 @@ <h2 class="anchored" data-anchor-id="cyclic-and-acyclic-graphs">Cyclic and Acycl
1021
1021
</div>
1022
1022
</div>
1023
1023
<p>Now that we’re convinced that the algorithm works, let’s go ahead and implement it in Python. Our implementation accepts a NetworkX <code>DiGraph</code> object as an argument, returning <code>True</code> if the network is cyclic and <code>False</code> if the network is acyclic.</p>
<p>All trees are necessarily simple graphs, because self- and multiedges would create cycles. Trees always have exactly <spanclass="math inline">\(n-1\)</span> edges, as can be proven via induction. Furthermore, any connected graph with <spanclass="math inline">\(n-1\)</span> edges is a tree.</p>
1111
1111
<p>Trees are often drawn as <em>rooted trees</em> with a <em>root node</em> at the top and <em>leaf nodes</em> below. Any node can be chosen as the root of a tree.</p>
0 commit comments