Backend accessors
An AnnNet object gives access to the algorithms of three graph libraries:
| accessor | library | what anet.<accessor>.<name> calls |
|---|---|---|
anet.nx |
NetworkX | the function networkx.<name>, for example from the NetworkX algorithms |
anet.ig |
igraph | the method igraph.Graph.<name> of the converted graph (see the Graph API and graph analysis), or else the function igraph.<name> |
anet.gt |
graph-tool | the function graph_tool.<namespace>.<name>, called as anet.gt.<namespace>.<name> |
The accessor converts anet to a graph of the library, calls the function,
and gives back the result of the library. The conversion is cached.
# networkx.betweenness_centrality(...)
scores = anet.nx.betweenness_centrality(anet)
# igraph.Graph.pagerank() on the converted graph
pagerank = anet.ig.pagerank()
# graph_tool.centrality.pagerank(...)
pagerank = anet.gt.centrality.pagerank(anet)
Pass anet where the library function expects its graph. The accessor puts the
converted graph in its place. Where the library takes a node, you can give the
annnet node ID.
The graph-tool namespaces are those of the
graph-tool documentation:
topology,
centrality,
clustering,
flow,
inference,
generation,
search
and util. A name
that only one namespace has also works without the namespace:
anet.gt.pagerank(anet).
Accessors and adapters
The adapter functions in annnet.adapters also convert, but they give you the
graph of the other library:
annnet.adapters.to_nx(...)andannnet.adapters.from_nx(...)annnet.adapters.to_igraph(...)andannnet.adapters.from_igraph(...)annnet.adapters.to_graphtool(...)andannnet.adapters.from_graphtool(...)
Use an adapter when you want to work with the other graph object yourself. Use
anet.nx, anet.ig or anet.gt when anet stays your data and you only
want the result of an algorithm.
Clear the cache after a change
Not every change of anet clears the cached conversion. After you edit the
graph, call clear() on the accessor before you run another algorithm, or
convert again with an adapter. The
computation guide shows both
forms.
Methods of every accessor
backend(...): the converted graph of the library.clear(): remove the cached conversions of this accessor.
anet.nx and anet.ig also have:
peek_nodes(k=10): a few node identifiers of the converted graph.
Conversion options
anet.nx.backend(...) and anet.ig.backend(...) take these options:
directedhyperedge_modesliceslicesneeded_attrssimpleedge_aggs
An algorithm call takes the same options with a prefix, so that they do not
mix with the arguments of the library function: _nx_directed,
_nx_hyperedge, _nx_slice, _nx_slices, _nx_label_field, _nx_simple
and _nx_edge_aggs for NetworkX, and the same names with _ig_ for igraph.
# Betweenness on the graph read as undirected
scores = anet.nx.betweenness_centrality(anet, _nx_directed=False)
anet.gt.backend() takes no options and gives the converted graph-tool graph.