Esempio n. 1
0
plt.legend()
plt.axis('equal')
plt.title('Available Data')
# construct the H matrix that SVMtrain_FB requires
# set the parameters
sig = 0.5
C = 10.0
# compute H
dist = ( ( np.tile(x[0,:],(N,1)) -  np.tile(x[0,:],(N,1)).transpose() )**2 \
        + ( np.tile(x[1,:],(N,1)) -  np.tile(x[1,:],(N,1)).transpose() )**2 )
Y = np.tile(y, (N, 1)) * np.tile(y, (N, 1)).transpose()
H = (np.exp(-dist / (sig**2)) + np.identity(N) / C) * Y

# train!
MAX_ITER = 2000
alp = SVM.SVMdual_FB(H, y, MAX_ITER)

# only need the support vectors for classification
ind = alp > 1e-5
alpsup = alp[ind]
ysup = y[ind]
xsup = x[:, ind]

# determine b
k = np.argmax(alpsup)
b = 0
f = Gaussf(xsup[:, k].reshape((2, 1)), alpsup, xsup, ysup, sig, b)
b = (1 - alpsup[k] / C) / y[k] - f

# display the results
grid = np.arange(-3, 3, 0.05)