Ejemplo n.º 1
0
    def estimation(self, y, ds=None):
        """ Estimate multivariate extension of Blomqvist's beta.
        
        Parameters
        ----------
        y : (number of samples, dimension)-ndarray
             One row of y corresponds to one sample.
        ds : int vector, vector of ones
             ds[i] = 1 (for all i): the i^th subspace is one-dimensional.
             If ds is not given (ds=None), the vector of ones [ds =
             ones(y.shape[1],dtype='int')] is emulated inside the function.
    
        Returns
        -------
        a : float
            Estimated multivariate extension of Blomqvist's beta.

        References
        ----------
        Friedrich Schmid, Rafael Schmidt, Thomas Blumentritt, Sandra
        Gaiser, and Martin Ruppert. Copula Theory and Its Applications,
        Chapter Copula based Measures of Multivariate Association. Lecture
        Notes in Statistics. Springer, 2010. (multidimensional case,
        len(ds)>=2)
        
        Manuel Ubeda-Flores. Multivariate versions of Blomqvist's beta and 
        Spearman's footrule. Annals of the Institute of Statistical 
        Mathematics, 57:781-788, 2005.
        
        Nils Blomqvist. On a measure of dependence between two random 
        variables. The Annals of Mathematical Statistics, 21:593-600, 1950. 
        (2D case, statistical properties)
        
        Frederick Mosteller. On some useful ''inefficient'' statistics.
        Annals of Mathematical Statistics, 17:377--408, 1946. (2D case,
        def)


        Examples
        --------
        a = co.estimation(y,ds)  

        """

        if ds is None:  # emulate 'ds = vector of ones'
            ds = ones(y.shape[1], dtype='int')

        # verification:
        self.verification_compatible_subspace_dimensions(y, ds)
        self.verification_one_dimensional_subspaces(ds)

        num_of_samples, dim = y.shape  # number of samples, dimension
        u = copula_transformation(y)

        h = 2**(dim - 1) / (2**(dim - 1) - 1)  # h(dim)
        c1 = mean(all(u <= 1 / 2, axis=1))  # C(1/2)
        c2 = mean(all(u > 1 / 2, axis=1))  # \bar{C}(1/2)
        a = h * (c1 + c2 - 2**(1 - dim))

        return a
Ejemplo n.º 2
0
    def estimation(self, y, ds=None):
        """ Estimate the second multivariate extension of Spearman's rho.
        
        Parameters
        ----------
        y : (number of samples, dimension)-ndarray
             One row of y corresponds to one sample.
        ds : int vector, vector of ones
             ds[i] = 1 (for all i): the i^th subspace is one-dimensional.
             If ds is not given (ds=None), the vector of ones [ds =
             ones(y.shape[1],dtype='int')] is emulated inside the function.

        Returns
        -------
        a : float
            Estimated second multivariate extension of Spearman's rho.

        References
        ----------
        Friedrich Shmid, Rafael Schmidt, Thomas Blumentritt, Sandra
        Gaiser, and Martin Ruppert. Copula Theory and Its Applications,
        Chapter Copula based Measures of Multivariate Association. Lecture
        Notes in Statistics. Springer, 2010.
        
        Friedrich Schmid and Rafael Schmidt. Multivariate extensions of 
        Spearman's rho and related statistics. Statistics & Probability 
        Letters, 77:407-416, 2007.
        
        Roger B. Nelsen. Nonparametric measures of multivariate
        association. Lecture Notes-Monograph Series, Distributions with
        Fixed Marginals and Related Topics, 28:223-232, 1996.
        
        Harry Joe. Multivariate concordance. Journal of Multivariate
        Analysis, 35:12-30, 1990.
        
        C. Spearman. The proof and measurement of association between two 
        things. The American Journal of Psychology, 15:72-101, 1904.        

        Examples
        --------
        a = co.estimation(y,ds)  

        """

        if ds is None:  # emulate 'ds = vector of ones'
            ds = ones(y.shape[1], dtype='int')

        # verification:
        self.verification_compatible_subspace_dimensions(y, ds)
        self.verification_one_dimensional_subspaces(ds)

        dim = y.shape[1]  # dimension
        u = copula_transformation(y)
        h = (dim + 1) / (2**dim - (dim + 1))  # h_rho(dim)

        a = h * (2**dim * mean(prod(u, axis=1)) - 1)

        return a
Ejemplo n.º 3
0
    def estimation(self, y, ds=None):
        """ Estimate the fourth multivariate extension of Spearman's rho.
        
        Parameters
        ----------
        y : (number of samples, dimension)-ndarray
             One row of y corresponds to one sample.
        ds : int vector, vector of ones
             ds[i] = 1 (for all i): the i^th subspace is one-dimensional.
             If ds is not given (ds=None), the vector of ones [ds =
             ones(y.shape[1],dtype='int')] is emulated inside the function.
    
        Returns
        -------
        a : float
            Estimated fourth multivariate extension of Spearman's rho.

        References
        ----------
        Friedrich Shmid, Rafael Schmidt, Thomas Blumentritt, Sandra
        Gaiser, and Martin Ruppert. Copula Theory and Its Applications,
        Chapter Copula based Measures of Multivariate Association. Lecture
        Notes in Statistics. Springer, 2010.

        Friedrich Schmid and Rafael Schmidt. Multivariate extensions of 
        Spearman's rho and related statistics. Statistics & Probability 
        Letters, 77:407-416, 2007.
        
        Maurice G. Kendall. Rank correlation methods. London, Griffin,
        1970.
       
        C. Spearman. The proof and measurement of association between two 
        things. The American Journal of Psychology, 15:72-101, 1904.        

        Examples
        --------
        a = co.estimation(y,ds)  

        """

        if ds is None:  # emulate 'ds = vector of ones'
            ds = ones(y.shape[1], dtype='int')

        # verification:
        self.verification_compatible_subspace_dimensions(y, ds)
        self.verification_one_dimensional_subspaces(ds)

        num_of_samples, dim = y.shape  # number of samples, dimension
        u = copula_transformation(y)

        m_triu = triu(ones((dim, dim)), 1)  # upper triangular mask
        b = binom(dim, 2)
        a = 12 * sum(dot((1 - u).T, (1 - u)) * m_triu) /\
            (b * num_of_samples) - 3

        return a
Ejemplo n.º 4
0
    def estimation(self, y, ds=None):
        """ Estimate the third multivariate extension of Spearman's rho.
        
        Parameters
        ----------
        y : (number of samples, dimension)-ndarray
             One row of y corresponds to one sample.
        ds : int vector, vector of ones
             ds[i] = 1 (for all i): the i^th subspace is one-dimensional.
             If ds is not given (ds=None), the vector of ones [ds =
             ones(y.shape[1],dtype='int')] is emulated inside the function.
    
        Returns
        -------
        a : float
            Estimated third multivariate extension of Spearman's rho.

        References
        ----------
        Friedrich Shmid, Rafael Schmidt, Thomas Blumentritt, Sandra
        Gaiser, and Martin Ruppert. Copula Theory and Its Applications,
        Chapter Copula based Measures of Multivariate Association. Lecture
        Notes in Statistics. Springer, 2010.
        
        Roger B. Nelsen. An Introduction to Copulas (Springer Series in 
        Statistics). Springer, 2006.
        
        Roger B. Nelsen. Distributions with Given Marginals and
        Statistical Modelling, chapter Concordance and copulas: A survey,
        pages 169-178. Kluwer Academic Publishers, Dordrecht, 2002.
        
        C. Spearman. The proof and measurement of association between two 
        things. The American Journal of Psychology, 15:72-101, 1904.        

        Examples
        --------
        a = co.estimation(y,ds)

        """

        if ds is None:  # emulate 'ds = vector of ones'
            ds = ones(y.shape[1], dtype='int')

        # verification:
        self.verification_compatible_subspace_dimensions(y, ds)
        self.verification_one_dimensional_subspaces(ds)

        dim = y.shape[1]  # dimension
        u = copula_transformation(y)
        h = (dim + 1) / (2**dim - (dim + 1))  # h_rho(d)

        a1 = h * (2**dim * mean(prod(1 - u, axis=1)) - 1)
        a2 = h * (2**dim * mean(prod(u, axis=1)) - 1)
        a = (a1 + a2) / 2

        return a
Ejemplo n.º 5
0
    def estimation(self, y, ds=None):
        """ Estimate multivariate conditional version of Spearman's rho.
        
        Parameters
        ----------
        y : (number of samples, dimension)-ndarray
             One row of y corresponds to one sample.
        ds : int vector, vector of ones
             ds[i] = 1 (for all i): the i^th subspace is one-dimensional.
             If ds is not given (ds=None), the vector of ones [ds =
             ones(y.shape[1],dtype='int')] is emulated inside the function.
    
        Returns
        -------
        a : float
            Estimated multivariate conditional version of Spearman's rho.

        References
        ----------
        Friedrich Schmid and Rafael Schmidt. Multivariate conditional
        versions of Spearman's rho and related measures of tail
        dependence. Journal of Multivariate Analysis, 98:1123-1140, 2007.
        
        C. Spearman. The proof and measurement of association between two 
        things. The American Journal of Psychology, 15:72-101, 1904.        
        
        Examples
        --------
        a = co.estimation(y,ds)

        """

        if ds is None:  # emulate 'ds = vector of ones'
            ds = ones(y.shape[1], dtype='int')

        # verification:
        self.verification_compatible_subspace_dimensions(y, ds)
        self.verification_one_dimensional_subspaces(ds)

        num_of_samples, dim = y.shape  # number of samples, dimension
        u = copula_transformation(y)

        c = mean(prod(1 - maximum(u, 1 - self.p), axis=1))
        c1 = (self.p * (2 - self.p) / 2)**dim
        c2 = self.p**dim * (dim + 1 - self.p * dim) / (dim + 1)

        a = (c - c1) / (c2 - c1)

        return a
    def estimation(self, y, ds=None):
        """ Estimate Renyi mutual information.
        
        Parameters
        ----------
        y : (number of samples, dimension)-ndarray
             One row of y corresponds to one sample.
        ds : int vector, vector of ones
             If ds is not given (ds=None), the vector of ones [ds = 
             ones(y.shape[1],dtype='int')] is emulated inside the function.
    
        Returns
        -------
        i : float
            Estimated Renyi mutual information.
            
        References
        ----------
        David Pal, Barnabas Poczos, Csaba Szepesvari. Estimation of Renyi 
        Entropy and Mutual Information Based on Generalized
        Nearest-Neighbor Graphs. Advances in Neural Information Processing
        Systems (NIPS), pages 1849-1857, 2010.
        
        Barnabas Poczos, Sergey Krishner, Csaba Szepesvari. REGO:
        Rank-based Estimation of Renyi Information using Euclidean Graph
        Optimization. International Conference on Artificial Intelligence
        and Statistics (AISTATS), pages 605-612, 2010.
            
        Examples
        --------
        i = co.estimation(y,ds)  
            
        """

        if ds is None:  # emulate 'ds = vector of ones'
            ds = ones(y.shape[1], dtype='int')

        # verification:
        self.verification_compatible_subspace_dimensions(y, ds)
        self.verification_one_dimensional_subspaces(ds)

        z = copula_transformation(y)
        i = -self.renyi_co.estimation(z)

        return i
    def estimation(self, y, ds=None):
        """ Estimate copula and MMD based kernel dependency.
        
        Parameters
        ----------
        y : (number of samples, dimension)-ndarray
             One row of y corresponds to one sample.
        ds : int vector, vector of ones
             If ds is not given (ds=None), the vector of ones [ds =
             ones(y.shape[1],dtype='int')] is emulated inside the function.

        Returns
        -------
        i : float
            Estimated copula and MMD based kernel dependency.
           
        References
        ----------
        Barnabas Poczos, Zoubin Ghahramani, Jeff Schneider. Copula-based 
        Kernel Dependency Measures. International Conference on Machine 
        Learning (ICML), 2012.           
        
        Examples
        --------
        i = co.estimation(y,ds)  
            
        """

        if ds is None:  # emulate 'ds = vector of ones'
            ds = ones(y.shape[1], dtype='int')

        # verification:
        self.verification_compatible_subspace_dimensions(y, ds)
        self.verification_one_dimensional_subspaces(ds)

        z = copula_transformation(y)
        u = rand(z.shape[0], z.shape[1])

        i = self.mmd_co.estimation(z, u)

        return i
Ejemplo n.º 8
0
    def estimation(self, y, ds):
        """ Estimate multivariate version of Hoeffding's Phi.

        Parameters
        ----------
        y : (number of samples, dimension)-ndarray
             One row of y corresponds to one sample.
        ds : int vector
             Dimensions of the individual subspaces in y; ds[i] = i^th
             subspace dimension = 1 for this estimator.

        Returns
        -------
        i : float
            Estimated value of the multivariate version of Hoeffding's Phi.

        References
        ----------
        Sandra Gaiser, Martin Ruppert, Friedrich Schmid. A multivariate
        version of Hoeffding's Phi-Square. Journal of Multivariate
        Analysis. 101: pages 2571-2586, 2010.

        Examples
        --------
        i = co.estimation(y,ds)

        """

        # verification:
        self.verification_compatible_subspace_dimensions(y, ds)
        self.verification_one_dimensional_subspaces(ds)

        num_of_samples, dim = y.shape
        u = copula_transformation(y)

        # term1:
        m = 1 - maximum(u[:, 0][:, newaxis], u[:, 0])
        for i in range(1, dim):
            m *= 1 - maximum(u[:, i][:, newaxis], u[:, i])

        term1 = mean(m)

        # term2:
        if self.small_sample_adjustment:
            term2 = \
                - mean(prod(1 - u**2 - (1 - u) / num_of_samples,
                            axis=1)) / \
                (2**(dim - 1))
        else:
            term2 = - mean(prod(1 - u**2, axis=1)) / (2 ** (dim - 1))

        # term3:
        if self.small_sample_adjustment:
            term3 = \
                ((num_of_samples - 1) * (2 * num_of_samples-1) /
                 (3 * 2 * num_of_samples**2))**dim
        else:
            term3 = 1 / 3**dim

        i = term1 + term2 + term3

        if self.mult:
            if self.small_sample_adjustment:
                t1 = \
                    sum((1 - arange(1,
                                    num_of_samples) / num_of_samples)**dim
                        * (2*arange(1, num_of_samples) - 1)) \
                    / num_of_samples**2
                t2 = \
                    -2 * mean(((num_of_samples * (num_of_samples - 1) -
                                arange(1, num_of_samples+1) *
                                arange(num_of_samples)) /
                               (2 * num_of_samples ** 2))**dim)
                t3 = term3
                inv_hd = t1 + t2 + t3  # 1 / h(d, n)
            else:
                inv_hd = \
                    2 / ((dim + 1) * (dim + 2)) - factorial(dim) / \
                    (2 ** dim * prod(arange(dim + 1) + 1 / 2)) + \
                    1 / 3 ** dim  # 1 / h(d)s

            i /= inv_hd

        i = sqrt(abs(i))

        return i