rsatoolbox.rdm.compare module

Comparison methods for comparing two RDMs objects

rsatoolbox.rdm.compare.compare(rdm1: RDMs, rdm2: RDMs, method='cosine', sigma_k: NDArray | None = None) NDArray[source]

Calculates the similarity between two RDMs objects using a chosen method

Parameters:
  • rdm1 (rsatoolbox.rdm.RDMs) – first set of RDMs

  • rdm2 (rsatoolbox.rdm.RDMs) – second set of RDMs

  • method (string) –

    which method to use, options are:

    ’cosine’ = cosine similarity

    ’spearman’ = spearman rank correlation

    ’corr’ = pearson correlation

    ’kendall’ = kendall-tau b

    ’tau-a’ = kendall-tau a

    ’rho-a’ = spearman correlation without tie correction

    ’corr_cov’ = pearson correlation after whitening

    ’cosine_cov’ = unbiased distance correlation which is equivalent to the cosine dinstance after whitening

    ’neg_riem_dist’ = negative riemannian distance

    ’bures’ = bures similarity of equivalend cented kernel matrices

    ’bures_metric’ = distances based on bures similarity, which is a metric

  • sigma_k (numpy.ndarray) – covariance matrix of the pattern estimates. Used only for methods ‘corr_cov’ and ‘cosine_cov’.

Returns:

dist:

pariwise similarities between the RDMs from the RDMs objects

Return type:

numpy.ndarray

rsatoolbox.rdm.compare.compare_bures_metric(rdm1: RDMs, rdm2: RDMs) NDArray[source]

calculates the squared Bures metric between two RDMs objects.

Parameters:
  • rdm1 (rsatoolbox.rdm.RDMs) – first set of RDMs

  • rdm2 (rsatoolbox.rdm.RDMs) – second set of RDMs

Returns:

dist:

squared Bures metric between the two RDMs

Return type:

numpy.ndarray

rsatoolbox.rdm.compare.compare_bures_similarity(rdm1: RDMs, rdm2: RDMs) NDArray[source]

calculates the Bures similarity between two RDMs objects.

Parameters:
  • rdm1 (rsatoolbox.rdm.RDMs) – first set of RDMs

  • rdm2 (rsatoolbox.rdm.RDMs) – second set of RDMs

Returns:

dist:

Bures similarity between the two RDMs

Return type:

numpy.ndarray

rsatoolbox.rdm.compare.compare_correlation(rdm1: RDMs, rdm2: RDMs) NDArray[source]

Calculates the correlations between two RDMs objects

Parameters:
  • rdm1 (rsatoolbox.rdm.RDMs) – first set of RDMs

  • rdm2 (rsatoolbox.rdm.RDMs) – second set of RDMs

Returns:

dist:

correlations between the two RDMs

Return type:

numpy.ndarray

rsatoolbox.rdm.compare.compare_correlation_cov_weighted(rdm1: RDMs, rdm2: RDMs, sigma_k: NDArray | None = None) NDArray[source]

Calculates the correlations between two RDMs objects after whitening with the covariance of the entries

Parameters:
  • rdm1 (rsatoolbox.rdm.RDMs) – first set of RDMs

  • rdm2 (rsatoolbox.rdm.RDMs) – second set of RDMs

Returns:

dist:

correlations between the two RDMs

Return type:

numpy.ndarray

rsatoolbox.rdm.compare.compare_cosine(rdm1: RDMs, rdm2: RDMs) NDArray[source]

Calculates the cosine similarities between two RDMs objects

Parameters:
  • rdm1 (rsatoolbox.rdm.RDMs) – first set of RDMs

  • rdm2 (rsatoolbox.rdm.RDMs) – second set of RDMs

Returns:

dist

cosine similarity between the two RDMs

Return type:

numpy.ndarray

rsatoolbox.rdm.compare.compare_cosine_cov_weighted(rdm1: RDMs, rdm2: RDMs, sigma_k: NDArray | None = None) NDArray[source]

Calculates the cosine similarities between two RDMs objects

Parameters:
  • rdm1 (rsatoolbox.rdm.RDMs) – first set of RDMs

  • rdm2 (rsatoolbox.rdm.RDMs) – second set of RDMs

Returns:

dist:

cosine similarities between the two RDMs

Return type:

numpy.ndarray

rsatoolbox.rdm.compare.compare_kendall_tau(rdm1: RDMs, rdm2: RDMs) NDArray[source]

Calculates the conventional Kendall rank correlation coefficient (i.e. Kendall-tau b) between two RDMs objects (slow and inadequate if any of the models predicts some tied dissimilarities). We here use the implementation from scipy.

Parameters:
  • rdm1 (rsatoolbox.rdm.RDMs) – first set of RDMs

  • rdm2 (rsatoolbox.rdm.RDMs) – second set of RDMs

Returns:

dist:

kendall-tau correlation between the two RDMs

Return type:

numpy.ndarray

rsatoolbox.rdm.compare.compare_kendall_tau_a(rdm1: RDMs, rdm2: RDMs) NDArray[float64][source]

Calculates the Kendall rank correlation coefficient without tie adjustment in the denominator (i.e. Kendall-tau a) between two RDMs objects (slow and appropriate in general, even when some or all models predict some tied dissimilarities). We here use the implementation from scipy.

Parameters:
  • rdm1 (rsatoolbox.rdm.RDMs) – first set of RDMs

  • rdm2 (rsatoolbox.rdm.RDMs) – second set of RDMs

Returns:

dist:

kendall-tau a between the two RDMs

Return type:

numpy.ndarray

rsatoolbox.rdm.compare.compare_neg_riemannian_distance(rdm1: RDMs, rdm2: RDMs, sigma_k: NDArray | None = None) NDArray[source]

Calculates the negative Riemannian distance between two RDMs objects.

Parameters:
  • rdm1 (rsatoolbox.rdm.RDMs) – first set of RDMs

  • rdm2 (rsatoolbox.rdm.RDMs) – second set of RDMs

Returns:

dist:

negative Riemannian distance between the two RDMs

Return type:

numpy.ndarray

rsatoolbox.rdm.compare.compare_rho_a(rdm1: RDMs, rdm2: RDMs) NDArray[source]

Calculates the spearman rank correlation coefficient under random tie breaking between two RDMs objects, specifically an analytical solution for the expected value thereof (fast and appropriate in general, even when some or all models predict some tied dissimilarities)

Parameters:
  • rdm1 (rsatoolbox.rdm.RDMs) – first set of RDMs

  • rdm2 (rsatoolbox.rdm.RDMs) – second set of RDMs

Returns:

dist:

rank correlations between the two RDMs

Return type:

numpy.ndarray

rsatoolbox.rdm.compare.compare_spearman(rdm1: RDMs, rdm2: RDMs) NDArray[source]

Calculates the spearman rank correlation coefficient between two RDMs objects (fast, but inadequate if any of the models predicts some tied dissimilarities)

Parameters:
  • rdm1 (rsatoolbox.rdm.RDMs) – first set of RDMs

  • rdm2 (rsatoolbox.rdm.RDMs) – second set of RDMs

Returns:

dist:

rank correlations between the two RDMs

Return type:

numpy.ndarray