in LA-MCTS/lamcts/Classifier.py [0:0]
def plot_samples_and_boundary(self, func, name):
assert func.dims == 2
plabels = self.svm.predict( self.X )
good_counts = len( self.X[np.where( plabels == 0 )] )
bad_counts = len( self.X[np.where( plabels == 1 )] )
good_mean = np.mean( self.fX[ np.where( plabels == 0 ) ] )
bad_mean = np.mean( self.fX[ np.where( plabels == 1 ) ] )
if np.isnan(good_mean) == False and np.isnan(bad_mean) == False:
assert good_mean > bad_mean
lb = func.lb
ub = func.ub
x = np.linspace(lb[0], ub[0], 100)
y = np.linspace(lb[1], ub[1], 100)
xv, yv = np.meshgrid(x, y)
true_y = []
for row in range(0, xv.shape[0]):
for col in range(0, xv.shape[1]):
x = xv[row][col]
y = yv[row][col]
true_y.append( func( np.array( [x, y] ) ) )
true_y = np.array( true_y )
pred_labels = self.svm.predict( np.c_[xv.ravel(), yv.ravel()] )
pred_labels = pred_labels.reshape( xv.shape )
fig, ax = plt.subplots()
ax.contour(xv, yv, true_y.reshape(xv.shape), cmap=cm.coolwarm)
ax.contourf(xv, yv, pred_labels, alpha=0.4)
ax.scatter(self.X[ np.where(plabels == 0) , 0 ], self.X[ np.where(plabels == 0) , 1 ], marker='x', label="good-"+str(np.round(good_mean, 2))+"-"+str(good_counts) )
ax.scatter(self.X[ np.where(plabels == 1) , 0 ], self.X[ np.where(plabels == 1) , 1 ], marker='x', label="bad-"+str(np.round(bad_mean, 2))+"-"+str(bad_counts) )
ax.legend(loc="best")
ax.set_xlabel('x1')
ax.set_ylabel('x2')
ax.set_xlim([-10, 10])
ax.set_ylim([-10, 10])
plt.savefig(name)
plt.close()