pyntbci.utilities.euclidean

pyntbci.utilities.euclidean(A: NDArray, B: NDArray, sum_aa_old: NDArray = None, sum_bb_old: NDArray = None, sum_ab_old: NDArray = None, running: bool = False) NDArray | tuple[NDArray, NDArray, NDArray, NDArray][source]

Compute the Euclidean distance. Computed between two sets of variables.

Parameters:
  • A (NDArray) – The first set of variables of shape (n_A, n_samples).

  • B (NDArray) – The second set of variables of shape (n_B, n_samples).

  • sum_aa_old (NDArray (default: None)) – Already observed sum of A**2 of shape (n_A, 1). Only used if running=True.

  • sum_bb_old (NDArray (default: None)) – Already observed sum of B**2 of shape (1, n_B). Only used if running=True.

  • sum_ab_old (NDArray (default: None)) – Already observed sum of A @ B.T of shape (n_A, n_B). Only used if running=True.

  • running (bool (default: False)) – Whether to use a running Euclidean distance, adding samples to previously accumulated sums rather than recomputing from scratch. If True, A and B are taken to be only the newly observed samples (not the full history), and sum_aa_old/sum_bb_old/sum_ab_old the state accumulated so far (as returned by a previous call); omit them (default None) for the first call in a sequence. Unlike correlation()’s running mode, this does not go through covariance(), since Euclidean distance is defined on the raw (uncentered) values, so there is no mean to track; the three sums below are, by construction, exactly additive across chunks (no correction term is needed, unlike a running mean/covariance), so this is not an approximation.

Returns:

  • scores (NDArray) – The distance matrix of shape (n_A, n_B).

  • sum_aa_new (NDArray) – The sum of A**2 of shape (n_A, 1). Only returned if running=True.

  • sum_bb_new (NDArray) – The sum of B**2 of shape (1, n_B). Only returned if running=True.

  • sum_ab_new (NDArray) – The sum of A @ B.T of shape (n_A, n_B). Only returned if running=True.