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

Non-optimal results from the OneToOneAssociator when an association_threshold is used #895

Open
gawebb-dstl opened this issue Nov 21, 2023 · 0 comments · May be fixed by #894
Open

Non-optimal results from the OneToOneAssociator when an association_threshold is used #895

gawebb-dstl opened this issue Nov 21, 2023 · 0 comments · May be fixed by #894
Assignees

Comments

@gawebb-dstl
Copy link
Contributor

You can get non-optimal results from the OneToOneAssociator when an association_threshold is used. See the code below

from stonesoup.dataassociator.general import OneToOneAssociator


def print_results(assoc_dict_print, unassocs_a_print, unassocs_b_print, measure):
    print(assoc_dict_print, "\n", unassocs_a_print, "\n", unassocs_b_print)
    total = sum(measure(obj_1, obj_2) for obj_1, obj_2 in assoc_dict_print.items())
    print(f"Total Measure={total}")


def multiply(item1: float, item2: float) -> float:
    return item1 * item2


numbers_a = (1, 2, 3, 5)
numbers_b = (1, 2, 4, 7)

associator = OneToOneAssociator(measure=multiply,
                                maximise_measure=True,
                                association_threshold=5)

all_assoc_dict = associator.association_dict(numbers_a, numbers_b)
assoc_dict = {a: all_assoc_dict[a]
              for a in numbers_a
              if all_assoc_dict[a] is not None}

unassocs_a = {x for x in numbers_a if all_assoc_dict[x] is None}
unassocs_b = {x for x in numbers_b if all_assoc_dict[x] is None}

print("1-2-1 Output")
print_results(assoc_dict, unassocs_a, unassocs_b, multiply)

# {3: 4, 5: 7} 
#  {1, 2} 
#  {1, 2}
# Total Measure=47

print("Better output")
better_output = {2: 4, 3: 2, 5: 7}
print_results(better_output, {1}, {1}, multiply)

# Total Measure=49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant