Cast correction term to float in LCCUpdater #627
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
TLDR: Gaussian components updated using the
LCCUpdater
have weights which areProbability
objects. This in turn causes some component state vectors to be made of Probabilities instead of floats. To fix this, we can cast the l1 correction term from a Probability to a float.Problem:
When using the GM-LCC filter, sometimes an updated component's state vector is filled with Probability types, instead of floats. For example, an updated component may have state vector
[Probability(15.0), Probability(0.5), 8.0, Probability(0.3)]
On its own, this is not a big problem. But it isn't the proper use of a Probability object and none of the other filters behave this way.
Cause:
I traced the problem back and found that it was caused by two things:
The LCCUpdater calculates an l1 correction factor. As seen in the code below, that correction factor will be a Probability object (I have checked this).
Stone-Soup/stonesoup/updater/pointprocess.py
Lines 164 to 187 in d38a196
Later, the correction factor is used as a factor in the weight calculation for updated components. Thus, the calculated weight will be a Probability. This means that updated components in a GM-LCC (other than the birth component) will have Probability weights.
Stone-Soup/stonesoup/updater/pointprocess.py
Lines 99 to 112 in d38a196
This Probability weight causes problems further down the line in the GaussianMixtureReducer. When merging two components, the state vector of each original component is multiplied by its weight. If that weight is a Probability, it will make the merged component mean have Probability elements. It is also true that a Probability weight will perpetuate the problem in the next timesteps even if the component is not merged with another.
Proposed Solution:
In the LCCUpdater function
_calculate_update_terms()
, simply cast l1 as a numpy float64 before returning it. Note that it is cast as a numpy 64 float so that the weights are also numpy64, thus matching the result from a PHDUpdater.