-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplotting.py
More file actions
81 lines (62 loc) · 2.13 KB
/
plotting.py
File metadata and controls
81 lines (62 loc) · 2.13 KB
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
# -*- coding: utf-8 -*-
"""
Created on Tue Jan 14 10:05:06 2020
@author: Ryan Roussel
"""
import logging
logging.basicConfig(level=logging.INFO)
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import minimize
from pygmo import hypervolume
def plot_hypervolume(data,ref):
#plot the hypervolume as a function of iteration #,
#assume that the points are ordered by iteration #
n_pts = len(data)
HV = []
for i in range(1,n_pts+1):
hv = hypervolume(data[:i])
HV += [hv.compute(ref)]
fig,ax = plt.subplots()
ax.plot(HV)
ax.set_ylabel('Hypervolume')
ax.set_xlabel('Iteration #')
return fig
def plot_1D_GP(X,X_sample,Y_sample,gpr):
pass
def plot_2D_acquisition(acquisition, X_sample, Y_sample, gpr, bounds, *args, **kwargs):
dim = X_sample.shape[1]
n_restarts = 25
min_val = 10000000
min_x = None
def min_obj(X):
# Minimization objective is the negative acquisition function
return -acquisition(X.reshape(-1, dim), X_sample, Y_sample, gpr, *args,**kwargs)
# Find the best optimum by starting from n_restart different random points.
#for x0 in np.random.uniform(bounds[:, 0], bounds[:, 1], size=(n_restarts, dim)):
# res = minimize(min_obj, x0=x0, bounds=bounds, method='L-BFGS-B')
# if res.fun < min_val:
# min_val = res.fun[0]
# min_x = res.x
fig,ax = plt.subplots()
n = 20
x = np.linspace(*bounds[0],n)
y = np.linspace(*bounds[1],n)
xx,yy = np.meshgrid(x,y)
acq = np.zeros_like(xx).ravel()
for i in range(len(xx.ravel())):
acq[i] = -min_obj(np.vstack((xx.ravel()[i],yy.ravel()[i])))
im = ax.contourf(xx,yy,acq.reshape(n,n))
fig.colorbar(im)
logging.info(X_sample)
for ele in X_sample:
ax.plot(*ele,'+r')
def get_func_value(X,func,*args,**kwargs):
vals = np.zeros(len(X))
for i in range(len(X)):
vals[i] = func(X[i],*args,**kwargs)
return vals
def main():
pass
if __name__=='__main__':
main()