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!

5
  • 1
    Just use Jython and compile it in Java bytecodes? ;) Commented Jun 5, 2013 at 2:46
  • @AshwinMukhija Could you please kindly elaborate? Ive never heard of it. thanks! Commented Jun 5, 2013 at 2:51
  • @AshwinMukhija Oh oh.My ultimate goal is to transfer the Java codes to an Android phone. So cannot run the codes in Python Commented Jun 5, 2013 at 2:52
  • what's wrong in doing it by hand ? Commented Jun 5, 2013 at 3:20
  • @akshayb as easy as abc Commented Jun 5, 2013 at 5:27

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.