def Entropy_analysis(parallel_inputs): t0 = time.time() # Unpack the parallel input x = parallel_inputs['x'] # Input EEG segment r = parallel_inputs['r'] # Tolerance value emb_dim = parallel_inputs['emb_dim'] # Embedding dimension ### Perform entropy analysis ApEn = measures.ApEn(x, emb_dim, r) # Sample Entropy SampEn = measures.SampEn(x, emb_dim, r) # RangeEn-A (Modified Approximate Entropy) RangeEn_A = measures.RangeEn_A(x, emb_dim, r) # RangeEn-B (Modified Sample Entropy) RangeEn_B = measures.RangeEn_B(x, emb_dim, r) print('Entropy analysis of the EEG segment was finished! Elapsed time: ' + str(time.time() - t0)) return ApEn, SampEn, RangeEn_A, RangeEn_B
SampEn_r = np.zeros((3, N_r)) RangeEn_A_r = np.zeros((3, N_r)) RangeEn_B_r = np.zeros((3, N_r)) for n_r in range(0, N_r): t0 = time.time() # Approximate Entropy ApEn_r[0, n_r] = measures.ApEn(x1, m_single, r_span[0, n_r]) ApEn_r[1, n_r] = measures.ApEn(x2, m_single, r_span[0, n_r]) ApEn_r[2, n_r] = measures.ApEn(x3 / np.std(x3), m_single, r_span[0, n_r]) # Sample Entropy SampEn_r[0, n_r] = measures.SampEn(x1, m_single, r_span[0, n_r]) SampEn_r[1, n_r] = measures.SampEn(x2, m_single, r_span[0, n_r]) SampEn_r[2, n_r] = measures.SampEn(x3 / np.std(x3), m_single, r_span[0, n_r]) # RangeEn-A (Modified Approximate Entropy) RangeEn_A_r[0, n_r] = measures.RangeEn_A(x1, m_single, r_span[0, n_r]) RangeEn_A_r[1, n_r] = measures.RangeEn_A(x2, m_single, r_span[0, n_r]) RangeEn_A_r[2, n_r] = measures.RangeEn_A(x3, m_single, r_span[0, n_r]) # RangeEn-B (Modified Sample Entropy) RangeEn_B_r[0, n_r] = measures.RangeEn_B(x1, m_single, r_span[0, n_r]) RangeEn_B_r[1, n_r] = measures.RangeEn_B(x2, m_single, r_span[0, n_r]) RangeEn_B_r[2, n_r] = measures.RangeEn_B(x3, m_single, r_span[0, n_r]) ##### Save the entropy values in an external .npz file
elif (sig_type == 'fBm025'): x = sim_data.fBm(int(N_single), 0.25) elif (sig_type == 'MIX'): x = sim_data.MIX(int(N_single), 0, 50) elif (sig_type == 'logistic_map'): x = np.array(sim_data.Logistic_map(N_single)) elif (sig_type == 'henon_map'): x, y = sim_data.Henon_map(N_single) elif (sig_type == 'roessler_osc'): x, y, z = sim_data.Roessler_osc(N_single, t1=0, t2=50) # Approximate Entropy ApEn_r[n_surr, n_r] = measures.ApEn(x, m_single, r_span[0, n_r]) # Sample Entropy SampEn_r[n_surr, n_r] = measures.SampEn(x, m_single, r_span[0, n_r]) # RangeEn-A (Modified Approximate Entropy) RangeEn_A_r[n_surr, n_r] = measures.RangeEn_A(x, m_single, r_span[0, n_r]) # RangeEn-B (Modified Sample Entropy) RangeEn_B_r[n_surr, n_r] = measures.RangeEn_B(x, m_single, r_span[0, n_r]) ##### Save the entropy values in an external .npz file np.savez(output_filename, SampEn_r=SampEn_r, ApEn_r=ApEn_r, RangeEn_B_r=RangeEn_B_r, RangeEn_A_r=RangeEn_A_r)
for n_alpha in range(0, 6): ############## Simulate fractional Levy motion ## Ref: https://github.com/cpgr/flm alpha = N_alpha[n_alpha] x = sim_data.fLm(alpha, H, n, dim=1, nm=10) x = x[0:N_single] ############## Calculate ApEn, SampEn and RangeEn t00 = time.time() for n_r in range(0, N_r): ApEn_h[n_alpha, n_r] = measures.ApEn(x, m_single, r_span[0, n_r]) # Sample Entropy SampEn_h[n_alpha, n_r] = measures.SampEn(x, m_single, r_span[0, n_r]) # RangeEn-A (Modified Approximate Entropy) RangeEn_A_h[n_alpha, n_r] = measures.RangeEn_A(x, m_single, r_span[0, n_r]) # RangeEn-B (Modified Sample Entropy) RangeEn_B_h[n_alpha, n_r] = measures.RangeEn_B(x, m_single, r_span[0, n_r]) print('r = ' + str(r_span[0, n_r]) + ', alpha = ' + str(alpha)) print('alpha = ' + str(alpha) + 'was finished. Entire elapsed time = ' + str(time.time() - t00)) ##### Save the entropy values in an external .npz file np.savez(output_filename,
t0 = time.time() for n_surr in range(0, N_surr): # Simulate the input signal if(sig_type=='white_noise'): x = sim_data.white_noise(N_span[0, n_N]) elif (sig_type == 'pink_noise'): x = sim_data.Pink_noise(N_span[0, n_N]) elif (sig_type == 'brown_noise'): x = sim_data.fBm(int(N_span[0, n_N]), 0.5) # Approximate Entropy ApEn_N[n_surr, n_N] = measures.ApEn(x, m_single, r_single) # Sample Entropy SampEn_N[n_surr, n_N] = measures.SampEn(x, m_single, r_single) # RangeEn-A (Modified Approximate Entropy) RangeEn_A_N[n_surr, n_N] = measures.RangeEn_A(x, m_single, r_single) # RangeEn-B (Modified Sample Entropy) RangeEn_B_N[n_surr, n_N] = measures.RangeEn_B(x, m_single, r_single) ##### Save the entropy values in an external .npz file np.savez(output_filename, SampEn_N=SampEn_N, ApEn_N=ApEn_N, RangeEn_B_N=RangeEn_B_N, RangeEn_A_N=RangeEn_A_N) print('Length ' + str(N_span[0, n_N]) + ', elapsed time = ' + str(time.time()-t0)) print('Entire elapsed time = ' + str(time.time() - t00)) else: