Revision 23c7ab1e plotterBCrealization.py

View differences:

plotterBCrealization.py
16 16
import seaborn as sns
17 17
sns.set()
18 18

  
19

  
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

  
19 47
folder = sys.argv[1]
20 48
interval = 100
21 49
if len(sys.argv) > 2:
......
33 61
    df = pd.read_csv(snap, names=['time', str(node_id)], skiprows=1)
34 62
    dfn = pd.concat([dfn, df[str(node_id)]], axis=1)
35 63

  
64
code.interact(local=dict(globals(), **locals()))
36 65

  
37 66
print "Processing and plotting..."
38 67
if not os.path.exists("plots"+nick):
......
164 193
#            'label': '\"Core Or Not\" (Blue or White)'})
165 194

  
166 195
small=pd.DataFrame(resDF.iloc[:,0:1000])
167
sns.heatmap(small, cmap=cmap1, xticklabels=range(1000), yticklabels=range(len(small)), cbar_kws={
196
#code.interact(local=dict(globals(), **locals()))
197
sns.heatmap(small.applymap(int), cmap=cmap1, xticklabels=range(1000), yticklabels=range(len(small)), cbar_kws={
168 198
            'label': '\"Core Or Not\" (Blue or White)'})
169 199

  
170 200
plt.savefig(nick+"coreResistMap-EntryTOP10LeavingTOP20.pdf", format='pdf')
......
212 242

  
213 243
f = open(nick + "stats.txt", 'w')
214 244
f.write(str(pd.DataFrame(allint).describe()))
215
f.close()
245
f.close()

Also available in: Unified diff