我在卷积的帮助下实现了加权移动平均算法。
在 Python 中使用 numpy 提供的卷积函数非常容易。
代码如下:
# Method 2 WMA
WINDOW_SIZE = 70
DATA_SET_NUMBER = 7090
smoothedAcc = ndarray(DATA_SET_NUMBER)
weights = ndarray(WINDOW_SIZE)
accWindow = ndarray(WINDOW_SIZE)
for i, v in enumerate(weights):
weights[i] = (WINDOW_SIZE - i) / (WINDOW_SIZE * (WINDOW_SIZE + 1) / 2)
for x in xrange(0, (DATA_SET_NUMBER - WINDOW_SIZE)):
for y in xrange(0, WINDOW_SIZE):
accWindow[y] = acc[x + y]
smoothedAcc[x] = np.convolve(weights, accWindow, 'valid')
但是,最后我必须在 Java 中实现它。我试图在 Java 中找到易于构建的卷积 API,但失败了。
任何人都可以帮助我获得上述 Python 片段的等效 Java 代码吗?
提前致谢!