Skip to content

scdef.tl.add_l0_lineage_aggregate_scores

add_l0_lineage_aggregate_scores(per_factor: DataFrame, layer_names: Sequence[str]) -> DataFrame

Add lineage-averaged clarity and effective parents for layer-0 factors only.

For each L0 factor, follows best_parent upward through layers L1 … L{n-2}, collecting clarity_score_01 and n_eff_parents from each factor along the path (same definitions as compute_hierarchy_scores). Stores the mean over those positions in avg_clarity and avg_n_eff_parents on the L0 row only; other rows get NaN.

This is called automatically from compute_hierarchy_scores; it remains public for advanced use on a pre-built per_factor frame.

This captures cases where an L0 factor maps cleanly to one L1 parent (low local n_eff_parents) while that parent is ambiguous relative to L2, by letting lineage averages reflect uncertainty higher in the hierarchy.

Parameters:

Name Type Description Default
per_factor DataFrame

per-factor scores from compute_hierarchy_scores. Factor identity for lookups uses row index labels (not the child_factor column when present).

required
layer_names Sequence[str]

ordered model layer names (model.layer_names). The walk length is len(layer_names) - 1 (one score per child layer, L0 through L{n-2}); layer order is not inferred from strings in the frame so non-lexicographic names stay correct.

required

Returns:

Type Description
DataFrame

Copy of per_factor with two additional float columns.