0

I am implementing a Weighted Moving Average algorithm with the help of convolution.

It is quite easy in Python using the convolution function provided by numpy.

The codes are as follows:

# 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')

However, in the end I have to implement this in Java. I tried to find the readily-built convolution API in Java, but failed.

Anyone can help me get the equivalent Java codes of the above-mentioned Python snippet?

Thanks in advance!

Sibbs Gambling
  • 19,274
  • 42
  • 103
  • 174

0 Answers0