-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstress_test.py
85 lines (56 loc) · 1.56 KB
/
stress_test.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
from __future__ import division
import numpy as np
import pylab
import pprint
import random
from collections import defaultdict
# for debugging
import ipdb
import sys
import traceback
import dcd_data
def stress_test(num_runs):
"""
call dcd and record duality gap
"""
obj = defaultdict(list)
gaps = []
for i in xrange(num_runs):
# pick random values
off_diag = random.uniform(0.0, 1.0)
num_data = random.randint(10,500)
shift = random.uniform(0.0, 2.0)
# define task similarity matrix
task_sim = np.array([[1.0, off_diag],[off_diag, 1.0]])
# generate toy data
xt_1, lt_1 = dcd_data.generate_training_data(num_data, 1.5, shift)
xt_2, lt_2 = dcd_data.generate_training_data(num_data, 1.5, shift)
data = {"task_1": {"xt": xt_1, "lt": lt_1},
"task_2": {"xt": xt_2, "lt": lt_2}}
# new implementation
solver = "dcd"
W, p_obj, d_obj = dcd.train_mtl_svm(data, task_sim, solver)
gap = abs(p_obj[-1] - d_obj[-1])
gaps.append(gap)
gaps = np.log(gaps)
pylab.figure()
pylab.hist(gaps)
pylab.show()
pylab.figure()
pylab.boxplot(gaps, 0, 'gD')
pylab.show()
def main():
"""
runs experiment in different settings
"""
stress_test(500)
if __name__ == '__main__':
# enable post-mortem debugging
try:
main()
except:
type, value, tb = sys.exc_info()
traceback.print_exc()
ipdb.post_mortem(tb)
if __name__ == "pyreport.main":
main()