-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathrandom_search.py
43 lines (33 loc) · 981 Bytes
/
random_search.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
import time
import platform
import numpy as np
def timestamp():
return time.strftime("%Y%m%d-%H%M%S", time.localtime())
def hostname():
return platform.node()
def generate_expid():
return "%s-%s" % (hostname(), timestamp())
# samplers
def pick_one(*options):
def sample():
idx = np.random.randint(len(options))
return options[idx]
return sample
def uniform(start, end):
def sample():
return np.random.uniform(start, end)
return sample
def uniform_int(start, end): # including 'end'!
def sample():
return np.random.randint(start, end + 1)
return sample
def log_uniform(start, end):
ls, le = np.log(start), np.log(end)
def sample():
return np.exp(np.random.uniform(ls, le))
return sample
def log_uniform_int(start, end):
ls, le = np.log(start), np.log(end + 1)
def sample():
return int(np.floor(np.exp(np.random.uniform(ls, le))))
return sample