Skip to main content

XSwap: Fast degree-preserving network permutation

XSwap is an algorithm for degree-preserving network randomization (permutation) [1]. Permuted networks can be used for a number of purposes in network analysis, including for generating counterfactual distributions of features when only the network's degree sequence is maintained or for computing a prior probability of an edge given only the network's degree sequence. Overall, permuted networks allow one to quantify the effects of degree on analysis and prediction methods. Understanding this effect is useful when a network's degree sequence is subject to biases. This implementation is a modified version of the algorithm due to Hanhijärvi et al. with two additional parameters (allow_self_loops and allow_antiparallel), which enable greater generalizability to bipartite, directed, and undirected networks.

  1. Randomization Techniques for Graphs Sami Hanhijärvi, Gemma C. Garriga, Kai Puolamäki Proceedings of the 2009 SIAM International Conference on Data Mining (2009-04-30) https://doi.org/f3mn58 DOI: 10.1137/1.9781611972795.67

Usage examples

Permuting an edge list

>>> edges = [(0, 1), (1, 0)]
>>> permuted_edges, permutation_statistics = xswap.permute_edge_list(
        edges, allow_self_loops=True, allow_antiparallel=True,
        multiplier=10)
>>> permuted_edges
[(0, 0), (1, 1)]
>>> permutation_statistics
{'swap_attempts': 20, 'same_edge': 10, 'self_loop': 0, 'duplicate': 1,
 'undir_duplicate': 0, 'excluded': 0}

Computing degree-sequence based prior probabilities of edges existing

>>> edges = [(0, 1), (1, 0)]
>>> prior_prob_df = xswap.prior.compute_xswap_priors(
        edges, n_permutations=10000, shape=(2, 2), allow_self_loops=True,
        allow_antiparallel=True)
>>> prior_prob_df
   source_id  target_id   edge  source_degree  target_degree  xswap_prior
0          0          0  False              1              1          0.5
1          0          1   True              1              1          0.5
2          1          0   True              1              1          0.5
3          1          1  False              1              1          0.5

Choice of parameters

Bipartite networks

Bipartite networks should be indexed using the bi-adjacency matrix, meaning that the edge (0, 0) is from source node 0 to target node 0, and is not a self-loop. Moreover, bipartite networks should be permuted using allow_self_loops=False and allow_antiparallel=True.

Directed and undirected networks

For non-bipartite networks, the decisions of allow_self_loops and allow_antiparallel are not always the same. For undirected networks, set allow_antiparallel=False, as otherwise the edges (1, 0) and (0, 1), which represent the same edge, will be treated as separate. Antiparallel edges may or may not be allowed for directed networks, depending on context. Similarly, self-loops may or may not be allowed for directed or undirected networks, depending on the specific network being permuted.

Libraries

The XSwap library includes Roaring Bitmaps (https://github.com/RoaringBitmap/CRoaring), available under the Apache 2.0 license (https://github.com/RoaringBitmap/CRoaring/blob/LICENSE).

Acknowledgments

Development of this project has largely taken place in the Greene Lab at the University of Pennsylvania. However, as an open source project under the hetio organization, this repository is grateful for its community of maintainers, contributors, and users.

This work is funded in part by the Gordon and Betty Moore Foundation’s Data-Driven Discovery Initiative through Grants GBMF4552 to Casey Greene, GBMF4560 to Blair Sullivan, and the National Institutes of Health’s National Human Genome Research Institute R01 HG010067.

Metadata

Release files for xswap 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for xswap 0.0.2
File
xswap-0.0.2-cp37-cp37m-manylinux2010_x86_64.whl CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.12+ x86-64 Details
xswap-0.0.2-cp37-cp37m-manylinux1_x86_64.whl CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.5+ x86-64 Details
xswap-0.0.2-cp37-cp37m-manylinux1_i686.whl CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.5+ x86-32 Details
xswap-0.0.2-cp36-cp36m-manylinux2010_x86_64.whl CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.12+ x86-64 Details
xswap-0.0.2-cp36-cp36m-manylinux1_x86_64.whl CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-64 Details
xswap-0.0.2-cp36-cp36m-manylinux1_i686.whl CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-32 Details
xswap-0.0.2-cp35-cp35m-manylinux2010_x86_64.whl CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.12+ x86-64 Details
xswap-0.0.2-cp35-cp35m-manylinux1_x86_64.whl CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.5+ x86-64 Details
xswap-0.0.2-cp35-cp35m-manylinux1_i686.whl CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.5+ x86-32 Details

Total release size: 4.0 MB

Release files / xswap-0.0.2-cp37-cp37m-manylinux2010_x86_64.whl

Download URL xswap-0.0.2-cp37-cp37m-manylinux2010_x86_64.whl
Size 473.6 kB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.12+ x86-64
SHA-256 checksum
How to use checksums
ea2d49e1ae4367e595eaf6ec6c6cd498a8059a2cd7e2337ed2a5764ace0a37ba
BLAKE2b-256 checksum
How to use checksums
d888f159a7895058706f9fdbfe81d12fb2020a1848b75c3b7466451da96956ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/28.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.3

Release files / xswap-0.0.2-cp37-cp37m-manylinux1_x86_64.whl

Download URL xswap-0.0.2-cp37-cp37m-manylinux1_x86_64.whl
Size 426.1 kB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
266614df150b830f31cfedf8b68070544b50a213707017ae885554f63f2e7182
BLAKE2b-256 checksum
How to use checksums
bb524f269b43e8e1acd18c9a401bf41e55dccfef07434d33b38827abbd2af8df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/28.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.3

Release files / xswap-0.0.2-cp37-cp37m-manylinux1_i686.whl

Download URL xswap-0.0.2-cp37-cp37m-manylinux1_i686.whl
Size 402.6 kB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.5+ x86-32
SHA-256 checksum
How to use checksums
22b57690c0782d41c0fb93f7d82a3e6858e26f8e1050fc74945e3065e3a6a9da
BLAKE2b-256 checksum
How to use checksums
2b7b86929ad64575b0763f3e6f37230bd591242893c291c2a4b149393763036c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/28.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.3

Release files / xswap-0.0.2-cp36-cp36m-manylinux2010_x86_64.whl

Download URL xswap-0.0.2-cp36-cp36m-manylinux2010_x86_64.whl
Size 471.5 kB
Tags CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.12+ x86-64
SHA-256 checksum
How to use checksums
69742fcca57e82664924bcb54fa2a16a28461e37d8758e69c9cd70597d977a47
BLAKE2b-256 checksum
How to use checksums
45653d4ca9533f18b107917906a09b920b8a8d716772d5fa9c29285256941e89
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/28.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.3

Release files / xswap-0.0.2-cp36-cp36m-manylinux1_x86_64.whl

Download URL xswap-0.0.2-cp36-cp36m-manylinux1_x86_64.whl
Size 471.5 kB
Tags CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
bec28d2ae24c8fb18b31e5a1fac10b8bc5ab9db70ed1775ac3988a0d59f377dc
BLAKE2b-256 checksum
How to use checksums
ec72430ea01d631a003edbad07d50d8972ed774e8533d98bc12e743b3b833eef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/28.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.3

Release files / xswap-0.0.2-cp36-cp36m-manylinux1_i686.whl

Download URL xswap-0.0.2-cp36-cp36m-manylinux1_i686.whl
Size 402.6 kB
Tags CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-32
SHA-256 checksum
How to use checksums
be43e4272a901e95eba578fdcb507e4be5123f28f049b05501f24460db26ee57
BLAKE2b-256 checksum
How to use checksums
836e9da394d99be4d64abee2af2cefbf9bbea28bf2ec44bd4f1213b23eda67fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/28.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.3

Release files / xswap-0.0.2-cp35-cp35m-manylinux2010_x86_64.whl

Download URL xswap-0.0.2-cp35-cp35m-manylinux2010_x86_64.whl
Size 470.8 kB
Tags CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.12+ x86-64
SHA-256 checksum
How to use checksums
895cd4c5bc9e9d8c1ab19de0f08bd5538644839f8f6bf3f6ed593316ddfcc797
BLAKE2b-256 checksum
How to use checksums
66c81ce89c5c1dd07b361100cbbc852c5146dd6efb264618e384a6b89b5f8b2d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/28.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.3

Release files / xswap-0.0.2-cp35-cp35m-manylinux1_x86_64.whl

Download URL xswap-0.0.2-cp35-cp35m-manylinux1_x86_64.whl
Size 470.8 kB
Tags CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
613319f79b4a3c8c2068419a80d00f7309850f871e11142b3b4a123d161573cd
BLAKE2b-256 checksum
How to use checksums
b65015a95e994b92afeebf5354589cd7fbe8d2b5fc9331951363c83d8cb131a1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/28.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.3

Release files / xswap-0.0.2-cp35-cp35m-manylinux1_i686.whl

Download URL xswap-0.0.2-cp35-cp35m-manylinux1_i686.whl
Size 402.6 kB
Tags CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.5+ x86-32
SHA-256 checksum
How to use checksums
84803392629d7968d54903129b6a7f6bfbce9aa66f8593b4fdd0d2caf324cb14
BLAKE2b-256 checksum
How to use checksums
a5fa839a0e146cbf7c5d11c2d2749065290ab6630d108ee613b53c6249b34439
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/28.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.3

Release history Release notifications | RSS feed

This release

0.0.2 This release

9 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page