Skip to content

Commit 27e70c3

Browse files
committed
Go over docs for graph measures and metrics...
Also add some examples which will also be used on the Danjo side in the gallery
1 parent fef519e commit 27e70c3

File tree

3 files changed

+50
-20
lines changed

3 files changed

+50
-20
lines changed

pymathics/graph/__init__.py

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,40 @@
11
"""
22
Graphs - Vertices and Edges
33
4+
5+
A Graph is a tuple of a set of Nodes and Edges.
6+
47
Mathics3 Module that provides functions and variables for working with graphs.
58
6-
Example:
7-
In[1]:= LoadModule["pymathics.graph"]
8-
Out[1]= pymathics.graph
9-
In[2]:= BinomialTree[3]
10-
In[3]:= BinomialTree[6]
11-
In[4]:= CompleteKaryTree[3, VertexLabels->True]
9+
Examples:
10+
11+
>> LoadModule["pymathics.graph"]
12+
= pymathics.graph
13+
14+
>> BinomialTree[3, DirectedEdges->True]
15+
= -Graph-
16+
17+
>> BalencedTree[3, 3]
18+
= -Graph-
19+
20+
>> g = Graph[{1 -> 2, 2 -> 3, 3 <-> 4}, VertexLabels->True]
21+
= -Graph-
22+
23+
>> ConnectedComponents[g]
24+
= {{3, 4}, {2}, {1}}
25+
26+
>> WeaklyConnectedComponents[g]
27+
= {{1, 2, 3, 4}}
28+
29+
>> GraphDistance[g, 1, 4]
30+
= 3
31+
32+
>> GraphDistance[g, 3, 2]
33+
= Infinity
1234
13-
Networkx does the heavy lifting here.
35+
<url>
36+
:NetworkX:
37+
https://networkx.org</url> does the heavy lifting here.
1438
"""
1539

1640
from pymathics.graph.base import (

pymathics/graph/base.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
"""
44
Core routines for working with Graphs.
5-
A Graph is a tuple of a set of Nodes and Edges.
6-
7-
networkx does all the heavy lifting.
85
"""
96

107
# uses networkx
@@ -1647,14 +1644,11 @@ def boxes_to_tex(self, elements, **options):
16471644
class HITSCentrality(_Centrality):
16481645
"""
16491646
<url>
1650-
:https://en.wikipedia.org/wiki/HITS_algorithm:
1651-
https://en.wikipedia.org/wiki/HITS_centrality</url> (<url>
1652-
:Networkx:
1647+
:NetworkX:
16531648
https://networkx.org/documentation/networkx-2.8.8/reference/algorithms/\
1654-
generated/networkx.algorithms.link_analysis.hits_alg.hits.html</url>,
1655-
<url>
1649+
generated/networkx.algorithms.link_analysis.hits_alg.hits.html</url>, <url>
16561650
:WMA:
1657-
https://reference.wolfram.com/language/ref/HITSCentrality.html</url>)
1651+
https://reference.wolfram.com/language/ref/HITSCentrality.html</url>
16581652
16591653
<dl>
16601654
<dt>'HITSCentrality'[$g$]

pymathics/graph/measures_and_metrics.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ def eval_patt(
5555
class EdgeCount(_PatternCount):
5656
"""
5757
<url>
58-
:WMA link:
58+
:NetworkX:
59+
https://networkx.org/documentation/latest/reference/generated/networkx.classes.function.edges.html#edges</url>, <url>
60+
:WMA:
5961
https://reference.wolfram.com/language/ref/EdgeCount.html</url>
6062
6163
<dl>
@@ -82,6 +84,12 @@ def _items(self, graph):
8284

8385
class GraphDistance(_NetworkXBuiltin):
8486
"""
87+
<url>
88+
:NetworkX:
89+
https://networkx.org/documentation/latest/reference/algorithms/generated/networkx.algorithms.shortest_paths.generic.shortest_path_length.html</url>, <url>
90+
:WMA:
91+
https://reference.wolfram.com/language/ref/GraphDistance.html</url>
92+
8593
<dl>
8694
<dt>'GraphDistance'[$g$, $s$, $t$]
8795
<dd>returns the distance from source vertex $s$ to target vertex $t$ in the graph $g$.
@@ -155,7 +163,9 @@ def eval_s_t(self, graph, s, t, expression, evaluation: Evaluation, options: dic
155163
class VertexCount(_PatternCount):
156164
"""
157165
<url>
158-
:WMA link:
166+
:NetworkX:
167+
https://networkx.org/documentation/latest/reference/generated/networkx.classes.function.nodes.html</url>, <url>
168+
:WMA:
159169
https://reference.wolfram.com/language/ref/VertexCount.html</url>
160170
161171
<dl>
@@ -193,8 +203,10 @@ def _items(self, graph):
193203
class VertexDegree(_NetworkXBuiltin):
194204
"""
195205
<url>
196-
:WMA link:
197-
https://reference.wolfram.com/language/ref/EdgeCount.html</url>
206+
:NetworkX:
207+
https://networkx.org/documentation/latest/reference/classes/generated/networkx.Graph.degree.html</url>, <url>
208+
:WMA:
209+
https://reference.wolfram.com/language/ref/VertexDegree.html</url>
198210
199211
<dl>
200212
<dt>'VertexDegree[$g$]'

0 commit comments

Comments
 (0)