Code Target API¶
Dense taxonomy distances and unary partners provide code-to-code targets and keep masks in codebook order. The anchor and its unary partner are removed from each target/candidate row.
The fixed inputs of Req 11's code–code and radial terms (spec 4.1(ii), (iii)), read once.
For every code, in codebook order: its level λ, the number of its digits; the tree metric D* to every code (Req 7); and its unary partner (Req 9), for a five-digit code and its only six-digit child each other. The code–code term's J_a is every code but the anchor and its partner, so a unary pair is neither a positive nor a negative.
The pair facts give D* and the unary flag. No exclusion column is read, so no exclusion pair can act as a code–code negative (Req 8(c)).
CodeTargets
dataclass
¶
Each code's level, D* to every code and unary partner, in codebook order.
Built by from_bundle. The arrays are fresh and writable, so torch.from_numpy can share
them; nothing here writes to them.
Attributes:
| Name | Type | Description |
|---|---|---|
codes |
Tuple[str, ...]
|
The codes, in codebook order. |
levels |
ndarray
|
λ, each code's number of digits, (N,) int64. |
structural_distance |
ndarray
|
D*, (N, N) float32, symmetric and zero on the diagonal only. |
unary_partner |
ndarray
|
Each code's unary partner's id, or -1 for none, (N,) int64. |
__eq__(other)
¶
Equal codes, and arrays of equal dtype and values.
from_bundle(bundle)
classmethod
¶
Read the codebook and the pair facts' PAIR_FACT_COLUMNS from a validated bundle.
The loader has checked that the code ids run from zero in codebook order, that the pair facts hold every pair of distinct codes once with D* as their distance, and that the unary flag marks exactly each five-digit code and its only six-digit child.
keep(ids)
¶
J_a for each anchor: every code but the anchor itself and its unary partner.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ids
|
ndarray
|
The anchors' code ids, (A,), an integer array (a CPU tensor converts). |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
A fresh bool mask over the codes, (A, N). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |