Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions doc/source/pyplots/plot_thresholds.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@

s_soft = pywt.threshold(s, value=0.5, mode='soft')
s_hard = pywt.threshold(s, value=0.5, mode='hard')
s_garotte = pywt.threshold(s, value=0.5, mode='garotte')
s_garrote = pywt.threshold(s, value=0.5, mode='garrote')
s_firm1 = pywt.threshold_firm(s, value_low=0.5, value_high=1)
s_firm2 = pywt.threshold_firm(s, value_low=0.5, value_high=2)
s_firm3 = pywt.threshold_firm(s, value_low=0.5, value_high=4)

fig, ax = plt.subplots(1, 2, figsize=(10, 4))
ax[0].plot(s, s_soft)
ax[0].plot(s, s_hard)
ax[0].plot(s, s_garotte)
ax[0].legend(['soft (0.5)', 'hard (0.5)', 'non-neg. garotte (0.5)'])
ax[0].plot(s, s_garrote)
ax[0].legend(['soft (0.5)', 'hard (0.5)', 'non-neg. garrote (0.5)'])
ax[0].set_xlabel('input value')
ax[0].set_ylabel('thresholded value')

Expand Down
13 changes: 8 additions & 5 deletions pywt/_thresholding.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def soft(data, value, substitute=0):


def nn_garrote(data, value, substitute=0):
"""Non-negative Garotte."""
"""Non-negative Garrote."""
data = np.asarray(data)
magnitude = np.absolute(data)

Expand Down Expand Up @@ -73,7 +73,10 @@ def less(data, value, substitute=0):
'hard': hard,
'greater': greater,
'less': less,
'garotte': nn_garrote}
'garrote': nn_garrote,
# misspelled garrote for backwards compatibility
'garotte': nn_garrote,
}


def threshold(data, value, mode='soft', substitute=0):
Expand All @@ -90,7 +93,7 @@ def threshold(data, value, mode='soft', substitute=0):
less than the value param are replaced with `substitute`. Data values with
absolute value greater or equal to the thresholding value stay untouched.

``garotte`` corresponds to the Non-negative garrote threshold [2]_, [3]_.
``garrote`` corresponds to the Non-negative garrote threshold [2]_, [3]_.
It is intermediate between ``hard`` and ``soft`` thresholding. It behaves
like soft thresholding for small data values and approaches hard
thresholding for large data values.
Expand All @@ -109,7 +112,7 @@ def threshold(data, value, mode='soft', substitute=0):
Numeric data.
value : scalar
Thresholding value.
mode : {'soft', 'hard', 'garotte', 'greater', 'less'}
mode : {'soft', 'hard', 'garrote', 'greater', 'less'}
Decides the type of thresholding to be applied on input data. Default
is 'soft'.
substitute : float, optional
Expand Down Expand Up @@ -148,7 +151,7 @@ def threshold(data, value, mode='soft', substitute=0):
array([ 0. , 0. , 0. , 0.5, 1. , 1.5, 2. ])
>>> pywt.threshold(data, 2, 'hard')
array([ 0. , 0. , 2. , 2.5, 3. , 3.5, 4. ])
>>> pywt.threshold(data, 2, 'garotte')
>>> pywt.threshold(data, 2, 'garrote')
array([ 0. , 0. , 0. , 0.9 , 1.66666667,
2.35714286, 3. ])
>>> pywt.threshold(data, 2, 'greater')
Expand Down