Skip to content

Commit 43aa126

Browse files
Felix StammFelix Stamm
Felix Stamm
authored and
Felix Stamm
committed
First commit
0 parents  commit 43aa126

39 files changed

+8477
-0
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.ipynb filter=jupyternotebook

.gitconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[filter "jupyternotebook"]
2+
clean = python clean_errors.py %f
3+
required

.github/workflows/pythonapp.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# This workflow will install Python dependencies, run tests and lint with a single version of Python
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
3+
4+
name: build
5+
6+
on:
7+
push:
8+
branches: [ main ]
9+
pull_request:
10+
branches: [ main ]
11+
12+
jobs:
13+
build:
14+
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
python-version: ["3.8", "3.9", "3.10"]
19+
20+
steps:
21+
- uses: actions/checkout@v3
22+
- name: Set up Python ${{ matrix.python-version }}
23+
uses: actions/setup-python@v4
24+
with:
25+
python-version: ${{ matrix.python-version }}
26+
- name: Install dependencies
27+
run: |
28+
python -m pip install --upgrade pip
29+
pip install .
30+
31+
- name: Test with pytest
32+
run: |
33+
pip install pytest
34+
pytest
35+
36+
# - name: Lint with flake8
37+
# run: |
38+
# pip install flake8
39+
# # stop the build if there are Python syntax errors or undefined names
40+
# flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
41+
# # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
42+
# flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics

.gitignore

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
/datasets/*
2+
/scripts/images
3+
/scripts/results/
4+
5+
# Byte-compiled / optimized / DLL files
6+
__pycache__/
7+
*.py[cod]
8+
*$py.class
9+
10+
# C extensions
11+
*.so
12+
13+
# Distribution / packaging
14+
.Python
15+
build/
16+
develop-eggs/
17+
dist/
18+
downloads/
19+
eggs/
20+
.eggs/
21+
lib/
22+
lib64/
23+
parts/
24+
sdist/
25+
var/
26+
wheels/
27+
share/python-wheels/
28+
*.egg-info/
29+
.installed.cfg
30+
*.egg
31+
MANIFEST
32+
33+
# PyInstaller
34+
# Usually these files are written by a python script from a template
35+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
36+
*.manifest
37+
*.spec
38+
39+
# Installer logs
40+
pip-log.txt
41+
pip-delete-this-directory.txt
42+
43+
# Unit test / coverage reports
44+
htmlcov/
45+
.tox/
46+
.nox/
47+
.coverage
48+
.coverage.*
49+
.cache
50+
nosetests.xml
51+
coverage.xml
52+
*.cover
53+
*.py,cover
54+
.hypothesis/
55+
.pytest_cache/
56+
cover/
57+
58+
# Translations
59+
*.mo
60+
*.pot
61+
62+
# Django stuff:
63+
*.log
64+
local_settings.py
65+
db.sqlite3
66+
db.sqlite3-journal
67+
68+
# Flask stuff:
69+
instance/
70+
.webassets-cache
71+
72+
# Scrapy stuff:
73+
.scrapy
74+
75+
# Sphinx documentation
76+
docs/_build/
77+
78+
# PyBuilder
79+
.pybuilder/
80+
target/
81+
82+
# Jupyter Notebook
83+
.ipynb_checkpoints
84+
85+
# IPython
86+
profile_default/
87+
ipython_config.py
88+
89+
# pyenv
90+
# For a library or package, you might want to ignore these files since the code is
91+
# intended to run in multiple environments; otherwise, check them in:
92+
# .python-version
93+
94+
# pipenv
95+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
96+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
97+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
98+
# install all needed dependencies.
99+
#Pipfile.lock
100+
101+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
102+
__pypackages__/
103+
104+
# Celery stuff
105+
celerybeat-schedule
106+
celerybeat.pid
107+
108+
# SageMath parsed files
109+
*.sage.py
110+
111+
# Environments
112+
.env
113+
.venv
114+
env/
115+
venv/
116+
ENV/
117+
env.bak/
118+
venv.bak/
119+
120+
# Spyder project settings
121+
.spyderproject
122+
.spyproject
123+
124+
# Rope project settings
125+
.ropeproject
126+
127+
# mkdocs documentation
128+
/site
129+
130+
# mypy
131+
.mypy_cache/
132+
.dmypy.json
133+
dmypy.json
134+
135+
# Pyre type checker
136+
.pyre/
137+
138+
# pytype static type analyzer
139+
.pytype/
140+
141+
# Cython debug symbols
142+
cython_debug/
143+
scripts/Katz convergence.py
144+
scripts/ca-netscience.edges
145+
scripts/ERGM.pkl
146+
tmp.txt
147+
scripts/convergence2_eigenvector.py
148+
scripts/convergence2_hits.py
149+
scripts/convergence2_jaccard.py
150+
scripts/convergence2_katz.py
151+
scripts/convergence2_pagerank.py
152+
scripts/datasets_path.txt
153+
env
154+
nestmodel.egginfo

.pylintrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[MASTER]
2+
disable= missing-module-docstring
3+
[FORMAT]
4+
max-line-length=200
5+
6+
# allow 1 or 2 length variable names
7+
good-names-rgxs=^[_a-zGW][_a-z0-9L]?$
8+
good-names=WL_fast,WL_both, M, A, A0, A1, A_work, M_in, C1, C2, WL1, WL2, SAE, ERGM, ERGM_experiments, G_str

README.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Neighborhood Structure Configuration Model
2+
![Teaser Figure for the Neighborhood Structure Configuration Model](./teaser.png)
3+
4+
![build](https://github.com/Feelx234/nestmodel-test/actions/workflows/pythonapp.yml/badge.svg)
5+
6+
Neighborhood Structure Configuration Models (short NeSt-models) allow to generate random graphs that preserved the neighborhood structure of a given graph for arbitrary depth d.
7+
8+
This package provides the implementation as used in our paper.
9+
10+
11+
# Installation instructions
12+
You can install this library like any other python package, depending packages are also installed along with it.
13+
14+
15+
### Installing nestmodel
16+
```
17+
git clone https://github.com/Feelx234/nestmodel.git
18+
pip install nestmodel
19+
```
20+
The installation should take less than a minute.
21+
If you also want to notebooks in the scripts folder please install `jupyter` as outlined below.
22+
```
23+
pip install jupyter
24+
```
25+
26+
### Making sure the installation went smoothly
27+
28+
To make sure the installation has succeeded we need to install pytest as well and then run the tests
29+
```
30+
pip install pytest
31+
python -m pytest nestmodel
32+
```
33+
If you do not have the graph tools library installed, the tests will emit a warning that it is not installed which can be ignored for now.
34+
35+
# Reproducing the results from the paper
36+
37+
Before reproducing the results you need to get the **datasets**. We provide a download script `/scripts/get_datasets.py` which will download all datasets for you.
38+
```
39+
cd nestmodel
40+
python ./scripts/get_datasets.py
41+
```
42+
43+
To reproduce the results from the paper we provided different scripts. The detailed convergence results on HepPh are available in `/scripts/convergence2_example.ipynb`.
44+
This file can be opened in jupyter and should work out of the box.
45+
46+
47+
The convergence results in sum absolute error (SAE) can all be produced by using
48+
```python ./scripts/convergence2_runner.py -all```
49+
The runtime of this script is about 1 day.
50+
The script will first convert the notebook files into `.py` files and then run tests on the karate network which will only take about 1 min.
51+
Once the script is run, plots can be created by opening the `convergence2_plot.ipynb` file in jupyter. The plot file requires the time of completion for the different centrality calculations which can be read of from the result files which appear in `./scripts/results/` and are also stored in a file: `./scripts/convergence2_run_results.txt`.
52+
53+
If you are interested in convergence results for individual centralities you can also checkout any of the `./scripts/convergence2_XXXXX.ipynb` (for example `./scripts/convergence2_pagerank.ipynb`) in jupyter.
54+
55+
56+
57+
The runtime results comparing NeSt with ERGM and Erdös Renyi models can be reproduced using
58+
```python ./scripts/Baselines.ipynb```
59+
Notice that the runtime of the Baselines file for the phonecalls is *several days* because the ERGM is so slow! The baseline results can be visualized in the `./scripts/Baselines_plot.ipynb` notebook.
60+
61+
62+
63+
### System requirements
64+
The package should run on any modern standard computer.
65+
66+
67+
### Software requirements
68+
#### OS Requirements
69+
This package has been tested on *Linux*.
70+
71+
#### Python Dependencies
72+
The package was tested with various version of python (>=3.8). It depends on other packages that are automatically installed along with nestmodel and can be looked up at the setup.py file.
73+
Parts of it also depend on the just-in-time compiler `numba` we used version 0.56.4 but should work on other versions as well.

clean_errors.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import json
2+
import sys
3+
from pathlib import Path
4+
5+
# <<< encoding UTF8 !!!!! >>>
6+
#print(sys.argv)
7+
8+
j=None
9+
if len(sys.argv[1])<2:
10+
print("No file provided")
11+
exit()
12+
13+
path = Path(sys.argv[1])
14+
with open(path, "r", encoding="utf-8") as f:
15+
j = json.load(f)
16+
17+
destination = path
18+
19+
#print(len())
20+
cells = j["cells"]
21+
deleted = 0
22+
cells = j["cells"]
23+
deleted = 0
24+
for i in range(len(cells)-1, -1, -1):
25+
cell = cells[i]
26+
if cell["cell_type"] == "code":
27+
if len(cell["outputs"])>0:
28+
to_remove = []
29+
for i, output in enumerate(cell["outputs"]):
30+
if "name" in output and output["name"]=="stderr":
31+
to_remove.append(i)
32+
to_remove = reversed(to_remove)
33+
for i in to_remove:
34+
cell["outputs"].pop(i)
35+
deleted+=1
36+
#print(f"deleted {deleted} cells")
37+
destination = path# path.with_name(path.stem + "_stripped.ipynb")
38+
#print(f"deleted {deleted} cells")
39+
#destination = path.with_name(path.stem + "_stripped.ipynb")
40+
#destination = path.with_stem(path.stem + "_stripped")
41+
#print(f"writing to {destination}")
42+
if deleted > 0:
43+
with open(destination, 'w', encoding="utf-8") as f:
44+
json.dump(j, f, indent=1)
45+
f.write("\n")
46+
47+
print(json.dumps(j, indent=1))

0 commit comments

Comments
 (0)