Example #1
0
def entropy(X, P, n, precision, truncate, verbose=False):
    '''
    Using the correlator matrices, find the nth entropy.
    :param X: spatial correlator matrix (sympy)
    :param P: momentum correlator matrix (sympy)
    :param n: Renyi index
    :param precision: arithmetic precision 
    :param verbose: runtime output flag
    '''
    XP = sp.dot(X, P)

    # DEBUGGING: Saving the correlator matrices.
    #         prec = sympy.mpmath.mp.dps
    #         sp.savetxt("xmat.txt", X, fmt='%.{0}f'.format(prec),delimiter=",")
    #         sp.savetxt("pmat.txt",P, fmt='%.{0}f'.format(prec),delimiter=",")

    # Scipy eigenvalues
    sqrt_eigs = sp.sqrt(linalg.eigvals(XP))

    # Check that the eigenvalues are well-defined.
    to_remove = []
    for i, eig in enumerate(sqrt_eigs):
        if eig.real <= 0.5:
            if truncate:
                # Remove the eigenvalue
                to_remove.append(i)
            else:
                raise ValueError(
                    "At least one of the eigenvalues of sqrt(XP) is below 0.5! \n eig = {0}"
                    .format(eig))
        if eig.imag != 0:
            print "Warning: got an imaginary eigvalue component: " + str(
                eig.imag)

    sqrt_eigs = sp.delete(sqrt_eigs, to_remove)

    # Chop off imaginary component.
    sqrt_eigs = sqrt_eigs.real

    # Calculate entropy.
    S_n = 0
    if n == 1:
        for vk in sqrt_eigs:
            S_n += ((vk + 0.5) * log(vk + 0.5) - (vk - 0.5) * log(vk - 0.5))
    else:
        for vk in sqrt_eigs:
            S_n += log((vk + 0.5)**n - (vk - 0.5)**n)
        S_n *= 1. / (n - 1)

    if verbose == True:
        print "Calculated entropy of {0}".format(S_n)

    S_n = float(S_n)
    return S_n
def entropy(X, P, n, precision, truncate, verbose=False):
    '''
    Using the correlator matrices, find the nth entropy.
    :param X: spatial correlator matrix (sympy)
    :param P: momentum correlator matrix (sympy)
    :param n: Renyi index
    :param precision: arithmetic precision 
    :param verbose: runtime output flag
    '''
    XP = sp.dot(X,P)
    
    # DEBUGGING: Saving the correlator matrices.
#         prec = sympy.mpmath.mp.dps
#         sp.savetxt("xmat.txt", X, fmt='%.{0}f'.format(prec),delimiter=",")
#         sp.savetxt("pmat.txt",P, fmt='%.{0}f'.format(prec),delimiter=",")
            
    # Scipy eigenvalues
    sqrt_eigs = sp.sqrt(linalg.eigvals(XP))
    
    # Check that the eigenvalues are well-defined.
    to_remove = []
    for i, eig in enumerate(sqrt_eigs):
        if eig.real <= 0.5:
            if truncate:
                # Remove the eigenvalue
                to_remove.append(i)
            else:
                raise ValueError("At least one of the eigenvalues of sqrt(XP) is below 0.5! \n eig = {0}".format(eig))
        if eig.imag != 0:
            print "Warning: got an imaginary eigvalue component: " + str(eig.imag)
        
    sqrt_eigs = sp.delete(sqrt_eigs,to_remove)
   
    # Chop off imaginary component.
    sqrt_eigs = sqrt_eigs.real
    
    # Calculate entropy.
    S_n = 0
    if n == 1:
        for vk in sqrt_eigs:
            S_n += ((vk + 0.5)*log(vk + 0.5) - (vk - 0.5)*log(vk - 0.5))
    else:
        for vk in sqrt_eigs:
            S_n += log((vk + 0.5)**n - (vk - 0.5)**n)
        S_n *= 1./(n-1)
        
    if verbose==True:
        print "Calculated entropy of {0}".format(S_n)
        
    S_n = float(S_n)
    return S_n
def test_log():
    """
    Se verifica que la operacion logaritmo funcione.
    """

    num, num2 = TwoReals()

    try:
        a = mp.log(num)
        b = mp.log(num2)
        c = Intervalo(num, num2).log()
        assert a == c.lo and b == c.hi
    except:
        if num2 < 0:
            pass
            #Debemos checar que se de el ValueError
        elif num < 0 and num2 >= 0:
            a = mp.log(num + np.abs(num))
            b = mp.log(num2)
            c = Intervalo(num, num2).log()
            assert a == c.lo and b == c.hi
Example #4
0
 def eval(self, *args):
     return mpmath.log(args[1], args[0])
Example #5
0
 def eval(self, *args):
     return mpmath.log(args[1], args[0])