/
distributions.py
78 lines (56 loc) · 2.12 KB
/
distributions.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
import scipy, sys, getopt, pickle
from scipy.stats import norm,rayleigh, expon, entropy
import numpy as np
def movingaverage(interval, window_size=512):
window = np.ones(int(window_size))/float(window_size)
return np.convolve(interval, window, 'same')
def rayleigh_statistic(data,bins):
rayleigh_param[-1,-1]
rayleigh_pdf=[-1]
try :
rayleigh_param = rayleigh.fit(data)
except:
rayleigh_param[-2,-2]
try:
pdf_rayleigh_fitted = rayleigh.pdf(bins, *rayleigh_param[:-2],loc=rayleigh_param[0],scale=rayleigh_param[1]) # fitted distribution
except :
rayleigh_pdf=[-1]
return [rayleigh_param, rayleigh_pdf]
def exp_statistics(data,bins):
exp_param[-1,-1]
exp_pdf=[-1]
try :
exp_param = expon.fit(data)
except:
exp_param[-2,-2]
try:
pdf_exp_fitted = expon.pdf(bins, *exp_param[:-2],loc=exp_param[0],scale=exp_param[1]) # fitted distribution
except :
exp_param[-1]
return [exp_param, pdf_exp_fitted]
def norm_statistics(data,bins):
norm_param[-1,-1]
norm_pdf=[-1]
try :
norm_param = norm.fit(data)
except:
norm_param[-2,-2]
try:
pdf_norm_fitted = norm.pdf(bins, *norm_param[:-2],loc=norm_param[0],scale=norm_param[1]) # fitted distribution
except :
norm_pdf=[-2]
return [norm_param, pdf_norm_fitted]
def rayleigh_noise_signal_error(bins, param_s1,param_s2,param_n1, param_n2, flag):
pdf_fitted1 = rayleigh.pdf(bins,loc=param_s1,scale=param_s2)
pdf_fitted2 = rayleigh.pdf(bins,loc=param_n1,scale=param_n2)
mean_square_err =mean_squared_error(pdf_fitted1, pdf_fitted2)
rmse = sqrt(mean_square_err)
return rmse
def rayleigh_noise_signal_error(bins, param_s1,param_s2,param_n1, param_n2, flag):
pdf_fitted1 = expon.pdf(bins,loc=param_s1,scale=param_s2)
pdf_fitted2 = expon.pdf(bins,loc=param_n1,scale=param_n2)
mean_square_err =mean_squared_error(pdf_fitted1, pdf_fitted2)
root_mean_square_err = sqrt(mean_square_err)
return rmse
#l1_norm = sum(abs(pdf_fitted1 - pdf_fitted2))
#mean_l1_norm = 1.0*l1_norm/len(pdf_fitted1)