Stone-Soup icon indicating copy to clipboard operation
Stone-Soup copied to clipboard

Measurement model inverse functions aren't vectorised

Open sdhiscocks opened this issue 2 years ago • 3 comments

Unlike function on the measurement models, the inverse_function on many/all models isn't vectorised, and limits its use in some places.

sdhiscocks avatar Apr 14 '23 12:04 sdhiscocks

I just had a look through all the nonlinear measurement models and it looks like all of the reversible models are vectorized. Did you have anything else in mind? Everything beyond nonlinear does not appear to have an inverse_function.

ajland avatar Oct 09 '25 04:10 ajland

Hi @ajland. So thought was more on the inverse_function. For example: https://github.com/dstl/Stone-Soup/blob/a890a748f937112c7c6cd827492b0b55a1d9ca6d/stonesoup/models/measurement/nonlinear.py#L289-L300

I think this need to be changed to something like this (not tested):

    def inverse_function(self, detection, **kwargs) -> StateVector:

        theta, phi, rho = detection.state_vector[0, :], detection.state_vector[1, :], detection.state_vector[2, :]
        xyz = StateVector(sphere2cart(rho, phi, theta))

        inv_rotation_matrix = inv(self.rotation_matrix)
        xyz = inv_rotation_matrix @ xyz

        res = np.zeros((self.ndim_state, detection.state_vector.shape[1])).view(StateVector)
        res[self.mapping, :] = xyz + self.translation_offset

        return res

sdhiscocks avatar Oct 09 '25 07:10 sdhiscocks

@sdhiscocks oh I see, so accommodating StateVectors instead of just a single StateVector. Thanks for the clarification!

ajland avatar Oct 09 '25 13:10 ajland