Note
Go to the end to download the full example code.
Basic Example
import numpy as np
Formulating the possible associations between targets and measurements
Both EHM and EHM2 operate on a validation_matrix and a likelihood_matrix. The
validation_matrix is an indicator matrix that represents the possible associations between different targets
and measurements, while the likelihood_matrix contains the respective likelihoods/probabilities of these
associations. Both matrices have a shape (N_T, N_M+1), where N_T is the number of targets and N_M is
the numer of measurements.
For example, assume we have the following scenario of 4 targets and 4 measurements (taken from Section 4.4 of [EHM2]):
Target index |
Gated measurement indices |
|---|---|
0 |
0, 1 |
1 |
0, 1, 2, 3 |
2 |
0, 1, 2 |
3 |
0, 3, 4 |
where the null measurement hypothesis is given the index of 0. Then the validation_matrix would be a (4, 5)
numpy array of the following form:
validation_matrix = np.array([[1, 1, 0, 0, 0], # 0 -> 0,1
[1, 1, 1, 1, 0], # 1 -> 0,1,2,3
[1, 1, 1, 0, 0], # 2 -> 0,1,2
[1, 0, 0, 1, 1]]) # 3 -> 0,3,4
The likelihood_matrix is such that each element likelihood_matrix[i, j] contains the respective likelihood
of target i being associated to measurement j. Therefore, based on the above example, the
likelihood_matrix could be the following:
likelihood_matrix = np.array([[0.1, 0.9, 0, 0, 0],
[0.1, 0.3, 0.2, 0.4, 0],
[0.7, 0.1, 0.2, 0, 0],
[0.2, 0, 0, 0.75, 0.05]])
Computing joint association probabilities
Based on the above, we can use EHM or EHM2 to compute the joint association probabilities
matrix assoc_matrix as follows:
from pyehm.core import EHM, EHM2
assoc_matrix_ehm = EHM().run(validation_matrix, likelihood_matrix)
print('assoc_matrix_ehm =\n {}\n'.format(assoc_matrix_ehm))
# or
assoc_matrix_ehm2 = EHM2().run(validation_matrix, likelihood_matrix)
print('assoc_matrix_ehm2 =\n {}'.format(assoc_matrix_ehm2))
assoc_matrix_ehm =
[[0.17948718 0.82051282 0. 0. 0. ]
[0.25925926 0.07692308 0.4045584 0.25925926 0. ]
[0.85754986 0.01139601 0.13105413 0. 0. ]
[0.35555556 0. 0. 0.55555556 0.08888889]]
assoc_matrix_ehm2 =
[[0.17948718 0.82051282 0. 0. 0. ]
[0.25925926 0.07692308 0.4045584 0.25925926 0. ]
[0.85754986 0.01139601 0.13105413 0. 0. ]
[0.35555556 0. 0. 0.55555556 0.08888889]]
Note that both EHM and EHM2 should produce the same results, although EHM2 should,
in principle, be significantly faster for large numbers of targets and measurements.
# Check if the probability matrices produced by EHM and EHM2 are equal
print(np.allclose(assoc_matrix_ehm, assoc_matrix_ehm2))
True
Total running time of the script: (0 minutes 0.006 seconds)