Explain code predict_step

Hi,

I understand these lines:

For instance, with input = [1, 0, 2, 3, 0, 1, 1] and kernel = [3, 1, 3], the result of the convolution is [9, 11, 9, 12, 4], which is calculated in the following way:

 9 = 1 * 3 + 0 * 1 + 2 * 3  
11 = 0 * 3 + 2 * 1 + 3 * 3  
 9 = 2 * 3 + 3 * 1 + 0 * 3  
12 = 3 * 3 + 0 * 1 + 1 * 3  
 4 = 0 * 3 + 1 * 1 + 1 * 3

But not the ones. Could you explain them more details

Add predict_step function HERE

def predict_step(belief, offset, kernel):
“”“Applies a convolution by sliding kernel over the belief”“”
N = len(belief)
kN = len(kernel)
width = int((kN - 1) / 2)
output = [0] * N
for i in range(N):
for k in range (kN):
index = (i + (width-k) - offset) % N
output[i] += belief[index] * kernel[k]
return output

Hi @NguyenDuyDuc
The function you’ve provided represents the prediction step within the Kalman filter. I recommend incorporating print statements for index, belief[index], and kernel[k] in your code. This will help in understanding its functionality better.
It seems there might be a misunderstanding regarding the iteration order within the for ...in range...loop. The loop starts from 0, generating values like i = [0, 1, 2, 3, 4, 5, 6] and k = [0, 1, 2]. Consequently, based on your input and kernel, the result will be [4, 9, 11, 9, 12, 4, 7].

Eg: output[0] = 0x3 + 1x1 + 3x1 = 4

Please let me know if my answer can help you
Best regard,

I test like this:

a = [1,2,3,4] | b = [1,1-1,1]

I use discrete time convolution formular: Result = [1, 3, 4, 6, 3, -1, 4]
Use predict_step: Result = [4, 2, 8, 6]

Why?

Hi @NguyenDuyDuc
In the discrete time convolution, it involves summing the products of two sequences, while there are similarities to the prediction step in the Kalman filter (sliding a kernel over a sequence). However, the convolution equation summarizes all valid indices (from 0 to N-1). At the same time, the predict step handles wrapping around the indices %N which ensures that the resulting index remains within the valid range of indices for the belief vector. That is crucial for handling cases where the calculated index might exceed the vector’s bounds.
I hope it is clear to you.
If you still have doubts, please let me know
Best regard,