ConfigModel-MCMC


NameConfigModel-MCMC JSON
Version 0.1.1 PyPI version JSON
download
home_pagehttps://arxiv.org/abs/2105.12120
SummaryA tool for sampling networks from the Configuration model
upload_time2024-02-13 02:10:23
maintainer
docs_urlNone
authorUpasana Dutta; Bailey K. Fosdick; Aaron Clauset
requires_python
license
keywords configmodel_mcmc mcmc configuration model double edge swap degree sequence null distribution random graph
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ConfigModel_MCMC

## What is it?

**ConfigModel_MCMC** is a tool for sampling networks from the Configuration model, given a network and a graph space. This code package builds upon the Double Edge Swap MCMC Graph Sampler by Fosdick et al. [1]. It detects convergence in the Double Edge Swap MCMC and samples networks from the MCMC's stationary distribution, so that the samples are uniform random draws from the Configuration model.

The corresponding paper can be found on the arXiv [here](https://arxiv.org/abs/2105.12120).


[[1]](https://epubs.siam.org/doi/pdf/10.1137/16M1087175) Bailey K. Fosdick, Daniel B. Larremore, Joel Nishimura, Johan Ugander (2018) Configuring Random Graph Models with Fixed Degree Sequences. SIAM Review 60(2):315–355.

### Why use ConfigModel_MCMC?

The random stub-matching algorithm as described by Newman [2] and also implemented by the [configuration_model](https://networkx.org/documentation/networkx-1.10/reference/generated/networkx.generators.degree_seq.configuration_model.html) function of the [networkx](https://pypi.org/project/networkx/) package in Python works best only for the loopy multigraph space where every stub of network has distinct labels. This is because the graph returned by algorithm is a pseudograph, i.e., the graph is allowed to have both self-loops and parallel edges(multi-edges). Often times practitioners remove the self-loops and collapse the multi-edges in the network returned by the function to get a *simple network*, but this modification changes the degree sequence of the network. It also introduces a bias in the network generating process because the high-degree nodes are more likely to have self-loops and multi-edges attached to them than are the low-degree nodes. Therefore, the network generated is a biased sample. The **ConfigModel_MCMC** package lets you sample an unbiased sample from the Configuration model on eight different graph spaces parameterized by self-loops/no self-loops, multi-edges/no multi-edges and stub-labeled/vertex-labeled.

[[2]](https://epubs.siam.org/doi/pdf/10.1137/S003614450342480) M.E.J. Newman (2003), “The structure and function of complex networks”, SIAM REVIEW 45(2):167-256.


## Installing

`pip install ConfigModel_MCMC`

This package has been tested with Python=3.11 and the required packages numpy==1.26.4, networkx==3.2.1, scipy==1.12.0, numba==0.55.1, arch==5.3.1, python-igraph==0.11.3 and tqdm==4.62.2. These dependencies are automatically installed while installing the `ConfigModel_MCMC` package.

Make sure the latest version of the package has been installed. To check, execute the following command:

`pip show ConfigModel_MCMC`

Details about the package including summary, version, authors, etc., would be displayed. The version number should be **0.1**. If not, try uninstalling and installing the package again, or execute the following command:

`pip install ConfigModel_MCMC==0.1.1`


## Set-up

The [arch module](https://pypi.org/project/arch/) uses the [OpenBLAS module](https://www.openblas.net/) for estimating the model parameters for the DFGLS test. Since `OpenBLAS` uses multithreading on its own, it is recommended to limit the number of threads before you start Python, especially if running this package on a high-computing cluster.

For example, if you are using Jupyter Notebook, execute the following commands in your terminal before launching Jupyter.

```
$ export MKL_NUM_THREADS=1
$ export OPENBLAS_NUM_THREADS=1
$ jupyter notebook
```

Or if you are running a script named test.py from your terminal, you may execute the following commands.

```
$ export MKL_NUM_THREADS=1
$ export OPENBLAS_NUM_THREADS=1
$ python test.py
```

This will limit the multithreading to a single thread. You can choose other number of threads e.g., 2, 4, etc, depending on the number of availabile CPU cores. On clusters it is usually recommended to limit it to 1 thread per process.


## Examples

### A simple example.

Here is a basic example.

```python
import ConfigModel_MCMC as CM
import networkx as nx

# An example network 
G = nx.gnp_random_graph(n = 100, p = 0.1)

# Specify the graph space and create a new object
allow_loops = False
allow_multi = False
is_vertex_labeled = True
mcmc_object = CM.MCMC(G, allow_loops, allow_multi, is_vertex_labeled)

# Get a new graph (G2) from the Configuration model
G2 = mcmc_object.get_graph()
```

In the above example, `G_2` is sampled from the vertex-labeled simple graph space. The graph space is specified depending on whether the generated network is allowed to have self-loops or not, multi-edges or not, and whether it is stub-labeled or vertex-labeled. `G_2` has the same degree sequence as the example network `G`. Please refer to [[1]](https://epubs.siam.org/doi/pdf/10.1137/16M1087175) for details on how to choose the correct graph space for a given research question.

If no graph space is specified, the simple vertex-labeled graph space will be chosen by default. In the example below, the graph `G_2` is obtained from the simple vertex-labeled graph space.

```python
# An example network 
G = nx.gnp_random_graph(n = 100, p = 0.1)

# Specify the graph space and create a new object
mcmc_object = CM.MCMC(G)

# Get a new graph (G_2) from the Configuration model
G2 = mcmc_object.get_graph()
```


### Sample multiple graphs

Multiple graphs can also be sampled from the Configuration model with/without using a loop.

```python
# An example network 
G = nx.gnp_random_graph(n = 100, p = 0.1)

# Specify the graph space and create a new object
allow_loops = False
allow_multi = False
is_vertex_labeled = True
mcmc_object = CM.MCMC(G, allow_loops, allow_multi, is_vertex_labeled)

# Get 5 graphs from the Configuration model over a loop and print their degree assortativity.
for i in range(5):
    G_new = mcmc_object.get_graph()
    print(round(nx.degree_pearson_correlation_coefficient(G_new),4), end = " ")
print()

# Get 5 more graphs using a single line.
list_of_graphs = mcmc_object.get_graph(count=5)
for each_graph in list_of_graphs:
    print(round(nx.degree_pearson_correlation_coefficient(each_graph),4), end = " ")
print()

```
Output:
```
-0.0564 -0.0177 -0.0583 0.027 0.0778 
-0.0405 -0.0276 -0.0053 0.016 -0.0153
```

In the above code, the first 5 networks are generated over a loop, while the next 5 networks are generated using a single command by specifying ```count=5``` as an argument to the function `get_graph( )`. Both ways are equally efficient on average. The default value of ```count``` is 1. The degree assortativity values of each of the networks generated are printed for reference.

### Using igraph 

The networks sampled from the Configuration model are by default `networkx` Graph objects. If the sampled networks are instead desired to be `igraph` Graph objects, you can specify it as the `return_type` argument to the `get_graph( )` function as shown below. Using "igraph" is typically much faster than using "networkx". This is also helpful when the end goal is to calculate some networks statistic of the sampled graphs, since [igraph](https://pypi.org/project/python-igraph/) offers extremely time-efficient [implementations](https://igraph.org/python/doc/api/igraph._igraph.GraphBase.html) of several widely-used network statistics.

```python
# An example network 
G = nx.gnp_random_graph(n = 100, p = 0.1)

# Specify the graph space and create a new object (using default graph space here)
mcmc_object = CM.MCMC(G)

# Get 5 more graphs using a single line.
list_of_graphs = mcmc_object.get_graph(count=5, return_type = "igraph")
```

### Sampling Gap heuristics

If the network does not satisfy the conditions under which the automatic selection of the Sampling Gap is possible, the Sampling Gap algorithm will be run. This function might take a while, if the network is large.

```python
# read the Davis Southern women social network
G = nx.davis_southern_women_graph()

# Specify the graph space and create a new object
allow_loops = False
allow_multi = False
is_vertex_labeled = True
mcmc_object = CM.MCMC(G, allow_loops, allow_multi, is_vertex_labeled)

# Obtain 5 graphs from the Configuration model
list_of_graphs = mcmc_object.get_graph(count=5)
```

Output:
```
The network does not satisfy the density criterion for automatic selection of sampling gap.
Running the Sampling Gap Algorithm. This might take a while for large graphs.....
----- Running Burn-in -----
100%|██████████████████████        | 89000/89000 [00:00<00:00, 1175522.53it/s]
----- Burn-in Complete -----
-- Obtaining Sampling Gap --
```

The above code reads the Davis Southern women social network and samples 5 graphs from the vertex-labeled simple graph space. The network does not satisfy the contraints necessary for the automatic selection of the sampling gap, because of its fairly high density. So the Sampling Gap Algorithm is called. A progress bar is displayed during the burn-in period of the MCMC walk. The variable `list_of_graphs` contains the 5 simple vertex-labeled graphs sampled from the Configuration model.

The messages printed in the output can be muted by specifying ```verbose = False``` while creating the MCMC object. The deafult value is ```verbose = True```.

```python
# read the Davis Southern women social network
G = nx.davis_southern_women_graph()

# Specify the graph space and create a new object
allow_loops = False
allow_multi = False
is_vertex_labeled = True
mcmc_object = MCMC(G, allow_loops, allow_multi, is_vertex_labeled, verbose=False)

# Obtain 5 graphs from the Configuration model
list_of_graphs = mcmc_object.get_graph(count=5)
```

### Running the Sampling Gap Algorithm

If you want to run the Sampling Gap Algorithm to obatin the sampling gap for your graph, you may do so as follows:

```python
# read the Davis Southern women social network
G = nx.davis_southern_women_graph()

# Specify the graph space and create a new object
allow_loops = False
allow_multi = False
is_vertex_labeled = True
mcmc_object = CM.MCMC(G, allow_loops, allow_multi, is_vertex_labeled, verbose=False)

# run the Sampling Gap Algorithm
sampling_gap = mcmc_object.run_sampling_gap_algorithm()
print("Sampling gap obtained = ", sampling_gap)
```

Output:
~~~
Sampling gap obtained = 194
~~~

Note that the sampling gap obtained in each run might vary a bit, although it would be mostly stable around a value. Again, the print statements are muted here by specifying ```verbose = False``` at the time of creating the MCMC object. The print statements of particularly the sampling gap algorithm can be muted using the following code, even when it was not muted while creating the MCMC object.

```python
# read the Davis Southern women social network
G = nx.davis_southern_women_graph()

# Specify the graph space and create a new object
allow_loops = False
allow_multi = False
is_vertex_labeled = True
mcmc_object = MCMC(G, allow_loops, allow_multi, is_vertex_labeled)

# run the Sampling Gap Algorithm
sampling_gap = mcmc_object.run_sampling_gap_algorithm(verbose=False)
print("Sampling gap obtained = ", sampling_gap)
```

Output:
~~~
Sampling gap obtained = 186
~~~


The default significance level of the autocorrelation hypothesis tests = 0.04 and the default number of parallel MCMC chains run for the Sampling Gap Algorithm = 10. However, you can change them by specifying as arguments to the function. For example, we can set the significance level as 10% and run 20 parallel MCMC chains as follows:

```python
# read the Davis Southern women social network
G = nx.davis_southern_women_graph()

# Specify the graph space and create a new object
allow_loops = False
allow_multi = False
is_vertex_labeled = True
mcmc_object = MCMC(G, allow_loops, allow_multi, is_vertex_labeled, verbose=False)

# run the Sampling Gap Algorithm
sampling_gap = mcmc_object.run_sampling_gap_algorithm(alpha = 0.1, D = 20)
print("Sampling gap obtained = ", sampling_gap)
```

Output:
~~~
Sampling gap obtained = 246
~~~

Since both significance level and the number of parallel chains have been increased (from 0.04 to 0.1 and from 10 to 20, respectively), the Sampling Gap will be higher than what was obtained before since the test is more conservative now, and the Sampling Gap Algorithm would take some more time to run.


### Customising the sampling gap

You can also specify a custom sampling gap that you want to run the convergence detection test with, using the ```sampling_gap``` function parameter.

```python
# read the Davis Southern women social network
G = nx.davis_southern_women_graph()

# Specify the graph space and create a new object
allow_loops = False
allow_multi = False
is_vertex_labeled = True
mcmc_object = MCMC(G, allow_loops, allow_multi, is_vertex_labeled, verbose=False)

# Specify the sampling gap 
gap = 100 # any user-defined value
list_of_graphs = mcmc_object.get_graph(count=5, sampling_gap = gap)
for each_graph in list_of_graphs:
    print(round(nx.degree_pearson_correlation_coefficient(each_graph),4), end = " ")

print()
print("User-defined sampling gap = ", mcmc_object.spacing)
```
Output:
```
-0.1318 -0.1944 -0.148 -0.1102 -0.1718 
User-defined sampling gap =  100
```


## Notes

The package will not work for weighted networks, directed networks, hypergraphs, or simplical complexes.

## Feedback and bugs

If you find a bug or you have any feedback, please email me at upasanad@seas.upenn.edu.

## License
GNU General Public License v3

            

Raw data

            {
    "_id": null,
    "home_page": "https://arxiv.org/abs/2105.12120",
    "name": "ConfigModel-MCMC",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "ConfigModel_MCMC,MCMC,Configuration model,double edge swap,degree sequence,null distribution,random graph",
    "author": "Upasana Dutta; Bailey K. Fosdick; Aaron Clauset",
    "author_email": "upasana.dutta@colorado.edu",
    "download_url": "https://files.pythonhosted.org/packages/83/1e/34fc47d84ccb86aa5c432f7d5dd16a32bb1541fdf28daf73e85afb8d13ae/ConfigModel_MCMC-0.1.1.tar.gz",
    "platform": null,
    "description": "# ConfigModel_MCMC\n\n## What is it?\n\n**ConfigModel_MCMC** is a tool for sampling networks from the Configuration model, given a network and a graph space. This code package builds upon the Double Edge Swap MCMC Graph Sampler by Fosdick et al. [1]. It detects convergence in the Double Edge Swap MCMC and samples networks from the MCMC's stationary distribution, so that the samples are uniform random draws from the Configuration model.\n\nThe corresponding paper can be found on the arXiv [here](https://arxiv.org/abs/2105.12120).\n\n\n[[1]](https://epubs.siam.org/doi/pdf/10.1137/16M1087175) Bailey K. Fosdick, Daniel B. Larremore, Joel Nishimura, Johan Ugander (2018) Configuring Random Graph Models with Fixed Degree Sequences. SIAM Review 60(2):315\u2013355.\n\n### Why use ConfigModel_MCMC?\n\nThe random stub-matching algorithm as described by Newman [2] and also implemented by the [configuration_model](https://networkx.org/documentation/networkx-1.10/reference/generated/networkx.generators.degree_seq.configuration_model.html) function of the [networkx](https://pypi.org/project/networkx/) package in Python works best only for the loopy multigraph space where every stub of network has distinct labels. This is because the graph returned by algorithm is a pseudograph, i.e., the graph is allowed to have both self-loops and parallel edges(multi-edges). Often times practitioners remove the self-loops and collapse the multi-edges in the network returned by the function to get a *simple network*, but this modification changes the degree sequence of the network. It also introduces a bias in the network generating process because the high-degree nodes are more likely to have self-loops and multi-edges attached to them than are the low-degree nodes. Therefore, the network generated is a biased sample. The **ConfigModel_MCMC** package lets you sample an unbiased sample from the Configuration model on eight different graph spaces parameterized by self-loops/no self-loops, multi-edges/no multi-edges and stub-labeled/vertex-labeled.\n\n[[2]](https://epubs.siam.org/doi/pdf/10.1137/S003614450342480) M.E.J. Newman (2003), \u201cThe structure and function of complex networks\u201d, SIAM REVIEW 45(2):167-256.\n\n\n## Installing\n\n`pip install ConfigModel_MCMC`\n\nThis package has been tested with Python=3.11 and the required packages numpy==1.26.4, networkx==3.2.1, scipy==1.12.0, numba==0.55.1, arch==5.3.1, python-igraph==0.11.3 and tqdm==4.62.2. These dependencies are automatically installed while installing the `ConfigModel_MCMC` package.\n\nMake sure the latest version of the package has been installed. To check, execute the following command:\n\n`pip show ConfigModel_MCMC`\n\nDetails about the package including summary, version, authors, etc., would be displayed. The version number should be **0.1**. If not, try uninstalling and installing the package again, or execute the following command:\n\n`pip install ConfigModel_MCMC==0.1.1`\n\n\n## Set-up\n\nThe [arch module](https://pypi.org/project/arch/) uses the [OpenBLAS module](https://www.openblas.net/) for estimating the model parameters for the DFGLS test. Since `OpenBLAS` uses multithreading on its own, it is recommended to limit the number of threads before you start Python, especially if running this package on a high-computing cluster.\n\nFor example, if you are using Jupyter Notebook, execute the following commands in your terminal before launching Jupyter.\n\n```\n$ export MKL_NUM_THREADS=1\n$ export OPENBLAS_NUM_THREADS=1\n$ jupyter notebook\n```\n\nOr if you are running a script named test.py from your terminal, you may execute the following commands.\n\n```\n$ export MKL_NUM_THREADS=1\n$ export OPENBLAS_NUM_THREADS=1\n$ python test.py\n```\n\nThis will limit the multithreading to a single thread. You can choose other number of threads e.g., 2, 4, etc, depending on the number of availabile CPU cores. On clusters it is usually recommended to limit it to 1 thread per process.\n\n\n## Examples\n\n### A simple example.\n\nHere is a basic example.\n\n```python\nimport ConfigModel_MCMC as CM\nimport networkx as nx\n\n# An example network \nG = nx.gnp_random_graph(n = 100, p = 0.1)\n\n# Specify the graph space and create a new object\nallow_loops = False\nallow_multi = False\nis_vertex_labeled = True\nmcmc_object = CM.MCMC(G, allow_loops, allow_multi, is_vertex_labeled)\n\n# Get a new graph (G2) from the Configuration model\nG2 = mcmc_object.get_graph()\n```\n\nIn the above example, `G_2` is sampled from the vertex-labeled simple graph space. The graph space is specified depending on whether the generated network is allowed to have self-loops or not, multi-edges or not, and whether it is stub-labeled or vertex-labeled. `G_2` has the same degree sequence as the example network `G`. Please refer to [[1]](https://epubs.siam.org/doi/pdf/10.1137/16M1087175) for details on how to choose the correct graph space for a given research question.\n\nIf no graph space is specified, the simple vertex-labeled graph space will be chosen by default. In the example below, the graph `G_2` is obtained from the simple vertex-labeled graph space.\n\n```python\n# An example network \nG = nx.gnp_random_graph(n = 100, p = 0.1)\n\n# Specify the graph space and create a new object\nmcmc_object = CM.MCMC(G)\n\n# Get a new graph (G_2) from the Configuration model\nG2 = mcmc_object.get_graph()\n```\n\n\n### Sample multiple graphs\n\nMultiple graphs can also be sampled from the Configuration model with/without using a loop.\n\n```python\n# An example network \nG = nx.gnp_random_graph(n = 100, p = 0.1)\n\n# Specify the graph space and create a new object\nallow_loops = False\nallow_multi = False\nis_vertex_labeled = True\nmcmc_object = CM.MCMC(G, allow_loops, allow_multi, is_vertex_labeled)\n\n# Get 5 graphs from the Configuration model over a loop and print their degree assortativity.\nfor i in range(5):\n    G_new = mcmc_object.get_graph()\n    print(round(nx.degree_pearson_correlation_coefficient(G_new),4), end = \" \")\nprint()\n\n# Get 5 more graphs using a single line.\nlist_of_graphs = mcmc_object.get_graph(count=5)\nfor each_graph in list_of_graphs:\n    print(round(nx.degree_pearson_correlation_coefficient(each_graph),4), end = \" \")\nprint()\n\n```\nOutput:\n```\n-0.0564 -0.0177 -0.0583 0.027 0.0778 \n-0.0405 -0.0276 -0.0053 0.016 -0.0153\n```\n\nIn the above code, the first 5 networks are generated over a loop, while the next 5 networks are generated using a single command by specifying ```count=5``` as an argument to the function `get_graph( )`. Both ways are equally efficient on average. The default value of ```count``` is 1. The degree assortativity values of each of the networks generated are printed for reference.\n\n### Using igraph \n\nThe networks sampled from the Configuration model are by default `networkx` Graph objects. If the sampled networks are instead desired to be `igraph` Graph objects, you can specify it as the `return_type` argument to the `get_graph( )` function as shown below. Using \"igraph\" is typically much faster than using \"networkx\". This is also helpful when the end goal is to calculate some networks statistic of the sampled graphs, since [igraph](https://pypi.org/project/python-igraph/) offers extremely time-efficient [implementations](https://igraph.org/python/doc/api/igraph._igraph.GraphBase.html) of several widely-used network statistics.\n\n```python\n# An example network \nG = nx.gnp_random_graph(n = 100, p = 0.1)\n\n# Specify the graph space and create a new object (using default graph space here)\nmcmc_object = CM.MCMC(G)\n\n# Get 5 more graphs using a single line.\nlist_of_graphs = mcmc_object.get_graph(count=5, return_type = \"igraph\")\n```\n\n### Sampling Gap heuristics\n\nIf the network does not satisfy the conditions under which the automatic selection of the Sampling Gap is possible, the Sampling Gap algorithm will be run. This function might take a while, if the network is large.\n\n```python\n# read the Davis Southern women social network\nG = nx.davis_southern_women_graph()\n\n# Specify the graph space and create a new object\nallow_loops = False\nallow_multi = False\nis_vertex_labeled = True\nmcmc_object = CM.MCMC(G, allow_loops, allow_multi, is_vertex_labeled)\n\n# Obtain 5 graphs from the Configuration model\nlist_of_graphs = mcmc_object.get_graph(count=5)\n```\n\nOutput:\n```\nThe network does not satisfy the density criterion for automatic selection of sampling gap.\nRunning the Sampling Gap Algorithm. This might take a while for large graphs.....\n----- Running Burn-in -----\n100%|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588        | 89000/89000 [00:00<00:00, 1175522.53it/s]\n----- Burn-in Complete -----\n-- Obtaining Sampling Gap --\n```\n\nThe above code reads the Davis Southern women social network and samples 5 graphs from the vertex-labeled simple graph space. The network does not satisfy the contraints necessary for the automatic selection of the sampling gap, because of its fairly high density. So the Sampling Gap Algorithm is called. A progress bar is displayed during the burn-in period of the MCMC walk. The variable `list_of_graphs` contains the 5 simple vertex-labeled graphs sampled from the Configuration model.\n\nThe messages printed in the output can be muted by specifying ```verbose = False``` while creating the MCMC object. The deafult value is ```verbose = True```.\n\n```python\n# read the Davis Southern women social network\nG = nx.davis_southern_women_graph()\n\n# Specify the graph space and create a new object\nallow_loops = False\nallow_multi = False\nis_vertex_labeled = True\nmcmc_object = MCMC(G, allow_loops, allow_multi, is_vertex_labeled, verbose=False)\n\n# Obtain 5 graphs from the Configuration model\nlist_of_graphs = mcmc_object.get_graph(count=5)\n```\n\n### Running the Sampling Gap Algorithm\n\nIf you want to run the Sampling Gap Algorithm to obatin the sampling gap for your graph, you may do so as follows:\n\n```python\n# read the Davis Southern women social network\nG = nx.davis_southern_women_graph()\n\n# Specify the graph space and create a new object\nallow_loops = False\nallow_multi = False\nis_vertex_labeled = True\nmcmc_object = CM.MCMC(G, allow_loops, allow_multi, is_vertex_labeled, verbose=False)\n\n# run the Sampling Gap Algorithm\nsampling_gap = mcmc_object.run_sampling_gap_algorithm()\nprint(\"Sampling gap obtained = \", sampling_gap)\n```\n\nOutput:\n~~~\nSampling gap obtained = 194\n~~~\n\nNote that the sampling gap obtained in each run might vary a bit, although it would be mostly stable around a value. Again, the print statements are muted here by specifying ```verbose = False``` at the time of creating the MCMC object. The print statements of particularly the sampling gap algorithm can be muted using the following code, even when it was not muted while creating the MCMC object.\n\n```python\n# read the Davis Southern women social network\nG = nx.davis_southern_women_graph()\n\n# Specify the graph space and create a new object\nallow_loops = False\nallow_multi = False\nis_vertex_labeled = True\nmcmc_object = MCMC(G, allow_loops, allow_multi, is_vertex_labeled)\n\n# run the Sampling Gap Algorithm\nsampling_gap = mcmc_object.run_sampling_gap_algorithm(verbose=False)\nprint(\"Sampling gap obtained = \", sampling_gap)\n```\n\nOutput:\n~~~\nSampling gap obtained = 186\n~~~\n\n\nThe default significance level of the autocorrelation hypothesis tests = 0.04 and the default number of parallel MCMC chains run for the Sampling Gap Algorithm = 10. However, you can change them by specifying as arguments to the function. For example, we can set the significance level as 10% and run 20 parallel MCMC chains as follows:\n\n```python\n# read the Davis Southern women social network\nG = nx.davis_southern_women_graph()\n\n# Specify the graph space and create a new object\nallow_loops = False\nallow_multi = False\nis_vertex_labeled = True\nmcmc_object = MCMC(G, allow_loops, allow_multi, is_vertex_labeled, verbose=False)\n\n# run the Sampling Gap Algorithm\nsampling_gap = mcmc_object.run_sampling_gap_algorithm(alpha = 0.1, D = 20)\nprint(\"Sampling gap obtained = \", sampling_gap)\n```\n\nOutput:\n~~~\nSampling gap obtained = 246\n~~~\n\nSince both significance level and the number of parallel chains have been increased (from 0.04 to 0.1 and from 10 to 20, respectively), the Sampling Gap will be higher than what was obtained before since the test is more conservative now, and the Sampling Gap Algorithm would take some more time to run.\n\n\n### Customising the sampling gap\n\nYou can also specify a custom sampling gap that you want to run the convergence detection test with, using the ```sampling_gap``` function parameter.\n\n```python\n# read the Davis Southern women social network\nG = nx.davis_southern_women_graph()\n\n# Specify the graph space and create a new object\nallow_loops = False\nallow_multi = False\nis_vertex_labeled = True\nmcmc_object = MCMC(G, allow_loops, allow_multi, is_vertex_labeled, verbose=False)\n\n# Specify the sampling gap \ngap = 100 # any user-defined value\nlist_of_graphs = mcmc_object.get_graph(count=5, sampling_gap = gap)\nfor each_graph in list_of_graphs:\n    print(round(nx.degree_pearson_correlation_coefficient(each_graph),4), end = \" \")\n\nprint()\nprint(\"User-defined sampling gap = \", mcmc_object.spacing)\n```\nOutput:\n```\n-0.1318 -0.1944 -0.148 -0.1102 -0.1718 \nUser-defined sampling gap =  100\n```\n\n\n## Notes\n\nThe package will not work for weighted networks, directed networks, hypergraphs, or simplical complexes.\n\n## Feedback and bugs\n\nIf you find a bug or you have any feedback, please email me at upasanad@seas.upenn.edu.\n\n## License\nGNU General Public License v3\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "A tool for sampling networks from the Configuration model",
    "version": "0.1.1",
    "project_urls": {
        "Homepage": "https://arxiv.org/abs/2105.12120"
    },
    "split_keywords": [
        "configmodel_mcmc",
        "mcmc",
        "configuration model",
        "double edge swap",
        "degree sequence",
        "null distribution",
        "random graph"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2b2fc8bb819b2926ec46b590b3f31e67e6fb98e2c0c1e5b4d4d94abcdd8d49c1",
                "md5": "10fe492504f6d1f025b64ceb69f285f0",
                "sha256": "501b92d7f5756b2816979446c337e2d2a6e5d3ba25b95b4950da9ee9c02e26ab"
            },
            "downloads": -1,
            "filename": "ConfigModel_MCMC-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "10fe492504f6d1f025b64ceb69f285f0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 27312,
            "upload_time": "2024-02-13T02:10:22",
            "upload_time_iso_8601": "2024-02-13T02:10:22.199871Z",
            "url": "https://files.pythonhosted.org/packages/2b/2f/c8bb819b2926ec46b590b3f31e67e6fb98e2c0c1e5b4d4d94abcdd8d49c1/ConfigModel_MCMC-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "831e34fc47d84ccb86aa5c432f7d5dd16a32bb1541fdf28daf73e85afb8d13ae",
                "md5": "e425d35f17264166fd0b3dff5b38b16f",
                "sha256": "a868df2e291d1a72dacd5e95a656b15a948e92829bae8a390a20c42a4fe0f3ed"
            },
            "downloads": -1,
            "filename": "ConfigModel_MCMC-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "e425d35f17264166fd0b3dff5b38b16f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 31362,
            "upload_time": "2024-02-13T02:10:23",
            "upload_time_iso_8601": "2024-02-13T02:10:23.928058Z",
            "url": "https://files.pythonhosted.org/packages/83/1e/34fc47d84ccb86aa5c432f7d5dd16a32bb1541fdf28daf73e85afb8d13ae/ConfigModel_MCMC-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-13 02:10:23",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "configmodel-mcmc"
}
        
Elapsed time: 0.24687s