Repository navigation
Expand file tree
/
Copy pathcompute_structure_SBM.py
More file actions
executable file
·68 lines (55 loc) · 2.16 KB
/
Copy pathcompute_structure_SBM.py
File metadata and controls
executable file
·68 lines (55 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python3
import sys
import os
import argparse
import logging
from src.file_handler import file_handler
import src.graph_tool_functions as gt
from src.version import repo_version
__version__ = repo_version()
DESCRIPTION = '''
Identify large-scale network structure by fitting the stochastic block model, by minimizing its description length using an agglomerative heuristic.
For more info:
https://graph-tool.skewed.de/static/doc/demos/inference/inference.html
https://graph-tool.skewed.de/static/doc/autosummary/graph_tool.inference.minimize_blockmodel_dl.html
'''
## Pass arguments.
def main():
## Pass command line arguments.
parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter, description=DESCRIPTION)
parser.add_argument('-i', '--input_graph', metavar='graph.gt.xz',
required=False, default='/dev/stdin', type=lambda x: file_handler(x, 'rs'),
help='Input graph file (default: stdin)'
)
parser.add_argument('-o', '--output_graph', metavar='graph.SBM.gt.xz',
required=False, default='/dev/stdout', type=lambda x: file_handler(x, 'ws'),
help='Output graph file with fitted stochastic block model (default: stdout)'
)
parser.add_argument('-n', '--ncpus',
required=False, default=6, type=int,
help='Number of CPUs to use (default: %(default)s)'
)
parser.add_argument('--version', action='version',
version=f"{__version__}",
help='Print repo version'
)
parser.add_argument('--debug',
required=False, action='store_true',
help='Print DEBUG info (default: %(default)s)'
)
args = parser.parse_args()
## Set up basic debugger
if args.debug:
logging.getLogger().setLevel(logging.DEBUG)
logging.debug('%s', args) ## DEBUG
logging.info('Version: %s', __version__) ##INFO
## Workflow
with args.input_graph as in_graph_file, args.output_graph as out_graph_file:
gt.set_ncpus(args.ncpus)
G = gt.load_graph_file(in_graph_file)
G = gt.run_minimize_blockmodel_dl(G)
gt.save_graph_file(G, out_graph_file)
if __name__ == '__main__':
log_format = "%(asctime)s [%(levelname)s] "+os.path.basename(__file__)+": %(message)s"
logging.basicConfig(format=log_format, stream=sys.stderr, level=logging.INFO)
main()