Test statistics#

Test statistics to compare two samples (H0 vs H1).

This module provides simple statistics (mean, median, AUC of distances, etc.) as well as non-parametric tests (SciPy) to measure the separability between two data distributions.

phise.modules.test_statistics.get_vectors(
ctx=None,
nmc: int = 1000,
size: int = 1000,
progress_callback=None,
flatten: bool = True,
randomize_position: bool = False,
)[source]#

Generate two sets of statistic vectors under H0 and H1.

This simulates observations with and without companion(s) to build statistic arrays of shape (nb_processed_outputs, nmc, size) under H0 (no companion) and H1 (with companions), then concatenates each set along the first axis.

Notes

  • Assumes a compatible Context object exists (see phise.classes.context.Context) and relies on its observe() method.

  • To avoid circular imports, the Context import is local and only used if ctx is None.

Parameters:
  • ctx – Observation context (if None, a default VLTI context is instantiated). The context must contain at least one companion to generate H1.

  • nmc – Number of Monte-Carlo realizations.

  • size – Number of samples per realization.

  • progress_callback (callable, optional) – function accepting a float (0-1) representing the progress.

  • flatten (bool, optional) – If True, concatenates independent kernel outputs. If False, returns shapes (nb_processed_outputs, nmc, size). Defaults to True.

  • randomize_position (bool, optional) – If True, randomizes companion position (uniform in FOV) for each sample. If False, uses the fixed position defined in ctx. Defaults to False.

Returns:

  • T0: Concatenated vectors under H0, shape (nb_processed_outputs * nmc * size,) if flatten=True.

  • T1: Concatenated vectors under H1, shape (nb_processed_outputs * nmc * size,) if flatten=True.

Return type:

Tuple (T0, T1) where

Raises:

ValueError – If ctx contains no companions.

phise.modules.test_statistics.mean(u, v)[source]#

Absolute value of the mean of u.

Parameters:
  • u – Samples under H1 (or any real/complex vector).

  • v – Samples under H0 (unused).

Returns:

Absolute value of mean(u).

Return type:

float

phise.modules.test_statistics.median(u, v)[source]#

Absolute value of the median of u.

Parameters:
  • u – Samples under H1.

  • v – Samples under H0 (unused).

Returns:

Absolute value of median(u).

Return type:

float

phise.modules.test_statistics.argmax(u, v, bins: int = 100)[source]#

Approximate mode of u using a histogram (most frequent bin).

Parameters:
  • u – Samples under H1.

  • v – Samples under H0 (unused).

  • bins – Number of histogram bins.

Returns:

Absolute center value of the bin maximizing the histogram.

Return type:

float

phise.modules.test_statistics.argmax50(u, v)[source]#

Shortcut for argmax(u, v, bins=50).

phise.modules.test_statistics.argmax100(u, v)[source]#

Shortcut for argmax(u, v, bins=100).

phise.modules.test_statistics.argmax500(u, v)[source]#

Shortcut for argmax(u, v, bins=500).

phise.modules.test_statistics.kolmogorov_smirnov(u, v)[source]#

Two-sample Kolmogorov–Smirnov statistic.

Returns:

Absolute value of D, the maximal distance between empirical CDFs.

Return type:

float

phise.modules.test_statistics.cramer_von_mises(u, v)[source]#

Two-sample Cramér–von Mises statistic.

Returns:

Absolute value of the statistic.

Return type:

float

phise.modules.test_statistics.mannwhitneyu(u, v)[source]#

Mann–Whitney U statistic (Wilcoxon rank-sum).

Returns:

Absolute value of the statistic.

Return type:

float

phise.modules.test_statistics.wilcoxon_mann_whitney(u, v)[source]#

Wilcoxon signed-rank test statistic (paired samples).

Returns:

Absolute value of the statistic.

Return type:

float

phise.modules.test_statistics.anderson_darling(u, v)[source]#

Anderson–Darling k-sample statistic.

Returns:

Absolute value of the statistic.

Return type:

float

phise.modules.test_statistics.brunner_munzel(u, v)[source]#

Brunner–Munzel test statistic.

Returns:

Absolute value of the statistic.

Return type:

float

phise.modules.test_statistics.wasserstein_distance(u, v)[source]#

Wasserstein distance (earth mover’s distance, order 1).

Returns:

Absolute value of the Wasserstein distance W1(u, v).

Return type:

float

phise.modules.test_statistics.flattening(u, v)[source]#

Sum of absolute deviations from the median.

Returns:

Measure of “flattening” around the median.

Return type:

float

phise.modules.test_statistics.shift_and_flattening(u, v)[source]#

Area under the curve of sorted distances to the median (AUC).

Definition: if d_i = abs(u_i - median(u)) sorted, returns the area of d(x) + abs(median) over x in [0, 1].

Returns:

Area under the curve approximated via numerical integration.

Return type:

float

phise.modules.test_statistics.median_of_abs(u, v)[source]#

Median of absolute values: median(abs(u)).

phise.modules.test_statistics.full_sum(u, v)[source]#

Sum of absolute values: sum(abs(u)).