【发布时间】:2023-03-11 10:54:02
【问题描述】:
我将如何添加到 this code 以在网络中包含偏见?就像在think(self, inputs)method 中向正向传递中添加 + 1 一样简单吗?我如何将此解决方案推广到多层感知器?
【问题讨论】:
标签: python machine-learning neural-network
我将如何添加到 this code 以在网络中包含偏见?就像在think(self, inputs)method 中向正向传递中添加 + 1 一样简单吗?我如何将此解决方案推广到多层感知器?
【问题讨论】:
标签: python machine-learning neural-network
是的,因为只有 1 个神经元,你可以直接在 think() 函数的 return 语句中加 1。
def think(self, inputs):
return self.__sigmoid(dot(inputs, self.synaptic_weights) + 1)
记住永远不要将权重初始化为零!您始终可以使用偏差值来做到这一点。对于特定层,偏置向量的维数为 [number_of_neurons_in_the_layer, 1]
class NeuralNetwork():
def __init__(self):
random.seed(1)
self.synaptic_weights = 2 * random.random((3, 1)) - 1
# Now you have to initialize bias
# You can either keep it 0 or and random number
self.bias = random.randn(1,1)
# Here as there is only 1 neuron, dimension becomes (1, 1)
【讨论】: