This repository has been archived by the owner on Aug 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
initModel.py
executable file
·69 lines (58 loc) · 2.26 KB
/
initModel.py
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
69
#!/usr/bin/env python
'''
CREATED:2012-03-22 14:52:20 by Brian McFee <[email protected]>
Initialize a hypergraph playlist model from a collection of edge sets
'''
import sys
import hypergraph
import cPickle as pickle
import argparse
def processArguments():
parser = argparse.ArgumentParser(description='HyperGraph playlist model constructor')
parser.add_argument( '-m',
required = False,
dest = 'm',
type = int,
default = 512,
help = 'Minimum edge size')
parser.add_argument( '-r',
required = False,
dest = 'rho',
type = float,
default = 0.5,
help = 'Maximum fraction of input sets to retain in quadratic expansion')
parser.add_argument( '-q',
required = False,
dest = 'quadratic',
default = False,
action = 'store_true',
help = 'Enable quadratic edge expansion')
parser.add_argument( 'outfile',
nargs = 1,
help = 'Path to output pickle')
parser.add_argument( 'infiles',
nargs = '+',
help = 'Path to input pickles')
return vars(parser.parse_args(sys.argv[1:]))
def constructModel(params):
G = hypergraph.Hypergraph()
for infile in params['infiles']:
print 'Loading ', infile
with open(infile, 'r') as f:
G.importEdge(pickle.load(f)['X'])
pass
pass
print 'Pruning edges'
G.pruneEdges(params['m'])
if params['quadratic']:
print 'Expanding edges'
G.quadraticExpansion(MIN_SIZE=params['m'], rho=params['rho'])
pass
return G
if __name__ == '__main__':
params = processArguments()
model = constructModel(params)
with open(params['outfile'][0], 'w') as f:
pickle.dump({'G': model}, f)
pass
pass