+def f_from_k(coeffs, support_set, k, x):
+ output = 0
+ for c, s in zip(coeffs, support_set):
+ output += c * s[1] * k(s[0], x)
+ return output
+
+
+def k1(X1, X2):
+ return 1 + X1[0] * X2[0] + X1[1] * X2[1] + X1[0]**2 * X2[0]**2 \
+ + X1[0] * X1[1] * X2[0] * X2[1] + X1[1]**2 * X2[1]**2
+
+
+def kg(x, y, sigma=10):
+ return np.exp(-((x[0] - y[0])**2 + (x[1] - y[1])**2) / sigma**2)
+
+
+def perceptron_k(X, Y, k):
+ coeffs = []
+ support_set = []
+ # Go in the loop at least one time
+ classification_error = 1
+ while not classification_error == 0:
+ classification_error = 0
+ for x, y in zip(X, Y):
+ if y * f_from_k(coeffs, support_set, k, x) <= 0:
+ if x not in support_set:
+ support_set.append((x, y))
+ coeffs.append(1)
+ else:
+ coeffs[support_set.index((x, y))] += 1
+ classification_error += 1
+ print(classification_error)
+ return np.array(coeffs), np.array(support_set)
+
+
+def f(w, x, y):
+ return w[0] + w[1] * x + w[2] * y + w[3] * x**2 + w[4] * x * y + w[5] * y**2
+
+