【问题标题】:MLP = Sin(x1-x2+x3-x4)MLP = Sin(x1-x2+x3-x4)
【发布时间】:2018-09-24 02:48:16
【问题描述】:

我有这个函数来更新我的 mlp 的 sin 函数的权重

它适用于 xor 没问题,但我不知道为什么它不适用于我的罪,两者都以相同的方式调用,但我不断得到 ​​p>

错误:

unsupported operand type(s) for *: 'float' and 'builtin_function_or_method'
def update_weights(self, learning_rate):

    self.weights1 = np.add(self.weights1, learning_rate * self.delta_weights1)
    self.weights2 = np.add(self.weights2, learning_rate * self.delta_weights2)
    self.delta_weights1 = np.array
    self.delta_weights2 = np.array

谁能指出我正确的方向?

【问题讨论】:

    标签: python-3.x neural-network perceptron


    【解决方案1】:

    问题出在以下几行:

    self.delta_weights1 = np.array
    self.delta_weights2 = np.array
    

    self.delta_weights1 将被分配函数(或函数指针)np.array 而无需调用它。

    例如,如果你这样做:

    type(np.array)
    

    你会得到:

    <type 'builtin_function_or_method'>
    

    如果调用函数(即添加括号),需要将对象转换为数组:

    type(np.array([]))
    

    你会得到:

    <type 'numpy.ndarray'>
    

    如果您想在权重更新后(例如,在累积下一个小批量的贡献之前)将 delta_weights 变量重置为零,请使用类似:

    self.delta_weights1 = np.zeros(self.weights1.shape)
    self.delta_weights2 = np.zeros(self.weights2.shape)
    

    (另请参阅np.zeros() 文档)。

    【讨论】:

      猜你喜欢
      • 2020-01-28
      • 2015-06-04
      • 1970-01-01
      • 2016-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-17
      相关资源
      最近更新 更多