Skip to content

Commit 1bbdff9

Browse files
authored
Merge pull request #15 from Mathics3/tweak-docs-for-measures-and-metrics
Go over docs for graph measures and metrics...
2 parents fef519e + 10433d3 commit 1bbdff9

File tree

4 files changed

+69
-36
lines changed

4 files changed

+69
-36
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+
>> BalancedTree[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: 18 additions & 22 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
@@ -1028,9 +1025,9 @@ def eval_patt(self, graph, patt, expression, evaluation, options):
10281025
class AdjacencyList(_NetworkXBuiltin):
10291026
"""
10301027
<url>
1031-
:Adjacenty list:
1028+
:Adjacency list:
10321029
https://en.wikipedia.org/wiki/Adjacency_list</url> (<url>
1033-
:Networkx:
1030+
:NetworkX:
10341031
https://networkx.org/documentation/networkx-2.8.8/reference/readwrite/adjlist.html</url>,
10351032
<url>
10361033
:WMA:
@@ -1039,9 +1036,10 @@ class AdjacencyList(_NetworkXBuiltin):
10391036
<dl>
10401037
<dt>'AdjacencyList'[$graph$, $v$]
10411038
<dd>gives a list of vertices adjacent to $v$ in a 'Graph' \
1042-
or a list of edges $g$..
1039+
or a list of edges $g$.
1040+
10431041
<dt>'AdjacencyList'[$graph$, $pattern$]
1044-
<dd>gives a list of vertices adjacent to vertices \.
1042+
<dd>gives a list of vertices adjacent to vertices \
10451043
matching $pattern$.
10461044
</dl>
10471045
@@ -1102,7 +1100,7 @@ class BetweennessCentrality(_Centrality):
11021100
<url>
11031101
:Betweenness centrality:
11041102
https://en.wikipedia.org/wiki/Betweenness_centrality</url> (<url>
1105-
:Networkx:
1103+
:NetworkX:
11061104
https://networkx.org/documentation/networkx-2.8.8/reference/algorithms/generated/\
11071105
networkx.algorithms.centrality.betweenness_centrality.html</url>,
11081106
<url>
@@ -1146,7 +1144,7 @@ class ClosenessCentrality(_Centrality):
11461144
<url>
11471145
:Betweenness centrality:
11481146
https://en.wikipedia.org/wiki/Closeness_centrality</url> (<url>
1149-
:Networkx:
1147+
:NetworkX:
11501148
https://networkx.org/documentation/networkx-2.8.8/reference/algorithms/generated/\
11511149
networkx.algorithms.centrality.closeness_centrality.html</url>,
11521150
<url>
@@ -1194,7 +1192,7 @@ class DegreeCentrality(_Centrality):
11941192
<url>
11951193
:Degree centrality:
11961194
https://en.wikipedia.org/wiki/Degree_centrality</url> (<url>
1197-
:Networkx:
1195+
:NetworkX:
11981196
https://networkx.org/documentation/networkx-2.8.8/reference/algorithms/generated/\
11991197
networkx.algorithms.centrality.degree_centrality.html</url>,
12001198
<url>
@@ -1252,7 +1250,7 @@ class DirectedEdge(Builtin):
12521250
<url>
12531251
:Directed edge:
12541252
https://en.wikipedia.org/wiki/Directed_graph</url> (<url>
1255-
:Networkx:
1253+
:NetworkX:
12561254
https://networkx.org/documentation/stable/reference/classes/digraph.html</url>,
12571255
<url>
12581256
:WMA:
@@ -1273,7 +1271,7 @@ class EdgeConnectivity(_NetworkXBuiltin):
12731271
<url>
12741272
:Edge connectivity:
12751273
https://en.wikipedia.org/wiki/Directed_graph</url> (<url>
1276-
:Networkx:
1274+
:NetworkX:
12771275
https://networkx.org/documentation/stable/reference/algorithms/\
12781276
generated/networkx.algorithms.connectivity.connectivity.edge_connectivity.html</url>,
12791277
<url>
@@ -1397,7 +1395,7 @@ class EigenvectorCentrality(_ComponentwiseCentrality):
13971395
<url>
13981396
:Eigenvector Centrality:
13991397
https://en.wikipedia.org/wiki/Eigenvector_centrality</url> (<url>
1400-
:Networkx:
1398+
:NetworkX:
14011399
https://networkx.org/documentation/networkx-2.8.8/reference/algorithms\
14021400
/generated/networkx.algorithms.centrality.eigenvector_centrality.html</url>,
14031401
<url>
@@ -1462,7 +1460,7 @@ class FindShortestPath(_NetworkXBuiltin):
14621460
<url>
14631461
:Shortest path problem:
14641462
https://en.wikipedia.org/wiki/Shortest_path_problem</url> (<url>
1465-
:Networkx:
1463+
:NetworkX:
14661464
https://networkx.org/documentation/networkx-2.8.8/reference/algorithms\
14671465
/generated/networkx.algorithms.shortest_paths.generic.shortest_path.html</url>,
14681466
<url>
@@ -1647,14 +1645,11 @@ def boxes_to_tex(self, elements, **options):
16471645
class HITSCentrality(_Centrality):
16481646
"""
16491647
<url>
1650-
:https://en.wikipedia.org/wiki/HITS_algorithm:
1651-
https://en.wikipedia.org/wiki/HITS_centrality</url> (<url>
1652-
:Networkx:
1648+
:NetworkX:
16531649
https://networkx.org/documentation/networkx-2.8.8/reference/algorithms/\
1654-
generated/networkx.algorithms.link_analysis.hits_alg.hits.html</url>,
1655-
<url>
1650+
generated/networkx.algorithms.link_analysis.hits_alg.hits.html</url>, <url>
16561651
:WMA:
1657-
https://reference.wolfram.com/language/ref/HITSCentrality.html</url>)
1652+
https://reference.wolfram.com/language/ref/HITSCentrality.html</url>
16581653
16591654
<dl>
16601655
<dt>'HITSCentrality'[$g$]
@@ -1731,7 +1726,7 @@ class KatzCentrality(_ComponentwiseCentrality):
17311726
<url>
17321727
:Katz Centrality:
17331728
https://en.wikipedia.org/wiki/Katz_centrality</url> (<url>
1734-
:Networkx:
1729+
:NetworkX:
17351730
https://networkx.org/documentation/networkx-2.8.8/reference/algorithms\
17361731
/generated/networkx.algorithms.centrality.katz_centrality.html\
17371732
#networkx.algorithms.centrality.katz_centrality</url>, <url>
@@ -1793,7 +1788,7 @@ class PageRankCentrality(_Centrality):
17931788
<url>
17941789
:Pagerank Centrality:
17951790
https://en.wikipedia.org/wiki/Pagerank</url> (<url>
1796-
:Networkx:
1791+
:NetworkX:
17971792
https://networkx.org/documentation/networkx-2.8.8/reference/algorithms\
17981793
/generated/networkx.algorithms.link_analysis.pagerank_alg.pagerank.html</url>,
17991794
<url>
@@ -1814,6 +1809,7 @@ class PageRankCentrality(_Centrality):
18141809
# >> g = Graph[{a -> d, b -> c, d -> c, d -> a, e -> c, d -> c}]; PageRankCentrality[g, 0.2]
18151810
= {0.184502, 0.207565, 0.170664, 0.266605, 0.170664}
18161811
"""
1812+
18171813
summary_text = "get the page rank centralities"
18181814

18191815
def eval_alpha_beta(self, graph, alpha, expression, evaluation, options):

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$]'

pymathics/graph/parametric.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,10 @@ def eval(self, r, n, expression, evaluation: Evaluation, options: dict):
320320

321321

322322
class GraphAtlas(_NetworkXBuiltin):
323-
"""<dl>
323+
"""
324+
<dl>
324325
<dt>'GraphAtlas[$n$]'
325-
<dd>Returns graph number $i$ from the Networkx's Graph \
326+
<dd>Returns graph number $i$ from the NetworkX's Graph \
326327
Atlas. There are about 1200 of them and get large as $i$ \
327328
increases.
328329
</dl>
@@ -334,7 +335,7 @@ class GraphAtlas(_NetworkXBuiltin):
334335
messages = {
335336
"ilsmp": "Expected a positive integer at position 1 in ``.",
336337
}
337-
summary_text = "build the i-esim graph from the Networkx atlas"
338+
summary_text = "build the i-esim graph from the NetworkX atlas"
338339

339340
def eval(self, n, expression, evaluation: Evaluation, options: dict):
340341
"%(name)s[n_Integer, OptionsPattern[%(name)s]]"

0 commit comments

Comments
 (0)