paramnet
paramnet provides a convenience mixin, Parametrized, for creating subclasses of NetworkX’s Graph (DiGraph) that have numeric parameters associated with nodes and edges (for example, a dynamical system on a network). It provides the following key features:
Simplified reads/writes for the parameter value for a specific node/edge, without navigating NetworkX’s nested dict structure
Enforcing a well-defined node order on the graph, which in turn allows…
Extraction of all values of a given node (edge) parameter as a 1D (2D) numpy array
Examples
A parametrized network class can be created by subclassing from Graph or DiGraph using the Parametrized mixin. The names of any node/edge parameters can be specified in the class definition:
>>> class MyGraph(Parametrized, Graph, node_params=['x'], edge_params=['y']):
... pass
G = MyGraph()
Note: As with all mixins, Parametrized should be inherited from first as above.
paramnet automatically adds named fields for each declared parameter, supporting clean random access (both read and write) by node or edge
>>> G.add_edge('a', 'b', y=3)
>>> G.x['a']
100
>>> G.x['a'] = 4
>>> G.y['a', 'b']
3
>>> G.y['a', 'b'] = 50
Contrast this with the more cumbersome random access in base NetworkX (which can be used interchangeably if you wish):
>>> G.nodes['a']['x']
100
>>> G.nodes['a']['x'] = 4
>>> G.edges['a', 'b']['y']
3
>>> G.edges['a', 'b']['y'] = 50
What’s more, paramnet maintains the order in which nodes were added, allowing index lookup:
>>> G.index('a')
0
>>> G.index('b')
1
>>> G.add_node('c')
>>> G.index('c')
2
But that’s not all. Because the nodes are ordered, we can get a well-defined representation of all values of a given node (edge) parameter at once as a vector (matrix). This is accomplished within paramnet by accessing the associated parameter attribute without square brackets:
>>> G.x
array([100, 100])
>>> G.y
array([[0., 3.],
[3., 0.]])
>>> G.A
array([[0., 1.],
[1., 0.]])
Note the special case for the weighted network adjacency matrix, which is automatically defined for every graph through the field A (instead of weight), regardless of whether weight is supplied in edge_params.
Under the hood, the parameter fields return View objects that wrap most numpy functionality, allowing vector arithmetic and other array operations
>>> G = MyGraph()
>>> G.add_nodes_from([(node, {'x': 5*node+1}) for node in range(5)])
>>> G.add_cycle(range(5), y=1)
# number of paths of length two between node pairs
>>> np.dot(G.A, G.A)
array([[0., 3., 1., 1., 3.],
[3., 0., 3., 1., 1.],
[1., 3., 0., 3., 1.],
[1., 1., 3., 0., 3.],
[3., 1., 1., 3., 0.]])
>>> G.x + 1
array([ 2, 7, 12, 17, 22])
Dependencies
NetworkX (>= 2.0)
numpy
License
paramnet is released under the MIT license. See LICENSE for details.
Metadata
Release files for paramnet 2.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| paramnet-2.3.0.tar.gz | 7.0 kB | Without provenance | Details for paramnet-2.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| paramnet-2.3.0-py3-none-any.whl | Python 3 | none | any | Details for paramnet-2.3.0-py3-none-any.whl |
Total release size: 18.4 kB
Release files / paramnet-2.3.0.tar.gz
| Download URL | paramnet-2.3.0.tar.gz |
|---|---|
| Size | 7.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c6482a92f9ac1c13ddcbabe1cd8f14c9e18a4380b25a86314d455440c0c7abc5
|
|
BLAKE2b-256 checksum How to use checksums |
39f7487b69c8f7452d9de1028451a0ff9b820cde3611c9a2e4429103c8281919
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.1
|
Release files / paramnet-2.3.0-py3-none-any.whl
| Download URL | paramnet-2.3.0-py3-none-any.whl |
|---|---|
| Size | 11.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b556e9e935a04aaf3bc7fc25ada517891c469911beccd1551552cd405fcd2c3e
|
|
BLAKE2b-256 checksum How to use checksums |
f39753f271e0e3d8834fd914fc0ed042e9e956f8ca0e90a07bb30037c96fd117
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.1
|
Security for paramnet 2.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.