import numpy as np
#定义网络结构
layers=np.array([4,3,4,2])
'''
第0层 输入层,维度为4
第一层 4*3 矩阵
第二层 3*4 矩阵
第三层 4*2 矩阵
'''
#权重 范围设置在-0.25~0.25之间
weights=[]
for i in range(len(layers)-1):
tmp = (np.random.random([layers[i],layers[i+1]])*2-1)*0.25
weights.append(tmp)
#bias
'''
第一层 3个
第二层 4个
第三层 2个
'''
bias=[]
for i in range(1,len(layers)):
tmp = (np.random.random(layers[i])*2-1)*0.25
bias.append(tmp)
print weights
print bias
exit(0)
初始化神经网络的权重和偏置
猜你喜欢
转载自blog.csdn.net/lylclz/article/details/79742760
今日推荐
周排行