-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmutual_inf_filt_meanHIST_Catalina.py
81 lines (74 loc) · 2.39 KB
/
mutual_inf_filt_meanHIST_Catalina.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
import numpy as np
import numpy.random as nprn
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
from sklearn import metrics as mt
import math as math
import array
from scipy import signal
import scipy.io as sio
import pdb
stn_record='Diab1catalina'
class struct_MI:
def __init__(self, means_mi_p, times_p, my_name_p):
self.means_mi = means_mi_p
self.times = times_p
self.my_name = my_name_p
Fs = 256
events = sio.loadmat('./data/'+stn_record+'.mat')
v_TimeStartEvts = events['v_TimeStartEvts']
m_signals_mat = sio.loadmat('./data/m_SignalsMat_Diab.mat')
m_signals_mat = m_signals_mat['m_SignalsMat']
st_Header = sio.loadmat('./data/st_Header_Diab.mat')
st_Header = st_Header['st_Header']
st_Header = st_Header[0]; st_Header = st_Header[0]
st_Header = st_Header[9]
st_Header = st_Header[0]
my_list = []
my_name = []
# pdb.set_trace()
for kk in range(0,1):
# x_mat = sio.loadmat('./data/x_m_SignalsMat1.mat')
# x = x_mat['x']
x = m_signals_mat[kk]
# x = np.random.randn(len(x))
# y_mat = sio.loadmat('./data/y_m_SignalsMat8.mat')
# y = y_mat['y']
y = m_signals_mat[2]
# y = np.random.randn(len(y))
v_delay = np.arange(0,80)
mean_mi = []
time_mean = []
for kkk in range(0,len(v_delay)): #####################
mi = []
# pdb.set_trace()
for k in range(0,v_TimeStartEvts.shape[1]):
t1 = int((v_TimeStartEvts[0,k]*Fs)+(Fs*0.5)); # -(Fs*2)) #############################3
t2 = int(t1+(Fs*1.5))
t3 = int((v_TimeStartEvts[0,k]*Fs)-(Fs*2)+(v_delay[kkk]*25))
t4 = int(t3+(Fs*1.5))
xn = x[t1:t2]
yn = y[t3:t4]
mi.append(mt.normalized_mutual_info_score(xn, yn))
sio.savemat('./mi_delays/v_mi_Diab1_'+str(kkk)+'.mat', {'mi':mi})
mean_mi.append(np.mean(mi))
time_mean.append((v_delay[kkk]*25/256)-2)
my_name.append(st_Header[kk][0])
temp = struct_MI(mean_mi, time_mean,my_name)
my_list.append(temp)
plt.figure()
for o in range(0, len(my_list)):
a = my_list[o]
times = a.times
means = a.means_mi
myName = a.my_name
plt.hold(True)
# plt.subplot(2,2,o+1)
plt.plot(times,means)
plt.ylabel('Norm_MI_Score')
plt.title('Mutual Information, '+myName[o]+', '+stn_record)
if o+1<5:
plt.xticks([])
else:
plt.xlabel('Time [s]')
plt.show()