| 1 | import numpy as np |
| 2 | import matplotlib.pyplot as plt |
| 3 | import pywt |
| 4 | |
| 5 | s = np.linspace(-4, 4, 1000) |
| 6 | |
| 7 | s_soft = pywt.threshold(s, value=0.5, mode='soft') |
| 8 | s_hard = pywt.threshold(s, value=0.5, mode='hard') |
| 9 | s_garrote = pywt.threshold(s, value=0.5, mode='garrote') |
| 10 | s_firm1 = pywt.threshold_firm(s, value_low=0.5, value_high=1) |
| 11 | s_firm2 = pywt.threshold_firm(s, value_low=0.5, value_high=2) |
| 12 | s_firm3 = pywt.threshold_firm(s, value_low=0.5, value_high=4) |
| 13 | |
| 14 | fig, ax = plt.subplots(1, 2, figsize=(10, 4)) |
| 15 | ax[0].plot(s, s_soft) |
| 16 | ax[0].plot(s, s_hard) |
| 17 | ax[0].plot(s, s_garrote) |
| 18 | ax[0].legend(['soft (0.5)', 'hard (0.5)', 'non-neg. garrote (0.5)']) |
| 19 | ax[0].set_xlabel('input value') |
| 20 | ax[0].set_ylabel('thresholded value') |
| 21 | |
| 22 | ax[1].plot(s, s_soft) |
| 23 | ax[1].plot(s, s_hard) |
| 24 | ax[1].plot(s, s_firm1) |
| 25 | ax[1].plot(s, s_firm2) |
| 26 | ax[1].plot(s, s_firm3) |
| 27 | ax[1].legend(['soft (0.5)', 'hard (0.5)', 'firm(0.5, 1)', 'firm(0.5, 2)', |
| 28 | 'firm(0.5, 4)']) |
| 29 | ax[1].set_xlabel('input value') |
| 30 | ax[1].set_ylabel('thresholded value') |
| 31 | plt.show() |