-
Notifications
You must be signed in to change notification settings - Fork 0
/
opt.py
65 lines (51 loc) · 1.45 KB
/
opt.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
"""
Search for optimal aggregation parameters using Bayesian optimization.
Free parameters we consider:
- Extremization factor, d
- Forecast-specific weights
- Forecast half-life
- Forecaster-specific weights
- Metaculus reputation
- Average update frequency
- Average update magnitude
"""
import pandas as pd
from bayes_opt import BayesianOptimization
from bayes_opt.logger import JSONLogger
from bayes_opt.event import Events
from utils import score_preds, log_score
from aggregation import get_aggregate, neyman_agg, neyman_opt
bdf = pd.read_csv("data/bdf.csv")
def lscore(d, hl, rep_weight, mag_weight, freq_weight):
return -score_preds(
get_aggregate(
bdf,
neyman_agg,
{"get_d": lambda _: d,
"half_life": hl,
"rep_weight": rep_weight,
"mag_weight": mag_weight,
"freq_weight": freq_weight,
"relative_t": True,
"col_name": "np_test"}),
["np_test"],
log_score).mean()[0]
pbounds = {
'd' : (1, 3**.5),
'hl' : (.01, 2),
'rep_weight' : (.01, 2),
'mag_weight' : (.01, 2),
'freq_weight' : (.01, 2),
}
optimizer = BayesianOptimization(
f=lscore,
pbounds=pbounds,
verbose=2,
random_state=1,
)
logger = JSONLogger(path="data/opt_logs.json")
optimizer.subscribe(Events.OPTIMIZATION_STEP, logger)
optimizer.maximize(
init_points=5,
n_iter=100,
)