Skip to content

Commit

Permalink
Minor adjustments for PEP compliance.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmfolgado committed Sep 11, 2024
1 parent 69be8f0 commit 4c33138
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
16 changes: 8 additions & 8 deletions tests/test_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,41 +34,41 @@ class TestFeatures(unittest.TestCase):
# ############################################### STATISTICAL FEATURES ############################################### #
def test_hist(self):
np.testing.assert_almost_equal(
hist(const0, 10),
hist_mode(const0, 10),
0.050000000000000044,
decimal=5,
)
np.testing.assert_almost_equal(
hist(const1, 10),
hist_mode(const1, 10),
1.05,
decimal=5,
)
np.testing.assert_almost_equal(
hist(constNeg, 10),
hist_mode(constNeg, 10),
-0.95,
decimal=5,
)
np.testing.assert_almost_equal(
hist(constF, 10),
hist_mode(constF, 10),
2.55,
decimal=5,
)
np.testing.assert_almost_equal(
hist(lin, 10),
hist_mode(lin, 10),
0.95,
)
np.testing.assert_almost_equal(
hist(wave, 10),
hist_mode(wave, 10),
-0.9,
decimal=5,
)
np.testing.assert_almost_equal(
hist(offsetWave, 10),
hist_mode(offsetWave, 10),
1.1,
decimal=5,
)
np.testing.assert_almost_equal(
hist(noiseWave, 10),
hist_mode(noiseWave, 10),
-0.8862517157830269,
decimal=5,
)
Expand Down
4 changes: 2 additions & 2 deletions tests/tests_tools/test_features.json
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@
"Histogram mode": {
"complexity": "log",
"description": "Computes the mode of the signal's histogram.",
"function": "tsfel.hist",
"function": "tsfel.hist_mode",
"n_features": 1,
"parameters": {
"nbins": 10
Expand Down Expand Up @@ -703,4 +703,4 @@
"use": "yes"
}
}
}
}
2 changes: 1 addition & 1 deletion tsfel/feature_extraction/features.json
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@
"Histogram mode": {
"complexity": "log",
"description": "Computes the mode of the signal's histogram.",
"function": "tsfel.hist",
"function": "tsfel.hist_mode",
"parameters": {
"nbins": 10
},
Expand Down
24 changes: 12 additions & 12 deletions tsfel/feature_extraction/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,31 +470,31 @@ def entropy(signal, prob="standard"):


@set_domain("domain", "statistical")
def hist(signal, nbins=10):
"""Computes the mode of the signal's histogram.
def hist_mode(signal, nbins=10):
"""Compute the mode of a histogram using a given number of (linearly spaced)
bins.
Feature computational cost: 1
Parameters
----------
signal : nd-array
Input from histogram is computed
signal : np.ndarray
Input signal from which the histogram is computed.
nbins : int
The number of equal-width bins in the given range
The number of equal-width bins in the given range, by default 10.
Returns
-------
float
The mode of the histogram
The mode of the histogram (the midpoint of the bin with the highest
count).
"""

histsig, bin_edges = np.histogram(signal, bins=nbins)

idx_max = np.argmax(histsig)

mode_hist = (bin_edges[idx_max] + bin_edges[idx_max + 1]) * 0.5
hist_values, bin_edges = np.histogram(signal, bins=nbins)
max_bin_idx = np.argmax(hist_values)
mode_value = (bin_edges[max_bin_idx] + bin_edges[max_bin_idx + 1]) / 2.0

return mode_hist
return mode_value


@set_domain("domain", "statistical")
Expand Down

0 comments on commit 4c33138

Please sign in to comment.