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

Generalize handling of return type of Initiators

Open DaveKirkland opened this issue 3 years ago • 0 comments

@sdhiscocks I was working with the IMM branch that Lyudmil and I had come up with. I was merging it with the main branch to try and get it more up to date. In testing the IMM predictors/updater I ran into an issue with the SimpleInitiator. At present the SimpleInitiator returns a track with a GaussianStateUpdate type. This works for simple predictor, however the IMM predictor expects a GaussianMixtureStateUpdate (note - currently this class is only in my local branch) since the IMM predictor uses some aspects of that particular subclass. The easiest way around this is to write a specific initiator for the IMM, I've done this below:

class SimpleIMM_MeasurementInitiator(SimpleMeasurementInitiator):
    # Assumes prior_state is a weighted gaussian mixture
    def initiate(self, detections, **kwargs):
        tmp_tracks = super().initiate(detections, **kwargs)
        tracks = set()
        for track in tmp_tracks:
            priors = []
            hypothesis = track.hypothesis
            for item in self.prior_state.components:
                tmp = WeightedGaussianStateUpdate(
                            track.mean,
                            track.covar,
                            track.hypothesis,
                            weight=item.weight,
                            timestamp=track.timestamp)
                priors.append(tmp)
            gmsu = GaussianMixtureStateUpdate(priors, hypothesis)
            tracks.add(Track(gmsu))
        return tracks

The issue is that for different types of predictors (classic, IMM, Particle, etc) we would need to create an associated initiator - much like what we already have. We currently have a MultiMeasurementInitiator but it wouldn't work with an IMM. We would need to create a new version specifically for this. Unfortunately, I don't think this is a very good / maintainable solution.

I have a couple of ideas:

  1. Provide functions in the XXXUpdate class to return properly initialized instance. The Initiator still has to be passed the proper subclass of XXXUpdate class - at the moment it isn't. E.g. the prior passed in for SimpleMeasurementInitiator is a GaussianState not GaussianStateUpdate as would be required.
  2. The user can provide their own routine to the SimpleMeasurementInitiator class when it is instantiated.
  3. Other suggestions?

One additional complication - the XXXUpdate classes tend to include a hypothesis element. Typically these are some instance of a SingleHypothesis - I don't know if this is always appropriate.

DaveKirkland avatar Mar 25 '21 12:03 DaveKirkland