Repository navigation
feat(matching): opt-in required_match for physical AI object lists #539
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
Changes from 1 commit
25db8d3
966bcc0
d38d9c5
292d282
17b1961
8d60ce5
381b6bb
649ad4a
aacef3f
76683cc
7641529
348d632
f591dc1
8e877b2
2e1986a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- add the exclusion phase and the FN plus FA rule for a vetoed pair - state that export drops the flag and that aggregate omits vetoed objects - add an example and the rule to mark every identifying field as required
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -77,7 +77,25 @@ Fields with higher weights pull the overall score toward their individual result | |||||
|
|
||||||
| **`clip_under_threshold`** -- When enabled (the default), a field that scores below its threshold contributes 0.0 to the weighted average instead of its partial similarity. This prevents low-confidence matches from inflating the overall score. | ||||||
|
|
||||||
| **`required_match`** -- Without it, an object with one wrong field still matches when its overall score reaches the element class's `match_threshold`. A required field that is not at or above its resolved threshold (the field's `threshold`, else one named on the comparator, else `0.5`) vetoes the pair before the Hungarian assignment, so a better pairing is found if one exists. A veto takes priority over similarity: the assignment keeps as many allowed pairs as it can, even at lower scores. The two objects left unmatched count as one False Negative (ground truth) and one False Alarm (prediction), never as a False Discovery. A value that is null on one side fails; null on both sides passes. Only `str`, `int`, `float` and `bool` fields (optionally `Optional`) may be required; any other annotation raises `ValueError` when the class is defined. The veto applies where objects are paired in a `List[StructuredModel]`. A single nested object has no pairing step, so it is not vetoed. The setting is Python only: `to_json_schema()` and `to_stickler_config()` do not write it, and `model_from_json()` and `from_json_schema()` do not read it. | ||||||
| **`required_match`** -- Without it, an object with one wrong field still matches when its overall score reaches the element class's `match_threshold`. Use it instead of `weight` when a wrong value must never pair two objects, however well the rest agrees. | ||||||
|
|
||||||
| ```python | ||||||
| class Det(StructuredModel): | ||||||
| match_threshold = 0.5 | ||||||
| cls: str = ComparableField(threshold=1.0, required_match=True) | ||||||
| x: float = ComparableField(threshold=0.9) | ||||||
| ``` | ||||||
|
|
||||||
| A `Det` with `cls="tote"` against one with `cls="pallet"` and the same `x` scores `0.0` and counts as one FN plus one FA. Without `required_match` the same pair scores `0.5` and is a TP. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Applied as suggested. Measured: the pair scores the same either way, and the list scores |
||||||
|
|
||||||
| - A required field that is not at or above its resolved threshold (the field's `threshold`, else one named on the comparator, else `0.5`) vetoes the pair before the Hungarian assignment. A threshold of `0.0` never vetoes a pair whose values are both present. | ||||||
| - A veto takes priority over similarity: the assignment keeps as many allowed pairs as it can, even at lower scores. Mark every field that identifies an object as required. A field that is not required can be traded off by the matcher, so similar objects may be paired with each other. | ||||||
| - The two objects left unmatched count as one False Negative (ground truth) and one False Alarm (prediction), never as a False Discovery, and add nothing to the list score. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Applied as suggested. Measured: |
||||||
| - A value that is null on one side fails; null on both sides passes. | ||||||
| - When the two objects have different classes, a field required by either class can veto the pair, so swapping ground truth and prediction gives the same result. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since 649ad4a, each field is scored ground truth first, so with an asymmetric comparator swapping can change the result (gt
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Applied as suggested. Measured with |
||||||
| - Only `str`, `int`, `float` and `bool` fields (optionally `Optional`) may be required, and a class may not hold a nested `StructuredModel` field whose class has required fields. Both raise `ValueError` when the class is defined. Only a direct, `Optional` or `Annotated` nested field is checked; one reached through a `Dict` or a `Union` is not, and its required fields are ignored. | ||||||
| - The veto applies where objects are paired in a `List[StructuredModel]`. A single nested object has no pairing step, so it is not vetoed. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On your question: document these here for now; a warning at class definition is #678.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Applied the For #678: mixed lists already raise |
||||||
| - The setting is Python only: `to_json_schema()` and `to_stickler_config()` do not write it, and `model_from_json()` and `from_json_schema()` do not read it. | ||||||
|
|
||||||
| ### Example Model | ||||||
|
|
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -33,8 +33,8 @@ matcher.calculate_metrics(["apple", "banana"], ["banana", "aple"]) | |||||||||||
|
|
||||||||||||
| The assignment decides what is paired. `match_threshold` then splits the paired | ||||||||||||
| items into two groups. It never puts a pair back into the unpaired counts. With | ||||||||||||
| `m` and `n` as the two list lengths and `k` as the pair count, which is always | ||||||||||||
| `min(m, n)`: | ||||||||||||
| `m` and `n` as the two list lengths and `k` as the pair count, which is | ||||||||||||
| `min(m, n)` unless `is_pair_excluded` vetoes pairs: | ||||||||||||
|
|
||||||||||||
| | Key | Meaning | Closed form | | ||||||||||||
| |---|---|---| | ||||||||||||
|
|
@@ -44,8 +44,9 @@ items into two groups. It never puts a pair back into the unpaired counts. With | |||||||||||
| | `fa` | prediction item with no partner, a false alarm | `n` minus `k` | | ||||||||||||
| | `fp` | the rollup, `fd` plus `fa` | `n` minus `tp` | | ||||||||||||
|
|
||||||||||||
| The four leaf counts cover `max(m, n)` items once each, so nothing is counted | ||||||||||||
| twice and nothing is dropped. Only one of `fn` and `fa` can be non zero. | ||||||||||||
| The four leaf counts cover `m + n - k` items once each, so nothing is counted | ||||||||||||
| twice and nothing is dropped. Without exclusions `k` is `min(m, n)` and only one | ||||||||||||
| of `fn` and `fa` can be non zero; one vetoed pair leaves `fn` 1 and `fa` 1. | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Applied as suggested. Measured: a 1 x 1 input whose pair is vetoed gives |
||||||||||||
| `tp + fp == n` and `tp + fn + fd == m`, which is why `precision` and `recall` | ||||||||||||
| have a denominator in closed form and the method needs no special case per | ||||||||||||
| input shape. | ||||||||||||
|
|
||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Applied as suggested.