Class DCor

  • All Implemented Interfaces:
    Dependence

    @Reference(authors="G. J. Sz\u00e9kely, M. L. Rizzo, N. K. Bakirov",
               title="Measuring and testing dependence by correlation of distances",
               booktitle="The Annals of Statistics, 35(6), 2769-2794",
               url="https://doi.org/10.1214/009053607000000505",
               bibkey="doi:10.1214/009053607000000505")
    @Priority(200)
    public class DCor
    extends java.lang.Object
    implements Dependence
    Distance correlation.

    The value returned is the square root of the dCor² value. This matches the R implementation by the original authors.

    Reference:

    G. J. Székely, M. L. Rizzo, N. K. Bakirov
    Measuring and testing dependence by correlation of distances
    The Annals of Statistics, 35(6), 2769-2794

    Implementation notice: we exploit symmetry, and thus use diagonal matrixes. While initially the diagonal is zero, after double-centering the matrix these values can become non-zero!

    Since:
    0.7.0
    Author:
    Marie Kiermeier, Erich Schubert
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  DCor.Par
      Parameterization class
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static DCor STATIC
      Static instance.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected DCor()
      Constructor - use STATIC instance instead!
    • Field Detail

      • STATIC

        public static final DCor STATIC
        Static instance.
    • Constructor Detail

      • DCor

        protected DCor()
        Constructor - use STATIC instance instead!
    • Method Detail

      • dependence

        public <A,​B> double dependence​(NumberArrayAdapter<?,​A> adapter1,
                                             A data1,
                                             NumberArrayAdapter<?,​B> adapter2,
                                             B data2)
        Description copied from interface: Dependence
        Measure the dependence of two variables.

        This is the more flexible API, which allows using different internal data representations.

        Specified by:
        dependence in interface Dependence
        Type Parameters:
        A - First array type
        B - Second array type
        Parameters:
        adapter1 - First data adapter
        data1 - First data set
        adapter2 - Second data adapter
        data2 - Second data set
        Returns:
        Dependence measure
      • dependence

        public <A> double[] dependence​(NumberArrayAdapter<?,​A> adapter,
                                       java.util.List<? extends A> data)
        Description copied from interface: Dependence
        Measure the dependence of two variables.

        This is the more flexible API, which allows using different internal data representations.

        The resulting data is a serialized lower triangular matrix:

          X  S  S  S  S  S
          0  X  S  S  S  S
          1  2  X  S  S  S
          3  4  5  X  S  S
          6  7  8  9  X  S
         10 11 12 13 14  X
         
        Specified by:
        dependence in interface Dependence
        Type Parameters:
        A - Array type
        Parameters:
        adapter - Data adapter
        data - Data sets. Must have fast random access!
        Returns:
        Lower triangular serialized matrix
      • computeDistances

        protected static <A> double[] computeDistances​(NumberArrayAdapter<?,​A> adapter,
                                                       A data)
        Compute the double-centered delta matrix.
        Parameters:
        adapter - Data adapter
        data - Input data
        Returns:
        Double-centered delta matrix.
      • doubleCenterMatrix

        public static double[] doubleCenterMatrix​(double[] dMatrix,
                                                  int size)
        Computes the distance variance matrix of one axis.
        Parameters:
        dMatrix - distance matrix of the axis
        size - Dimensionality
        Returns:
        dMatrix
      • computeDCovar

        protected double computeDCovar​(double[] dVarMatrixA,
                                       double[] dVarMatrixB,
                                       int n)
        Computes the distance covariance for two axis. Can also be used to compute the distance variance of one axis (dVarMatrixA = dVarMatrixB).
        Parameters:
        dVarMatrixA - distance variance matrix of the first axis
        dVarMatrixB - distance variance matrix of the second axis
        n - number of points
        Returns:
        distance covariance