Revision c457778e plotterBCrealization.py

View differences:

plotterBCrealization.py
18 18

  
19 19

  
20 20

  
21
# https://en.wikipedia.org/wiki/Sample_entropy
22
def SampEn(U, m, r):
23
    """Compute Sample entropy"""
24
    def _maxdist(x_i, x_j):
25
        return max([abs(ua - va) for ua, va in zip(x_i, x_j)])
26

  
27
    def _phi(m):
28
        x = [[U[j] for j in range(i, i + m - 1 + 1)] for i in range(N - m + 1)]
29
        C = [len([1 for j in range(len(x)) if i != j and _maxdist(x[i], x[j]) <= r]) for i in range(len(x))]
30
        return sum(C)
31

  
32
    N = len(U)
33
    return -np.log(_phi(m+1) / _phi(m))
34

  
35
ss = pd.read_csv('https://raw.githubusercontent.com/selva86/datasets/master/sunspotarea.csv')
36
a10 = pd.read_csv('https://raw.githubusercontent.com/selva86/datasets/master/a10.csv')
37
rand_small = np.random.randint(0, 100, size=36)
38
rand_big = np.random.randint(0, 100, size=136)
39

  
40
print(SampEn(ss.value, m=2, r=0.2*np.std(ss.value)))      # 0.78
41
print(SampEn(a10.value, m=2, r=0.2*np.std(a10.value)))    # 0.41
42
print(SampEn(rand_small, m=2, r=0.2*np.std(rand_small)))  # 1.79
43
print(SampEn(rand_big, m=2, r=0.2*np.std(rand_big)))      # 2.42
44

  
45

  
46

  
47 21
folder = sys.argv[1]
48 22
interval = 100
49 23
if len(sys.argv) > 2:

Also available in: Unified diff