import numpy as np class DeepNet: def __init__(self,in_num,out_num,hidden_num): self.model = [in_num]+hidden_num+[out_num] self.weight =[] self.layer_num = len(self.model) for i in range(self.layer_num -1): current_weight = np.random.rand(self.model[i],self.model[i+1]) self.weight.append(current_weight) self.bias = 0 def calculate(self,data): for w in self.weight: y = np.dot(data,w) y = 1 / (1 +np.exp(-y)) data = y return y in_num = 3 out_num = 1 hidden_num = [3,2,4] mynn = DeepNet(in_num=in_num,out_num=out_num,hidden_num=hidden_num) input = np.array([1,2,3]) output = mynn.calculate(input) print(output)
音频&深度学习Lesson17_神经网络的深度学习
最新推荐文章于 2024-11-04 18:23:08 发布
文章展示了一个使用numpy构建的深度神经网络(DeepNet)类,它包含初始化权重、计算方法,并通过一个例子展示了如何处理输入数据并产生输出。网络结构由输入层、隐藏层和输出层组成,隐藏层的数量和节点可变,使用了Sigmoid激活函数。
摘要由CSDN通过智能技术生成