partipy.compute_selection_metrics

partipy.compute_selection_metrics#

partipy.compute_selection_metrics(adata, min_k=None, max_k=None, n_archetypes_list=None, n_restarts=5, init=None, optim=None, weight=None, max_iter=None, early_stopping=True, rel_tol=None, coreset_algorithm=None, coreset_fraction=0.1, coreset_size=None, delta=0.0, seed=42, save_to_anndata=True, return_result=False, verbose=False, force_recompute=False, **optim_kwargs)#

Compute selection diagnostics for Archetypal Analysis (AA) across different archetype counts.

This function fits AA models for each value in n_archetypes_list, optionally across multiple restarts, and records variance explained, information criterion, and residual sum of squares. Results are cached in adata.uns["AA_selection_metrics"] keyed by the AA optimization configuration, and the corresponding AA fits are stored in adata.uns["AA_results"] via compute_archetypes().

Parameters:
  • adata (anndata.AnnData) – AnnData object containing the matrix configured through set_obsm.

  • min_k (int | None, optional) – Deprecated. Minimum number of archetypes to test. Use n_archetypes_list instead.

  • max_k (int | None, optional) – Deprecated. Maximum number of archetypes to test. Use n_archetypes_list instead.

  • n_archetypes_list (int | list[int] | None, optional) – Number(s) of archetypes to evaluate. Defaults to range(2, 11) when not provided.

  • n_restarts (int, default 5) – Number of random restarts per archetype count.

  • %(init)s

  • %(optim)s

  • %(weight)s

  • %(max_iter)s

  • %(early_stopping)s

  • %(rel_tol)s

  • %(coreset_algorithm)s

  • %(coreset_fraction)s

  • %(coreset_size)s

  • %(delta)s

  • %(seed)s

  • save_to_anndata (bool, default True) – Whether to cache the results in the AnnData object.

  • return_result (bool, default False) – If True, return the aggregated results DataFrame.

  • verbose (bool, default False) – Whether to run AA in verbose mode.

  • force_recompute (bool, default False) – Recompute metrics even if cached results for the configuration exist.

  • **optim_kwargs – Additional keyword arguments forwarded to the AA class.

  • init (None | str)

  • optim (None | str)

  • weight (None | str)

  • max_iter (None | int)

  • early_stopping (bool)

  • rel_tol (None | float)

  • coreset_algorithm (None | str)

  • coreset_fraction (float)

  • coreset_size (None | int)

  • delta (float)

  • seed (int)

Return type:

None | DataFrame

Returns:

None | pandas.DataFrame Returns None unless return_result is True, in which case the aggregated DataFrame is returned. Cached per-configuration tables can later be concatenated via summarize_aa_metrics().