【发布时间】:2021-07-26 19:52:07
【问题描述】:
所以我遇到了一个逻辑门问题。 我正在尝试通过组合现有的门(如 OR、AND、NOR 或 NAND)来创建一个 XOR 门。
我有 2 个辅助函数:
def logic_gate(w1, w2, b): # weight_x1, weight_x2, and bias
return lambda x1, x2: sigmoid(w1 * x1 + w2 * x2 + b)
# Helper function to test out our weight functions.
def test(gate):
for x1, x2 in (0, 0), (0, 1), (1, 0), (1, 1):
print(f"{x1}, {x2}: {np.round(gate(x1 , x2))}")
我已经定义了其他的门:
or_gate = logic_gate(20, 20, -10)
test(or_gate)
output:
0, 0: 0.0
0, 1: 1.0
1, 0: 1.0
1, 1: 1.0
and_gate = logic_gate(15,15,-20)
test(and_gate)
output:
0, 0: 0.0
0, 1: 0.0
1, 0: 0.0
1, 1: 1.0
nor_gate = logic_gate(-15,-15,10)
test(nor_gate)
output:
0, 0: 1.0
0, 1: 0.0
1, 0: 0.0
1, 1: 0.0
nand_gate = logic_gate(-15,-15,20)
test(nand_gate)
output:
0, 0: 1.0
0, 1: 1.0
1, 0: 1.0
1, 1: 0.0
所以目标是创建 2 个 XOR 函数。
-
(不是 a 和 b) 或 (a 而不是 b) (¬????∧????)∨(????∧¬????) 或稍微简化的版本
-
(a or b) 而不是 (a and b) (??????∨????)∧¬(??????∧????)
函数如下:
def xor_gate_1(a, b):
return ...
test(xor_gate_1)
def xor_gate_2(a, b):
return ...
test(xor_gate_2)
我正在努力找出 a 和 b 作为输入的含义。它们应该像 logic_gate 函数的权重吗? 如何在 XOR 函数中使用已经创建的门? 向正确的方向推进将不胜感激!
谢谢!
【问题讨论】:
标签: python machine-learning neural-network logical-operators