diff --git a/tests/test_calc_features.py b/tests/test_calc_features.py index cd117c7..711400e 100644 --- a/tests/test_calc_features.py +++ b/tests/test_calc_features.py @@ -75,7 +75,7 @@ def test_input_list_window_multi_axis_multi(self): ) np.testing.assert_array_equal( features0.shape, - (16, 495), + (16, 468), ) def test_input_array_window_tosplit_axis_single(self): @@ -92,7 +92,7 @@ def test_input_array_window_tosplit_axis_single(self): np.testing.assert_array_equal( features1.shape, - (16, 165), + (16, 156), ) def test_input_series_window_tosplit_axis_single(self): @@ -108,7 +108,7 @@ def test_input_series_window_tosplit_axis_single(self): np.testing.assert_array_equal( features2.shape, - (16, 165), + (16, 156), ) def test_input_dataframe_window_single_axis_multi(self): @@ -152,7 +152,7 @@ def test_input_series_window_single_axis_single(self): np.testing.assert_array_equal( features5.shape, - (1, 40), + (1, 31), ) def test_input_array_window_single_axis_single(self): @@ -183,14 +183,14 @@ def test_personal_features(self): np.testing.assert_array_equal( features7.shape, - (1, 169), + (1, 160), ) def test_get_number_features(self): feature_sets_size = [get_number_features(get_features_by_domain(domain)) for domain in domains] np.testing.assert_array_equal( feature_sets_size, - [40, 14, 124, 6], # 184 is the total + [31, 14, 124, 6], # 184 is the total ) def test_dataset_extractor(self): diff --git a/tests/test_features.py b/tests/test_features.py index caf6cc2..af96add 100644 --- a/tests/test_features.py +++ b/tests/test_features.py @@ -34,38 +34,42 @@ class TestFeatures(unittest.TestCase): # ############################################### STATISTICAL FEATURES ############################################### # def test_hist(self): np.testing.assert_almost_equal( - hist(const0, 10, 5)["values"], - (0.0, 0.0, 0.0, 0.0, 0.0, 20.0, 0.0, 0.0, 0.0, 0.0), + hist(const0, 10), + 0.050000000000000044, + decimal=5, ) np.testing.assert_almost_equal( - hist(const1, 10, 5)["values"], - (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 20.0, 0.0, 0.0, 0.0), + hist(const1, 10), + 1.05, + decimal=5, ) np.testing.assert_almost_equal( - hist(constNeg, 10, 5)["values"], - (0.0, 0.0, 0.0, 0.0, 20.0, 0.0, 0.0, 0.0, 0.0, 0.0), + hist(constNeg, 10), + -0.95, + decimal=5, ) np.testing.assert_almost_equal( - hist(constF, 10, 5)["values"], - (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 20.0, 0.0, 0.0), + hist(constF, 10), + 2.55, + decimal=5, ) np.testing.assert_almost_equal( - hist(lin, 10, 5)["values"], - (0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 2), + hist(lin, 10), + 0.95, ) np.testing.assert_almost_equal( - hist(wave, 10, 5)["values"], - (0.0, 0.0, 0.0, 0.0, 499, 496, 5, 0.0, 0.0, 0.0), + hist(wave, 10), + -0.9, decimal=5, ) np.testing.assert_almost_equal( - hist(offsetWave, 10, 5)["values"], - (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 499, 496, 5, 0.0), + hist(offsetWave, 10), + 1.1, decimal=5, ) np.testing.assert_almost_equal( - hist(noiseWave, 10, 5)["values"], - (0.0, 0.0, 0.0, 48, 446, 450, 56, 0.0, 0.0, 0.0), + hist(noiseWave, 10), + -0.8862517157830269, decimal=5, ) diff --git a/tests/tests_tools/test_features.json b/tests/tests_tools/test_features.json index 91e2aa7..29a0499 100644 --- a/tests/tests_tools/test_features.json +++ b/tests/tests_tools/test_features.json @@ -430,14 +430,13 @@ "tag": "eeg", "use": "yes" }, - "Histogram": { + "Histogram mode": { "complexity": "log", - "description": "Computes histogram of the signal.", + "description": "Computes the mode of the signal's histogram.", "function": "tsfel.hist", - "n_features": "nbins", + "n_features": 1, "parameters": { - "nbins": 10, - "r": 1 + "nbins": 10 }, "use": "yes" }, @@ -704,4 +703,4 @@ "use": "yes" } } -} \ No newline at end of file +} diff --git a/tsfel/feature_extraction/features.json b/tsfel/feature_extraction/features.json index 858dfed..4eb235d 100644 --- a/tsfel/feature_extraction/features.json +++ b/tsfel/feature_extraction/features.json @@ -355,15 +355,14 @@ "use": "yes", "tag": "eeg" }, - "Histogram": { + "Histogram mode": { "complexity": "log", - "description": "Computes histogram of the signal.", + "description": "Computes the mode of the signal's histogram.", "function": "tsfel.hist", "parameters": { - "nbins": 10, - "r": 1 + "nbins": 10 }, - "n_features": "nbins", + "n_features": 1, "use": "yes" }, "Interquartile range": { diff --git a/tsfel/feature_extraction/features.py b/tsfel/feature_extraction/features.py index 9a7d2c9..fc78490 100644 --- a/tsfel/feature_extraction/features.py +++ b/tsfel/feature_extraction/features.py @@ -13,9 +13,6 @@ + " data points." ) -future_warn_flag = False -warnings.simplefilter("once", FutureWarning) - # ############################################# TEMPORAL DOMAIN ##################################################### # @@ -473,8 +470,8 @@ def entropy(signal, prob="standard"): @set_domain("domain", "statistical") -def hist(signal, nbins=10, r=1): - """Computes histogram of the signal. +def hist(signal, nbins=10): + """Computes the mode of the signal's histogram. Feature computational cost: 1 @@ -484,34 +481,20 @@ def hist(signal, nbins=10, r=1): Input from histogram is computed nbins : int The number of equal-width bins in the given range - r : float - The lower(-r) and upper(r) range of the bins Returns ------- - nd-array - The values of the histogram + float + The mode of the histogram """ - global future_warn_flag - if not future_warn_flag: - warnings.warn( - ( - "The histogram feature was deprecated in version 0.1.8 and will be replaced by the mode of histogram in 0.1.9." - " From then on, only a single feature value will be returned." - ), - FutureWarning, - ) - future_warn_flag = True + histsig, bin_edges = np.histogram(signal, bins=nbins) - # TODO: r value must be revised! - histsig, bin_edges = np.histogram(signal, bins=nbins, range=[-r, r]) + idx_max = np.argmax(histsig) - names = [ - str(np.around(bin_edges[i], 2)) + ":" + str(np.around(bin_edges[i + 1], 2)) for i in range(len(bin_edges) - 1) - ] + mode_hist = (bin_edges[idx_max] + bin_edges[idx_max + 1]) * 0.5 - return {"names": names, "values": histsig} + return mode_hist @set_domain("domain", "statistical")