コード例 #1
0
def getMultiScaleEntropyWithWindow(signal,
                                   type="freq",
                                   window_size=40,
                                   step_size=20):
    entropy = []
    step_size = window_size
    i = 0
    while (i < signal.shape[1]):
        j = 0
        she_feat = []
        while (j < signal.shape[0]):
            print i
            if (j + window_size < signal.shape[0]):
                sh_ent = ent.multiscale_entropy(
                    signal[j:j + window_size + 1, i],
                    len(signal[j:j + window_size + 1, i]),
                    0.2 * np.std(signal[j:j + window_size + 1, i]))
                #print sh_ent
                she_feat.append(sh_ent)
            else:
                sh_ent = ent.multiscale_entropy(
                    signal[j:j + window_size + 1, i],
                    len(signal[j:j + window_size + 1, i]),
                    0.2 * np.std(signal[j:j + window_size + 1, i]))
                #print sh_ent
                she_feat.append(sh_ent)

            j += step_size
        entropy.append(she_feat)
        i += 1
    return entropy
コード例 #2
0
def compute_multiscale_entropy(flux):
    """
	Returns the multiscale entropy

	Inputs
	-----------------
	flux:
		flux data

	Returns
	-----------------
	mean:	float
		mean of the mse curve
	max_v:	float
		maximum of the mse curve
	stdev:	float
		standard deviation of the mse curve
	power:	float
		power present in the mse curve
	"""

    ms_ent = ent.multiscale_entropy(flux, 2, maxscale=10)
    mean = np.mean(ms_ent)
    stdev = np.std(ms_ent)
    max_v = np.max(ms_ent)
    power = 1 / len(ms_ent) * np.sum(ms_ent**2)

    return mean, max_v, stdev, power
コード例 #3
0
ファイル: test_entropy.py プロジェクト: zhaoqiuye/pyEntropy
 def test_multiScaleEntropy(self):
     multi_scale_entropy = ent.multiscale_entropy(RANDOM_TIME_SERIES,
                                                  4,
                                                  maxscale=4)
     np.testing.assert_allclose(
         multi_scale_entropy,
         np.array([2.52572864, 2.31911439, 1.65292302, 1.86075234]))
コード例 #4
0
 def test_multiScaleEntropy(self):
     multi_scale_entropy = ent.multiscale_entropy(RANDOM_TIME_SERIES,
                                                  4,
                                                  maxscale=4)
     np.testing.assert_array_equal(
         np.round(multi_scale_entropy, 8),
         np.array([2.52572864, 2.33537492, 1.65292302, 1.86075234]))
コード例 #5
0
 def test_multiScaleEntropy(self):
     ts = TS_SAMPLE_ENTROPY
     std_ts = np.std(ts)
     multi_scale_entropy = ent.multiscale_entropy(ts, 4, 0.2 * std_ts)
     np.testing.assert_array_equal(
         np.round(multi_scale_entropy, 4),
         np.array([2.2119, 2.6221, 1.7473, 1.9902]))
コード例 #6
0
def computeShannonEntropy(signal):
    she_feat = [0] * signal.shape[1]
    # compute fft for each channel
    i = 0
    while (i < signal.shape[1]):
        print i
        she_feat[i] = ent.multiscale_entropy(signal[:, i], 2,
                                             0.1 * np.std(signal[:, i]))
        i += 1
    return she_feat
コード例 #7
0
def multiscale_entropy(x, sample_length=2, maxscale=20):
    """Return multiscale entropy of the given signal

    Args:
        :param x: 1-dim list
    Return:
        the multiscale entropy of x (returned type: list of float)
    """
    return ent.multiscale_entropy(x,
                                  sample_length=sample_length,
                                  maxscale=maxscale)
コード例 #8
0
ファイル: features.py プロジェクト: spolex/spiral
def multi_entrp(l):
    """
    Multiscale entropy
    :param l:
    :return:
    """
    start = time.time()
    me = e.multiscale_entropy(l)
    elapsed_time = time.time() - start
    logger.debug("Elapsed time to calculate Multiscale entropy value is %s",
                 elapsed_time)
    return me
コード例 #9
0
 def computeMSE(self, index, m_length=20):
     indexStart = index['indexStart']
     indexEnd = index['indexEnd']
     dfData = self.xData.loc[indexStart:indexEnd]
     MSE_means = []
     for feature in self.xFeatures:
         ts = list(dfData[feature])
         tsStd = np.std(ts)
         MSEs = ent.multiscale_entropy(ts,
                                       sample_length=m_length,
                                       tolerance=0.2 * tsStd)
         MSE_means.append(np.mean(MSEs))
     return MSE_means
コード例 #10
0
def sig_sample_entropy(sig):
    sig_std = np.std(sig)
    return ent.multiscale_entropy(sig, 4, 0.2 * sig_std)[0]
コード例 #11
0
    def calculate_rri_nonlinear_statistics(self,
                                           rri,
                                           diff_rri,
                                           diff2_rri,
                                           suffix=''):

        # Empty dictionary
        rri_nonlinear_statistics = dict()

        # Non-linear RR statistics
        if len(rri) > 1:
            rri_nonlinear_statistics['rri_approximate_entropy' + suffix] = \
                self.safe_check(pyeeg.ap_entropy(rri, M=2, R=0.1*np.std(rri)))
            rri_nonlinear_statistics['rri_sample_entropy' + suffix] = \
                self.safe_check(ent.sample_entropy(rri, sample_length=2, tolerance=0.1*np.std(rri))[0])
            rri_nonlinear_statistics['rri_multiscale_entropy' + suffix] = \
                self.safe_check(ent.multiscale_entropy(rri, sample_length=2, tolerance=0.1*np.std(rri))[0])
            rri_nonlinear_statistics['rri_permutation_entropy' + suffix] = \
                self.safe_check(ent.permutation_entropy(rri, m=2, delay=1))
            rri_nonlinear_statistics['rri_multiscale_permutation_entropy' + suffix] = \
                self.safe_check(ent.multiscale_permutation_entropy(rri, m=2, delay=1, scale=1)[0])
            rri_nonlinear_statistics['rri_fisher_info' + suffix] = fisher_info(
                rri, tau=1, de=2)
            hjorth_parameters = hjorth(rri)
            rri_nonlinear_statistics['rri_activity' +
                                     suffix] = hjorth_parameters[0]
            rri_nonlinear_statistics['rri_complexity' +
                                     suffix] = hjorth_parameters[1]
            rri_nonlinear_statistics['rri_morbidity' +
                                     suffix] = hjorth_parameters[2]
            rri_nonlinear_statistics['rri_hurst_exponent' + suffix] = pfd(rri)
            rri_nonlinear_statistics['rri_svd_entropy' + suffix] = svd_entropy(
                rri, tau=2, de=2)
            rri_nonlinear_statistics['rri_petrosian_fractal_dimension' +
                                     suffix] = pyeeg.pfd(rri)
        else:
            rri_nonlinear_statistics['rri_approximate_entropy' +
                                     suffix] = np.nan
            rri_nonlinear_statistics['rri_sample_entropy' + suffix] = np.nan
            rri_nonlinear_statistics['rri_multiscale_entropy' +
                                     suffix] = np.nan
            rri_nonlinear_statistics['rri_permutation_entropy' +
                                     suffix] = np.nan
            rri_nonlinear_statistics['rri_multiscale_permutation_entropy' +
                                     suffix] = np.nan
            rri_nonlinear_statistics['rri_fisher_info' + suffix] = np.nan
            rri_nonlinear_statistics['rri_activity' + suffix] = np.nan
            rri_nonlinear_statistics['rri_complexity' + suffix] = np.nan
            rri_nonlinear_statistics['rri_morbidity' + suffix] = np.nan
            rri_nonlinear_statistics['rri_hurst_exponent' + suffix] = np.nan
            rri_nonlinear_statistics['rri_svd_entropy' + suffix] = np.nan
            rri_nonlinear_statistics['rri_petrosian_fractal_dimension' +
                                     suffix] = np.nan

        # Non-linear RR difference statistics
        if len(diff_rri) > 1:
            rri_nonlinear_statistics['diff_rri_approximate_entropy' + suffix] = \
                self.safe_check(pyeeg.ap_entropy(diff_rri, M=2, R=0.1*np.std(rri)))
            rri_nonlinear_statistics['diff_rri_sample_entropy' + suffix] = \
                self.safe_check(ent.sample_entropy(diff_rri, sample_length=2, tolerance=0.1*np.std(rri))[0])
            rri_nonlinear_statistics['diff_rri_multiscale_entropy' + suffix] = \
                self.safe_check(ent.multiscale_entropy(diff_rri, sample_length=2, tolerance=0.1*np.std(rri))[0])
            rri_nonlinear_statistics['diff_rri_permutation_entropy' + suffix] = \
                self.safe_check(ent.permutation_entropy(diff_rri, m=2, delay=1))
            rri_nonlinear_statistics['diff_rri_multiscale_permutation_entropy' + suffix] = \
                self.safe_check(ent.multiscale_permutation_entropy(diff_rri, m=2, delay=1, scale=1)[0])
            rri_nonlinear_statistics['diff_rri_fisher_info' +
                                     suffix] = fisher_info(diff_rri,
                                                           tau=1,
                                                           de=2)
            hjorth_parameters = hjorth(diff_rri)
            rri_nonlinear_statistics['diff_rri_activity' +
                                     suffix] = hjorth_parameters[0]
            rri_nonlinear_statistics['diff_rri_complexity' +
                                     suffix] = hjorth_parameters[1]
            rri_nonlinear_statistics['diff_rri_morbidity' +
                                     suffix] = hjorth_parameters[2]
            rri_nonlinear_statistics['diff_rri_hurst_exponent' +
                                     suffix] = pfd(diff_rri)
            rri_nonlinear_statistics['diff_rri_svd_entropy' +
                                     suffix] = svd_entropy(diff_rri,
                                                           tau=2,
                                                           de=2)
            rri_nonlinear_statistics['diff_rri_petrosian_fractal_dimension' +
                                     suffix] = pyeeg.pfd(diff_rri)
        else:
            rri_nonlinear_statistics['diff_rri_approximate_entropy' +
                                     suffix] = np.nan
            rri_nonlinear_statistics['diff_rri_sample_entropy' +
                                     suffix] = np.nan
            rri_nonlinear_statistics['diff_rri_multiscale_entropy' +
                                     suffix] = np.nan
            rri_nonlinear_statistics['diff_rri_permutation_entropy' +
                                     suffix] = np.nan
            rri_nonlinear_statistics['diff_rri_multiscale_permutation_entropy'
                                     + suffix] = np.nan
            rri_nonlinear_statistics['diff_rri_fisher_info' + suffix] = np.nan
            rri_nonlinear_statistics['diff_rri_activity' + suffix] = np.nan
            rri_nonlinear_statistics['diff_rri_complexity' + suffix] = np.nan
            rri_nonlinear_statistics['diff_rri_morbidity' + suffix] = np.nan
            rri_nonlinear_statistics['diff_rri_hurst_exponent' +
                                     suffix] = np.nan
            rri_nonlinear_statistics['diff_rri_svd_entropy' + suffix] = np.nan
            rri_nonlinear_statistics['diff_rri_petrosian_fractal_dimension' +
                                     suffix] = np.nan

        # Non-linear RR difference difference statistics
        if len(diff2_rri) > 1:
            rri_nonlinear_statistics['diff2_rri_shannon_entropy' + suffix] = \
                self.safe_check(ent.shannon_entropy(diff2_rri))
            rri_nonlinear_statistics['diff2_rri_approximate_entropy' + suffix] = \
                self.safe_check(pyeeg.ap_entropy(diff2_rri, M=2, R=0.1*np.std(rri)))
            rri_nonlinear_statistics['diff2_rri_sample_entropy' + suffix] = \
                self.safe_check(ent.sample_entropy(diff2_rri, sample_length=2, tolerance=0.1*np.std(rri))[0])
            rri_nonlinear_statistics['diff2_rri_multiscale_entropy' + suffix] = \
                self.safe_check(ent.multiscale_entropy(diff2_rri, sample_length=2, tolerance=0.1*np.std(rri))[0])
            rri_nonlinear_statistics['diff2_rri_permutation_entropy' + suffix] = \
                self.safe_check(ent.permutation_entropy(diff2_rri, m=2, delay=1))
            rri_nonlinear_statistics['diff2_rri_multiscale_permutation_entropy' + suffix] = \
                self.safe_check(ent.multiscale_permutation_entropy(diff2_rri, m=2, delay=1, scale=1)[0])
            rri_nonlinear_statistics['diff2_rri_fisher_info' +
                                     suffix] = fisher_info(diff2_rri,
                                                           tau=1,
                                                           de=2)
            hjorth_parameters = hjorth(diff2_rri)
            rri_nonlinear_statistics['diff2_rri_activity' +
                                     suffix] = hjorth_parameters[0]
            rri_nonlinear_statistics['diff2_rri_complexity' +
                                     suffix] = hjorth_parameters[1]
            rri_nonlinear_statistics['diff2_rri_morbidity' +
                                     suffix] = hjorth_parameters[2]
            rri_nonlinear_statistics['diff2_rri_hurst_exponent' +
                                     suffix] = pfd(diff2_rri)
            rri_nonlinear_statistics['diff2_rri_svd_entropy' +
                                     suffix] = svd_entropy(diff2_rri,
                                                           tau=2,
                                                           de=2)
            rri_nonlinear_statistics['diff2_rri_petrosian_fractal_dimension' +
                                     suffix] = pyeeg.pfd(diff2_rri)
        else:
            rri_nonlinear_statistics['diff2_rri_shannon_entropy' +
                                     suffix] = np.nan
            rri_nonlinear_statistics['diff2_rri_approximate_entropy' +
                                     suffix] = np.nan
            rri_nonlinear_statistics['diff2_rri_sample_entropy' +
                                     suffix] = np.nan
            rri_nonlinear_statistics['diff2_rri_multiscale_entropy' +
                                     suffix] = np.nan
            rri_nonlinear_statistics['diff2_rri_permutation_entropy' +
                                     suffix] = np.nan
            rri_nonlinear_statistics['diff2_rri_multiscale_permutation_entropy'
                                     + suffix] = np.nan
            rri_nonlinear_statistics['diff2_rri_fisher_info' + suffix] = np.nan
            rri_nonlinear_statistics['diff2_rri_activity' + suffix] = np.nan
            rri_nonlinear_statistics['diff2_rri_complexity' + suffix] = np.nan
            rri_nonlinear_statistics['diff2_rri_morbidity' + suffix] = np.nan
            rri_nonlinear_statistics['diff2_rri_hurst_exponent' +
                                     suffix] = np.nan
            rri_nonlinear_statistics['diff2_rri_svd_entropy' + suffix] = np.nan
            rri_nonlinear_statistics['diff2_rri_petrosian_fractal_dimension' +
                                     suffix] = np.nan

        return rri_nonlinear_statistics