コード例 #1
0
mat = loadmat(data_path + 'eeg_data.mat')
eeg_signal = mat['eeg_signal']
eeg_label = mat['eeg_label']

#Extract the wanted subset of data 
eeg_signal = eeg_signal[99,:]
eeg_signal = eeg_signal[None, :]

n_signal = 1 #the number of signals
n_sample = eeg_signal.shape[1] #dimension of each signal

#Normalize the data to be run
b = eeg_signal
b = ((b.T - np.mean(b, axis = 1)) / np.std(b, axis = 1)).T

#Define the parameters
#Size of d, i.e. 128 kernels with size of 201
size_kernel = [128, 201]

#Optim options
max_it = 30 #the number of iterations
tol = np.float64(1e-3) #the stop threshold for the algorithm 

#RUN THE ALGORITHM
[temp, z, Dz, list_obj_val, list_obj_val_filter, list_obj_val_z, reconstr_err] = \
        CSC.learn_conv_sparse_coder(b, size_kernel, max_it, tol,\
                                    known_d=d)
        
end = time.clock()

print end - start
mat = loadmat(data_path + 'eeg_data.mat')
eeg_signal = mat['eeg_signal']
eeg_label = mat['eeg_label']

#Extract the wanted subset of data
eeg_signal = eeg_signal[99, :]
eeg_signal = eeg_signal[None, :]

n_signal = 1  #the number of signals
n_sample = eeg_signal.shape[1]  #dimension of each signal

#Normalize the data to be run
b = eeg_signal
b = ((b.T - np.mean(b, axis=1)) / np.std(b, axis=1)).T

#Define the parameters
#Size of d, i.e. 128 kernels with size of 201
size_kernel = [128, 201]

#Optim options
max_it = 30  #the number of iterations
tol = np.float64(1e-3)  #the stop threshold for the algorithm

#RUN THE ALGORITHM
[temp, z, Dz, list_obj_val, list_obj_val_filter, list_obj_val_z, reconstr_err] = \
        CSC.learn_conv_sparse_coder(b, size_kernel, max_it, tol,\
                                    known_d=d)

end = time.clock()

print end - start
# Normalize the data to be run
b = eeg_signal
b = ((b.T - np.mean(b, axis=1)) / np.std(b, axis=1)).T

# Define the parameters
# 128 kernels with size of 201
size_kernel = [2, 61]
# size_kernel = [2, 51]

ch_names = ['EEG%03d' % i for i in range(n_signal)]
info = create_info(ch_names, sfreq=sfreq, ch_types='eeg')
raw = RawArray(eeg_signal * 1e-6, info)
raw.plot(scalings=dict(eeg='auto'), duration=300)

# Optim options
max_it = 200  # the number of iterations
tol = np.float64(1e-3)  # the stop threshold for the algorithm

# RUN THE ALGORITHM
[d, z, Dz, list_obj_val, list_obj_val_filter, list_obj_val_z, reconstr_err] = \
    CSC.learn_conv_sparse_coder(b, size_kernel, max_it, tol, random_state=42)

plt.figure()
plt.plot(d[0, :])
plt.plot(d[1, :])
plt.show()

end = time.clock()

print end - start
コード例 #4
0
                             eeg_signal[40:41,:], eeg_signal[60:61,:],\
                             eeg_signal[80:81,:]), axis=0)

n_signal = eeg_signal.shape[0] #the number of signals
n_sample = eeg_signal.shape[1] #dimension of each signal

#Normalize the data to be run
b = eeg_signal
b = ((b.T - np.mean(b, axis = 1)) / np.std(b, axis = 1)).T

#Define the parameters
#128 kernels with size of 201
size_kernel = [128, 201]

#Optim options
max_it = 30 #the number of iterations
tol = np.float64(1e-3) #the stop threshold for the algorithm 

#RUN THE ALGORITHM
[d, z, Dz, list_obj_val, list_obj_val_filter, list_obj_val_z, reconstr_err] = \
        CSC.learn_conv_sparse_coder(b, size_kernel, max_it, tol)
  
#Save into an external struct .npz the kernel, the codes, the reconstruction
#and list of objective function's values     
np.savez(result_path + 'result_eeg.npz',\
         d=d, z=z, Dz=Dz, list_obj_val=list_obj_val,\
         list_obj_val_filter=list_obj_val_filter, list_obj_val_z=list_obj_val_z)

end = time.clock()

print end - start