我正在尝试计算粒子过滤器中某些粒子的权重,然后相应地对这些权重进行归一化。我的代码:
def update(particles, weights, landmark, sigma):
n = 0.0
for i in range(len(weights)):
distance = np.power((particles[i][0] - landmark[0]) ** 2 + (particles[i][1] -
landmark[1])**2, 0.5)
likelihood = exp(-(np.power(distance, 2))/2 * sigma ** 2)
weights[i] = weights[i] * likelihood
n += weights[i]
weights += 1.e-30
if n != 0:
weights = weights / n
但是,我收到错误消息:/Users/scottdayton/PycharmProjects/Uncertainty Research/particle.py:30: RuntimeWarning: 在 true_divide weights = weights = weights/n /Users/scottdayton/Uncertainty Research/particle.py:30 中遇到溢出: RuntimeWarning: true_divide weights = weights / n中遇到的无效值