Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors while using EKF #5

Open
souljaboy764 opened this issue Aug 19, 2021 · 1 comment
Open

Errors while using EKF #5

souljaboy764 opened this issue Aug 19, 2021 · 1 comment

Comments

@souljaboy764
Copy link

TL;DR

I encountered some errors while using the EKF filtering for performing BIP inference both from my code and from the minimal.py example that is provided. The corresponding fixes can be seen in the commit: souljaboy764/intprim@4ab692c

Long Version:

I was trying to use the EKF filter for performing the performing inference with the BIP, but was getting the following error:

  File "build/bdist.linux-x86_64/egg/intprim/bayesian_interaction_primitives.py", line 298, in generate_probable_trajectory_recursive
  File "build/bdist.linux-x86_64/egg/intprim/filter/spatiotemporal/ekf.py", line 157, in localize
  File "build/bdist.linux-x86_64/egg/intprim/filter/spatiotemporal/nonlinear_system.py", line 109, in get_measurement_model
  File "build/bdist.linux-x86_64/egg/intprim/basis/basis_model.py", line 91, in get_weighted_vector_derivative
IndexError: invalid index to scalar variable.

I thought it might have been an issue in my code but I was getting this issue even when I was running minimal.py with the EKF filter. I am getting the issue in both python2 and python3.

The stack trace shows the error in basis_model.py in the get_weighted_vector_derivative function at the following line:

basis_func_derivs = self.get_basis_function_derivatives(x[0])

On reading the docstring of the function, it says:that x should be a scalar value:

# @param x Scalar containing the phase value to use in the creation of the block diagonal matrix.

I am able to resolve this issue with dropping the index used for x and the line now looks like:

        basis_func_derivs = self.get_basis_function_derivatives(x)

After fixing the above, I get the next error:

  File "build/bdist.linux-x86_64/egg/intprim/bayesian_interaction_primitives.py", line 298, in generate_probable_trajectory_recursive
  File "build/bdist.linux-x86_64/egg/intprim/filter/spatiotemporal/ekf.py", line 157, in localize
  File "build/bdist.linux-x86_64/egg/intprim/filter/spatiotemporal/nonlinear_system.py", line 110, in get_measurement_model
  File "build/bdist.linux-x86_64/egg/intprim/basis/basis_model.py", line 50, in get_block_diagonal_basis_matrix
ValueError: could not broadcast input array from shape (8) into shape (8,1)

On looking further, I saw that the phase value x passed to the get_block_diagonal_basis_matrix function in basis_model.py is a scalar value, which is used here:

basis_funcs = self.get_basis_functions(x)

The docstrings of the get_basis_functions function for all the different basis functions state that the shape of the return value would be shape(degree, ) if x is a scalar. so I am able to fix this by expanding the dimensions of the value returned by the function:

        basis_funcs = self.get_basis_functions(x)
        if np.isscalar(x):
            basis_funcs = basis_funcs[:, None]

Since this is the same case in the get_block_diagonal_basis_matrix_derivative function, I felt a similar change there would fit.

The next error I get is:

  File "build/bdist.linux-x86_64/egg/intprim/bayesian_interaction_primitives.py", line 298, in generate_probable_trajectory_recursive
  File "build/bdist.linux-x86_64/egg/intprim/filter/spatiotemporal/ekf.py", line 157, in localize
AttributeError: 'GaussianModel' object has no attribute 'inverse_transform'

which is basically this line:

predicted_measurement = np.dot(measurement_model[:,self.system_size:], self.basis_model.inverse_transform(self.state_mean[self.system_size:]))

After digging further, I saw that the only use of inverse_transform is for the scalers and not for any basis functions. Maybe it is from a previous version? I changed that part of the code to how it is in kf.py:

            predicted_measurement = np.dot(measurement_model[:,self.system_size:], self.state_mean[self.system_size:])
@junfoot
Copy link

junfoot commented Apr 8, 2024

thank you, that helps me a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants