コード例 #1
0
def entropy_cc(X, Y):  #ENTROPY CORRELATION COEFFICIENT
    """
    Entropy correlation coefficient p(H) = sqrt(I(X,Y)/0.5*(H(X)+H(Y)))
    """
    import numpy as np
    from CPAC.series_mod import entropy
    from CPAC.series_mod import mutual_information

    Hx = entropy(X)
    Hy = entropy(Y)
    Ixy = mutual_information(Y, X)
    ECC = np.sqrt(Ixy / (0.5 * (Hx + Hy)))

    return ECC
コード例 #2
0
ファイル: utils.py プロジェクト: roijo/C-PAC_complexitytools
def entropy_cc(X,Y): #ENTROPY CORRELATION COEFFICIENT
    
    """
    Entropy correlation coefficient p(H) = sqrt(I(X,Y)/0.5*(H(X)+H(Y)))
    """
    import numpy as np
    from CPAC.series_mod import entropy
    from CPAC.series_mod import mutual_information
    
    Hx = entropy(X)
    Hy = entropy(Y)
    Ixy = mutual_information(Y,X)
    ECC = np.sqrt(Ixy/(0.5*(Hx+Hy)))
    
    return ECC   
コード例 #3
0
def compute_MI(in_file):
    """
    Computes Mutual Information from a 1D datafile and returns a np.array.
    
    Parameters
    ----------

    in_file : 1D file

    Returns
    -------

    data_array =  voxel(x,y,z) * voxel(x,y,z)

    """

    from CPAC.series_mod import transform
    from CPAC.series_mod import mutual_information
    import numpy as np
    import math

    data = np.genfromtxt(in_file, skip_header=1)[:, 2:].T

    n_var = data.shape[0]
    points = data.shape[1]
    bins = math.pow(points,
                    1 / 3.)  #to the 3rd due to Equiquantization formula
    # Proposed by Milan Palus. n+1 where n is the number of vars in the computation
    # as it is pairwise, n+1 is 3
    bins = np.round(bins)

    data = transform(data, bins).astype(int)

    MI_mat = np.zeros((n_var, n_var))

    for i_ in range(n_var):
        for j_ in range(n_var):
            MI_mat[i_, j_] = mutual_information(data[i_, :], data[j_, :])

    np.save(in_file[:-7] + '_MI.npy', MI_mat)

    return MI_mat
コード例 #4
0
ファイル: utils.py プロジェクト: roijo/C-PAC_complexitytools
def compute_MI(in_file):
    """
    Computes Mutual Information from a 1D datafile and returns a np.array.
    
    Parameters
    ----------

    in_file : 1D file

    Returns
    -------

    data_array =  voxel(x,y,z) * voxel(x,y,z)

    """

    from CPAC.series_mod import transform
    from CPAC.series_mod import mutual_information
    import numpy as np
    import math

    data = np.genfromtxt(in_file, skip_header = 1)[:,2:].T
    
    n_var = data.shape[0]
    points = data.shape[1]
    bins = math.pow(points, 1/3.) #to the 3rd due to Equiquantization formula
    # Proposed by Milan Palus. n+1 where n is the number of vars in the computation
    # as it is pairwise, n+1 is 3
    bins = np.round(bins)
    
    data = transform(data,bins).astype(int)
    
    MI_mat = np.zeros((n_var,n_var))    
    
    for i_ in range(n_var):
        for j_ in range(n_var):
            MI_mat[i_,j_] = mutual_information(data[i_,:],data[j_,:])
        
    np.save(in_file[:-7]+'_MI.npy', MI_mat)

    return MI_mat