Ejemplo n.º 1
0
def compute_TE(in_file, lag = 1):
    """
    Computes Transfer Entropy from a 1D datafile and returns a np.array.
    
    Parameters
    ----------

    in_file : 1D file
    lag  :  lag to calculate the second term of the Transfer Entropy

    Returns
    -------

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

    """

    from CPAC.series_mod import transform
    from CPAC.series_mod import transfer_entropy
    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)
    
    TE_mat = np.zeros((n_var,n_var))    
    
    for i_ in range(n_var):
        for j_ in range(n_var):
            TE_mat[i_,j_] = transfer_entropy(data[i_,:],data[j_,:],lag)
    
    
    np.save(in_file[:-7]+'_TE.npy', TE_mat)
    
    return TE_mat
Ejemplo n.º 2
0
def compute_TE(in_file, lag=1):
    """
    Computes Transfer Entropy from a 1D datafile and returns a np.array.
    
    Parameters
    ----------

    in_file : 1D file
    lag  :  lag to calculate the second term of the Transfer Entropy

    Returns
    -------

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

    """

    from CPAC.series_mod import transform
    from CPAC.series_mod import transfer_entropy
    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)

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

    for i_ in range(n_var):
        for j_ in range(n_var):
            TE_mat[i_, j_] = transfer_entropy(data[i_, :], data[j_, :], lag)

    np.save(in_file[:-7] + '_TE.npy', TE_mat)

    return TE_mat
Ejemplo n.º 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
Ejemplo n.º 4
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