BiuBiuBiLL / NPEET_LNC

local non-uniformity correction for mutual information estimation
68 stars 18 forks source link

tests failure in python 3 - and solution #5

Open eigenvectorBazuz opened 7 months ago

eigenvectorBazuz commented 7 months ago

When trying to run the code in a python 3 environment (after 2to3 and autopep8) I got an error for the test:

  File "/opt/anaconda3/lib/python3.9/site-packages/numpy/core/_methods.py", line 191, in _mean
    ret = ret / rcount
TypeError: unsupported operand type(s) for /: 'map' and 'int'

The solution is simply to replace map by list(map) in lnc.py, line 220:

    @staticmethod
    def entropy(x, k=3, base=np.exp(1), intens=1e-10):
        """ The classic K-L k-nearest neighbor continuous entropy estimator
            x should be a list of vectors, e.g. x = [[1.3],[3.7],[5.1],[2.4]]
            if x is a one-dimensional scalar and we have four samples
        """
        assert k <= len(x)-1, "Set k smaller than num. samples - 1"
        d = len(x[0])
        N = len(x)
        x = [list(p + intens*nr.rand(len(x[0]))) for p in x]
        tree = ss.cKDTree(x)
        nn = [tree.query(point, k+1, p=float('inf'))[0][k] for point in x]
        const = digamma(N)-digamma(k) + d*log(2)
        return (const + d*np.mean(list(map(log, nn))))/log(base)