.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/basic.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_basic.py: Basic Example ============= .. GENERATED FROM PYTHON SOURCE LINES 7-10 .. code-block:: Python import numpy as np .. GENERATED FROM PYTHON SOURCE LINES 11-37 Formulating the possible associations between targets and measurements ---------------------------------------------------------------------- Both :class:`~.EHM` and :class:`~.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: .. GENERATED FROM PYTHON SOURCE LINES 37-43 .. code-block:: Python 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 .. GENERATED FROM PYTHON SOURCE LINES 44-47 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: .. GENERATED FROM PYTHON SOURCE LINES 47-53 .. code-block:: Python 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]]) .. GENERATED FROM PYTHON SOURCE LINES 54-58 Computing joint association probabilities ----------------------------------------- Based on the above, we can use :class:`~.EHM` or :class:`~.EHM2` to compute the joint association probabilities matrix ``assoc_matrix`` as follows: .. GENERATED FROM PYTHON SOURCE LINES 58-67 .. code-block:: Python 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)) .. rst-class:: sphx-glr-script-out .. code-block:: none 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]] .. GENERATED FROM PYTHON SOURCE LINES 68-70 Note that both :class:`~.EHM` and :class:`~.EHM2` should produce the same results, although :class:`~.EHM2` should, in principle, be significantly faster for large numbers of targets and measurements. .. GENERATED FROM PYTHON SOURCE LINES 70-72 .. code-block:: Python # Check if the probability matrices produced by EHM and EHM2 are equal print(np.allclose(assoc_matrix_ehm, assoc_matrix_ehm2)) .. rst-class:: sphx-glr-script-out .. code-block:: none True .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.005 seconds) .. _sphx_glr_download_auto_examples_basic.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: basic.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: basic.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: basic.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_