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 metric MultiManager and MetricPlotter #811

Merged
merged 117 commits into from
Sep 1, 2023
Merged

Conversation

rcgorman-dstl
Copy link
Contributor

@rcgorman-dstl rcgorman-dstl commented Jun 1, 2023

  • Have replaced SimpleManager metric manager with new MultiManager class so this will be a breaking change.
  • MultiManager can take multiple metric generators of the same type and multiple sets of the same type to generate metrics.
  • All metrics that take in track and truth can now also take in 2 tracks.
  • Additional functionality added to MultiManager through new methods to help easier extraction of metrics and insights.
  • New MetricPlotter class created to make plotting metrics easier.

Update:

  • Have added SimpleManager metric manager back in to avert breaking change. It should operate in the same way as before.

@rcgorman-dstl rcgorman-dstl added enhancement documentation breaking A breaking change that required other to modify their code labels Jun 1, 2023
@rcgorman-dstl rcgorman-dstl requested a review from a team as a code owner June 1, 2023 16:06
Copy link
Contributor

@nperree-dstl nperree-dstl left a comment

Choose a reason for hiding this comment

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

Seems to work really well, comments are mostly documentation issues. I think you also need to remove the old SimpleManager from test_pcrbmetric and test_uncertaintymetric to stop tests failing.

docs/examples/Metrics.py Outdated Show resolved Hide resolved
docs/examples/Metrics.py Show resolved Hide resolved
docs/examples/Metrics.py Outdated Show resolved Hide resolved
docs/examples/Metrics.py Outdated Show resolved Hide resolved
docs/examples/Metrics.py Outdated Show resolved Hide resolved
docs/examples/Metrics.py Outdated Show resolved Hide resolved
stonesoup/metricgenerator/ospametric.py Outdated Show resolved Hide resolved
stonesoup/plotter.py Outdated Show resolved Hide resolved
…ack-truth metrics. change inputs to MultiManager to dicts instead of sets
add new plot_metrics method to Plotter class. add new plot_timeseries
parameter to Plotter.__init__ which defaults to False and sets fig axes
to 'equal'. must be set to True to display axes correctly when plotting
timeseries data including metrics.
Copy link
Contributor Author

@rcgorman-dstl rcgorman-dstl left a comment

Choose a reason for hiding this comment

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

Adding overall comments for each file to summarise changes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

update single sensor management tutorial to work with updated metrics, MultiManager, and MetricPlotter

Copy link
Contributor Author

Choose a reason for hiding this comment

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

update multi sensor management tutorial to work with updated metrics, MultiManager, and MetricPlotter

Copy link
Contributor Author

Choose a reason for hiding this comment

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

update optimised sensor management tutorial to work with updated metrics, MultiManager, and MetricPlotter

Copy link
Contributor Author

Choose a reason for hiding this comment

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

correct typos in DataAssociator base class

Copy link
Contributor Author

Choose a reason for hiding this comment

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

correct typos in MetricGenerator base class

Copy link
Contributor Author

Choose a reason for hiding this comment

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

new Metrics example to show updated metrics, MultiManager, and MetricPlotter

Copy link
Contributor Author

Choose a reason for hiding this comment

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

update Multitracker example to work with updated metrics, MultiManager, and MetricPlotter

Copy link
Contributor Author

Choose a reason for hiding this comment

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

update Gromov Particle flow example to work with updated metrics, MultiManager, and MetricPlotter

Copy link
Contributor Author

Choose a reason for hiding this comment

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

update multi-sensor fusion example to work with updated metrics, MultiManager, and MetricPlotter

Copy link
Contributor Author

Choose a reason for hiding this comment

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

update track stitching example to work with updated metrics, MultiManager, and MetricPlotter

ylabel="Sum of covariance matrix norms")
fig3 = MetricPlotter()
fig3.plot_metrics(metrics, generator_names=['Uncertainty metric'])
fig3.fig.axes[0].set_title(label='Track uncertainty over time')
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add set_title as a MetricPlotter method? This will allow a user not to have to worry about "fig.axes[0]" and allows the MetricPlotter to be extended to plotly in the future.

docs/examples/Metrics.py Outdated Show resolved Hide resolved
docs/examples/Metrics.py Outdated Show resolved Hide resolved
docs/examples/Metrics.py Outdated Show resolved Hide resolved
docs/examples/Metrics.py Outdated Show resolved Hide resolved
docs/examples/Metrics.py Outdated Show resolved Hide resolved
rcgorman-dstl and others added 7 commits August 8, 2023 13:42
Co-authored-by: James Wright <69153443+jswright-dstl@users.noreply.github.com>
Co-authored-by: James Wright <69153443+jswright-dstl@users.noreply.github.com>
minor additions/corrections in metrics example

Co-authored-by: James Wright <69153443+jswright-dstl@users.noreply.github.com>
@sdhiscocks
Copy link
Member

The breaking change makes this difficult to merge at this point. However, it may be possible to make it backwards compatible fairly easy:

  • Add back in the SimpleManager, inheriting from MultiManager, with "tracks", "groundtruth_paths" and "detections" as default keys in states_set.
  • Have property on SimpleManager for tracks, groundtruth_paths and detections that returns values from those dictionary keys mentioned above.
  • Change metrics so default for tracks_key and truths_key are "tracks" and "groundtruth_paths".
  • Also provide sensible default generator_name for each metric.

I've not tried this, but something like this should work or at least be a good start.

generators = self.generators if isinstance(self.generators, list) else [self.generators]

for generator in generators:
if isinstance(generator, SIAPMetrics):
Copy link
Member

Choose a reason for hiding this comment

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

Referencing to specific metric here doesn't seem appropriate. Why does this need to be done?

Copy link
Contributor Author

@rcgorman-dstl rcgorman-dstl Aug 10, 2023

Choose a reason for hiding this comment

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

I believe I added it in as an attempt to save unnecessary computation but not entirely sure. I think it can be removed easily. Will do so and test.

edit: nope, was to avoid an error. now updated with improved code, no hard-coding.

Comment on lines 108 to 131
def display_basic_metrics(self):
"""
Print basic metrics generated for each :class:`BasicMetrics` generator.
"""
for generator_name, generator in self.metrics.items():
if "Number of targets" in generator.keys():
print(f'\nGenerator: {generator_name}')
for metric_key, metric in generator.items():
if isinstance(metric.generator, BasicMetrics):
print(f"{metric.title}: {metric.value}")

def get_siap_averages(self, generator_name):
"""
Get SIAP averages metrics from SIAP metric generator specified by generator_name

Returns
----------
: dict of :class`SIAPMetrics` averages
"""
siap_metrics = self.metrics[generator_name]
siap_averages = {siap_metrics.get(metric) for metric in siap_metrics
if metric.startswith("SIAP") and not metric.endswith(" at times")}

return siap_averages
Copy link
Member

Choose a reason for hiding this comment

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

These methods also seem specific to the name or specific metric. A different approach is needed here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Had to remove the methods as they're too specific to each metric type.

update documentation of MetricManager and Metrics to include information
about input parameters for different methods. Also remove hard-coded
reference to SIAP metrics in associate_tracks method of MetricManager as
requested in review.
Add SimpleManager MetricManager class back in and make backwards
compatible with new updates to all Metrics Generators related to
MultiManager.

Update MultiManager parent class to work with SimpleManager and return
data from SimpleManager in original format.
allow simplemanager add_data method to add data with any number of
kwargs instead of requiring all kwargs.
add simplemanager tests back into test_manager and update all metrics
tests files so that they use default generator_name, tracks_key, and
truths_key arguments where relevant now that default values are
available.
@rcgorman-dstl rcgorman-dstl removed the breaking A breaking change that required other to modify their code label Aug 11, 2023
update indentation in manager.py and fix compute_metric method of
abstract dummy metric generator class in test_manager.
remove methods from MultiManager and instances of use in
tutorials/examples to avoid hard-coding any references to specific
MetricGenerators in MetricManager code.
@sdhiscocks sdhiscocks merged commit f24090c into main Sep 1, 2023
6 checks passed
gawebb-dstl pushed a commit that referenced this pull request Oct 3, 2023
- MultiManager can take multiple metric generators of the same type and multiple sets of the same type to generate metrics. 
- Have made SimpleManager metric manager subclass of MultiManager class so this will be a breaking change. 
- All metrics that take in track and truth can now also take in 2 tracks.
- Additional functionality added to MultiManager through new methods to help easier extraction of metrics and insights.
- New MetricPlotter class created to make plotting metrics easier.
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.

4 participants