-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatistical_test.py
139 lines (103 loc) · 3.56 KB
/
statistical_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from puf_dataset import *
from scipy.stats import norm,shapiro,probplot
from scipy.signal import periodogram
import tikzplotlib
def kolmogorov_smirnov_test(f,save=False):
df = load(f)
Winmax = df["winsize"].max()
df = df[df["winsize"]==Winmax]
Delta = df.groupby(["pin_setting","index"]).agg("mean")["delta_freq"].to_numpy()
Delta = np.reshape(Delta,-1)
Delta -= np.mean(Delta)
Delta /= np.std(Delta)
x = np.linspace(-5,5,10**4)
Fnorm = norm.cdf(x)
Fdelta = np.mean( Delta.reshape((len(Delta),1)) < x.reshape(1,10**4),axis=0)
probplot(Delta,dist='norm',fit=True,plot=plt)
plt.title("")
plt.grid()
if save:
plt.savefig(f+"_QQplot.pdf",format="pdf",dpi=600)
plt.show()
print("For Kolmogorov Smirnov Test : ")
print(np.max(np.abs(Fnorm-Fdelta)))
print("Shapiro Test : ")
print(shapiro(Delta))
plt.plot(x,Fnorm)
plt.plot(x,Fdelta)
plt.grid()
plt.show()
def kolmogorov_smirnov_test_folder(F,name="dummy_name.tex"):
Delta = []
for f in F:
if "BOARD3" in f:
df = load(f)
print("Treating " + f)
delta = df["delta_freq"].to_numpy().reshape((-1,64))/df["number_measurments"].to_numpy().reshape((-1,64))
d = np.mean(delta,axis=0)[0:64]
Delta.append(d)
Delta = np.reshape(Delta,-1)
Delta -= np.mean(Delta)
print(np.std(Delta))
Delta /= np.std(Delta)
x = np.linspace(-5,5,10**4)
Fnorm = norm.cdf(x)
Fdelta = np.mean( Delta.reshape((len(Delta),1)) < x.reshape(1,10**4),axis=0)
probplot(Delta,dist='norm',fit=True,plot=plt)
plt.title("")
plt.grid()
### Takes To Much Memory ###
#tikzplotlib.clean_figure()
#tikzplotlib.save(name)
#plt.savefig("QQplot_delay_"+name+".pdf",dpi=600,format="pdf")
plt.savefig(name)
plt.show()
print("For Kolmogorov Smirnov Test : ")
print(np.max(np.abs(Fnorm-Fdelta)))
print("Shapiro Test : ")
print(shapiro(Delta))
return Delta
def noise(df,save=False,save2=False,name="dummy_name"):
Noise = []
for i in range(64):
noise = df[(df["winsize"]==2**19) * (df["index"]==i) * (df["pin_setting"]==0)]["delta_freq"].to_numpy().astype("float")
noise -= np.mean(noise)
noise /= np.std(noise)
Noise.append(noise)
Noise = np.array(Noise).reshape(-1)
probplot(Noise,dist='norm',fit=True,plot=plt)
plt.title("")
plt.grid()
if save:
plt.savefig("QQplot_noise_"+name,dpi=600,format="pdf")
plt.show()
print("With Shapiro Test : ")
print(shapiro(Noise))
x = np.linspace(-5,5,10**4)
Fnorm = norm.cdf(x)
Fnoise = np.mean( Noise.reshape((len(Noise),1)) < x.reshape(1,10**4),axis=0)
print("For Kolmogorov Smirnov Test : ")
print(np.max(np.abs(Fnorm-Fnoise)))
fs = 400 * 10 ** 6 / 2**19 / 2
f,P = periodogram(Noise,fs)
plt.plot(f,P)
plt.ylabel("Power Spectral Density of Noise")
plt.xlabel("Frequency in Hz")
plt.grid()
if save2:
plt.savefig("DSPnoise_"+name,dpi=600,format="pdf")
plt.show()
return Noise
def time_cb(F):
Rep = []
for f in F:
if ("puf_6" not in f):
df = load(f)
print("Treating " + f)
rep = df["number_measurments"].to_numpy().reshape((-1,64))
Rep.append(np.mean(rep,axis=0))
Rep = np.reshape(Rep,-1)
return Rep