コード例 #1
0
def j_prob(x, y, z=None, symbols=None):
    """The joint probability of the symbols in x and y"""
    #print "symbls", symbols
    #extract variables from args
    #print args
    if z == None:
        assert len(x) == len(y), "Sequences must have same length"
    else:
        assert len(x) == len(y) and len(x) == len(
            z), "Sequences must have same length"
    #Which symbols exist
    if symbols == None:
        symbols = np.unique(np.r_[x, y])
    elif type(symbols) == str:
        symbols = make_all_permutation_symbols(symbols)
    if z == None:
        ps = N.zeros((len(symbols), len(symbols)), "d")
        ks = list(symbols)
        ks.sort()
        idx_dict = dict([(k, ks.index(k)) for k in ks])
        for i in range(len(x)):
            ps[idx_dict[x[i]], idx_dict[y[i]]] += 1
        ps /= x.shape[0]
    else:
        ps = N.zeros((len(symbols), len(symbols), len(symbols)), "d")
        ks = list(symbols)
        ks.sort()
        idx_dict = dict([(k, ks.index(k)) for k in ks])
        for i in range(len(x)):
            ps[idx_dict[x[i]], idx_dict[y[i]], idx_dict[z[i]]] += 1
        ps /= x.shape[0]
    return ps
コード例 #2
0
ファイル: base.py プロジェクト: thorstenkranz/eegpy
def j_prob(x,y,z=None,symbols=None):
    """The joint probability of the symbols in x and y"""
    #print "symbls", symbols
    #extract variables from args
    #print args
    if z==None:
        assert len(x) == len(y), "Sequences must have same length"
    else:
        assert len(x) == len(y) and len(x) == len(z), "Sequences must have same length"
    #Which symbols exist
    if symbols==None:
        symbols = np.unique(np.r_[x,y])
    elif type(symbols) == str:
        symbols = make_all_permutation_symbols(symbols)
    if z==None:
        ps = N.zeros((len(symbols),len(symbols)),"d")
        ks = list(symbols)
        ks.sort()
        idx_dict = dict([(k,ks.index(k)) for k in ks])
        for i in range(len(x)):
            ps[idx_dict[x[i]],idx_dict[y[i]]] +=1
        ps /= x.shape[0]
    else:
        ps = N.zeros((len(symbols),len(symbols),len(symbols)),"d")
        ks = list(symbols)
        ks.sort()
        idx_dict = dict([(k,ks.index(k)) for k in ks])
        for i in range(len(x)):
            ps[idx_dict[x[i]],idx_dict[y[i]],idx_dict[z[i]]] +=1
        ps /= x.shape[0]
    return ps
コード例 #3
0
def prob(x, symbols=None):
    """Calculate the probabilities for each symbol"""
    #print x
    if symbols == None:
        symbols = np.unique(x)
    elif type(symbols) == str:
        symbols = make_all_permutation_symbols(symbols)
    symbdict = dict([(k, 0) for k in symbols])
    for xi in x:
        symbdict[xi] += 1
    ks = symbols
    ks.sort()
    ps = np.array([symbdict[k] for k in ks]).astype(np.float)
    ps /= x.shape[0]
    return ps
コード例 #4
0
ファイル: base.py プロジェクト: thorstenkranz/eegpy
def prob(x,symbols=None):
    """Calculate the probabilities for each symbol"""
    #print x
    if symbols==None:
        symbols = np.unique(x)
    elif type(symbols) == str:
        symbols = make_all_permutation_symbols(symbols)
    symbdict = dict([(k,0) for k in symbols])
    for xi in x:
        symbdict[xi] += 1
    ks = symbols
    ks.sort()
    ps = np.array([symbdict[k] for k in ks]).astype(np.float)
    ps /= x.shape[0]
    return ps
コード例 #5
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))
コード例 #6
0
ファイル: base.py プロジェクト: thorstenkranz/eegpy
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))