Finish TP3 exo1 for real.
[TP_AA.git] / TP3 / exo2 / tp3_exo2.py
index 78392d9a193fcc9fbab2d0048a22bfd3d0daf6d2..e1c03dde8b616335b18aad4f442c64af8f5e1e68 100755 (executable)
@@ -28,7 +28,7 @@ def generateData2(n):
     Generates a 2D linearly separable dataset with 2n samples.
     The third element of the sample is the label
     """
-    xb = (rand(n) * 2 - 1) / 2 - 0.5
+    xb = (rand(n) * 2 - 1) / 2 + 0.5
     yb = (rand(n) * 2 - 1) / 2
     xr = (rand(n) * 2 - 1) / 2 + 1.5
     yr = (rand(n) * 2 - 1) / 2 - 0.5
@@ -87,7 +87,8 @@ def complete(sample):
 
 
 def plongement_phi(sample_element):
-    return [1, sample_element[0], sample_element[1], sample_element[0] * sample_element[0], sample_element[0] * sample_element[1], sample_element[1] * sample_element[1]]
+    return [1, sample_element[0], sample_element[1], sample_element[0]**2,
+            sample_element[0] * sample_element[1], sample_element[1]**2]
 
 
 def apply_plongement(sample, p):
@@ -106,7 +107,8 @@ def f_from_k(coeffs, support_set, k, x):
 
 
 def k1(X1, X2):
-    return 1 + X1[0] * X2[0] + X1[1] * X2[1] + X1[0] * X1[0] * X2[0] * X2[0] + X1[0] * X1[1] * X2[0] * X2[1] + X1[1] * X1[1] * X2[1] * X2[1]
+    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):
@@ -130,8 +132,14 @@ def perceptron_k(X, Y, k):
     return coeffs, support_set
 
 
-print(perceptron_k(X, Y, k1))
-# print(perceptron_k(X, Y, kg))
+def f(x, y, w):
+    return
+
+
+coeffs, support_set = perceptron_k(X, Y, k1)
+# coeffs, support_set = perceptron_k(X, Y, kg)
+print(coeffs)
+print(support_set)
 
 X = apply_plongement(X, plongement_phi)
 w = perceptron_nobias(X, Y)