Kalman-and-Bayesian-Filters-in-Python
Kalman-and-Bayesian-Filters-in-Python copied to clipboard
Chapter 2: Error in calculation of likelihood for train problem
Hi,
I think the method of calculating likelihood for train problem is incorrect. For example, if the sensor shows position 5, we can deduce from this that the train is definitely not in position 8, because it is too far from the sensor's readings. The current method treats positions 6 and 8 as equally likely when reading from sensor is 5.
I think the correct function should look like this:
def lh_train(track, m, sensor_accuracy):
result = []
T = len(track)
for i in range(T):
if i in [(m - 1) % T, (m + 1) % T]:
result.append((1 - sensor_accuracy) / 2)
elif i == m:
result.append(sensor_accuracy)
else:
result.append(0)
return np.array(result)
By the way, I would like to point out that the modulo operation is missing in Train.sense() method. Currently, when we add sensor error, the resulting position may go outside the allowed position range.