Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0cc7d18

Browse files
Add notes that correspond to Jupyter notebook
These notes are out of sync with the Jupyter notebook, so a bit of work will be needed to copy results from the Jupyter notebook over to this org-mode document.
1 parent 79786bc commit 0cc7d18

File tree

1 file changed

+47
-24
lines changed

1 file changed

+47
-24
lines changed

‎notes/network_outline.org‎

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ There are four basic tasks for interacting with networks
6868
- Understanding how to use Matplotlib to visualize and plot results
6969
- Describe basic analysis to be done on networks
7070

71-
* Working with Nodes and Objects
71+
* Creating Networks From Scratch and Manipulation
72+
73+
** Working with Nodes and Objects
7274

7375
| Method Command | Description |
7476
|--------------------------------+-----------------------------------------------|
@@ -77,24 +79,44 @@ There are four basic tasks for interacting with networks
7779
| ~nx.all_neighbors(G, node)~ | Return all neighbors of node in graph |
7880
| ~nx.non_neighbors(G, node)~ | Return non-neighbors of node in graph |
7981
| ~nx.common_neighbors(G, u, v)~ | Return common neighbors of two nodes in graph |
82+
| ~G.add_node(node)~ | Add node to graph object, G |
83+
| ~G.add_nodes_from(array)~ | Add array of nodes to graph object, G |
8084

8185
#+BEGIN_SRC python
8286
# Create (empty) graph with no nodes and no edges
83-
G = nx.Graph()
84-
#+END_SRC
87+
DG = nx.DiGraph()
8588

86-
* Creating Networks From Scratch and Manipulation
89+
# Add one node
90+
G.add_node("Michael")
91+
92+
# Add multiple nodes
93+
G.add_nodes_from(["Andy", "Jim", "Angela"])
94+
95+
# Look at nodes are in our object
96+
G.nodes()
97+
#+END_SRC
8798

8899
** Working with Edges and Connections
89100

90-
| Method Command | Description |
91-
|-------------------------+------------------------------------|
92-
| ~nx.edges(G)~ | Return edge view of edges |
93-
| ~nx.number_of_edges(G)~ | Return number of edges in graph |
94-
| ~nx.non_edges(G)~ | Return non-existent edges in graph |
101+
| Method Command | Description |
102+
|----------------------------+------------------------------------|
103+
| ~nx.edges(G)~ | Return edge view of edges |
104+
| ~nx.number_of_edges(G)~ | Return number of edges in graph |
105+
| ~nx.non_edges(G)~ | Return non-existent edges in graph |
106+
| ~G.add_edge(node1, node2)~ | Add edge between node1 and node2 |
107+
108+
#+BEGIN_SRC python
109+
# Add edges and connections between nodes
110+
DG.add_edge("Michael", "Jim")
111+
112+
# Or add a group of edge conections all at once
113+
DG.add_edges_from([("Michael", "Angela"), ("Michael", "Andy"), ("Angela", "Andy")])
114+
#+END_SRC
95115

96116
** Node and Edge Attributes
97117

118+
Nodes and edges can not only just exist, but can also take on values or *attributes*.
119+
98120
| Type | Method Command | Description |
99121
|------+-------------------------------------+----------------------------------------------------|
100122
| Node | ~nx.set_node_attributes(G, values)~ | Set node attributes from given value or dictionary |
@@ -112,16 +134,16 @@ G = nx.Graph()
112134

113135
** Drawing Graphs in Different Ways
114136

115-
There are lots of flexibility in drawing networks. You can find more
137+
There is lots of flexibility in drawing networks. You can find more
116138
[[https://networkx.github.io/documentation/networkx-1.10/reference/generated/networkx.drawing.nx_pylab.draw_networkx.html#networkx.drawing.nx_pylab.draw_networkx][here in the ~draw_networkx()~ reference documentation]].
117139

118140
*** Drawing Algorithms
119141

120142
While it is great to create and have a network in a data structure, it is also
121143
important and interesting to explore these networks visually by plotting them
122-
in various way.
144+
in various ways.
123145

124-
| Method Command | Description |
146+
| Method Command | Drawing Description |
125147
|-----------------------+------------------------------------------------------------------------|
126148
| ~nx.draw(G)~ | Draw graph with Matplotlib |
127149
| ~nx.draw_random(G)~ | Draw graph with random layout |
@@ -140,12 +162,12 @@ method.
140162

141163
#+BEGIN_SRC python
142164
# Use the *_layout() functions within the draw() method
143-
nx.draw(KG, pos=spring_layout(KG))
165+
nx.draw(KG, pos=nx.spring_layout(KG))
144166
#+END_SRC
145167

146168
*** Drawing Nodes
147169

148-
There are a few paramters for the ~nx.draw()~ method that can manipulate node
170+
There are a few parameters for the ~nx.draw()~ method that can manipulate node
149171
properties.
150172

151173
| Paramter | Description |
@@ -166,7 +188,7 @@ properties.
166188

167189
Here are some parameters specific for modifying how edges are displayed.
168190

169-
| Paramter | Description |
191+
| Parameter | Description |
170192
|--------------+-----------------------------------------------------------|
171193
| ~arrows~ | For directed graphs, if ~True~ draw arrowheads |
172194
| ~arrowstyle~ | For directed graphs, choose style of arrow |
@@ -219,8 +241,8 @@ Quick and basic metrics of a graph are the number of edges and nodes.
219241

220242
*** Degree of Nodes
221243

222-
Remember, that there are two basic kinds of graphs: directed and undirected. In
223-
the directed graph, there are two different kinds of edges: in and out.
244+
Remember, there are two basic kinds of graphs: directed and undirected. In the
245+
directed graph, there are two different kinds of edges: in and out.
224246

225247
#+BEGIN_SRC python
226248
# Find in-degree edges
@@ -260,11 +282,11 @@ Here are just a few.
260282
|------------------------+------------------------------------------------------+--------------------------------|
261283
| Degree centrality | Node is important based on degrees | ~nx.degree_centrality(G)~ |
262284
| Eigenvector centrality | Node is important if linked by other important nodes | ~nx.eigenvector_centrality(G)~ |
263-
| Betweenness centrality | Node is important if within shortest paths in nodes | ~nx.betweeneess_centrality(G)~ |
285+
| Betweenness centrality | Node is important if within shortest paths in nodes | ~nx.betweenness_centrality(G)~ |
264286

265287
#+BEGIN_SRC python
266288
# Calculate eigenvector centrality
267-
nx.eigenvector_centrality(DG)
289+
nx.eigenvector_centrality(KG)
268290
#+END_SRC
269291

270292
** Basic Graph Algorithms
@@ -279,9 +301,9 @@ Given a network, **graph traversal** is the problem of searching through a
279301
network for particular nodes or certain paths. A path is a sequence of edges
280302
between two nodes.
281303

282-
*Situation*: social networks like to recommend friends to you and one idea is to
283-
find friends close enough to your current social network, who else would you
284-
know?
304+
*Problem*: Social networks like to recommend friends to you and one idea is to
305+
find friends close enough to your current social network. So who else would you
306+
potentially know?
285307

286308
#+BEGIN_SRC python
287309
# Check a path can exist
@@ -302,7 +324,7 @@ Now we have the shortest path, we can then plot this.
302324

303325
*** Community Detection
304326

305-
In a social network, you may be interested in tightly connected group of
327+
In a social network, you may be interested in tightly connected groups of
306328
friends. We can use a method called *community detection* or *module detection*
307329
to answer this question.
308330

@@ -361,7 +383,8 @@ Return the results as a dictionary.
361383

362384
*Bonus Challenge*: Create a function and script to use the random network from the
363385
previous exercise, creates 10 networks of size 5, 10, 15 and use your just
364-
created function to return a dictionary with the average for each
386+
created function to return a dictionary with the average number of neighbors
387+
for each.
365388

366389
* Resources
367390

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /