AI Artificial Intelligence

Viele Teile ergeben ein Ganzes! Die Kunst unwichtige Details zu vermeiden!

Einfaches Neuron -  Perceptron

Die Idee:



Eine kurze Zusammenfassung der nötigen Elemente:



Der Vektor X muss nun ebenfalls um ein Element vergrößert werden:


Mit diesem Wissen bauen wir nun fofgende Zelle:





Python - Skript: EinfachesNeuron.py

Zum besseren Verständnis ohne Schleife.

# Stuhlpfarrer Ehrenfried - 2021
# Einfaches Neuron - Perceptron ohne Lernphase

import numpy as np


class EinfachesNeuron:

def __init__(self, txt):
print(txt)

# Heaviside - Funktion
def heaviside(self, summe):
# Input: Summe
# Output: 1, falls summe >= 0, sonst 0
if summe >= 0:
return 1
else:
return 0

def calcNeuron(self, X, w):
X = np.array(X)
print("Input X: ", X)
w = np.array(w)
print("Gewicht w: ", w)

# Skalarprodukt für X[0] - erster X Vektor mit dem Gewicht
Output_0 = self.heaviside(np.dot(w, X[0]))
print("Output_0: ", Output_0)
# Skalarprodukt für X[1] - erster X Vektor mit dem Gewicht
Output_1 = self.heaviside(np.dot(w, X[1]))
print("Output_1: ", Output_1)
# Skalarprodukt für X[2] - erster X Vektor mit dem Gewicht
Output_2 = self.heaviside(np.dot(w, X[2]))
print("Output_2: ", Output_2)
# Skalarprodukt für X[3] - erster X Vektor mit dem Gewicht
Output_3 = self.heaviside(np.dot(w, X[3]))
print("Output_3: ", Output_3)


# Main --------------------------------------------
# Input - Vektor
Input_X = [[1, 0, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1]]
Gewicht_W = [-2, 1, 1]
# Instanz der Klasse ------------------------------
en = EinfachesNeuron("Einfaches Neuron")
# -------------------------------------------------
en.calcNeuron(Input_X, Gewicht_W)
Ausgabe:
Einfaches Neuron
Input X:  [[1 0 0]
 [1 0 1]
 [1 1 0]
 [1 1 1]]
Gewicht w:  [-2  1  1]
Output_0:  0
Output_1:  0
Output_2:  0
Output_3:  1

KI

Copyright © 2022. All Rights Reserved. Ehrenfried Stuhlpfarrer