Created
July 21, 2020 11:43
-
-
Save netsatsawat/46bfd71196f138a514869615c3b30148 to your computer and use it in GitHub Desktop.
Partial example of NLMS filter on sample stock data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import numpy as np | |
import padasip as pa | |
SEED = 121 | |
np.random.seed(SEED) | |
n = 5 | |
s = ts['Close'].values.flatten()[: 1000] # initial timeseries data | |
x = pa.input_from_history(s, n) # input matrix | |
N = len(x) | |
d = np.zeros(len(x)) | |
# define target | |
for i, k in enumerate(range((n-1), N)): | |
d[i] = s[k+1] | |
# build filter on each mu | |
error_list = [] | |
pa_list = [] | |
for i, mu_ in enumerate([0.005, 0.05, 0.5]): | |
f_nlms = pa.filters.FilterNLMS(n=n, mu=mu_, w='random') | |
y, e, w = f_nlms.run(d, x) | |
plot_filter_result(pred=y, actual=d, error=e, mu_val=mu_, n=n) | |
_avg_error = round(np.mean(10*np.log10(e[: (len(e) - n)]**2)), 2) | |
pa_list.append(f_nlms) | |
error_list.append(_avg_error) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment