预测自适应滤波_使用自适应滤波的时间序列预测

预测自适应滤波

机器学习 (Machine Learning)

什么是自适应过滤? (What is Adaptive filtering?)

Adaptive filtering is a computational device that attempts to model the relationship between two signals, whose coefficients change with an objective to make the filter converge to an optimal state. The optimization criterion is a cost function, which is most commonly the mean square of the error between the output of the adaptive filter and the desired signal. The mean square error (MSE) will converge to its minimal value, while the filter adapts its coefficients. The figure below demonstrates the simple adaptive filter.

自适应滤波是一种计算设备,它试图对两个信号之间的关系进行建模,其信号随目标而变化,以使滤波器收敛到最佳状态。 最优化准则是代价函数,最常见的是自适应滤波器输出与所需信号之间误差的均方。 均方误差(MSE)将收敛到其最小值,而滤波器会调整其系数。 下图演示了简单的自适应滤波器。

The adaptive filter will try to match the filter output, y(k), with the desired signal, d(k). The adaptive filter will also learn using the error, e(k), and adjust the coefficient. Hence, it is adapted to the new environment, input x(k).

自适应滤波器将尝试使滤波器输出y(k)与所需信号d(k)匹配。 自适应滤波器还将学习使用误差e(k)并调整系数。 因此,它适应于新环境,输入x(k)

This brings us to the main feature of adaptive filtering, which is it has the real-time capability to adjust the response with the intent to improve its performance (sounds like self-learning, anyone?). The adaptation algorithm is implemented through two methods; gradient method and least square (LMS, RLS algorithm).

这将我们带到了自适应滤波的主要特征,即它具有实时功能,可以调整响应以提高其性能 (听起来像自学之类的声音,有人吗?)。 自适应算法是通过两种方法实现的: 梯度法和最小二乘(LMS,RLS算法)。

这是为了什么 (What is it for?)

If you have studied any digital signal and processing courses, you will see most of the adaptive filter application on identifying an unknown communications channel, canceling noise or interference, or predicting the future values of a periodic signal.

如果您已学习过任何数字信号和处理课程,则将在识别未知通信信道,消除噪声或干扰或预测周期信号的未来值时看到大多数自适应滤波器应用程序。

那么我们如何在业务环境中使用它呢? (So how we can use it in a business setting?)

Based on the last example of the digital use case, we can apply the concept to predict future values in real-time settings, for example; stock price prediction. However, predicting the future using this approach requires several key assumptions; the data is either steady or slowly varying over time, and periodic overtime as well.

例如,基于数字用例的最后一个示例,我们可以将其应用到实时设置中预测未来值。 股票价格预测。 但是,使用这种方法预测未来需要几个关键假设。 数据随时间变化是稳定的或缓慢变化的,以及周期性的超时变化

Accepting these assumptions, the adaptive filter must predict the future values of the desired output based on past input values. Hence, we need to structure the delay in the input signal and feed them to the adaptive filter system.

接受这些假设,自适应滤波器必须基于过去的输入值来预测所需输出的未来值。 因此,我们需要构造输入信号中的延迟,并将其馈入自适应滤波器系统。

Predicting future values using an adaptive filter 使用自适应滤波器预测未来价值

As stated earlier, the adaptive filter is used to identify and understand the unknown system, we can use this to identify and predict the time series behavior.

如前所述,自适应滤波器用于识别和了解未知系统,我们可以使用它来识别和预测时间序列行为。

Python实现 (Python implementation)

There is a library named padasip in Python, where you can use it to implement adaptive filtering. Check out the library at the following link.

Python中有一个名为padasip的库,您可以在其中使用它来实现自适应过滤。 在以下链接中检查库。

简单的实现示例 (Simple implementation example)

Let’s take a look at a simple example before using the adaptive filters on time series data. Assume we have the following equation:

让我们看一个简单的示例,然后再对时间序列数据使用自适应滤波器。 假设我们有以下等式:

We can then prepare the input, target, and run through the filter (using LMS, in this example). For additional sources of filter algorithm, please visit here.

然后,我们可以准备输入,目标并通过过滤器运行(在此示例中,使用LMS)。 有关过滤器算法的其他来源,请访问此处 。

After we run f.run(d, x) , we will get the prediction (y), error (e), and the weight of each iteration (w). We can see that the first several iterations, the filter cannot accurately predict the target but as the higher iterations, the filter starts to adapt and predict closely to target values.

运行f.run(d, x) ,我们将获得预测(y),误差(e)和每次迭代的权重(w)。 我们可以看到,在前几次迭代中,过滤器无法准确预测目标,但是随着迭代次数的增加,过滤器开始适应并预测目标值。

The comparison between actual and predicted value (upper figure), the error for each iteration (lower figure) 实际值和预测值之间的比较(上图),每次迭代的误差(下图)

使用NLMS对股价数据进行实施 (Implementation using NLMS on stock price data)

Now let’s try to predict the Uniqlo’s closing stock price (from 2012–2016).

现在,让我们尝试预测优衣库的收盘价(从2012年至2016年)。

Given time series data (Uniqlo’s closing price) 给定时间序列数据(优衣库的收盘价)

We will start by building the filter using the first 1000 data points with 5 lagged data points for each prediction iteration. Three values of mu have been tested, sample code with best mu (minimum error) has been shown below.

我们将使用每个预测迭代的前1000个数据点和5个滞后数据点构建滤波器。 已测试了三个mu值,下面显示了具有最佳mu(最小误差)的示例代码。

Partial code 部分代码
Visualization of NLMS filter result along with first and last 300 iterations 可视化的NLMS过滤器结果以及前300次和后300次迭代

We can see how the filter required several (around 60) iterations to adjust the weights to fit the data. During this phase, we are also getting the filter for further usage. Snippet code below shows how we can use them in a production environment.

我们可以看到过滤器如何需要几次(大约60次)迭代来调整权重以适合数据。 在此阶段,我们还将获取过滤器以供进一步使用。 下面的代码段显示了我们如何在生产环境中使用它们。

From the code, we get the best filter from the previous step and use it to predict the new data points (line 18). After the prediction is made, we then use the adapt the method of the filter to adjust the weights (line 20). The output and error have been visualized below.

从代码中,我们可以从上一步中获得最佳过滤器,并使用它来预测新的数据点(第18行)。 做出预测后,我们将使用过滤器的适应方法来调整权重(第20行)。 输出和错误已在下面显示。

Adaptive filter results on simulated real-time data 对模拟实时数据的自适应滤波器结果

尾注 (Endnote)

In this example, I demonstrate how we can use the adaptive filter on time series data to predict the future value. There is a lot of filter and algorithm to try for the adaptive filter. Proper filter type may need to view and select for the given problem you have. Hopefully, this introduces you to the adaptive filter and its basic implementation onto the real-world scenario.

在此示例中,我演示了如何在时间序列数据上使用自适应滤波器来预测未来价值。 自适应滤波器有很多滤波器和算法可以尝试。 适当的过滤器类型可能需要查看并选择给定的问题。 希望这将向您介绍自适应滤波器及其在实际场景中的基本实现。

You can view the full notebook and the sample dataset on my Github (or click here to view the notebook directly) and feel free to connect with me on LinkedIn.

您可以在我的Github上查看完整的笔记本和示例数据集(或单击此处直接查看笔记本),并随时在LinkedIn上与我联系。

翻译自: https://medium.com/towards-artificial-intelligence/time-series-prediction-using-adaptive-filtering-491a43d8fa93

预测自适应滤波

你可能感兴趣的:(python,机器学习,java,算法)