decipher.stats

Paradigm-agnostic statistical primitives: KDE, permutation testing, representational geometry.

function decipher.stats.kde_modes_and_valleys
def kde_modes_and_valleys(
    x: np.ndarray,
    *,
    bandwidth: float | str = "scott",
    n_grid: int = 1024,
    grid_lo: float | None = None,
    grid_hi: float | None = None,
) -> dict

1-D Gaussian KDE plus extracted modes and valleys. Returns the grid, density values, sorted modes, and sorted valleys.

function decipher.stats.permutation_test_vs_matched_baseline
def permutation_test_vs_matched_baseline(
    observed: float,
    sample_fn,                        # () → float
    n_permutations: int = 500,
    rng_seed: int = 42,
    alternative: str = "two-sided",   # "greater" | "less" | "two-sided"
) -> dict

Generic permutation-test machinery parameterised by a caller-supplied shuffle function. Returns p-value, null mean, null std, and quantiles.

function decipher.stats.rsa
def rsa(D_a: np.ndarray, D_b: np.ndarray) -> float

Representational Similarity Analysis: Spearman correlation between the upper-triangular entries of two pairwise distance matrices over the same items.

function decipher.stats.linear_cka
def linear_cka(X: np.ndarray, Y: np.ndarray) -> float

Linear Centered Kernel Alignment between two feature matrices over the same items, in [0, 1].

function decipher.stats.rsa_permutation_null
def rsa_permutation_null(
    D_a: np.ndarray, D_b: np.ndarray,
    n_permutations: int = 500,
    rng_seed: int = 42,
) -> dict

Null distribution of rsa(D_a, D_b) under random re-labeling of one matrix.