Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add k-d tree tutorial and update tree sub-module #771

Merged
merged 14 commits into from
May 22, 2023
Merged

Conversation

rcgorman-dstl
Copy link
Contributor

update tree sub-module with kd tree and tpr tree mixins

update tree sub-module with kd tree and tpr tree mixins
@rcgorman-dstl rcgorman-dstl requested a review from a team as a code owner February 20, 2023 10:50
@rcgorman-dstl rcgorman-dstl requested review from jswright-dstl and hpritchett-dstl and removed request for a team February 20, 2023 10:50
@sdhiscocks sdhiscocks requested review from spike-dstl and removed request for jswright-dstl February 21, 2023 10:11
@sglvladi sglvladi self-requested a review March 7, 2023 14:30
stonesoup/dataassociator/tree.py Show resolved Hide resolved
docs/tutorials/dataassociation/KDTree_Tutorial.py Outdated Show resolved Hide resolved
docs/tutorials/dataassociation/KDTree_Tutorial.py Outdated Show resolved Hide resolved
# .. image:: ../../_static/kd_tree_fig_2.png
# :width: 1200
# :height: 250
# :alt: Image showing diagrammatical representation of kd-tree in 2 dimensions, described further in figure 2 caption.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Figure 2B again.
Rather than saying move right because 8>5, it might be easier to follow if you show that you move right because abs(8-8) < abs(8-4) (Left descendant further from query node than right descendant in x dimension).

docs/tutorials/dataassociation/KDTree_Tutorial.py Outdated Show resolved Hide resolved
docs/tutorials/dataassociation/KDTree_Tutorial.py Outdated Show resolved Hide resolved
docs/tutorials/dataassociation/KDTree_Tutorial.py Outdated Show resolved Hide resolved
# Searching a :math:`k`-d tree with Nearest Neighbour
# ---------------------------------------------------
# Once the :math:`k`-d tree has been constructed from the detection set, it can then be used to search for the Nearest
# Neighbour of a given track prediction (which is the query vector).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The query vector here would be the track prediction as seen in measurement space. I believe we refer to it as the measurement prediction.

Copy link
Contributor

@spike-dstl spike-dstl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few minor changes - looks good

docs/tutorials/dataassociation/KDTree_Tutorial.py Outdated Show resolved Hide resolved
docs/tutorials/dataassociation/KDTree_Tutorial.py Outdated Show resolved Hide resolved
docs/tutorials/dataassociation/KDTree_Tutorial.py Outdated Show resolved Hide resolved
# :alt: Image showing diagrammatical representation of kd-tree in 2 dimensions, described further in figure 2 caption.
#
# Fig. 2a offers a graphical representation of the :math:`k`-d tree shown in 2b. 2a shows the prediction vector,
# :math:`[8,2]`, in blue. 2b shows the first part of the search taking place down the :math:`k`-d tree. Current best
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the constructing a k-d tree section you state a vector space of [x, y]^T using :math:\begin{bmatrix} x \\ y \\\end{bmatrix}. However for the rest of the document each vector is displayed as math:[x, y]. It might be best for continuity/mathematical correctness to display each vector as math:[x, y]^T to denote that each is a vector in the same form as previously stated. You could use :math:\begin{bmatrix} x \\ y \\\end{bmatrix} throughout but it might make the lines break up a bit.

Suggested change
# :math:`[8,2]`, in blue. 2b shows the first part of the search taking place down the :math:`k`-d tree. Current best
# :math:`[8,2]^T`, in blue. 2b shows the first part of the search taking place down the :math:`k`-d tree. Current best

Copy link
Contributor

@spike-dstl spike-dstl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have made a few suggestions... Please consider them more as points to consider rather than changes! Looks good - Explanation is much easier to follow now

docs/tutorials/dataassociation/KDTree_Tutorial.py Outdated Show resolved Hide resolved
docs/tutorials/dataassociation/KDTree_Tutorial.py Outdated Show resolved Hide resolved
#
# All detections with :math:`x` coordinate :math:`\leq` the median are placed in the left subtree from the root node,
# and all detections with :math:`x` coordinate :math:`>` median are placed in the right subtree from the root node. The
# left and right subtrees are then split into two further subtrees in the same way, except this time using the values in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This explanation is so much better - really clear now

# units, which becomes the new best distance. We then traverse back up the tree again. There are no other subtrees in
# the tree which can possibly contain detections that beat the current best distance, so the detection at :math:`[9,4]`
# is selected as the nearest neighbour and the search is complete when we reach the root.
#
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One extra thought, what happens if both descendant nodes from the root node are an equal distance from the root node? Does the code account for this situation?

stonesoup/dataassociator/tree.py Show resolved Hide resolved
Copy link
Contributor

@spike-dstl spike-dstl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have made a few suggestions... Please consider them more as points to consider rather than changes! Looks good - Explanation is much easier to follow now

stonesoup/dataassociator/tree.py Outdated Show resolved Hide resolved
stonesoup/dataassociator/tree.py Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented May 22, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.01 🎉

Comparison is base (b33f56c) 94.80% compared to head (a54fe21) 94.81%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #771      +/-   ##
==========================================
+ Coverage   94.80%   94.81%   +0.01%     
==========================================
  Files         175      175              
  Lines        9456     9477      +21     
  Branches     1884     1884              
==========================================
+ Hits         8965     8986      +21     
  Misses        350      350              
  Partials      141      141              
Flag Coverage Δ
integration 70.10% <100.00%> (+0.72%) ⬆️
unittests 89.66% <86.95%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
stonesoup/dataassociator/tree.py 97.72% <100.00%> (+0.42%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants