-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_elicitation.py
67 lines (53 loc) · 2.37 KB
/
run_elicitation.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
import os
import numpy as np
import matplotlib.pyplot as plt
import time
from sacred import Experiment
from tempfile import NamedTemporaryFile
import sdsft
from exp.ingredients import model
from exp.ingredients import auction_dataset as dataset
experiment = Experiment(
'training',
ingredients=[model.ingredient, dataset.ingredient]
)
@experiment.config
def cfg():
repetitions = 10
n_samples = 10000
@experiment.automain
def run(repetitions, n_samples, _run, _log):
result = {}
for rep in range(repetitions):
# Get data
seed = np.random.randint(100000)
bidders, n, seed = dataset.get_instance(seed=seed)
# Get model
ft = model.get_instance(n)
result['seed'] = result.get('seed', []) + [seed]
for idx, bidder in enumerate(bidders):
start = time.time()
estimate = ft.transform(bidder)
end = time.time()
n_queries = bidder.call_counter
rel = sdsft.eval_sf(bidder, estimate, n, n_samples = n_samples)
mae = sdsft.eval_sf(bidder, estimate, n, n_samples = n_samples,
err_type='mae')
t = end-start
bidder_result = result.get('Bidder %d'%idx, {})
bidder_result['rel'] = bidder_result.get('rel', []) + [rel]
bidder_result['mae'] =bidder_result.get('mae', []) + [mae]
bidder_result['n_queries'] = bidder_result.get('n_queries', []) + [n_queries]
bidder_result['time'] = bidder_result.get('time', []) + [t]
bidder_result['freqs'] = bidder_result.get('freqs', []) + [estimate.freqs.tolist()]
bidder_result['coefs'] = bidder_result.get('coefs', []) + [estimate.coefs.tolist()]
result['Bidder %d'%idx] = bidder_result
_run.log_scalar('Bidder %d, rel'%idx, rel, rep)
_run.log_scalar('Bidder %d, mae'%idx, mae, rep)
_run.log_scalar('Bidder %d, n_queries'%idx, n_queries, rep)
_run.log_scalar('Bidder %d, time'%idx, t, rep)
_run.log_scalar('Bidder %d, k'%idx, len(estimate.coefs), rep)
print()
print('%.2f'%(100*(rep * len(bidders) + idx+1)/(repetitions*len(bidders))), '%',
'rep %d, bidder %d, mae %f, rel %f, n_q %d, t %f'%(rep, idx, mae, rel, n_queries, t), end='\r')
return result