|
9 | 9 | [](https://discord.com/invite/vur45CbwMz)
|
10 | 10 | <!--- [](https://graphblas-algorithms.readthedocs.io/en/latest/) --->
|
11 | 11 |
|
12 |
| -GraphBLAS algorithms written in Python with [Python-graphblas](https://github.com/python-graphblas/python-graphblas). We are trying to target the NetworkX API algorithms where possible. |
| 12 | +GraphBLAS algorithms written in Python with [Python-graphblas](https://python-graphblas.readthedocs.io/en/latest/). We are trying to target the NetworkX API algorithms where possible. |
13 | 13 |
|
14 | 14 | ### Installation
|
15 | 15 | ```
|
| 16 | +conda install -c conda-forge graphblas-algorithms |
| 17 | +``` |
| 18 | +``` |
16 | 19 | pip install graphblas-algorithms
|
17 | 20 | ```
|
18 | 21 |
|
19 |
| -This is a work in progress. Stay tuned (or come help 😃)! |
| 22 | +## Basic Usage |
| 23 | + |
| 24 | +First, create a GraphBLAS Matrix. |
| 25 | + |
| 26 | +```python |
| 27 | +import graphblas as gb |
| 28 | + |
| 29 | +M = gb.Matrix.from_coo( |
| 30 | + [0, 0, 1, 2, 2, 3], |
| 31 | + [1, 3, 0, 0, 1, 2], |
| 32 | + [1., 2., 3., 4., 5., 6.], |
| 33 | + nrows=4, ncols=4, dtype='float32' |
| 34 | +) |
| 35 | +``` |
| 36 | + |
| 37 | +Next wrap the Matrix as `ga.Graph`. |
| 38 | + |
| 39 | +```python |
| 40 | +import graphblas_algorithms as ga |
| 41 | + |
| 42 | +G = ga.Graph(M) |
| 43 | +``` |
| 44 | + |
| 45 | +Finally call an algorithm. |
| 46 | + |
| 47 | +```python |
| 48 | +hubs, authorities = ga.hits(G) |
| 49 | +``` |
| 50 | + |
| 51 | +When the result is a value per node, a `gb.Vector` will be returned. |
| 52 | +In the case of [HITS](https://en.wikipedia.org/wiki/HITS_algorithm), |
| 53 | +two Vectors are returned representing the hubs and authorities values. |
| 54 | + |
| 55 | +Algorithms whose result is a subgraph will return `ga.Graph`. |
| 56 | + |
| 57 | +## Plugin for NetworkX |
| 58 | + |
| 59 | +Dispatching to plugins is a new feature in Networkx 3.0. |
| 60 | +When both `networkx` and `graphblas-algorithms` are installed in an |
| 61 | +environment, calls to NetworkX algorithms can be dispatched to the |
| 62 | +equivalent version in `graphblas-algorithms`. |
| 63 | + |
| 64 | +### Dispatch Example |
| 65 | +```python |
| 66 | +import networkx as nx |
| 67 | +import graphblas_algorithms as ga |
| 68 | + |
| 69 | +# Generate a random graph (5000 nodes, 1_000_000 edges) |
| 70 | +G = nx.erdos_renyi_graph(5000, 0.08) |
| 71 | + |
| 72 | +# Explicitly convert to ga.Graph |
| 73 | +G2 = ga.Graph.from_networkx(G) |
| 74 | + |
| 75 | +# Pass G2 to NetworkX's k_truss |
| 76 | +T5 = nx.k_truss(G2, 5) |
| 77 | +``` |
| 78 | + |
| 79 | +`G2` is not a `nx.Graph`, but it does have an attribute |
| 80 | +`__networkx_plugin__ = "graphblas"`. This tells NetworkX to |
| 81 | +dispatch the k_truss call to graphblas-algorithms. This link |
| 82 | +connection exists because graphblas-algorithms registers |
| 83 | +itself as a "networkx.plugin" entry point. |
| 84 | + |
| 85 | +The result `T5` is a `ga.Graph` representing the 5-truss structure of the |
| 86 | +original graph. To convert to a NetworkX Graph, use: |
| 87 | +```python |
| 88 | +T5.to_networkx() |
| 89 | +``` |
| 90 | + |
| 91 | +Note that even with the conversions to and from `ga.Graph`, this example still runs 10x |
| 92 | +faster than using the native NetworkX k-truss implementation. Speed improvements scale |
| 93 | +with graph size, so larger graphs will see an even larger speed-up relative to NetworkX. |
| 94 | + |
| 95 | +### Plugin Algorithms |
| 96 | + |
| 97 | +The following NetworkX algorithms have been implemented |
| 98 | +by graphblas-algorithms and can be used following the |
| 99 | +dispatch pattern shown above. |
| 100 | + |
| 101 | +- Boundary |
| 102 | + - edge_boundary |
| 103 | + - node_boundary |
| 104 | +- Centrality |
| 105 | + - degree_centrality |
| 106 | + - eigenvector_centrality |
| 107 | + - in_degree_centrality |
| 108 | + - katz_centrality |
| 109 | + - out_degree_centrality |
| 110 | +- Cluster |
| 111 | + - average_clustering |
| 112 | + - clustering |
| 113 | + - generalized_degree |
| 114 | + - square_clustering |
| 115 | + - transitivity |
| 116 | + - triangles |
| 117 | +- Community |
| 118 | + - inter_community_edges |
| 119 | + - intra_community_edges |
| 120 | +- Core |
| 121 | + - k_truss |
| 122 | +- Cuts |
| 123 | + - boundary_expansion |
| 124 | + - conductance |
| 125 | + - cut_size |
| 126 | + - edge_expansion |
| 127 | + - mixing_expansion |
| 128 | + - node_expansion |
| 129 | + - normalized_cut_size |
| 130 | + - volume |
| 131 | +- DAG |
| 132 | + - ancestors |
| 133 | + - descendants |
| 134 | +- Dominating |
| 135 | + - is_dominating_set |
| 136 | +- Isolate |
| 137 | + - is_isolate |
| 138 | + - isolates |
| 139 | + - number_of_isolates |
| 140 | +- Link Analysis |
| 141 | + - hits |
| 142 | + - pagerank |
| 143 | +- Reciprocity |
| 144 | + - overall_reciprocity |
| 145 | + - reciprocity |
| 146 | +- Regular |
| 147 | + - is_k_regular |
| 148 | + - is_regular |
| 149 | +- Shortest Paths |
| 150 | + - has_path |
| 151 | +- Simple Paths |
| 152 | + - is_simple_path |
| 153 | +- S Metric |
| 154 | + - s_metric |
| 155 | +- Structural Holes |
| 156 | + - mutual_weight |
| 157 | +- Tournament |
| 158 | + - is_tournament |
| 159 | + - score_sequence |
| 160 | + - tournament_matrix |
| 161 | +- Triads |
| 162 | + - is_triad |
0 commit comments