gpt4 book ai didi

python - 使用来自 Neupy 的 LMS 算法的溢出错误示例

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:15:29 24 4
gpt4 key购买 nike

我尝试了 LMS 算法的示例:

import numpy as np
from neupy import algorithms

input_data = np.array([[1, 0], [2, 2], [3, 3], [0, 0]])
target_data = np.array([[1], [0], [0], [1]])

lmsnet = algorithms.LMS((2, 1), step=0.5)

lmsnet.train(input_data, target_data, epochs=200)
lmsnet.predict(np.array([[4, 4], [0, 0]]))

但我在这一行 (file:summary_info.py) 中收到“OverflowError: cannot convert float infinity to integer”错误:

scale = math.ceil(self.delay_limit / average_delay)

我无法将示例中的输入参数与错误联系起来,我知道除以零会到达那里,但我不知道如何解决这个问题。我不想修改库文件来解决问题。

最佳答案

你的例子对我来说非常好

你可以克服这个问题,如果你像这样循环训练你的网络

import numpy as np
from neupy import algorithms

input_data = np.array([[1, 0], [2, 2], [3, 3], [0, 0]])
target_data = np.array([[1], [0], [0], [1]])

# Used smaller step since 0.5 is too big
lmsnet = algorithms.LMS((2, 1), step=0.1)

for _ in range(200):
lmsnet.train(input_data, target_data, epochs=1)

lmsnet.predict(np.array([[4, 4], [0, 0]]))

关于python - 使用来自 Neupy 的 LMS 算法的溢出错误示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47337134/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com