Skip to content

scdef.tl.find_sensible_top_layer

find_sensible_top_layer(model: scDEF, n_eff_parents_max: float = 1.5, min_best_parent_prob: Optional[float] = None, min_clear_fraction: float = 0.8, min_clear_children: int = 2, ignore_root: bool = True, use_filtered: bool = True, store: bool = True) -> Dict[str, Any]

Find the coarsest hierarchy layer supported by confident merges.

Each candidate parent is scored by both the W-row-weighted average of its children's n_eff_parents and the number of clear best-parent children it owns. A parent counts as a clear merge target when either the weighted average is at most n_eff_parents_max or it has at least min_clear_children clear best-parent children (children that name it as their best_parent and themselves pass the threshold). The transition is accepted only when the fraction of clear parents is at least min_clear_fraction.

Parameters:

Name Type Description Default
model scDEF

fitted scDEF model. Diagnostics are computed on the fly if adata.uns['factor_obs'] is missing.

required
n_eff_parents_max float

a child is "clear" when its effective number of parents is at most this. Values near 1 mean the child loads on essentially one parent; raise it to accept fuzzier merges.

1.5
min_best_parent_prob Optional[float]

additionally require a child's best-parent probability to reach this before counting it as clear. Defaults to not requiring it.

None
min_clear_fraction float

fraction of a layer's parents that must qualify as clear merge targets for the layer to be accepted as the top.

0.8
min_clear_children int

number of clear best-parent children that on its own qualifies a parent, even when the weighted average misses n_eff_parents_max.

2
ignore_root bool

skip a width-1 root layer when judging coarseness, since a single root always merges everything and would otherwise always win.

True
use_filtered bool

judge only the factors the model currently keeps, rather than all fitted factors.

True
store bool

write the result to adata.uns for reuse.

True

Returns:

Type Description
Dict[str, Any]

The chosen layer together with the per-layer evidence behind the choice.