add files for exercise 3

main
Nikola Munder 2026-10-20 16:26:41 +02:00
parent ca7819e055
commit 86e4c8662e
5 changed files with 2941 additions and 2819 deletions

Binary file not shown.

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,19 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "1b99095f",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

View File

@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
#%%
# AG1a
import numpy as np
import nnwplot
def neuron(X):
N = X.shape[...]
net = np.zeros(N)
W = [....]
b = # Bias ... ergibt sich aus Aktivierungsschwelle
for n in range(0,N):
for j in range ...:
net[..]+=
b verwenden ...
return net ... # threshold ....
#%%
iris = np.loadtxt("iris.csv",delimiter=',')
X=iris[...]
T=iris[...]
print(X)
print(T)
#%%
# AG1b
nnwplot.plotTwoFeatures(X[...], T, neuron)

View File

@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
# %%
import numpy as np
import nnwplot
import matplotlib.pyplot as plt
# %% ErrorRate
def ErrorRate(Y,T):
if Y.ndim==1 or Y.shape[0]==1:
errors=Y!=T
return errors.sum()/Y.size
else: # für mehrere Ausgaben in one-hot Kodierung:
errors=Y.argmax(0)!=T.argmax(0)
return errors.sum()/Y.shape[1]
# %%
class SLN:
def __init__(...): # Konstruktor
np.random.seed(42)
self._b=np.zeros((AAA,1))
self._W=np.random.randn(BBB,CCC)/np.sqrt(DDD)
# def DeltaTrain(self, X, T, eta, maxIter, maxErrorRate):
# N=X.shape[1] # Anzahl Trainingsdaten
# plt.ion() # interactive mode on
# for it in range(maxIter):
# Y = ... # nur ein Aufruf
# err = ErrorRate(..., ...)
# if (it%20) == 0:
# print('#{} err:{}\n{}\n{}'.format(it,err,self._W,self._b))
# nnwplot.plotTwoFeatures(...)
# plt.pause(0.05) # warte auf GUI event loop (je nach python Version notwendig oder nicht)
# if err <= maxErrorRate:
# break
# # update _W
# ...
# # update _b
# ...
# print('#{} err:{}\n{}\n{}'.format(it,err,self._W,self._b))
# nnwplot.plotTwoFeatures(...)
# plt.pause(0.05) # warte auf GUI event loop (je nach python Version notwendig oder nicht)
#
# input("Press Enter to continue...") # wenn gewünscht ...