Skip to content

scdef.tl.set_cell_entropies

set_cell_entropies(model: scDEF, layers: Optional[Sequence[Union[int, str]]] = None, key_suffix: str = 'entropy', effective_suffix: str = 'effective_n_factors', normalize: bool = True, eps: float = 1e-12) -> List[str]

Compute per-cell assignment entropy and store one column per layer.

For each selected layer, uses model.adata.obsm[f"X_{layer_name}"] to build per-cell membership probabilities and computes Shannon entropy.

If normalize=True, entropy is divided by log(n_factors_layer) so values are approximately in [0, 1] (for layers with >1 factors).

Also stores an effective number of factors per cell, defined as exp(H) where H is the non-normalized Shannon entropy.

Parameters:

Name Type Description Default
model scDEF

fitted scDEF model, with annotate_adata (or fit) already run so that adata.obsm['X_<layer>'] exists.

required
layers Optional[Sequence[Union[int, str]]]

layers to compute entropy for, as indices or names. Defaults to every layer.

None
key_suffix str

suffix of the entropy column written to adata.obs; the full name is f"{layer_name}_{key_suffix}".

'entropy'
effective_suffix str

suffix of the effective-number-of-factors column, written as f"{layer_name}_{effective_suffix}".

'effective_n_factors'
normalize bool

divide the entropy by log(n_factors) in that layer, putting it on a roughly [0, 1] scale so layers of different widths are comparable. The effective-factor column is always computed from the non-normalized entropy.

True
eps float

floor applied before normalizing and before taking logs, to keep zero memberships from producing infinities.

1e-12

Returns:

Type Description
List[str]

List of created/updated entropy column names.