Plugin library
Air Force Research Laboratory (AFRL) Autonomous Capabilities Team (ACT3) Reinforcement Learning (RL) Core.
This is a US Government Work not subject to copyright protection in the US.
The use, dissemination or disclosure of data in this file is subject to limitation or restriction. See accompanying README and LICENSE for details.
PluginLibrary.AddClassToGroup(CLASS, "NAME", {"simulator": INTEGRATION_CLASS, "platform_type": AvailablePlatformTypes.XXXX})
difference_metric(x1, x2)
ยค
Heuristic for determining how much of a match 2 dictionaries are Dictionaries may only be a single layer or this may not work correctly
This heuristic is calculated as follows
number of conditions matches / (total number of keys in both dicts /2)
this allows any match to get selected, and prioritize dictionaries with more matches
in the event that x2 is empty the match score is set to 0.5 / (total number of keys in both dicts /2). This essentially is a 0.5 match of a key and allows dictionaries with a single match to have a higher score while empty dicts to result in a non-zero match. Specifically, this is used for plugins with no conditions.
Furthermore, all keys that exist in both x1 and x2 must match or a metric of 0 is returned.
Returns:
Type | Description |
---|---|
float -- The heuristic value of the comparison between the two 1 is max - every single field matched) 0 is minimum - no field matches) 0 is minimum - field present in both dictionaries does not match |
Source code in corl/libraries/plugin_library.py
def difference_metric(x1: typing.Dict[str, typing.Any], x2: typing.Dict[str, typing.Any]):
"""
Heuristic for determining how much of a match 2 dictionaries are
Dictionaries may only be a single layer or this may not work correctly
This heuristic is calculated as follows
number of conditions matches /
(total number of keys in both dicts /2)
this allows any match to get selected, and prioritize
dictionaries with more matches
in the event that x2 is empty the match score is set to
0.5 / (total number of keys in both dicts /2). This essentially
is a 0.5 match of a key and allows dictionaries with a single
match to have a higher score while empty dicts to result in a
non-zero match. Specifically, this is used for plugins with
no conditions.
Furthermore, all keys that exist in both x1 and x2 must match or a
metric of 0 is returned.
Arguments:
x1 {dict} -- The dictionary used to query the list of dictionaries
x2 {dict} -- The dictionary being compared to x1
Returns:
float -- The heuristic value of the comparison between the two
1 is max - every single field matched)
0 is minimum - no field matches)
0 is minimum - field present in both dictionaries does not match
"""
match_score = 0
total = (len(x1) + len(x2)) / 2
if not x2:
return 0.5 / total
for key, value in x2.items():
if key not in x1:
continue
if value == x1[key]:
match_score += 1
else:
return 0
return match_score / total