我该如何添加到this code中以在网络中加入偏见?是否像在think(self, inputs)
方法中的正向传递中添加+ 1一样简单?我如何将这种解决方案推广到多层感知器?
答案 0 :(得分:0)
是的,因为只有1个神经元,所以可以将1直接添加到think()函数的返回语句中。
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)