为什么我输出的Draw_H都是[1 1 1]
for c in range(n):# H = np.zeros()
#print(Weight_Hid_Out)
n_h1 = np.dot(Weight_In_Hid[:,0].T,x_Drawing_In1Out1)
n_h2 = np.dot(Weight_In_Hid[:,1].T,x_Drawing_In1Out1)
h0 = 1.0
h1 = 1.0 / (1+np.exp(-n_h1))
h2 = 1.0 / (1+np.exp(-n_h2))
Draw_H = 发下完整代码吧
如何正确地发代码、上传图片和附件?
https://fishc.com.cn/thread-52272-1-1.html
(出处: 鱼C论坛)
数量积都为零?检查下这边的数据第1列和第2列:
n_h1 = np.dot(Weight_In_Hid[:,0].T,x_Drawing_In1Out1)
n_h2 = np.dot(Weight_In_Hid[:,1].T,x_Drawing_In1Out1) Twilight6 发表于 2020-5-19 13:33
发下完整代码吧
如何正确地发代码、上传图片和附件?
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import xlwt
data = pd.read_excel(io='D:/人工智能/作业/Homework7.xlsx', sheet_name='In1Out1')
data.insert(loc=1, column='x0', value=1) # 在每行数据的第二列添加x0=1
x_train = data.iloc[:, 1:3].to_numpy() # 抽取第二三列的数据,转换成数组格式
targets = data.iloc[:, 3].to_numpy() # 抽取第四列targets
data1 = pd.read_excel(io='D:/人工智能/作业/Homework7.xlsx', sheet_name='Drawing_In1Out1')
data1.insert(loc=1, column='x0', value=1)
x_Drawing_In1Out1 = data1.iloc[:, 1:3].to_numpy()
x1 = data1.iloc.to_numpy()
y1 = data1.iloc.to_numpy()
DeltaHid = 0.3
DeltaOut = 0.001
α = 0.1
CCount = 0 # 初始化计数变量
n = x_train.shape # 得到提取数据的数量
Max_iteration = int(input('Total Iteration:')) # 输入最大迭代次数
Weight_In_Hid = np.random.normal(size=(2,2))
Weight_Hid_Out = np.random.normal(size=(3,1))
Weight_In_Hid_Delta =np.zeros((2,2))
Weight_Hid_Out_Delta = np.zeros((3,1))
for i in range(Max_iteration):
for k in range(n):
H = np.zeros()
neth1 = np.dot(Weight_In_Hid[:,0],x_train)
neth2 = np.dot(Weight_In_Hid[:,1],x_train)
H = 1.0
H = 1/(1+np.e**(-neth1))
H = 1/(1+np.e**(-neth2))
# 确定输出层
Y = np.dot(Weight_Hid_Out.T,H) # Y值
Delta_Out = targets - Y
Delta_Hid = np.zeros((2,1))
Delta_Hid = Delta_Out * Weight_Hid_Out * H * (1-H)
Delta_Hid = Delta_Out * Weight_Hid_Out * H * (1-H)
for a in range(3):
Weight_Hid_Out_Delta = α * Weight_Hid_Out_Delta + DeltaOut * Delta_Out * H
for b in range(2):
for j in range(1,3):
Weight_In_Hid_Delta = α *Weight_In_Hid_Delta + DeltaHid * x_train
Weight_In_Hid = Weight_In_Hid + Weight_In_Hid_Delta
Weight_Hid_Out = Weight_Hid_Out + Weight_Hid_Out_Delta
CCount += 1 # 计数
if CCount == n: # 当循环次数等于数据数时跳出循环进行下一次循环
break
print('Weight_In_Hid:')
print(Weight_In_Hid)
print('Weight_Hid_Out:')
print(Weight_Hid_Out)
for c in range(n):
n_h1 = np.dot(Weight_In_Hid[:,0].T,x_Drawing_In1Out1)
n_h2 = np.dot(Weight_In_Hid[:,1].T,x_Drawing_In1Out1)
h0 = 1.0
h1 = 1.0 / (1+np.exp(-n_h1))
h2 = 1.0 / (1+np.exp(-n_h2))
Draw_H =
# 确定输出层
Draw_Y = np.zeros()
Draw_Y = np.dot(Weight_Hid_Out.T,Draw_H)# Y值
# 画图
plt.ion()
plt.cla() # 清空画布
plt.ylim(-1, 4) # 固定y轴的取值范围
plt.xlim(-10, 10) # 固定x轴的取值范围
x = np.linspace(-10, 10, 8)
plt.plot(x1,y1, color='red')
plt.plot(x_Drawing_In1Out1[:,1],Draw_Y,color='blue')
plt.pause(0.1) # 暂停一会
plt.ioff() # 关闭交互
plt.show() Wss312 发表于 2020-5-19 13:46
我刚刚忘记改评论了,发现你是numpy 处理数据发全代码也没得测试哈哈{:10_319:} Wss312 发表于 2020-5-19 13:46
你试着把自己一些地方数据加上print ,自己人工调试下看下哪里数据有问题
x_train = data.iloc[:, 1:3].to_numpy()
试着加上print 看下数据有没问题
Weight_In_Hid = np.random.normal(size=(2, 2))
Weight_Hid_Out = np.random.normal(size=(3, 1))
这里也试试 , 这种情况一般只能自己慢慢测了 Twilight6 发表于 2020-5-19 13:48
我刚刚忘记改评论了,发现你是numpy 处理数据发全代码也没得测试哈哈
呜呜呜呜,好吧{:9_234:} Wss312 发表于 2020-5-19 13:51
呜呜呜呜,好吧
幸苦了 ,你可用试试我刚刚建议你的
如果对你有帮助,记得设置最佳哈~{:10_287:} Twilight6 发表于 2020-5-19 13:40
数量积都为零?检查下这边的数据第1列和第2列:
第一列和第二列都是正确的数据,不知道为什么算出来就不对了,而且画出图来就是一条直线。我上传了完整代码,可以麻烦看一下吗 Twilight6 发表于 2020-5-19 13:51
你试着把自己一些地方数据加上print ,自己人工调试下看下哪里数据有问题
好的,我也试了,就是H值算的老是1,不知道哪错了,感觉式子都对。 Wss312 发表于 2020-5-19 13:53
第一列和第二列都是正确的数据,不知道为什么算出来就不对了,而且画出图来就是一条直线。我上传了完整代 ...
n_h1 = np.dot(Weight_In_Hid[:, 0].T, x_Drawing_In1Out1)
n_h2 = np.dot(Weight_In_Hid[:, 1].T, x_Drawing_In1Out1)
这下面你print一下试试? Twilight6 发表于 2020-5-19 13:58
这下面你print一下试试?
print的值都差不多,太难了{:9_234:} Wss312 发表于 2020-5-19 14:06
print的值都差不多,太难了
{:10_284:}同情你哈哈
页:
[1]