repositories
/
TP_AA.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Finish TP3 exo2.
[TP_AA.git]
/
TP3
/
exo2
/
tp3_exo2.py
diff --git
a/TP3/exo2/tp3_exo2.py
b/TP3/exo2/tp3_exo2.py
index b97c6ea4df6424608316272322dc3840da29428f..7ceadb1b8185610e7c5d66577261a187324bfe7f 100755
(executable)
--- a/
TP3/exo2/tp3_exo2.py
+++ b/
TP3/exo2/tp3_exo2.py
@@
-112,7
+112,12
@@
def k1(X1, X2):
+ X1[0] * X1[1] * X2[0] * X2[1] + X1[1]**2 * X2[1]**2
+ X1[0] * X1[1] * X2[0] * X2[1] + X1[1]**2 * X2[1]**2
-def kg(x, y, sigma=10):
+def kg(x, y):
+ # sigma = 20 # do not converge
+ # sigma = 10 # do not converge
+ sigma = 1
+ # sigma = 0.5 # overfitting
+ # sigma = 0.2 # overfitting
return np.exp(-((x[0] - y[0])**2 + (x[1] - y[1])**2) / sigma**2)
return np.exp(-((x[0] - y[0])**2 + (x[1] - y[1])**2) / sigma**2)
@@
-140,14
+145,16
@@
def f(w, x, y):
pl.scatter(X[:, 0], X[:, 1], c=Y, s=training_set_size)
pl.scatter(X[:, 0], X[:, 1], c=Y, s=training_set_size)
-pl.title(u"Perceptron - hyperplan")
+pl.title(u"Perceptron -
prolontaged
hyperplan")
-coeffs, support_set = perceptron_k(X, Y, k1)
-# coeffs, support_set = perceptron_k(X, Y, kg)
+# k = k1
+# coeffs, support_set = perceptron_k(X, Y, k)
+k = kg
+coeffs, support_set = perceptron_k(X, Y, k)
res = training_set_size
for x in range(res):
for y in range(res):
res = training_set_size
for x in range(res):
for y in range(res):
- if abs(f_from_k(coeffs, support_set, k
1
, [-3 / 2 + 3 * x / res, -3 / 2 + 3 * y / res])) < 0.01:
+ if abs(f_from_k(coeffs, support_set, k, [-3 / 2 + 3 * x / res, -3 / 2 + 3 * y / res])) < 0.01:
pl.plot(-3 / 2 + 3 * x / res, -3 / 2 + 3 * y / res, 'xr')
# X = apply_plongement(X, plongement_phi)
pl.plot(-3 / 2 + 3 * x / res, -3 / 2 + 3 * y / res, 'xr')
# X = apply_plongement(X, plongement_phi)