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
4 * sim_data.Uniform_noise(int(N_single / 5)), sim_data.Uniform_noise(int(N_single / 5))) x3 = np.concatenate(x3) #### Perform entropy analysis ApEn_r = np.zeros((3, N_r)) 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])
x = sim_data.Pink_noise(N_single) elif (sig_type == 'brown_noise'): x = sim_data.fBm(int(N_single), 0.5) 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,
for n_h in range(0, N_H): H = H_span[0, n_h] # Simulate the input signal (fBm) x = sim_data.fLm(alpha, H, int(n_nextpow2), dim=1, nm=1) x = x[0:N_single] if (STD_correction == 'yes'): x = x / np.std(x) t0 = time.time() for n_r in range(0, N_r): # Approximate Entropy ApEn_h[n_h, n_r] = measures.ApEn(x, m_single, r_span[0, n_r]) # Sample Entropy SampEn_h[n_h, n_r] = measures.SampEn(x, m_single, r_span[0, n_r]) # RangeEn-A (Modified Approximate Entropy) RangeEn_A_h[n_h, n_r] = measures.RangeEn_A( x, m_single, r_span[0, n_r]) # RangeEn-B (Modified Sample Entropy) RangeEn_B_h[n_h, n_r] = measures.RangeEn_B( x, m_single, r_span[0, n_r]) ##### Save the entropy values in an external .npz file
t00 = time.time() for n_N in range(0,N_N): 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))