-
Notifications
You must be signed in to change notification settings - Fork 0
/
construct.py
83 lines (62 loc) · 1.92 KB
/
construct.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import graph
import util
import machine
config = '''# Inputs!
graph_file = %(folder)s/%(title)s_input
data_format = edge_factored
# Seeds!
seed_file = %(folder)s/%(title)s_seed
# Labels!
gold_labels_file = %(folder)s/%(title)s_gold
# Tests!
test_file = %(folder)s/%(title)s_gold
# Parameters that were never explained!
iters = 10
verbose = false
prune_threshold = 0
# Algorithm things! (algos: lp_zgl, adsorption, mad)
algo = mad
mu1 = 1
mu2 = 1e-2
mu3 = 1e-2
beta = 2
# Outputs!
output_file = %(folder)s/%(title)s_out
'''
# Does all required work to make a set of junto files given the
# pickle-formatted input, the title. Optionally, one can specify a
# folder in which the junto files will be placed, the random numbers
# to be used, the threshold of instances needed for each protocol to be
# included, whether or not to return the underlying graph, and whether
# to construct multiple test files from the given input.
def make_junto(filename, title, folder='.', threshold=0, ret=False):
if not '_spread' in filename:
print 'Spreading file...\n'
filename = util.spread(filename)
print 'Making graph...'
g = graph.make_graph(filename)
if threshold:
print '\nTrimming...'
g['procedures'] = util.trim(g['procedures'], threshold)
print '\nConstructing junto files...'
graph.to_junto(g, title)
with open(title + '_config', 'w') as f:
f.write(config % {'title': title, 'folder': folder})
print '\n...Done'
if ret:
return g
# Does all required work to test the test cases in the (pickled) testing
# file
def do_test(outfile, testfile):
if not '_spread' in testfile:
print 'Spreading file...\n'
testfile = util.spread(testfile)
print 'Making graph...'
g = graph.make_graph(testfile)
procs = g['procedures']
print '\nReading output...'
learned = machine.read_out(outfile)
print '\nApplying to input file...'
results = machine.guess(learned, procs)
machine.summarize(results)
machine.matrix(results)