Percentron
perceptron
퍼셉트론에 대한 심플한 구현 theta = 임계값
def perceptron(x1, x2, w1, w2, theta):y = x1*w1 + x2*w2if y <= theta:return 0elif y > theta:return 1
perceptron for logical gate
class LogicalGate:def __init__(self, weight_dict):self.weight = weight_dictdef perceptron(self, x1, x2, key):w = self.weight[key]w1 = w["w"][0]w2 = w["w"][1]t = w["t"]y = x1*w1 + x2*w2 + tif(y <= 0)return 0elif(y > 0)return 1def run_gate(self, key)print ("0, 0 : " + self.percentron(0, 0, key))print ("0, 1 : " + self.percentron(0, 1, key))print ("1, 0 : " + self.percentron(1, 0, key))print ("1, 1 : " + self.percentron(1, 1, key))weight_dict = {"AND":{"w":[0.5, 0.5],"t":-0.5},"OR":{"w":[0.5, 0.5],"t":0.1},"NAND":{"w":[-0.5, -0.5],"t":0.5}}gate = LogicalGate(weight_dict)gate.run_gate("AND")gate.run_gate("NAND")gate.run_gate("OR")