partipy.compute_archetype_weights

partipy.compute_archetype_weights#

partipy.compute_archetype_weights(adata, mode='automatic', length_scale=None, save_to_anndata=True, result_filters=None)#

Calculate weights for the data points based on their distance to archetypes using a squared exponential kernel.

Parameters:
  • adata (anndata.AnnData) – An AnnData object containing the data and archetypes. The data should be stored in adata.obsm[obsm_key] and the archetypes in adata.uns["AA_results"]["Z"].

  • mode (str, default automatic) – The mode for determining the length scale of the kernel: - “automatic”: The length scale is calculated as half the median distance from the data centroid to the archetypes. - “manual”: The length scale is provided by the user via the length_scale parameter.

  • length_scale (float, default None) – If mode="manual", this is the user-defined length scale for the kernel. If mode="automatic", it is calculated automatically.

  • save_to_anndata (bool, default True) – If True, the weights are saved to adata.uns["AA_cell_weights"] under the resolved AA configuration. If False, the weights are returned as a NumPy array.

  • result_filters (Mapping[str, Any] | None, default None) – Filters forwarded to _resolve_aa_result to select the AA configuration for which weights are computed.

Return type:

None | ndarray

Returns:

np.ndarray - If save_to_anndata is True, weights are stored in adata.uns["AA_cell_weights"] and None is returned. - If save_to_anndata is False, the computed weights are returned as a NumPy array.