übung 3
parent
27e0899738
commit
d9efd7c0ff
|
|
@ -5,7 +5,7 @@ import matplotlib.pyplot as plt
|
|||
|
||||
def ErrorRate(Y, T):
|
||||
if Y.ndim == 1 or Y.shape[0] == 1:
|
||||
errors = Y != T
|
||||
errors = Y - T
|
||||
return errors.sum() / Y.size
|
||||
else: # für mehrere Ausgaben in one-hot Kodierung:
|
||||
errors = Y.argmax(0) != T.argmax(0)
|
||||
|
|
@ -28,8 +28,8 @@ class SLN:
|
|||
value = 0
|
||||
for i in range(self.dIn):
|
||||
value += X[i, n] * self._W[i][0]
|
||||
net[n] += value
|
||||
return net > self._b[0]
|
||||
net[n] += value + self._b[0][0]
|
||||
return net >= 0
|
||||
|
||||
def delta_train(self, X, T, eta, maxIter, maxErrorRate):
|
||||
N = X.shape[1] # Anzahl Trainingsdaten
|
||||
|
|
@ -37,23 +37,21 @@ class SLN:
|
|||
for it in range(maxIter):
|
||||
Y = self.neuron(X) # nur ein Aufruf
|
||||
err = ErrorRate(Y, T)
|
||||
# if (it % 20) == 0:
|
||||
print('#{} err:{}\n{}\n{}'.format(it, err, self._W, self._b))
|
||||
nnwplot.plotTwoFeatures(X, T, self.neuron)
|
||||
plt.pause(0.05) # warte auf GUI event loop (je nach python Version notwendig oder nicht)
|
||||
if (it % 20) == 0:
|
||||
print('#{} err:{}\n{}\n{}'.format(it, err, self._W, self._b))
|
||||
nnwplot.plotTwoFeatures(X, T, self.neuron)
|
||||
plt.pause(0.05) # warte auf GUI event loop (je nach python Version notwendig oder nicht)
|
||||
if err <= maxErrorRate:
|
||||
break
|
||||
# update _W
|
||||
total_to_learn = 0
|
||||
for n in range(N):
|
||||
error = T[n] - Y[n]
|
||||
for j in range(self.dIn):
|
||||
weighted_error = error * X[j, n]
|
||||
weighted_error = err * X[j, n]
|
||||
to_learn = weighted_error * eta
|
||||
print("{:.2f} = {} * {} * {}".format(to_learn, error, X[j, n], eta))
|
||||
total_to_learn += to_learn
|
||||
print(total_to_learn)
|
||||
self._W[j, 0] += total_to_learn
|
||||
#print("{:.2f} = {} * {} * {}".format(to_learn, err, X[j, n], eta))
|
||||
self._W[j, 0] += to_learn
|
||||
self._b[0][0] -= to_learn
|
||||
# update _b
|
||||
...
|
||||
print('#{} err:{}\n{}\n{}'.format(it, err, self._W, self._b))
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue