Exemplo n.º 1
0
def perm_M(x, y, w=4, t=1):
    """Permutation mutual information
    Creates symbolic timeseries from x and y and calculates the mutual information
    """
    s1 = make_permutation_symbols(x, w=w, t=t)
    s2 = make_permutation_symbols(y, w=w, t=t)
    return M(s1, s2, symbols="w%i" % w)
Exemplo n.º 2
0
def perm_M(x,y,w=4,t=1):
    """Permutation mutual information
    Creates symbolic timeseries from x and y and calculates the mutual information
    """
    s1 = make_permutation_symbols(x,w=w,t=t)
    s2 = make_permutation_symbols(y,w=w,t=t)
    return M(s1,s2,symbols="w%i"%w)
Exemplo n.º 3
0
def perm_D(x, y, w=4, t=1):
    """Metric based on mutual information. Normalized to [0,1]
    See http://en.wikipedia.org/wiki/Mutual_information#Metric
    """
    s1 = make_permutation_symbols(x, w=w, t=t)
    s2 = make_permutation_symbols(y, w=w, t=t)
    je = joint_entropy(s1, s2, symbols="w%i" % w)
    mi = M(s1, s2, symbols="w%i" % w)
    return (je - mi) / je
Exemplo n.º 4
0
def perm_D(x,y,w=4,t=1):
    """Metric based on mutual information. Normalized to [0,1]
    See http://en.wikipedia.org/wiki/Mutual_information#Metric
    """
    s1 = make_permutation_symbols(x,w=w,t=t)
    s2 = make_permutation_symbols(y,w=w,t=t)
    je = joint_entropy(s1,s2,symbols="w%i"%w) 
    mi = M(s1,s2,symbols="w%i"%w)
    return (je-mi)/je
Exemplo n.º 5
0
def perm_TE_ensemble(y, x, w=4, tau=1, test_surr=False):
    """Permutation transfer entropy of two sets of timeseries x and y
    Measures information transfer from y to x.
    
    Parameters:
     y: 2d-array, first index timepoints, second index ensemble
     x: equal-size array
     w: word-size for creation of permutation-symbols
     tau: time-delay for creation of permutation-symbols
     test_surr: bool. If a surrogate-test should be perfomed or not
    
    Returns: 1d-array of length y.shape[0]-1"""
    s1 = make_permutation_symbols(y, w=w, t=tau)
    s2 = make_permutation_symbols(x, w=w, t=tau)
    return TE_ensemble(s1, s2)
Exemplo n.º 6
0
def perm_TE_ensemble(y,x,w=4,tau=1,test_surr=False):
    """Permutation transfer entropy of two sets of timeseries x and y
    Measures information transfer from y to x.
    
    Parameters:
     y: 2d-array, first index timepoints, second index ensemble
     x: equal-size array
     w: word-size for creation of permutation-symbols
     tau: time-delay for creation of permutation-symbols
     test_surr: bool. If a surrogate-test should be perfomed or not
    
    Returns: 1d-array of length y.shape[0]-1"""
    s1 = make_permutation_symbols(y,w=w,t=tau)
    s2 = make_permutation_symbols(x,w=w,t=tau)
    return TE_ensemble(s1, s2)
Exemplo n.º 7
0
def perm_entropy(x, w=4, t=1, normalize=True):
    """Calculate the permutation-entropy of a time-series x."""
    pe = entropy(make_permutation_symbols(x, w, t))
    if normalize:
        pe = pe / N.log(factorial(w))
    return pe
Exemplo n.º 8
0
def perm_TE(y, x, w=4, t=1):
    """Creates symbolic timeseries from real data and calculates Transfer Entropy"""
    s1 = make_permutation_symbols(x, w=w, t=t)
    s2 = make_permutation_symbols(y, w=w, t=t)
    #return TE(s2,s1,symbols="w%i"%w)
    return TE(s2, s1, symbols=make_all_permutation_symbols(w))
Exemplo n.º 9
0
def perm_entropy(x,w=4,t=1,normalize=True):
    """Calculate the permutation-entropy of a time-series x."""
    pe = entropy(make_permutation_symbols(x,w,t))
    if normalize:
        pe=pe/N.log(factorial(w))
    return pe
Exemplo n.º 10
0
def perm_TE(y,x,w=4,t=1):
    """Creates symbolic timeseries from real data and calculates Transfer Entropy"""
    s1 = make_permutation_symbols(x,w=w,t=t)
    s2 = make_permutation_symbols(y,w=w,t=t)
    #return TE(s2,s1,symbols="w%i"%w)
    return TE(s2,s1,symbols=make_all_permutation_symbols(w))