import random
import math
x1 = [[1.0, 0.0, 0.0], [1.0, 0.0, 1.0], [1.0, 1.0, 0.0], [1.0, 1.0, 1.0]]
t1 = [0.0, 0.0, 0.0, 1.0]
dert = random.random()
error = 0.01
n = 0.001
wc = [1.0, 1.0, 1.0]
def ruamod(x):
return 1.0 / (1.0 + (1.0 / float(math.exp(x)))) # 定义函数,表示进行求偏导
for i in range(4):
for j in range(3):
while dert > error:
dert = 2.0 * (ruamod(wc[j] * x1[i][j]) - t1[i]) * (
ruamod(wc[j] * x1[i][j]) * (1.0 - ruamod(wc[j] * x1[i][j])) * x1[i][j])
wc[j] = wc[j] - n * dert
for i in range(3):
print(wc[i])